8 #define GET_NTUPLES(x) ((int *)(x + sizeof(prefetchqelem_t)))
9 #define GET_PTR_OID(x) ((unsigned int *)(x + sizeof(prefetchqelem_t) + sizeof(int)))
10 #define GET_PTR_EOFF(x,n) ((short *)(x + sizeof(prefetchqelem_t) + sizeof(int) + (n*sizeof(unsigned int))))
11 #define GET_PTR_ARRYFLD(x,n) ((short *)(x + sizeof(prefetchqelem_t) + sizeof(int) + (n*sizeof(unsigned int)) + (n*sizeof(short))))
14 //Coordinator Messages
15 #define READ_REQUEST 1
16 #define READ_MULT_REQUEST 2
17 #define MOVE_REQUEST 3
18 #define MOVE_MULT_REQUEST 4
19 #define TRANS_REQUEST 5
21 #define TRANS_COMMIT 7
22 #define TRANS_PREFETCH 8
23 #define TRANS_ABORT_BUT_RETRY_COMMIT_WITH_RELOCATING 9
25 //Participant Messages
26 #define OBJECT_FOUND 10
27 #define OBJECT_NOT_FOUND 11
28 #define OBJECTS_FOUND 12
29 #define OBJECTS_NOT_FOUND 13
30 #define TRANS_AGREE 17
31 #define TRANS_DISAGREE 18
32 #define TRANS_AGREE_BUT_MISSING_OBJECTS 19
33 #define TRANS_SOFT_ABORT 20
34 #define TRANS_SUCESSFUL 21
35 #define TRANS_PREFETCH_RESPONSE 22
37 //Control bits for status of objects in Machine pile
38 #define OBJ_LOCKED_BUT_VERSION_MATCH 14
39 #define OBJ_UNLOCK_BUT_VERSION_MATCH 15
40 #define VERSION_NO_MATCH 16
42 //Max number of objects
43 #define MAX_OBJECTS 20
54 #define DEFAULT_OBJ_STORE_SIZE 1048510 //1MB
56 //bit designations for status field of objheader
62 typedef struct objheader {
65 unsigned short version;
66 unsigned short rcount;
72 #define TYPE(x) x->type
74 #define STATUS(x) x->status
77 typedef struct objheader {
78 unsigned short version;
79 unsigned short rcount;
83 ((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___nextobject___
86 ((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___localcopy___
89 ((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->type
92 typedef struct objstr {
93 unsigned int size; //this many bytes are allocated after this header
98 typedef struct transrecord {
100 chashtable_t *lookupTable;
102 // Structure that keeps track of responses from the participants
103 typedef struct thread_response {
107 // Structure that holds fixed data sizes to be sent along with TRANS_REQUEST
108 typedef struct fixed_data {
110 char trans_id[TID_LEN];
111 int mcount; // Machine count
112 short numread; // Number of objects read
113 short nummod; // Number of objects modified
114 int sum_bytes; // Total bytes modified
117 // Structure that holds variable data sizes per machine participant
118 typedef struct trans_req_data {
120 unsigned int *listmid;
122 unsigned int *oidmod;
125 // Structure passed to dstmAcceptinfo() on server side to complete TRANS_COMMIT process
126 typedef struct trans_commit_data{
127 unsigned int *objmod;
128 unsigned int *objlocked;
129 unsigned int *objnotfound;
134 }trans_commit_data_t;
137 #define PRINT_TID(PTR) printf("DEBUG -> %x %d\n", PTR->mid, PTR->thread_id);
138 //structure for passing multiple arguments to thread
139 typedef struct thread_data_array {
143 trans_req_data_t *buffer;
144 thread_response_t *recvmsg;//shared datastructure to keep track of the control message receiv
145 pthread_cond_t *threshold; //threshhold for waking up a thread
146 pthread_mutex_t *lock; //lock the count variable
147 int *count; //variable to count responses of TRANS_REQUEST protocol from all participants
148 char *replyctrl; //shared ctrl message that stores the reply to be sent, filled by decideResp
149 char *replyretry; //shared variable to find out if we need retry (TRANS_COMMIT case)
150 transrecord_t *rec; // To send modified objects
151 } thread_data_array_t;
154 //Structure for passing arguments to the local m/c thread
155 typedef struct local_thread_data_array {
156 thread_data_array_t *tdata;
157 trans_commit_data_t *transinfo; //Required for trans commit process
158 } local_thread_data_array_t;
160 // Structure to save information about an oid necesaary for the decideControl()
161 typedef struct objinfo {
163 int poss_val; //Status of object(locked but version matches, version mismatch, oid not present in machine etc)
166 //Structure for members within prefetch tuples
167 typedef struct member {
174 //Structure that holds the compiler generated prefetch data
175 typedef struct compprefetchdata {
176 transrecord_t *record;
177 } compprefetchdata_t;
180 /* Initialize main object store and lookup tables, start server thread. */
183 /* Prototypes for object header */
184 unsigned int getNewOID(void);
185 unsigned int objSize(objheader_t *object);
186 /* end object header */
188 /* Prototypes for object store */
189 objstr_t *objstrCreate(unsigned int size); //size in bytes
190 void objstrDelete(objstr_t *store); //traverse and free entire list
191 void *objstrAlloc(objstr_t *store, unsigned int size); //size in bytes
192 /* end object store */
194 /* Prototypes for server portion */
196 void *dstmAccept(void *);
197 int readClientReq(trans_commit_data_t *, int);
198 int processClientReq(fixed_data_t *, trans_commit_data_t *,unsigned int *, char *, void *, int);
199 char handleTransReq(fixed_data_t *, trans_commit_data_t *, unsigned int *, char *, void *, int);
200 int decideCtrlMessage(fixed_data_t *, trans_commit_data_t *, int *, int *, int *, int *, int *, void *, unsigned int *, unsigned int *, unsigned int *, int);
201 int transCommitProcess(trans_commit_data_t *, int);
202 /* end server portion */
204 /* Prototypes for transactions */
205 void randomdelay(void);
206 transrecord_t *transStart();
207 objheader_t *transRead(transrecord_t *, unsigned int);
208 objheader_t *transCreateObj(transrecord_t *, unsigned short); //returns oid
209 int transCommit(transrecord_t *record); //return 0 if successful
210 void *transRequest(void *); //the C routine that the thread will execute when TRANS_REQUEST begins
211 void *handleLocalReq(void *); //the C routine that the local m/c thread will execute
212 int decideResponse(thread_data_array_t *);// Coordinator decides what response to send to the participant
213 char sendResponse(thread_data_array_t *, int); //Sends control message back to Participants
214 void *getRemoteObj(transrecord_t *, unsigned int, unsigned int);
215 int transAbortProcess(void *, unsigned int *, int, int, int);
216 int transComProcess(trans_commit_data_t *);
217 void prefetch(int, unsigned int *, short *, short*);
218 void *transPrefetch(void *);
219 void *mcqProcess(void *);
220 void checkPrefetchTuples(prefetchqelem_t *);
221 prefetchpile_t *foundLocal(prefetchqelem_t *);
222 prefetchpile_t *makePreGroups(prefetchqelem_t *, int *);
223 void checkPreCache(prefetchqelem_t *, int *, int, int, unsigned int, int, int, int);
224 int transPrefetchProcess(transrecord_t *, int **, short);
225 void sendPrefetchReq(prefetchpile_t*, int);
226 void getPrefetchResponse(int, int);
227 /* end transactions */