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
37 #define THREAD_NOTIFY_REQUEST 24
38 #define THREAD_NOTIFY_RESPONSE 25
40 //Control bits for status of objects in Machine pile
41 #define OBJ_LOCKED_BUT_VERSION_MATCH 14
42 #define OBJ_UNLOCK_BUT_VERSION_MATCH 15
43 #define VERSION_NO_MATCH 16
45 //Max number of objects
46 #define MAX_OBJECTS 20
56 #include "threadnotify.h"
59 #define DEFAULT_OBJ_STORE_SIZE 1048510 //1MB
61 //bit designations for status field of objheader
69 #include "structdefs.h"
71 typedef struct objheader {
72 threadlist_t *notifylist;
73 unsigned short version;
74 unsigned short rcount;
78 (*((unsigned int *)&((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___nextobject___))
81 (*((unsigned int *)&((struct ___Object___ *) x)->___nextobject___))
84 *((unsigned int *) &(((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___localcopy___))
87 ((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->type
89 #define GETSIZE(size, x) {\
91 if (type<NUMCLASSES) {\
92 size=classsize[type];\
94 size=classsize[type]*((struct ArrayObject *)&((objheader_t *)x)[1])->___length___+sizeof(struct ArrayObject);\
100 typedef struct objheader {
101 threadlist_t *notifylist;
104 unsigned short version;
105 unsigned short rcount;
109 #define OID(x) x->oid
110 #define TYPE(x) x->type
111 #define STATUS(x) x->status
112 #define GETSIZE(size, x) size=classsize[TYPE(x)]
116 typedef struct objstr {
117 unsigned int size; //this many bytes are allocated after this header
122 typedef struct transrecord {
124 chashtable_t *lookupTable;
126 struct ___Object___ * revertlist;
129 // Structure is a shared structure that keeps track of responses from the participants
130 typedef struct thread_response {
134 // Structure that holds fixed data to be sent along with TRANS_REQUEST
135 typedef struct fixed_data {
136 char control; /* control message */
137 char trans_id[TID_LEN]; /* transaction id */
138 int mcount; /* participant count */
139 short numread; /* no of objects read */
140 short nummod; /* no of objects modified */
141 short numcreated; /* no of objects created */
142 int sum_bytes; /* total bytes of modified objects in a transaction */
145 /* Structure that holds trans request information for each participant */
146 typedef struct trans_req_data {
147 fixed_data_t f; /* Holds first few fixed bytes of data sent during TRANS_REQUEST protcol*/
148 unsigned int *listmid; /* Pointer to array holding list of participants */
149 char *objread; /* Pointer to array holding oid and version number of objects that are only read */
150 unsigned int *oidmod; /* Pointer to array holding oids of objects that are modified */
151 unsigned int *oidcreated; /* Pointer to array holding oids of objects that are newly created */
154 /* Structure that holds information of objects that are not found in the participant
155 * and objs locked within a transaction during commit process */
156 typedef struct trans_commit_data{
157 unsigned int *objlocked; /* Pointer to array holding oids of objects locked inside a transaction */
158 unsigned int *objnotfound; /* Pointer to array holding oids of objects not found on the participant machine */
159 void *modptr; /* Pointer to the address in the mainobject store of the participant that holds all modified objects */
160 int numlocked; /* no of objects locked */
161 int numnotfound; /* no of objects not found */
162 } trans_commit_data_t;
165 #define PRINT_TID(PTR) printf("DEBUG -> %x %d\n", PTR->mid, PTR->thread_id);
166 /* Structure for passing multiple arguments to a thread
167 * spawned to process each transaction on a machine */
168 typedef struct thread_data_array {
171 trans_req_data_t *buffer; /* Holds trans request information sent to participants */
172 thread_response_t *recvmsg; /* Shared datastructure to keep track of the participants response to a trans request */
173 pthread_cond_t *threshold; /* Condition var to waking up a thread */
174 pthread_mutex_t *lock; /* Lock for counting participants response */
175 int *count; /* Variable to count responses from all participants to the TRANS_REQUEST protocol */
176 char *replyctrl; /* Shared ctrl message that stores the reply to be sent to participants, filled by decideResponse() */
177 char *replyretry; /* Shared variable that keep track if coordinator needs retry */
178 transrecord_t *rec; /* To send modified objects */
179 } thread_data_array_t;
182 //Structure for passing arguments to the local m/c thread
183 typedef struct local_thread_data_array {
184 thread_data_array_t *tdata; /* Holds all the arguments send to a thread that is spawned when transaction commits */
185 trans_commit_data_t *transinfo; /* Holds information of objects locked and not found in the participant */
186 } local_thread_data_array_t;
188 /* Initialize main object store and lookup tables, start server thread. */
191 /* Prototypes for object header */
192 unsigned int getNewOID(void);
193 /* end object header */
195 /* Prototypes for object store */
196 objstr_t *objstrCreate(unsigned int size); //size in bytes
197 void objstrDelete(objstr_t *store); //traverse and free entire list
198 void *objstrAlloc(objstr_t *store, unsigned int size); //size in bytes
199 /* end object store */
201 /* Prototypes for server portion */
203 void *dstmAccept(void *);
204 int readClientReq(trans_commit_data_t *, int);
205 int processClientReq(fixed_data_t *, trans_commit_data_t *,unsigned int *, char *, void *, unsigned int *, int);
206 char handleTransReq(fixed_data_t *, trans_commit_data_t *, unsigned int *, char *, void *, int);
207 int decideCtrlMessage(fixed_data_t *, trans_commit_data_t *, int *, int *, int *, int *, int *, void *, unsigned int *, unsigned int *, int);
208 int transCommitProcess(void *, unsigned int *, unsigned int *, int, int, int);
209 void processReqNotify(unsigned int numoid, unsigned int *oid, unsigned short *version, unsigned int mid, unsigned int threadid);
210 /* end server portion */
212 /* Prototypes for transactions */
213 /* Function called at beginning. Passes in the first parameter. */
214 /* Returns 1 if this thread should run the main process */
216 int dstmStartup(const char *);
218 int processConfigFile();
219 void addHost(unsigned int);
220 void mapObjMethod(unsigned short);
223 transrecord_t *transStart();
224 objheader_t *transRead(transrecord_t *, unsigned int);
225 objheader_t *transCreateObj(transrecord_t *, unsigned int); //returns oid
226 int transCommit(transrecord_t *record); //return 0 if successful
227 void *transRequest(void *); //the C routine that the thread will execute when TRANS_REQUEST begins
228 void decideResponse(thread_data_array_t *);// Coordinator decides what response to send to the participant
229 char sendResponse(thread_data_array_t *, int); //Sends control message back to Participants
230 void *getRemoteObj(transrecord_t *, unsigned int, unsigned int);
232 void *handleLocalReq(void *);
233 int transComProcess(local_thread_data_array_t *);
234 int transAbortProcess(local_thread_data_array_t *);
235 void transAbort(transrecord_t *trans);
237 void prefetch(int, unsigned int *, unsigned short *, short*);
238 void *transPrefetch(void *);
239 void *mcqProcess(void *);
240 void checkPrefetchTuples(prefetchqelem_t *);
241 prefetchpile_t *foundLocal(prefetchqelem_t *);
242 prefetchpile_t *makePreGroups(prefetchqelem_t *, int *);
243 void checkPreCache(prefetchqelem_t *, int *, unsigned int, int);
244 int transPrefetchProcess(transrecord_t *, int **, short);
245 void sendPrefetchReq(prefetchpile_t*, int);
246 void getPrefetchResponse(int, int);
247 unsigned short getObjType(unsigned int oid);
248 int startRemoteThread(unsigned int oid, unsigned int mid);
249 /* Sends notification request for thread join, if sucessful returns 0 else returns -1 */
250 int reqNotify(unsigned int *oidarry, unsigned short *versionarry, unsigned int numoid);
251 void threadNotify(unsigned int oid, unsigned short version, unsigned int tid);
252 int notifyAll(threadlist_t **head, unsigned int oid, unsigned int version);
254 /* end transactions */