6 //#include <sys/socket.h>
7 //#include <netinet/in.h>
8 //#include <arpa/inet.h>
10 extern objstr_t *mainobjstore;
11 //extern lhashtable_t llookup; //Global Hash table
12 //extern mhashtable_t mlookup; //Global Hash table
14 int classsize[]={sizeof(int),sizeof(char),sizeof(short), sizeof(void *)};
19 unsigned int createObjects(transrecord_t *record) {
20 objheader_t *header, *tmp;
21 unsigned int size, mid;
23 for(i = 20 ; i< 23; i++) {
24 size = sizeof(objheader_t) + classsize[i-20] ;
25 tmp = (objheader_t *)objstrAlloc(record->cache, size);
29 tmp->rcount = 0; //? not sure how to handle this yet
32 chashInsert(record->lookupTable, tmp->oid, tmp);
33 header = (objheader_t *) objstrAlloc(mainobjstore, size);
34 memcpy(header, tmp, size);
35 mhashInsert(header->oid, header);
36 mid = iptoMid("128.200.9.27");//machine d-2
37 printf("DEBUG -> createObjects mid is %x\n", mid);
38 lhashInsert(header->oid, mid);
40 // printf("Insert oid = %d at address %x\n",tmp->oid, tmp);
41 size = sizeof(objheader_t) + classsize[0] ;
42 header = (objheader_t *) objstrAlloc(mainobjstore, size);
46 header->rcount = 0; //? not sure how to handle this yet
48 header->status |= NEW;
49 mhashInsert(header->oid, header);
50 mid = iptoMid("128.200.9.27");
51 lhashInsert(header->oid, mid);
52 size = sizeof(objheader_t) + classsize[1] ;
53 header = (objheader_t *) objstrAlloc(mainobjstore, size);
57 header->rcount = 0; //? not sure how to handle this yet
59 header->status |= LOCK;
60 mhashInsert(header->oid, header);
61 mid = iptoMid("128.200.9.27");
62 lhashInsert(header->oid, mid);
63 size = sizeof(objheader_t) + classsize[2] ;
64 header = (objheader_t *) objstrAlloc(mainobjstore, size);
68 header->rcount = 0; //? not sure how to handle this yet
70 header->status |= LOCK;
71 mhashInsert(header->oid, header);
72 mid = iptoMid("128.200.9.27");
73 lhashInsert(header->oid, mid);
87 transrecord_t *record;
88 objheader_t *h1,*h2,*h3,*h4,*h5, *h6;
91 record = transStart();
92 printf("DEBUG -> Init done\n");
93 h1 = transRead(record, 1);
94 printf("oid = %d\tsize = %d\n", h1->oid,classsize[h1->type]);
95 h3 = transRead(record, 3);
96 printf("oid = %d\tsize = %d\n", h3->oid,classsize[h3->type]);
97 h4 = transRead(record, 4);
98 printf("oid = %d\tsize = %d\n", h4->oid,classsize[h4->type]);
99 h2 = transRead(record, 2);
100 printf("oid = %d\tsize = %d\n", h2->oid,classsize[h2->type]);
101 h4 = transRead(record, 4);
102 printf("oid = %d\tsize = %d\n", h4->oid,classsize[h4->type]);
103 h3 = transRead(record, 3);
104 printf("oid = %d\tsize = %d\n", h3->oid,classsize[h3->type]);
105 h5 = transRead(record, 5);
106 printf("oid = %d\tsize = %d\n", h5->oid,classsize[h5->type]);
107 // getRemoteObj(&record, 0,1);
112 transrecord_t *record;
113 objheader_t *h1,*h2,*h3,*h4,*h5, *h6;
116 record = transStart();
124 printf("DEBUG -> Init done\n");
125 h1 = transRead(record, 1);
126 lhashInsert(h1->oid, 1);
127 h2 = transRead(record, 2);
128 lhashInsert(h2->oid, 1);
129 h3 = transRead(record, 3);
130 lhashInsert(h3->oid, 1);
131 h4 = transRead(record, 4);
132 lhashInsert(h4->oid, 1);
133 // h4->status |= DIRTY;
134 h5 = transRead(record, 5);
135 lhashInsert(h5->oid, 1);
136 h6 = transRead(record, 6);
137 lhashInsert(h6->oid, 1);
138 // h6->status |= DIRTY;
144 //Test Read objects when objects are not found in any participant
146 transrecord_t *record;
150 record = transStart();
151 printf("DEBUG -> Init done\n");
153 if((h1 = transRead(record, 11)) == NULL){
154 printf("Object not found\n");
157 if((h2 = transRead(record, 12)) == NULL) {
158 printf("Object not found\n");
165 //Test Read objects when some objects are found and other objects not found in any participant
167 transrecord_t *record;
168 objheader_t *h1,*h2, *h3, *h4;
171 record = transStart();
172 printf("DEBUG -> Init done\n");
174 if((h1 = transRead(record, 1)) == NULL){
175 printf("Object not found\n");
178 if((h2 = transRead(record, 2)) == NULL) {
179 printf("Object not found\n");
182 if((h3 = transRead(record, 11)) == NULL) {
183 printf("Object not found\n");
186 if((h4 = transRead(record, 13)) == NULL) {
187 printf("Object not found\n");
189 if((h1 != NULL) && (h2 != NULL) && (h3 != NULL) && h4 !=NULL) {
192 printf("Cannot complete this transaction\n");
198 //Test for transaction objects when the objs are part of the Coordinator machine starting the
201 transrecord_t *record;
203 unsigned int size, mid;
204 pthread_t thread_Listen;
206 objheader_t *h1,*h2, *h3, *h4;
209 pthread_attr_init(&attr);
210 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
211 //pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
213 record = transStart();
214 printf("DEBUG -> Init done\n");
215 mid = iptoMid("128.200.9.10");// Machine demsky.eecs.uci.edu
222 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
224 //Create and Insert Oid 20
225 size = sizeof(objheader_t) + classsize[2] ;
226 header = (objheader_t *) objstrAlloc(mainobjstore, size);
230 header->rcount = 0; //? not sure how to handle this yet
232 header->status |= NEW;
233 mhashInsert(header->oid, header);
234 mid = iptoMid("128.200.9.27");
235 lhashInsert(header->oid, mid);
237 //Create and Insert Oid 21
238 size = sizeof(objheader_t) + classsize[1] ;
239 header = (objheader_t *) objstrAlloc(mainobjstore, size);
243 header->rcount = 0; //? not sure how to handle this yet
245 header->status |= NEW;
246 mhashInsert(header->oid, header);
247 mid = iptoMid("128.200.9.27");
248 lhashInsert(header->oid, mid);
250 if((h1 = transRead(record, 1)) == NULL){
251 printf("Object not found\n");
254 if((h2 = transRead(record, 5)) == NULL) {
255 printf("Object not found\n");
257 //read object 20(present in local machine)
258 if((h3 = transRead(record, 20)) == NULL) {
259 printf("Object not found\n");
261 //read object 21(present in local machine)
262 if((h4 = transRead(record, 21)) == NULL) {
263 printf("Object not found\n");
267 pthread_join(thread_Listen, NULL);