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
36 #define START_REMOTE_THREAD 23
38 //Control bits for status of objects in Machine pile
39 #define OBJ_LOCKED_BUT_VERSION_MATCH 14
40 #define OBJ_UNLOCK_BUT_VERSION_MATCH 15
41 #define VERSION_NO_MATCH 16
43 //Max number of objects
44 #define MAX_OBJECTS 20
55 #define DEFAULT_OBJ_STORE_SIZE 1048510 //1MB
57 //bit designations for status field of objheader
65 #include "structdefs.h"
67 typedef struct objheader {
68 unsigned short version;
69 unsigned short rcount;
73 (*((unsigned int *)&((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___nextobject___))
76 *((unsigned int *) &(((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___localcopy___))
79 ((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->type
83 typedef struct objheader {
86 unsigned short version;
87 unsigned short rcount;
92 #define TYPE(x) x->type
93 #define STATUS(x) x->status
98 typedef struct objstr {
99 unsigned int size; //this many bytes are allocated after this header
104 typedef struct transrecord {
106 chashtable_t *lookupTable;
108 struct ___Object___ * revertlist;
111 // Structure is a shared structure that keeps track of responses from the participants
112 typedef struct thread_response {
116 // Structure that holds fixed data to be sent along with TRANS_REQUEST
117 typedef struct fixed_data {
118 char control; /* control message */
119 char trans_id[TID_LEN]; /* transaction id */
120 int mcount; /* participant count */
121 short numread; /* no of objects read */
122 short nummod; /* no of objects modified */
123 short numcreated; /* no of objects created */
124 int sum_bytes; /* total bytes of modified objects in a transaction */
127 /* Structure that holds trans request information for each participant */
128 typedef struct trans_req_data {
129 fixed_data_t f; /* Holds first few fixed bytes of data sent during TRANS_REQUEST protcol*/
130 unsigned int *listmid; /* Pointer to array holding list of participants */
131 char *objread; /* Pointer to array holding oid and version number of objects that are only read */
132 unsigned int *oidmod; /* Pointer to array holding oids of objects that are modified */
133 unsigned int *oidcreated; /* Pointer to array holding oids of objects that are newly created */
136 /* Structure that holds information of objects that are not found in the participant
137 * and objs locked within a transaction during commit process */
138 typedef struct trans_commit_data{
139 unsigned int *objlocked; /* Pointer to array holding oids of objects locked inside a transaction */
140 unsigned int *objnotfound; /* Pointer to array holding oids of objects not found on the participant machine */
141 void *modptr; /* Pointer to the address in the mainobject store of the participant that holds all modified objects */
142 int numlocked; /* no of objects locked */
143 int numnotfound; /* no of objects not found */
144 } trans_commit_data_t;
147 #define PRINT_TID(PTR) printf("DEBUG -> %x %d\n", PTR->mid, PTR->thread_id);
148 /* Structure for passing multiple arguments to a thread
149 * spawned to process each transaction on a machine */
150 typedef struct thread_data_array {
153 int pilecount; /* No of remote machines involved */
154 trans_req_data_t *buffer; /* Holds trans request information sent to participants */
155 thread_response_t *recvmsg; /* Shared datastructure to keep track of the participants response to a trans request */
156 pthread_cond_t *threshold; /* Condition var to waking up a thread */
157 pthread_mutex_t *lock; /* Lock for counting participants response */
158 int *count; /* Variable to count responses from all participants to the TRANS_REQUEST protocol */
159 char *replyctrl; /* Shared ctrl message that stores the reply to be sent to participants, filled by decideResponse() */
160 char *replyretry; /* Shared variable that keep track if coordinator needs retry */
161 transrecord_t *rec; /* To send modified objects */
162 } thread_data_array_t;
165 //Structure for passing arguments to the local m/c thread
166 typedef struct local_thread_data_array {
167 thread_data_array_t *tdata; /* Holds all the arguments send to a thread that is spawned when transaction commits */
168 trans_commit_data_t *transinfo; /* Holds information of objects locked and not found in the participant */
169 } local_thread_data_array_t;
171 //Structure for members within prefetch tuples
172 typedef struct member {
173 short offset; /* Holds offset of the ptr field */
174 short index; /* Holds the array index value */
178 /* Initialize main object store and lookup tables, start server thread. */
181 /* Prototypes for object header */
182 unsigned int getNewOID(void);
183 unsigned int objSize(objheader_t *object);
184 /* end object header */
186 /* Prototypes for object store */
187 objstr_t *objstrCreate(unsigned int size); //size in bytes
188 void objstrDelete(objstr_t *store); //traverse and free entire list
189 void *objstrAlloc(objstr_t *store, unsigned int size); //size in bytes
190 /* end object store */
192 /* Prototypes for server portion */
194 void *dstmAccept(void *);
195 int readClientReq(trans_commit_data_t *, int);
196 int processClientReq(fixed_data_t *, trans_commit_data_t *,unsigned int *, char *, void *, unsigned int *, int);
197 char handleTransReq(fixed_data_t *, trans_commit_data_t *, unsigned int *, char *, void *, int);
198 int decideCtrlMessage(fixed_data_t *, trans_commit_data_t *, int *, int *, int *, int *, int *, void *, unsigned int *, unsigned int *, int);
199 //int transCommitProcess(trans_commit_data_t *, int);
200 int transCommitProcess(void *, unsigned int *, unsigned int *, int, int, int);
201 /* end server portion */
203 /* Prototypes for transactions */
204 /* Function called at beginning. Passes in the first parameter. */
205 /* Returns 1 if this thread should run the main process */
207 int dstmStartup(const char *);
210 void randomdelay(void);
211 transrecord_t *transStart();
212 objheader_t *transRead(transrecord_t *, unsigned int);
213 objheader_t *transCreateObj(transrecord_t *, unsigned int); //returns oid
214 int transCommit(transrecord_t *record); //return 0 if successful
215 void *transRequest(void *); //the C routine that the thread will execute when TRANS_REQUEST begins
216 void *handleLocalReq(void *); //the C routine that the local m/c thread will execute
217 int decideResponse(thread_data_array_t *);// Coordinator decides what response to send to the participant
218 char sendResponse(thread_data_array_t *, int); //Sends control message back to Participants
219 void *getRemoteObj(transrecord_t *, unsigned int, unsigned int);
220 int transAbortProcess(void *, unsigned int *, int, int);
221 int transComProcess(void*, unsigned int *, unsigned int *, unsigned int *, int, int, int);
222 void prefetch(int, unsigned int *, short *, short*);
223 void *transPrefetch(void *);
224 void *mcqProcess(void *);
225 void checkPrefetchTuples(prefetchqelem_t *);
226 prefetchpile_t *foundLocal(prefetchqelem_t *);
227 prefetchpile_t *makePreGroups(prefetchqelem_t *, int *);
228 void checkPreCache(prefetchqelem_t *, int *, int, int, unsigned int, int, int, int);
229 int transPrefetchProcess(transrecord_t *, int **, short);
230 void sendPrefetchReq(prefetchpile_t*, int);
231 void getPrefetchResponse(int, int);
232 unsigned short getObjType(unsigned int oid);
233 int startRemoteThread(unsigned int oid, unsigned int mid);
234 /* end transactions */