de0af029e82499052944a8208f20248d458b0586
[IRC.git] / Robust / src / Runtime / DSTM / interface / dstm.h
1 #ifndef _DSTM_H_
2 #define _DSTM_H_
3
4 #ifdef MAC
5 #define MSG_NOSIGNAL 0
6 #endif
7
8 //Coordinator Messages
9 #define READ_REQUEST            1
10 #define READ_MULT_REQUEST       2
11 #define MOVE_REQUEST            3
12 #define MOVE_MULT_REQUEST       4
13 #define TRANS_REQUEST           5
14 #define TRANS_ABORT             6
15 #define TRANS_COMMIT            7
16 #define TRANS_ABORT_BUT_RETRY_COMMIT    8
17 #define TRANS_ABORT_BUT_RETRY_COMMIT_WITH_RELOCATING    9
18
19 //Participant Messages
20 #define OBJECT_FOUND                    10
21 #define OBJECT_NOT_FOUND                11
22 #define OBJECTS_FOUND                   12
23 #define OBJECTS_NOT_FOUND               13
24 #define TRANS_AGREE                     17
25 #define TRANS_DISAGREE                  18
26 #define TRANS_AGREE_BUT_MISSING_OBJECTS 19
27 #define TRANS_SOFT_ABORT                20
28 #define TRANS_SUCESSFUL                 21
29
30 //Control bits for status of objects in Machine pile
31 #define OBJ_LOCKED_BUT_VERSION_MATCH    14
32 #define OBJ_UNLOCK_BUT_VERSION_MATCH    15
33 #define VERSION_NO_MATCH                16
34 //TODO REMOVE THIS
35 #define NO_MISSING_OIDS                 22
36 #define MISSING_OIDS_PRESENT            23
37
38
39 #include <stdlib.h>
40 #include <stdio.h>
41 #include <string.h>
42 #include <pthread.h>
43 #include "clookup.h"
44
45 #define DEFAULT_OBJ_STORE_SIZE 1048510 //1MB
46 #define TID_LEN 20
47 //bit designations for status field of objheader
48 #define DIRTY 0x01
49 #define NEW   0x02
50 #define LOCK  0x04
51
52 typedef struct objheader {
53         unsigned int oid;
54         unsigned short type;
55         unsigned short version;
56         unsigned short rcount;
57         char status;
58 } objheader_t;
59
60 typedef struct objstr {
61         unsigned int size; //this many bytes are allocated after this header
62         void *top;
63         struct objstr *next;
64 } objstr_t;
65
66 typedef struct transrecord {
67         objstr_t *cache;
68         chashtable_t *lookupTable;
69 } transrecord_t;
70 /*
71 typedef struct pile {
72         unsigned int mid;
73         unsigned int oid;
74         struct pile *next;
75 }pile_t;
76 */
77 // Structure that keeps track of responses from the participants
78 typedef struct thread_response {
79         char rcv_status;
80 }thread_response_t;
81
82 // Structure that holds  fixed data sizes to be sent along with TRANS_REQUEST
83 typedef struct fixed_data {
84         char control;
85         char trans_id[TID_LEN]; 
86         int mcount;             // Machine count
87         short numread;          // Number of objects read
88         short nummod;           // Number of objects modified
89         int sum_bytes;  // Total bytes modified
90 }fixed_data_t;
91
92 // Structure that holds  variable data sizes per machine participant
93 typedef struct trans_req_data {
94         fixed_data_t f;
95         unsigned int *listmid;
96         char *objread;
97         unsigned int *oidmod;
98 }trans_req_data_t;
99
100 #define PRINT_TID(PTR) printf("DEBUG -> %x %d\n", PTR->mid, PTR->thread_id);
101 //structure for passing multiple arguments to thread
102 typedef struct thread_data_array {
103         int thread_id;
104         int mid;    
105         int pilecount;
106         trans_req_data_t *buffer;
107         thread_response_t *recvmsg;//shared datastructure to keep track of the control message receiv
108         pthread_cond_t *threshold; //threshhold for waking up a thread
109         pthread_mutex_t *lock;    //lock the count variable
110         int *count;             //variable to count responses of TRANS_REQUEST protocol from all participants
111         transrecord_t *rec;     // To send modified objects
112 }thread_data_array_t;
113
114 // Structure to save information about an oid necesaary for the decideControl()
115 typedef struct objinfo {
116         unsigned int oid;
117         int poss_val; //Status of object(locked but version matches, version mismatch, oid not present in machine etc) 
118 }objinfo_t;
119
120 // Structure passed to dstmAcceptinfo() on server side to complete TRANS_COMMIT process 
121 typedef struct trans_commit_data{
122         unsigned int *objmod;
123         unsigned int *objlocked;
124         unsigned int *objnotfound;
125         void *modptr;
126         int nummod;
127         int numlocked;
128         int numnotfound;
129 }trans_commit_data_t;
130 /* Initialize main object store and lookup tables, start server thread. */
131 int dstmInit(void);
132
133 /* Prototypes for object header */
134 unsigned int getNewOID(void);
135 unsigned int objSize(objheader_t *object);
136 /* end object header */
137
138 /* Prototypes for object store */
139 objstr_t *objstrCreate(unsigned int size); //size in bytes
140 void objstrDelete(objstr_t *store); //traverse and free entire list
141 void *objstrAlloc(objstr_t *store, unsigned int size); //size in bytes
142 /* end object store */
143
144 /* Prototypes for server portion */
145 void *dstmListen();
146 void *dstmAccept(void *);
147 int readClientReq(int, trans_commit_data_t *);
148 char handleTransReq(int, fixed_data_t *, trans_commit_data_t *, unsigned int *, char *, void *);
149 /* end server portion */
150
151 /* Prototypes for transactions */
152 transrecord_t *transStart();
153 objheader_t *transRead(transrecord_t *record, unsigned int oid);
154 objheader_t *transCreateObj(transrecord_t *record, unsigned short type); //returns oid
155 int decideResponse(thread_data_array_t *tdata, int sd, int status);// Coordinator decides what response to send to the participant
156 void *transRequest(void *);     //the C routine that the thread will execute when TRANS_REQUEST begins
157 int transCommit(transrecord_t *record); //return 0 if successful
158 void *getRemoteObj(transrecord_t *, unsigned int, unsigned int);
159 int transCommitProcess(trans_commit_data_t *, int);
160 /* end transactions */
161
162 void *getRemoteObj(transrecord_t *, unsigned int, unsigned int);
163
164 #endif