7 #define LISTEN_PORT 2156
9 extern objstr_t *mainobjstore;
10 typedef struct testobj1 {
15 typedef struct testobj2 {
21 typedef struct testobj3 {
27 typedef struct testobj4 {
33 typedef struct testobj5 {
38 int classsize[]={sizeof(int),sizeof(char),sizeof(short), sizeof(void *), sizeof(testobj1_t),
39 sizeof(testobj2_t), sizeof(testobj3_t), sizeof(testobj4_t), sizeof(testobj5_t)};
41 unsigned int createObjects(transrecord_t *record) {
42 objheader_t *header, *tmp;
43 unsigned int size, mid;
45 for(i = 20 ; i< 23; i++) {
46 size = sizeof(objheader_t) + classsize[i-20] ;
47 tmp = (objheader_t *)objstrAlloc(record->cache, size);
51 tmp->rcount = 0; //? not sure how to handle this yet
54 chashInsert(record->lookupTable, tmp->oid, tmp);
55 header = (objheader_t *) objstrAlloc(mainobjstore, size);
56 memcpy(header, tmp, size);
57 mhashInsert(header->oid, header);
58 mid = iptoMid("128.200.9.27");//machine d-2
59 printf("DEBUG -> createObjects mid is %x\n", mid);
60 lhashInsert(header->oid, mid);
62 // printf("Insert oid = %d at address %x\n",tmp->oid, tmp);
63 size = sizeof(objheader_t) + classsize[0] ;
64 header = (objheader_t *) objstrAlloc(mainobjstore, size);
68 header->rcount = 0; //? not sure how to handle this yet
70 header->status |= NEW;
71 mhashInsert(header->oid, header);
72 mid = iptoMid("128.200.9.27");
73 lhashInsert(header->oid, mid);
74 size = sizeof(objheader_t) + classsize[1] ;
75 header = (objheader_t *) objstrAlloc(mainobjstore, size);
79 header->rcount = 0; //? not sure how to handle this yet
81 header->status |= LOCK;
82 mhashInsert(header->oid, header);
83 mid = iptoMid("128.200.9.27");
84 lhashInsert(header->oid, mid);
85 size = sizeof(objheader_t) + classsize[2] ;
86 header = (objheader_t *) objstrAlloc(mainobjstore, size);
90 header->rcount = 0; //? not sure how to handle this yet
92 header->status |= LOCK;
93 mhashInsert(header->oid, header);
94 mid = iptoMid("128.200.9.27");
95 lhashInsert(header->oid, mid);
114 transrecord_t *record;
115 objheader_t *h1,*h2,*h3,*h4,*h5, *h6;
118 record = transStart();
119 printf("DEBUG -> Init done\n");
120 h1 = transRead(record, 1);
121 printf("oid = %d\tsize = %d\n", h1->oid,classsize[h1->type]);
122 h3 = transRead(record, 3);
123 printf("oid = %d\tsize = %d\n", h3->oid,classsize[h3->type]);
124 h4 = transRead(record, 4);
125 printf("oid = %d\tsize = %d\n", h4->oid,classsize[h4->type]);
126 h2 = transRead(record, 2);
127 printf("oid = %d\tsize = %d\n", h2->oid,classsize[h2->type]);
128 h4 = transRead(record, 4);
129 printf("oid = %d\tsize = %d\n", h4->oid,classsize[h4->type]);
130 h3 = transRead(record, 3);
131 printf("oid = %d\tsize = %d\n", h3->oid,classsize[h3->type]);
132 h5 = transRead(record, 5);
133 printf("oid = %d\tsize = %d\n", h5->oid,classsize[h5->type]);
134 // getRemoteObj(&record, 0,1);
139 transrecord_t *record;
140 objheader_t *h1,*h2,*h3,*h4,*h5, *h6;
143 record = transStart();
151 printf("DEBUG -> Init done\n");
152 h1 = transRead(record, 1);
153 lhashInsert(h1->oid, 1);
154 h2 = transRead(record, 2);
155 lhashInsert(h2->oid, 1);
156 h3 = transRead(record, 3);
157 lhashInsert(h3->oid, 1);
158 h4 = transRead(record, 4);
159 lhashInsert(h4->oid, 1);
160 // h4->status |= DIRTY;
161 h5 = transRead(record, 5);
162 lhashInsert(h5->oid, 1);
163 h6 = transRead(record, 6);
164 lhashInsert(h6->oid, 1);
165 // h6->status |= DIRTY;
172 //Read objects when objects are found in remote location
174 unsigned int val, mid;
175 transrecord_t *myTrans;
177 objheader_t *header, *h1, *h2;
178 pthread_t thread_Listen;
182 pthread_attr_init(&attr);
183 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
185 //Create and Insert Oid 20
186 size = sizeof(objheader_t) + classsize[2] ;
187 header = (objheader_t *) objstrAlloc(mainobjstore, size);
191 header->rcount = 0; //? not sure how to handle this yet
193 header->status |= NEW;
194 mhashInsert(header->oid, header);
195 mid = iptoMid("128.200.9.27");
196 lhashInsert(header->oid, mid);
198 //Create and Insert Oid 21
199 size = sizeof(objheader_t) + classsize[1] ;
200 header = (objheader_t *) objstrAlloc(mainobjstore, size);
204 header->rcount = 0; //? not sure how to handle this yet
206 header->status |= NEW;
207 mhashInsert(header->oid, header);
208 mid = iptoMid("128.200.9.27");
209 lhashInsert(header->oid, mid);
211 //Create and Insert Oid 22
212 size = sizeof(objheader_t) + classsize[3] ;
213 header = (objheader_t *) objstrAlloc(mainobjstore, size);
217 header->rcount = 0; //? not sure how to handle this yet
219 header->status |= NEW;
220 mhashInsert(header->oid, header);
221 mid = iptoMid("128.200.9.27");
222 lhashInsert(header->oid, mid);
224 //Inserting into lhashtable
225 mid = iptoMid("128.200.9.26"); //d-1.eecs.uci.edu
226 lhashInsert(31, mid);
227 lhashInsert(32, mid);
229 mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
230 //Inserting into lhashtable
236 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
238 //Check if machine demsky is up and running
239 checkServer(mid, "128.200.9.10");
240 mid = iptoMid("128.200.9.26");
241 //Check if machine d-1 is up and running
242 checkServer(mid, "128.200.9.26");
245 myTrans = transStart();
249 if((h1 = transRead(myTrans, 1)) == NULL){
250 printf("Object not found\n");
253 if((h2 = transRead(myTrans, 2)) == NULL) {
254 printf("Object not found\n");
257 pthread_join(thread_Listen, NULL);
261 //Read objects that are both remote and local and are available on machines
264 unsigned int val, mid;
265 transrecord_t *myTrans;
267 objheader_t *header, *h1, *h2, *h3, *h4;
268 pthread_t thread_Listen;
272 pthread_attr_init(&attr);
273 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
275 //Create and Insert Oid 20
276 size = sizeof(objheader_t) + classsize[2] ;
277 header = (objheader_t *) objstrAlloc(mainobjstore, size);
281 header->rcount = 0; //? not sure how to handle this yet
283 header->status |= NEW;
284 mhashInsert(header->oid, header);
285 mid = iptoMid("128.200.9.27");
286 lhashInsert(header->oid, mid);
288 //Create and Insert Oid 21
289 size = sizeof(objheader_t) + classsize[1] ;
290 header = (objheader_t *) objstrAlloc(mainobjstore, size);
294 header->rcount = 0; //? not sure how to handle this yet
296 header->status |= NEW;
297 mhashInsert(header->oid, header);
298 mid = iptoMid("128.200.9.27");
299 lhashInsert(header->oid, mid);
301 //Create and Insert Oid 22
302 size = sizeof(objheader_t) + classsize[3] ;
303 header = (objheader_t *) objstrAlloc(mainobjstore, size);
307 header->rcount = 0; //? not sure how to handle this yet
309 header->status |= NEW;
310 mhashInsert(header->oid, header);
311 mid = iptoMid("128.200.9.27");
312 lhashInsert(header->oid, mid);
314 //Inserting into lhashtable
315 mid = iptoMid("128.200.9.26"); //d-1.eecs.uci.edu
316 lhashInsert(31, mid);
317 lhashInsert(32, mid);
318 lhashInsert(33, mid);
320 mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
321 //Inserting into lhashtable
327 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
329 //Check if machine demsky is up and running
330 checkServer(mid, "128.200.9.10");
331 mid = iptoMid("128.200.9.26");
332 //Check if machine d-1 is up and running
333 checkServer(mid, "128.200.9.26");
336 myTrans = transStart();
339 //read object 1 (found on demksy)
340 if((h1 = transRead(myTrans, 1)) == NULL){
341 printf("Object not found\n");
343 //read object 2 (found on demsky)
344 if((h2 = transRead(myTrans, 2)) == NULL) {
345 printf("Object not found\n");
348 //read object 21 (found on local)
349 if((h3 = transRead(myTrans, 21)) == NULL) {
350 printf("Object not found\n");
353 //read object 32 (found on d-1)
354 if((h4 = transRead(myTrans, 32)) == NULL) {
355 printf("Object not found\n");
358 pthread_join(thread_Listen, NULL);
364 //Read objects when objects are not found in any participant
366 transrecord_t *record;
370 record = transStart();
371 printf("DEBUG -> Init done\n");
373 if((h1 = transRead(record, 11)) == NULL){
374 printf("Object not found\n");
377 if((h2 = transRead(record, 12)) == NULL) {
378 printf("Object not found\n");
385 //Read objects when some objects are found and other objects not found in any participant
387 transrecord_t *record;
388 objheader_t *h1,*h2, *h3, *h4;
391 record = transStart();
392 printf("DEBUG -> Init done\n");
394 if((h1 = transRead(record, 1)) == NULL){
395 printf("Object not found\n");
398 if((h2 = transRead(record, 2)) == NULL) {
399 printf("Object not found\n");
402 if((h3 = transRead(record, 11)) == NULL) {
403 printf("Object not found\n");
406 if((h4 = transRead(record, 13)) == NULL) {
407 printf("Object not found\n");
409 if((h1 != NULL) && (h2 != NULL) && (h3 != NULL) && h4 !=NULL) {
412 printf("Cannot complete this transaction\n");
418 //Commit for transaction objects when the objs are part of other
419 //transactions running simultaneously
421 unsigned int val, mid;
422 transrecord_t *myTrans;
424 objheader_t *header, *h1, *h2, *h3, *h4, *h5, *h6;
425 pthread_t thread_Listen;
429 pthread_attr_init(&attr);
430 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
432 //Create and Insert Oid 20
433 size = sizeof(objheader_t) + classsize[2] ;
434 header = (objheader_t *) objstrAlloc(mainobjstore, size);
438 header->rcount = 0; //? not sure how to handle this yet
440 header->status |= NEW;
441 mhashInsert(header->oid, header);
442 mid = iptoMid("128.200.9.27");
443 lhashInsert(header->oid, mid);
445 //Create and Insert Oid 21
446 size = sizeof(objheader_t) + classsize[1] ;
447 header = (objheader_t *) objstrAlloc(mainobjstore, size);
451 header->rcount = 0; //? not sure how to handle this yet
453 header->status |= NEW;
454 mhashInsert(header->oid, header);
455 mid = iptoMid("128.200.9.27");
456 lhashInsert(header->oid, mid);
458 //Create and Insert Oid 22
459 size = sizeof(objheader_t) + classsize[3] ;
460 header = (objheader_t *) objstrAlloc(mainobjstore, size);
464 header->rcount = 0; //? not sure how to handle this yet
466 header->status |= NEW;
467 mhashInsert(header->oid, header);
468 mid = iptoMid("128.200.9.27");
469 lhashInsert(header->oid, mid);
471 //Inserting into lhashtable
472 mid = iptoMid("128.200.9.26"); //d-1.eecs.uci.edu
473 lhashInsert(31, mid);
474 lhashInsert(32, mid);
475 lhashInsert(33, mid);
477 mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
478 //Inserting into lhashtable
484 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
486 //Check if machine demsky is up and running
487 checkServer(mid, "128.200.9.10");
488 mid = iptoMid("128.200.9.26");
489 //Check if machine d-1 is up and running
490 checkServer(mid, "128.200.9.26");
493 myTrans = transStart();
495 //read object 1 (found on demksy)
496 if((h1 = transRead(myTrans, 1)) == NULL){
497 printf("Object not found\n");
499 //read object 31 (found on d-1)
500 if((h2 = transRead(myTrans, 31)) == NULL) {
501 printf("Object not found\n");
504 //read object 22 (found locally)
505 if((h3 = transRead(myTrans, 22)) == NULL) {
506 printf("Object not found\n");
509 //read object 2 (found on demsky)
510 if((h4 = transRead(myTrans, 2)) == NULL) {
511 printf("Object not found\n");
514 //read object 21 (found locally)
515 if((h5 = transRead(myTrans, 21)) == NULL) {
516 printf("Object not found\n");
519 //read object 32 (found on d-2)
520 if((h6 = transRead(myTrans, 32)) == NULL) {
521 printf("Object not found\n");
525 if((h1 != NULL) && (h2 != NULL) && (h3 != NULL) && (h4 !=NULL) && (h5 != NULL) && (h6 != NULL))
526 transCommit(myTrans);
528 printf("Cannot complete this transaction \n");
530 pthread_join(thread_Listen, NULL);
534 unsigned int val, mid;
535 transrecord_t *myTrans;
537 objheader_t *header, *h1, *h2, *h3;
538 pthread_t thread_Listen;
542 pthread_attr_init(&attr);
543 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
545 //Create and Insert Oid 20
546 size = sizeof(objheader_t) + classsize[2] ;
547 header = (objheader_t *) objstrAlloc(mainobjstore, size);
551 header->rcount = 0; //? not sure how to handle this yet
553 header->status |= NEW;
554 mhashInsert(header->oid, header);
555 mid = iptoMid("128.200.9.27");
556 lhashInsert(header->oid, mid);
558 //Create and Insert Oid 21
559 size = sizeof(objheader_t) + classsize[1] ;
560 header = (objheader_t *) objstrAlloc(mainobjstore, size);
564 header->rcount = 0; //? not sure how to handle this yet
566 header->status |= NEW;
567 mhashInsert(header->oid, header);
568 mid = iptoMid("128.200.9.27");
569 lhashInsert(header->oid, mid);
571 //Create and Insert Oid 22
572 size = sizeof(objheader_t) + classsize[3] ;
573 header = (objheader_t *) objstrAlloc(mainobjstore, size);
577 header->rcount = 0; //? not sure how to handle this yet
579 header->status |= NEW;
580 mhashInsert(header->oid, header);
581 mid = iptoMid("128.200.9.27");
582 lhashInsert(header->oid, mid);
584 //Inserting into lhashtable
585 mid = iptoMid("128.200.9.26"); //d-1.eecs.uci.edu
586 lhashInsert(31, mid);
587 lhashInsert(32, mid);
588 lhashInsert(33, mid);
590 mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
591 //Inserting into lhashtable
597 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
599 //Check if machine demsky is up and running
600 checkServer(mid, "128.200.9.10");
601 mid = iptoMid("128.200.9.26");
602 //Check if machine d-1 is up and running
603 checkServer(mid, "128.200.9.26");
606 myTrans = transStart();
608 //read object 1 (found on demksy)
609 if((h1 = transRead(myTrans, 1)) == NULL){
610 printf("Object not found\n");
612 //read object 31 (found on d-1)
613 if((h2 = transRead(myTrans, 32)) == NULL) {
614 printf("Object not found\n");
617 //read object 22 (found locally)
618 if((h3 = transRead(myTrans, 22)) == NULL) {
619 printf("Object not found\n");
623 if((h1 != NULL) && (h2 != NULL) && (h3 != NULL))
624 transCommit(myTrans);
626 printf("Cannot complete this transaction \n");
628 pthread_join(thread_Listen, NULL);
633 transrecord_t *record;
635 unsigned int size, mid;
636 pthread_t thread_Listen;
638 objheader_t *h1,*h2, *h3, *h4, *h5, *h6;
642 pthread_attr_init(&attr);
643 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
644 //pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
646 record = transStart();
647 //printf("DEBUG -> Init done\n");
648 mid = iptoMid("128.200.9.10");// Machine demsky.eecs.uci.edu
656 mid = iptoMid("128.200.9.26");// Machine demsky.eecs.uci.edu
661 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
663 checkServer(mid, "128.200.9.26");
664 mid = iptoMid("128.200.9.10");
665 checkServer(mid, "128.200.9.10");
667 //Create and Insert Oid 20
668 size = sizeof(objheader_t) + classsize[2] ;
669 header = (objheader_t *) objstrAlloc(mainobjstore, size);
673 header->rcount = 0; //? not sure how to handle this yet
675 header->status |= NEW;
676 mhashInsert(header->oid, header);
677 mid = iptoMid("128.200.9.27");
678 lhashInsert(header->oid, mid);
680 //Create and Insert Oid 21
681 size = sizeof(objheader_t) + classsize[1] ;
682 header = (objheader_t *) objstrAlloc(mainobjstore, size);
686 header->rcount = 0; //? not sure how to handle this yet
688 header->status |= NEW;
689 mhashInsert(header->oid, header);
690 mid = iptoMid("128.200.9.27");
691 lhashInsert(header->oid, mid);
693 //read object 1 //from demsky
694 if((h1 = transRead(record, 1)) == NULL){
695 printf("Object not found\n");
698 if((h2 = transRead(record, 2)) == NULL) {
699 printf("Object not found\n");
701 //read object 31 //Found in d-1
702 if((h2 = transRead(record, 31)) == NULL) {
703 printf("Object not found\n");
705 //read object 32 //Found in d-1
706 if((h2 = transRead(record, 32)) == NULL) {
707 printf("Object not found\n");
709 //read object 20(present in local machine)
710 if((h3 = transRead(record, 20)) == NULL) {
711 printf("Object not found\n");
713 //read object 21(present in local machine)
714 if((h4 = transRead(record, 21)) == NULL) {
715 printf("Object not found\n");
718 pthread_join(thread_Listen, NULL);
721 //Commit transactions on local and remote objects that are NOT a part of
722 //any other transaction
724 unsigned int val, mid;
725 transrecord_t *myTrans;
727 objheader_t *header, *h1, *h2, *h3;
728 pthread_t thread_Listen;
732 pthread_attr_init(&attr);
733 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
735 //Create and Insert Oid 20
736 size = sizeof(objheader_t) + classsize[2] ;
737 header = (objheader_t *) objstrAlloc(mainobjstore, size);
741 header->rcount = 0; //? not sure how to handle this yet
743 header->status |= NEW;
744 mhashInsert(header->oid, header);
745 mid = iptoMid("128.200.9.27");
746 lhashInsert(header->oid, mid);
748 //Create and Insert Oid 21
749 size = sizeof(objheader_t) + classsize[1] ;
750 header = (objheader_t *) objstrAlloc(mainobjstore, size);
754 header->rcount = 0; //? not sure how to handle this yet
756 header->status |= NEW;
757 mhashInsert(header->oid, header);
758 mid = iptoMid("128.200.9.27");
759 lhashInsert(header->oid, mid);
761 //Create and Insert Oid 22
762 size = sizeof(objheader_t) + classsize[3] ;
763 header = (objheader_t *) objstrAlloc(mainobjstore, size);
767 header->rcount = 0; //? not sure how to handle this yet
769 header->status |= NEW;
770 mhashInsert(header->oid, header);
771 mid = iptoMid("128.200.9.27");
772 lhashInsert(header->oid, mid);
774 //Inserting into lhashtable
775 mid = iptoMid("128.200.9.26"); //d-1.eecs.uci.edu
776 lhashInsert(31, mid);
777 lhashInsert(32, mid);
778 lhashInsert(33, mid);
780 mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
781 //Inserting into lhashtable
787 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
789 //Check if machine demsky is up and running
790 checkServer(mid, "128.200.9.10");
791 mid = iptoMid("128.200.9.26");
792 //Check if machine d-1 is up and running
793 checkServer(mid, "128.200.9.26");
796 myTrans = transStart();
798 //read object 3 (found on demksy)
799 if((h1 = transRead(myTrans, 3)) == NULL){
800 printf("Object not found\n");
802 //read object 32 (found on d-1)
803 if((h2 = transRead(myTrans, 32)) == NULL) {
804 printf("Object not found\n");
807 //read object 22 (found locally)
808 if((h3 = transRead(myTrans, 22)) == NULL) {
809 printf("Object not found\n");
813 transCommit(myTrans);
815 pthread_join(thread_Listen, NULL);