fix annoying race condition on startup
[IRC.git] / Robust / src / Runtime / DSTM / interface / dstm.h
index ede8fdda9e2da582707a46beda70dc8d9e168c93..98f60f8637af078419b9474d1dc4224017ce4d4b 100644 (file)
@@ -5,13 +5,16 @@
 #define MSG_NOSIGNAL 0
 #endif
 
-#define GET_NTUPLES(x)         ((int *)(x + sizeof(prefetchqelem_t)))
-#define GET_PTR_OID(x)         ((unsigned int *)(x + sizeof(prefetchqelem_t) + sizeof(int)))
-#define GET_PTR_EOFF(x,n) ((short *)(x + sizeof(prefetchqelem_t) + sizeof(int) + (n*sizeof(unsigned int))))
-#define GET_PTR_ARRYFLD(x,n) ((short *)(x + sizeof(prefetchqelem_t) + sizeof(int) + (n*sizeof(unsigned int)) + (n*sizeof(short))))
-
-
-//Coordinator Messages
+/***********************************************************
+ *       Macros
+ **********************************************************/
+#define GET_NTUPLES(x)         ((int *)(x))
+#define GET_PTR_OID(x)         ((unsigned int *)(x + sizeof(int)))
+#define GET_PTR_EOFF(x,n) ((short *)(x + sizeof(int) + (n*sizeof(unsigned int))))
+#define GET_PTR_ARRYFLD(x,n) ((short *)(x + sizeof(int) + (n*sizeof(unsigned int)) + (n*sizeof(short))))
+/*****************************************
+ *  Coordinator Messages
+ ***************************************/
 #define READ_REQUEST           1
 #define READ_MULT_REQUEST      2
 #define MOVE_REQUEST           3
@@ -22,7 +25,9 @@
 #define TRANS_PREFETCH         8
 #define TRANS_ABORT_BUT_RETRY_COMMIT_WITH_RELOCATING   9
 
-//Participant Messages
+/*********************************
+ * Participant Messages
+ *******************************/
 #define OBJECT_FOUND                   10
 #define OBJECT_NOT_FOUND               11
 #define OBJECTS_FOUND                  12
 #define TRANS_SUCESSFUL                        21
 #define TRANS_PREFETCH_RESPONSE                22
 #define START_REMOTE_THREAD            23
-
-//Control bits for status of objects in Machine pile
-#define OBJ_LOCKED_BUT_VERSION_MATCH   14
-#define OBJ_UNLOCK_BUT_VERSION_MATCH   15
-#define VERSION_NO_MATCH               16
+#define THREAD_NOTIFY_REQUEST          24
+#define THREAD_NOTIFY_RESPONSE         25
+#define TRANS_UNSUCESSFUL              26
+#define CLOSE_CONNECTION                27
 
 //Max number of objects 
 #define MAX_OBJECTS  20
+//Max remote-machine connections
+#define NUM_MACHINES 2
+#define LOADFACTOR 0.5
+#define DEFAULT_OBJ_STORE_SIZE 1048510 //1MB
+//Transaction id per machine
+#define TID_LEN 20
+#define LISTEN_PORT 2156
 
 
 #include <stdlib.h>
 #include "clookup.h"
 #include "queue.h"
 #include "mcpileq.h"
+#include "threadnotify.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <time.h>
+#include "sockpool.h"
+#include "prelookup.h"
 
-#define DEFAULT_OBJ_STORE_SIZE 1048510 //1MB
-#define TID_LEN 20
 //bit designations for status field of objheader
 #define DIRTY 0x01
 #define NEW   0x02
@@ -65,6 +85,7 @@
 #include "structdefs.h"
 
 typedef struct objheader {
+       threadlist_t *notifylist;
        unsigned short version;
        unsigned short rcount;
 } objheader_t;
@@ -78,6 +99,9 @@ typedef struct objheader {
 #define STATUS(x)\
         *((unsigned int *) &(((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___localcopy___))
 
+#define STATUSPTR(x)\
+        ((unsigned int *) &(((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___localcopy___))
+
 #define TYPE(x)\
         ((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->type
 
@@ -93,6 +117,7 @@ typedef struct objheader {
 #else
 
 typedef struct objheader {
+       threadlist_t *notifylist;
        unsigned int oid;
        unsigned short type;
        unsigned short version;
@@ -103,6 +128,7 @@ typedef struct objheader {
 #define OID(x) x->oid
 #define TYPE(x) x->type
 #define STATUS(x) x->status
+#define STATUSPTR(x) &x->status
 #define GETSIZE(size, x) size=classsize[TYPE(x)]
 #endif
 
@@ -113,6 +139,11 @@ typedef struct objstr {
        struct objstr *next;
 } objstr_t;
 
+typedef struct oidmidpair {
+    unsigned int oid;
+    unsigned int mid;
+} oidmidpair_t;
+
 typedef struct transrecord {
   objstr_t *cache;
   chashtable_t *lookupTable;
@@ -120,6 +151,7 @@ typedef struct transrecord {
   struct ___Object___ * revertlist;
 #endif
 } transrecord_t;
+
 // Structure is a shared structure that keeps track of responses from the participants
 typedef struct thread_response {
   char rcv_status;
@@ -130,9 +162,9 @@ typedef struct fixed_data {
   char control;                        /* control message */
   char trans_id[TID_LEN];      /* transaction id */
   int mcount;                  /* participant count */
-  short numread;               /* no of objects read */
-  short nummod;                        /* no of objects modified */
-  short numcreated;            /* no of objects created */
+  unsigned int numread;                /* no of objects read */
+  unsigned int nummod;                 /* no of objects modified */
+  unsigned int numcreated;             /* no of objects created */
   int sum_bytes;               /* total bytes of modified objects in a transaction */
 } fixed_data_t;
 
@@ -142,7 +174,7 @@ typedef struct trans_req_data {
   unsigned int *listmid;       /* Pointer to array holding list of participants */
   char *objread;               /* Pointer to array holding oid and version number of objects that are only read */ 
   unsigned int *oidmod;                /* Pointer to array holding oids of objects that are modified */
-  unsigned int *oidcreated;            /* Pointer to array holding oids of objects that are newly created */
+  unsigned int *oidcreated;    /* Pointer to array holding oids of objects that are newly created */
 } trans_req_data_t;            
 
 /* Structure that holds information of objects that are not found in the participant
@@ -179,15 +211,17 @@ typedef struct local_thread_data_array {
        trans_commit_data_t *transinfo; /* Holds information of objects locked and not found in the participant */ 
 } local_thread_data_array_t;
 
-//Structure for members within prefetch tuples
-typedef struct member {
-       short offset;           /* Holds offset of the ptr field */
-       short index;            /* Holds the array index value */ 
-       struct member *next;    
-}trans_member_t;
+//Structure to store mid and socketid information
+typedef struct midSocketInfo {
+       unsigned int mid;               /* To communicate with mid use sockid in this data structure*/
+       int sockid;
+} midSocketInfo_t;
 
 /* Initialize main object store and lookup tables, start server thread. */
 int dstmInit(void);
+void send_data(int fd, void *buf, int buflen);
+void recv_data(int fd, void *buf, int buflen);
+int recv_data_errorcode(int fd, void *buf, int buflen);
 
 /* Prototypes for object header */
 unsigned int getNewOID(void);
@@ -197,17 +231,19 @@ unsigned int getNewOID(void);
 objstr_t *objstrCreate(unsigned int size); //size in bytes
 void objstrDelete(objstr_t *store); //traverse and free entire list
 void *objstrAlloc(objstr_t *store, unsigned int size); //size in bytes
+void clearObjStore(); // TODO:currently only clears the prefetch cache object store
 /* end object store */
 
 /* Prototypes for server portion */
-void *dstmListen();
+void *dstmListen(void *);
+int startlistening();
 void *dstmAccept(void *);
 int readClientReq(trans_commit_data_t *, int);
 int processClientReq(fixed_data_t *, trans_commit_data_t *,unsigned int *, char *, void *, unsigned int *, int);
 char handleTransReq(fixed_data_t *, trans_commit_data_t *, unsigned int *, char *, void *, int);
-int decideCtrlMessage(fixed_data_t *, trans_commit_data_t *, int *, int *, int *, int *, int *, void *, unsigned int *, unsigned int *, int);
-//int transCommitProcess(trans_commit_data_t *, int);
+char decideCtrlMessage(fixed_data_t *, trans_commit_data_t *, int *, int *, int *, int *, int *, void *, unsigned int *, unsigned int *, int);
 int transCommitProcess(void *, unsigned int *, unsigned int *, int, int, int);
+void processReqNotify(unsigned int numoid, unsigned int *oid, unsigned short *version, unsigned int mid, unsigned int threadid);
 /* end server portion */
 
 /* Prototypes for transactions */
@@ -220,31 +256,34 @@ int processConfigFile();
 void addHost(unsigned int);
 void mapObjMethod(unsigned short);
 
-void randomdelay(void);
+void randomdelay();
 transrecord_t *transStart();
 objheader_t *transRead(transrecord_t *, unsigned int);
-objheader_t *transCreateObj(transrecord_t *, unsigned int); //returns oid
+objheader_t *transCreateObj(transrecord_t *, unsigned int); //returns oid header
 int transCommit(transrecord_t *record); //return 0 if successful
 void *transRequest(void *);    //the C routine that the thread will execute when TRANS_REQUEST begins
 void decideResponse(thread_data_array_t *);// Coordinator decides what response to send to the participant
 char sendResponse(thread_data_array_t *, int); //Sends control message back to Participants
-void *getRemoteObj(transrecord_t *, unsigned int, unsigned int);
-void *handleLocalReq(void *);
+void *getRemoteObj(transrecord_t *, unsigned int, unsigned int);// returns object header from main object store after object is copied into it from remote machine
+void *handleLocalReq(void *);//handles Local requests 
 int transComProcess(local_thread_data_array_t *);
 int transAbortProcess(local_thread_data_array_t *);
-
+void transAbort(transrecord_t *trans);
+void sendPrefetchResponse(int sd, char *control, char *sendbuffer, int *size);
 void prefetch(int, unsigned int *, unsigned short *, short*);
 void *transPrefetch(void *);
 void *mcqProcess(void *);
-void checkPrefetchTuples(prefetchqelem_t *);
-prefetchpile_t *foundLocal(prefetchqelem_t *);
-prefetchpile_t *makePreGroups(prefetchqelem_t *, int *);
-void checkPreCache(prefetchqelem_t *, int *, int, int, unsigned int, int, int, int);
+prefetchpile_t *foundLocal(char *);// returns node with prefetch elements(oids, offsets)
+int lookupObject(unsigned int * oid, short offset);
 int transPrefetchProcess(transrecord_t *, int **, short);
 void sendPrefetchReq(prefetchpile_t*, int);
-void getPrefetchResponse(int, int);
+int getPrefetchResponse(int);
 unsigned short getObjType(unsigned int oid);
 int startRemoteThread(unsigned int oid, unsigned int mid);
+/* Sends notification request for thread join, if sucessful returns 0 else returns -1 */
+int reqNotify(unsigned int *oidarry, unsigned short *versionarry, unsigned int numoid);
+void threadNotify(unsigned int oid, unsigned short version, unsigned int tid);
+int notifyAll(threadlist_t **head, unsigned int oid, unsigned int version);
+
 /* end transactions */
 #endif