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___ *) x)->___nextobject___))
79 *((unsigned int *) &(((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___localcopy___))
82 ((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->type
84 #define GETSIZE(size, x) {\
86 if (type<NUMCLASSES) {\
87 size=classsize[type];\
89 size=classsize[type]*((struct ArrayObject *)&((objheader_t *)x)[1])->___length___+sizeof(struct ArrayObject);\
95 typedef struct objheader {
98 unsigned short version;
99 unsigned short rcount;
103 #define OID(x) x->oid
104 #define TYPE(x) x->type
105 #define STATUS(x) x->status
106 #define GETSIZE(size, x) size=classsize[TYPE(x)]
110 typedef struct objstr {
111 unsigned int size; //this many bytes are allocated after this header
116 typedef struct transrecord {
118 chashtable_t *lookupTable;
120 struct ___Object___ * revertlist;
123 // Structure is a shared structure that keeps track of responses from the participants
124 typedef struct thread_response {
128 // Structure that holds fixed data to be sent along with TRANS_REQUEST
129 typedef struct fixed_data {
130 char control; /* control message */
131 char trans_id[TID_LEN]; /* transaction id */
132 int mcount; /* participant count */
133 short numread; /* no of objects read */
134 short nummod; /* no of objects modified */
135 short numcreated; /* no of objects created */
136 int sum_bytes; /* total bytes of modified objects in a transaction */
139 /* Structure that holds trans request information for each participant */
140 typedef struct trans_req_data {
141 fixed_data_t f; /* Holds first few fixed bytes of data sent during TRANS_REQUEST protcol*/
142 unsigned int *listmid; /* Pointer to array holding list of participants */
143 char *objread; /* Pointer to array holding oid and version number of objects that are only read */
144 unsigned int *oidmod; /* Pointer to array holding oids of objects that are modified */
145 unsigned int *oidcreated; /* Pointer to array holding oids of objects that are newly created */
148 /* Structure that holds information of objects that are not found in the participant
149 * and objs locked within a transaction during commit process */
150 typedef struct trans_commit_data{
151 unsigned int *objlocked; /* Pointer to array holding oids of objects locked inside a transaction */
152 unsigned int *objnotfound; /* Pointer to array holding oids of objects not found on the participant machine */
153 void *modptr; /* Pointer to the address in the mainobject store of the participant that holds all modified objects */
154 int numlocked; /* no of objects locked */
155 int numnotfound; /* no of objects not found */
156 } trans_commit_data_t;
159 #define PRINT_TID(PTR) printf("DEBUG -> %x %d\n", PTR->mid, PTR->thread_id);
160 /* Structure for passing multiple arguments to a thread
161 * spawned to process each transaction on a machine */
162 typedef struct thread_data_array {
165 trans_req_data_t *buffer; /* Holds trans request information sent to participants */
166 thread_response_t *recvmsg; /* Shared datastructure to keep track of the participants response to a trans request */
167 pthread_cond_t *threshold; /* Condition var to waking up a thread */
168 pthread_mutex_t *lock; /* Lock for counting participants response */
169 int *count; /* Variable to count responses from all participants to the TRANS_REQUEST protocol */
170 char *replyctrl; /* Shared ctrl message that stores the reply to be sent to participants, filled by decideResponse() */
171 char *replyretry; /* Shared variable that keep track if coordinator needs retry */
172 transrecord_t *rec; /* To send modified objects */
173 } thread_data_array_t;
176 //Structure for passing arguments to the local m/c thread
177 typedef struct local_thread_data_array {
178 thread_data_array_t *tdata; /* Holds all the arguments send to a thread that is spawned when transaction commits */
179 trans_commit_data_t *transinfo; /* Holds information of objects locked and not found in the participant */
180 } local_thread_data_array_t;
182 //Structure for members within prefetch tuples
183 typedef struct member {
184 short offset; /* Holds offset of the ptr field */
185 short index; /* Holds the array index value */
189 /* Initialize main object store and lookup tables, start server thread. */
192 /* Prototypes for object header */
193 unsigned int getNewOID(void);
194 /* end object header */
196 /* Prototypes for object store */
197 objstr_t *objstrCreate(unsigned int size); //size in bytes
198 void objstrDelete(objstr_t *store); //traverse and free entire list
199 void *objstrAlloc(objstr_t *store, unsigned int size); //size in bytes
200 /* end object store */
202 /* Prototypes for server portion */
204 void *dstmAccept(void *);
205 int readClientReq(trans_commit_data_t *, int);
206 int processClientReq(fixed_data_t *, trans_commit_data_t *,unsigned int *, char *, void *, unsigned int *, int);
207 char handleTransReq(fixed_data_t *, trans_commit_data_t *, unsigned int *, char *, void *, int);
208 int decideCtrlMessage(fixed_data_t *, trans_commit_data_t *, int *, int *, int *, int *, int *, void *, unsigned int *, unsigned int *, int);
209 //int transCommitProcess(trans_commit_data_t *, int);
210 int transCommitProcess(void *, unsigned int *, unsigned int *, int, int, int);
211 /* end server portion */
213 /* Prototypes for transactions */
214 /* Function called at beginning. Passes in the first parameter. */
215 /* Returns 1 if this thread should run the main process */
217 int dstmStartup(const char *);
219 int processConfigFile();
220 void addHost(unsigned int);
221 void mapObjMethod(unsigned short);
223 void randomdelay(void);
224 transrecord_t *transStart();
225 objheader_t *transRead(transrecord_t *, unsigned int);
226 objheader_t *transCreateObj(transrecord_t *, unsigned int); //returns oid
227 int transCommit(transrecord_t *record); //return 0 if successful
228 void *transRequest(void *); //the C routine that the thread will execute when TRANS_REQUEST begins
229 void *handleLocalReq(void *); //the C routine that the local m/c thread will execute
230 int decideResponse(thread_data_array_t *);// Coordinator decides what response to send to the participant
231 char sendResponse(thread_data_array_t *, int); //Sends control message back to Participants
232 void *getRemoteObj(transrecord_t *, unsigned int, unsigned int);
233 int transAbortProcess(void *, unsigned int *, int, int);
234 int transComProcess(void*, unsigned int *, unsigned int *, unsigned int *, int, int, int);
235 void prefetch(int, unsigned int *, unsigned short *, short*);
236 void *transPrefetch(void *);
237 void *mcqProcess(void *);
238 void checkPrefetchTuples(prefetchqelem_t *);
239 prefetchpile_t *foundLocal(prefetchqelem_t *);
240 prefetchpile_t *makePreGroups(prefetchqelem_t *, int *);
241 void checkPreCache(prefetchqelem_t *, int *, int, int, unsigned int, int, int, int);
242 int transPrefetchProcess(transrecord_t *, int **, short);
243 void sendPrefetchReq(prefetchpile_t*, int);
244 void getPrefetchResponse(int, int);
245 unsigned short getObjType(unsigned int oid);
246 int startRemoteThread(unsigned int oid, unsigned int mid);
247 /* end transactions */