Added new testcases
[IRC.git] / Robust / src / Runtime / DSTM / interface / dstm.h
1 #ifndef _DSTM_H_
2 #define _DSTM_H_
3
4 //Coordinator Messages
5 #define READ_REQUEST            1
6 #define READ_MULT_REQUEST       2
7 #define MOVE_REQUEST            3
8 #define MOVE_MULT_REQUEST       4
9 #define TRANS_REQUEST           5
10 #define TRANS_ABORT             6
11 #define TRANS_COMMIT            7
12 #define TRANS_ABORT_BUT_RETRY_COMMIT    8
13 #define TRANS_ABORT_BUT_RETRY_COMMIT_WITH_RELOCATING    9
14
15 //Participant Messages
16 #define OBJECT_FOUND                    10
17 #define OBJECT_NOT_FOUND                11
18 #define OBJECTS_FOUND                   12
19 #define OBJECTS_NOT_FOUND               13
20 #define TRANS_AGREE                     17
21 #define TRANS_DISAGREE                  18
22 #define TRANS_AGREE_BUT_MISSING_OBJECTS 19
23 #define TRANS_SOFT_ABORT                20
24 #define TRANS_SUCESSFUL                 21
25
26 //Control bits for status of objects in Machine pile
27 #define OBJ_LOCKED_BUT_VERSION_MATCH    14
28 #define OBJ_UNLOCK_BUT_VERSION_MATCH    15
29 #define VERSION_NO_MATCH                16
30 //TODO REMOVE THIS
31 #define NO_MISSING_OIDS                 22
32 #define MISSING_OIDS_PRESENT            23
33
34
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <pthread.h>
39 #include "clookup.h"
40
41 #define DEFAULT_OBJ_STORE_SIZE 1048510 //1MB
42 #define TID_LEN 20
43 //bit designations for status field of objheader
44 #define DIRTY 0x01
45 #define NEW   0x02
46 #define LOCK  0x04
47
48 typedef struct objheader {
49         unsigned int oid;
50         unsigned short type;
51         unsigned short version;
52         unsigned short rcount;
53         char status;
54 } objheader_t;
55
56 typedef struct objstr {
57         unsigned int size; //this many bytes are allocated after this header
58         void *top;
59         struct objstr *next;
60 } objstr_t;
61
62 typedef struct transrecord {
63         objstr_t *cache;
64         chashtable_t *lookupTable;
65 } transrecord_t;
66 /*
67 typedef struct pile {
68         unsigned int mid;
69         unsigned int oid;
70         struct pile *next;
71 }pile_t;
72 */
73 // Structure that keeps track of responses from the participants
74 typedef struct thread_response {
75         char rcv_status;
76 }thread_response_t;
77
78 // Structure that holds  fixed data sizes to be sent along with TRANS_REQUEST
79 typedef struct fixed_data {
80         char control;
81         char trans_id[TID_LEN]; 
82         int mcount;             // Machine count
83         short numread;          // Number of objects read
84         short nummod;           // Number of objects modified
85         int sum_bytes;  // Total bytes modified
86 }fixed_data_t;
87
88 // Structure that holds  variable data sizes per machine participant
89 typedef struct trans_req_data {
90         fixed_data_t f;
91         unsigned int *listmid;
92         char *objread;
93         unsigned int *oidmod;
94 }trans_req_data_t;
95
96 #define PRINT_TID(PTR) printf("DEBUG -> %x %d\n", PTR->mid, PTR->thread_id);
97 //structure for passing multiple arguments to thread
98 typedef struct thread_data_array {
99         int thread_id;
100         int mid;    
101         int pilecount;
102         trans_req_data_t *buffer;
103         thread_response_t *recvmsg;//shared datastructure to keep track of the control message receiv
104         pthread_cond_t *threshold; //threshhold for waking up a thread
105         pthread_mutex_t *lock;    //lock the count variable
106         int *count;             //variable to count responses of TRANS_REQUEST protocol from all participants
107         transrecord_t *rec;     // To send modified objects
108 }thread_data_array_t;
109
110 // Structure to save information about an oid necesaary for the decideControl()
111 typedef struct objinfo {
112         unsigned int oid;
113         int poss_val; //Status of object(locked but version matches, version mismatch, oid not present in machine etc) 
114 }objinfo_t;
115
116 // Structure passed to dstmAcceptinfo() on server side to complete TRANS_COMMIT process 
117 typedef struct trans_commit_data{
118         unsigned int *objmod;
119         unsigned int *objlocked;
120         unsigned int *objnotfound;
121         void *modptr;
122         int nummod;
123         int numlocked;
124         int numnotfound;
125 }trans_commit_data_t;
126 /* Initialize main object store and lookup tables, start server thread. */
127 int dstmInit(void);
128
129 /* Prototypes for object header */
130 unsigned int getNewOID(void);
131 unsigned int objSize(objheader_t *object);
132 /* end object header */
133
134 /* Prototypes for object store */
135 objstr_t *objstrCreate(unsigned int size); //size in bytes
136 void objstrDelete(objstr_t *store); //traverse and free entire list
137 void *objstrAlloc(objstr_t *store, unsigned int size); //size in bytes
138 /* end object store */
139
140 /* Prototypes for server portion */
141 void *dstmListen();
142 void *dstmAccept(void *);
143 int readClientReq(int, trans_commit_data_t *);
144 char handleTransReq(int, fixed_data_t *, trans_commit_data_t *, unsigned int *, char *, void *);
145 /* end server portion */
146
147 /* Prototypes for transactions */
148 transrecord_t *transStart();
149 objheader_t *transRead(transrecord_t *record, unsigned int oid);
150 objheader_t *transCreateObj(transrecord_t *record, unsigned short type); //returns oid
151 int decideResponse(thread_data_array_t *tdata, int sd, int status);// Coordinator decides what response to send to the participant
152 void *transRequest(void *);     //the C routine that the thread will execute when TRANS_REQUEST begins
153 int transCommit(transrecord_t *record); //return 0 if successful
154 void *getRemoteObj(transrecord_t *, unsigned int, unsigned int);
155 int transCommitProcess(trans_commit_data_t *, int);
156 /* end transactions */
157
158 void *getRemoteObj(transrecord_t *, unsigned int, unsigned int);
159
160 #endif