6 //#include <sys/socket.h>
7 //#include <netinet/in.h>
8 //#include <arpa/inet.h>
9 #define LISTEN_PORT 2156
11 extern objstr_t *mainobjstore;
12 //extern lhashtable_t llookup; //Global Hash table
13 //extern mhashtable_t mlookup; //Global Hash table
15 int classsize[]={sizeof(int),sizeof(char),sizeof(short), sizeof(void *)};
20 unsigned int createObjects(transrecord_t *record) {
21 objheader_t *header, *tmp;
22 unsigned int size, mid;
24 for(i = 20 ; i< 23; i++) {
25 size = sizeof(objheader_t) + classsize[i-20] ;
26 tmp = (objheader_t *)objstrAlloc(record->cache, size);
30 tmp->rcount = 0; //? not sure how to handle this yet
33 chashInsert(record->lookupTable, tmp->oid, tmp);
34 header = (objheader_t *) objstrAlloc(mainobjstore, size);
35 memcpy(header, tmp, size);
36 mhashInsert(header->oid, header);
37 mid = iptoMid("128.200.9.27");//machine d-2
38 printf("DEBUG -> createObjects mid is %x\n", mid);
39 lhashInsert(header->oid, mid);
41 // printf("Insert oid = %d at address %x\n",tmp->oid, tmp);
42 size = sizeof(objheader_t) + classsize[0] ;
43 header = (objheader_t *) objstrAlloc(mainobjstore, size);
47 header->rcount = 0; //? not sure how to handle this yet
49 header->status |= NEW;
50 mhashInsert(header->oid, header);
51 mid = iptoMid("128.200.9.27");
52 lhashInsert(header->oid, mid);
53 size = sizeof(objheader_t) + classsize[1] ;
54 header = (objheader_t *) objstrAlloc(mainobjstore, size);
58 header->rcount = 0; //? not sure how to handle this yet
60 header->status |= LOCK;
61 mhashInsert(header->oid, header);
62 mid = iptoMid("128.200.9.27");
63 lhashInsert(header->oid, mid);
64 size = sizeof(objheader_t) + classsize[2] ;
65 header = (objheader_t *) objstrAlloc(mainobjstore, size);
69 header->rcount = 0; //? not sure how to handle this yet
71 header->status |= LOCK;
72 mhashInsert(header->oid, header);
73 mid = iptoMid("128.200.9.27");
74 lhashInsert(header->oid, mid);
90 transrecord_t *record;
91 objheader_t *h1,*h2,*h3,*h4,*h5, *h6;
94 record = transStart();
95 printf("DEBUG -> Init done\n");
96 h1 = transRead(record, 1);
97 printf("oid = %d\tsize = %d\n", h1->oid,classsize[h1->type]);
98 h3 = transRead(record, 3);
99 printf("oid = %d\tsize = %d\n", h3->oid,classsize[h3->type]);
100 h4 = transRead(record, 4);
101 printf("oid = %d\tsize = %d\n", h4->oid,classsize[h4->type]);
102 h2 = transRead(record, 2);
103 printf("oid = %d\tsize = %d\n", h2->oid,classsize[h2->type]);
104 h4 = transRead(record, 4);
105 printf("oid = %d\tsize = %d\n", h4->oid,classsize[h4->type]);
106 h3 = transRead(record, 3);
107 printf("oid = %d\tsize = %d\n", h3->oid,classsize[h3->type]);
108 h5 = transRead(record, 5);
109 printf("oid = %d\tsize = %d\n", h5->oid,classsize[h5->type]);
110 // getRemoteObj(&record, 0,1);
115 transrecord_t *record;
116 objheader_t *h1,*h2,*h3,*h4,*h5, *h6;
119 record = transStart();
127 printf("DEBUG -> Init done\n");
128 h1 = transRead(record, 1);
129 lhashInsert(h1->oid, 1);
130 h2 = transRead(record, 2);
131 lhashInsert(h2->oid, 1);
132 h3 = transRead(record, 3);
133 lhashInsert(h3->oid, 1);
134 h4 = transRead(record, 4);
135 lhashInsert(h4->oid, 1);
136 // h4->status |= DIRTY;
137 h5 = transRead(record, 5);
138 lhashInsert(h5->oid, 1);
139 h6 = transRead(record, 6);
140 lhashInsert(h6->oid, 1);
141 // h6->status |= DIRTY;
147 //Test Read objects when objects are not found in any participant
149 transrecord_t *record;
153 record = transStart();
154 printf("DEBUG -> Init done\n");
156 if((h1 = transRead(record, 11)) == NULL){
157 printf("Object not found\n");
160 if((h2 = transRead(record, 12)) == NULL) {
161 printf("Object not found\n");
168 //Test Read objects when some objects are found and other objects not found in any participant
170 transrecord_t *record;
171 objheader_t *h1,*h2, *h3, *h4;
174 record = transStart();
175 printf("DEBUG -> Init done\n");
177 if((h1 = transRead(record, 1)) == NULL){
178 printf("Object not found\n");
181 if((h2 = transRead(record, 2)) == NULL) {
182 printf("Object not found\n");
185 if((h3 = transRead(record, 11)) == NULL) {
186 printf("Object not found\n");
189 if((h4 = transRead(record, 13)) == NULL) {
190 printf("Object not found\n");
192 if((h1 != NULL) && (h2 != NULL) && (h3 != NULL) && h4 !=NULL) {
195 printf("Cannot complete this transaction\n");
201 //Test for transaction objects when the objs are part of the Coordinator machine starting the
204 transrecord_t *record;
206 unsigned int size, mid;
207 pthread_t thread_Listen;
209 objheader_t *h1,*h2, *h3, *h4;
212 pthread_attr_init(&attr);
213 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
214 //pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
216 record = transStart();
217 printf("DEBUG -> Init done\n");
218 mid = iptoMid("128.200.9.10");// Machine demsky.eecs.uci.edu
225 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
227 //Create and Insert Oid 20
228 size = sizeof(objheader_t) + classsize[2] ;
229 header = (objheader_t *) objstrAlloc(mainobjstore, size);
233 header->rcount = 0; //? not sure how to handle this yet
235 header->status |= NEW;
236 mhashInsert(header->oid, header);
237 mid = iptoMid("128.200.9.27");
238 lhashInsert(header->oid, mid);
240 //Create and Insert Oid 21
241 size = sizeof(objheader_t) + classsize[1] ;
242 header = (objheader_t *) objstrAlloc(mainobjstore, size);
246 header->rcount = 0; //? not sure how to handle this yet
248 header->status |= NEW;
249 mhashInsert(header->oid, header);
250 mid = iptoMid("128.200.9.27");
251 lhashInsert(header->oid, mid);
253 if((h1 = transRead(record, 1)) == NULL){
254 printf("Object not found\n");
257 if((h2 = transRead(record, 5)) == NULL) {
258 printf("Object not found\n");
260 //read object 20(present in local machine)
261 if((h3 = transRead(record, 20)) == NULL) {
262 printf("Object not found\n");
264 //read object 21(present in local machine)
265 if((h4 = transRead(record, 21)) == NULL) {
266 printf("Object not found\n");
270 pthread_join(thread_Listen, NULL);
274 transrecord_t *record;
276 unsigned int size, mid;
277 pthread_t thread_Listen;
279 objheader_t *h1,*h2, *h3, *h4, *h5, *h6;
283 pthread_attr_init(&attr);
284 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
285 //pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
287 record = transStart();
288 //printf("DEBUG -> Init done\n");
289 mid = iptoMid("128.200.9.10");// Machine demsky.eecs.uci.edu
297 mid = iptoMid("128.200.9.26");// Machine demsky.eecs.uci.edu
302 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
304 checkServer(mid, "128.200.9.26");
305 mid = iptoMid("128.200.9.10");
306 checkServer(mid, "128.200.9.10");
308 //Create and Insert Oid 20
309 size = sizeof(objheader_t) + classsize[2] ;
310 header = (objheader_t *) objstrAlloc(mainobjstore, size);
314 header->rcount = 0; //? not sure how to handle this yet
316 header->status |= NEW;
317 mhashInsert(header->oid, header);
318 mid = iptoMid("128.200.9.27");
319 lhashInsert(header->oid, mid);
321 //Create and Insert Oid 21
322 size = sizeof(objheader_t) + classsize[1] ;
323 header = (objheader_t *) objstrAlloc(mainobjstore, size);
327 header->rcount = 0; //? not sure how to handle this yet
329 header->status |= NEW;
330 mhashInsert(header->oid, header);
331 mid = iptoMid("128.200.9.27");
332 lhashInsert(header->oid, mid);
334 //read object 1 //from demsky
335 if((h1 = transRead(record, 1)) == NULL){
336 printf("Object not found\n");
339 if((h2 = transRead(record, 2)) == NULL) {
340 printf("Object not found\n");
342 //read object 31 //Found in d-1
343 if((h2 = transRead(record, 31)) == NULL) {
344 printf("Object not found\n");
346 //read object 32 //Found in d-1
347 if((h2 = transRead(record, 32)) == NULL) {
348 printf("Object not found\n");
350 //read object 20(present in local machine)
351 if((h3 = transRead(record, 20)) == NULL) {
352 printf("Object not found\n");
354 //read object 21(present in local machine)
355 if((h4 = transRead(record, 21)) == NULL) {
356 printf("Object not found\n");
359 pthread_join(thread_Listen, NULL);