3 #include <sys/socket.h>
4 #include <netinet/in.h>
8 extern objstr_t *mainobjstore;
9 int classsize[]={sizeof(int),sizeof(char),sizeof(short), sizeof(void *)};
15 unsigned int createObjects(transrecord_t *record, unsigned short type) {
16 objheader_t *header, *tmp;
17 struct sockaddr_in antelope;
18 unsigned int size, mid;
19 size = sizeof(objheader_t) + classsize[type] ;
20 //Inserts in chashtable
21 header = transCreateObj(record, type);
22 tmp = (objheader_t *) objstrAlloc(mainobjstore, size);
23 memcpy(tmp, header, size);
24 mhashInsert(tmp->oid, tmp);
25 mid = iptoMid("128.200.9.10");
26 lhashInsert(tmp->oid, mid);
29 // tmp->status |= LOCK;
33 void init_obj(objheader_t *h, unsigned int oid, unsigned short type, \
34 unsigned short version,\
35 unsigned short rcount, char status) {
55 transrecord_t *myTrans;
56 pthread_t thread_Listen;
59 pthread_create(&thread_Listen, NULL, dstmListen, NULL);
61 myTrans = transStart();
63 printf("Creating Transaction\n");
65 if((val = createObjects(myTrans, 0)) != 0) {
66 printf("Error transCreateObj1");
69 if((val = createObjects(myTrans, 1)) != 0) {
70 printf("Error transCreateObj2");
73 if((val = createObjects(myTrans, 2)) != 0) {
74 printf("Error transCreateObj3");
77 if((val = createObjects(myTrans, 3)) != 0) {
78 printf("Error transCreateObj4");
81 if((val = createObjects(myTrans, 0)) != 0) {
82 printf("Error transCreateObj5");
85 if((val = createObjects(myTrans, 1)) != 0) {
86 printf("Error transCreateObj6");
88 pthread_join(thread_Listen, NULL);
94 unsigned int val, mid;
95 transrecord_t *myTrans;
96 pthread_t thread_Listen;
99 mid = iptoMid("128.200.9.27"); //d-2.eecs.uci.edu
100 //Inserting into lhashtable
101 lhashInsert(20, mid);
102 lhashInsert(21, mid);
103 lhashInsert(22, mid);
104 lhashInsert(23, mid);
105 lhashInsert(30, mid);
106 lhashInsert(28, mid);
107 lhashInsert(29, mid);
108 pthread_create(&thread_Listen, NULL, dstmListen, NULL);
110 myTrans = transStart();
112 printf("Creating Transaction\n");
114 if((val = createObjects(myTrans, 0)) != 0) {
115 printf("Error transCreateObj1");
118 if((val = createObjects(myTrans, 1)) != 0) {
119 printf("Error transCreateObj2");
122 if((val = createObjects(myTrans, 2)) != 0) {
123 printf("Error transCreateObj3");
126 if((val = createObjects(myTrans, 3)) != 0) {
127 printf("Error transCreateObj4");
130 if((val = createObjects(myTrans, 0)) != 0) {
131 printf("Error transCreateObj5");
134 if((val = createObjects(myTrans, 1)) != 0) {
135 printf("Error transCreateObj6");
137 pthread_join(thread_Listen, NULL);
139 //Commit transaction with all locally available objects
141 unsigned int val, mid;
142 transrecord_t *myTrans;
145 pthread_t thread_Listen;
147 objheader_t *h1, *h2, *h3;//h1,h2,h3 from local
150 pthread_attr_init(&attr);
151 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
153 // Create and Insert Oid 1
154 size = sizeof(objheader_t) + classsize[0] ;
155 header = (objheader_t *) objstrAlloc(mainobjstore, size);
156 init_obj(header, 1, 0, 1, 0, NEW);
157 mhashInsert(header->oid, header);
158 mid = iptoMid("128.200.9.10");
159 lhashInsert(header->oid, mid);
161 // Create and Insert Oid 2
162 size = sizeof(objheader_t) + classsize[1] ;
163 header = (objheader_t *) objstrAlloc(mainobjstore, size);
164 init_obj(header, 2, 1, 1, 0, NEW);
165 mhashInsert(header->oid, header);
166 mid = iptoMid("128.200.9.10");
167 lhashInsert(header->oid, mid);
170 // Create and Insert Oid 3
171 size = sizeof(objheader_t) + classsize[2] ;
172 header = (objheader_t *) objstrAlloc(mainobjstore, size);
173 init_obj(header, 3, 2, 1, 0, NEW);
174 mhashInsert(header->oid, header);
175 mid = iptoMid("128.200.9.10");
176 lhashInsert(header->oid, mid);
178 // Create and Insert Oid 4
179 size = sizeof(objheader_t) + classsize[3] ;
180 header = (objheader_t *) objstrAlloc(mainobjstore, size);
181 init_obj(header, 4, 3, 1, 0, NEW);
182 mhashInsert(header->oid, header);
183 mid = iptoMid("128.200.9.10");
184 lhashInsert(header->oid, mid);
186 //Inserting into lhashtable
187 mid = iptoMid("128.200.9.27"); //d-2.eecs.uci.edu
188 lhashInsert(20, mid);
189 lhashInsert(21, mid);
190 lhashInsert(22, mid);
192 mid = iptoMid("128.200.9.26"); //d-1.eecs.uci.edu
193 //Inserting into lhashtable
194 lhashInsert(31, mid);
195 lhashInsert(32, mid);
196 lhashInsert(33, mid);
197 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
198 // pthread_create(&thread_Listen, NULL, dstmListen, NULL);
200 //Check if machine d-1 is up and running
201 checkServer(mid, "128.200.9.26");
202 mid = iptoMid("128.200.9.27");
203 //Check if machine d-2 is up and running
204 checkServer(mid, "128.200.9.27");
207 myTrans = transStart();
209 //read object 1(present in local machine)
210 if((h1 = transRead(myTrans, 1)) == NULL){
211 printf("Object not found\n");
213 //read object 2present in local machine)
214 if((h2 = transRead(myTrans, 2)) == NULL) {
215 printf("Object not found\n");
217 //read object 3(present in local machine)
218 if((h3 = transRead(myTrans, 3)) == NULL) {
219 printf("Object not found\n");
222 // Commit transaction
223 transCommit(myTrans);
225 pthread_join(thread_Listen, NULL);
230 //Commit transaction with few locally available objects and other objects from machine d-1
234 unsigned int val, mid;
235 transrecord_t *myTrans;
238 pthread_t thread_Listen;
240 objheader_t *h1, *h2, *h3, *h4;//h1,h2 from local ; h3 from d-1 , h-4 from d-2
243 pthread_attr_init(&attr);
244 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
246 // Create and Insert Oid 1
247 size = sizeof(objheader_t) + classsize[0] ;
248 header = (objheader_t *) objstrAlloc(mainobjstore, size);
249 init_obj(header, 1, 0, 1, 0, NEW);
250 mhashInsert(header->oid, header);
251 mid = iptoMid("128.200.9.10");
252 lhashInsert(header->oid, mid);
254 // Create and Insert Oid 2
255 size = sizeof(objheader_t) + classsize[1] ;
256 header = (objheader_t *) objstrAlloc(mainobjstore, size);
257 init_obj(header, 2, 1, 1, 0, NEW);
258 mhashInsert(header->oid, header);
259 mid = iptoMid("128.200.9.10");
260 lhashInsert(header->oid, mid);
263 // Create and Insert Oid 3
264 size = sizeof(objheader_t) + classsize[2] ;
265 header = (objheader_t *) objstrAlloc(mainobjstore, size);
266 init_obj(header, 3, 2, 1, 0, NEW);
267 mhashInsert(header->oid, header);
268 mid = iptoMid("128.200.9.10");
269 lhashInsert(header->oid, mid);
271 // Create and Insert Oid 4
272 size = sizeof(objheader_t) + classsize[3] ;
273 header = (objheader_t *) objstrAlloc(mainobjstore, size);
274 init_obj(header, 4, 3, 1, 0, NEW);
275 mhashInsert(header->oid, header);
276 mid = iptoMid("128.200.9.10");
277 lhashInsert(header->oid, mid);
279 //Inserting into lhashtable
280 mid = iptoMid("128.200.9.27"); //d-2.eecs.uci.edu
281 lhashInsert(20, mid);
282 lhashInsert(21, mid);
283 lhashInsert(22, mid);
285 mid = iptoMid("128.200.9.26"); //d-1.eecs.uci.edu
286 //Inserting into lhashtable
287 lhashInsert(31, mid);
288 lhashInsert(32, mid);
289 lhashInsert(33, mid);
290 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
291 // pthread_create(&thread_Listen, NULL, dstmListen, NULL);
293 //Check if machine d-1 is up and running
294 checkServer(mid, "128.200.9.26");
295 mid = iptoMid("128.200.9.27");
296 //Check if machine d-2 is up and running
297 checkServer(mid, "128.200.9.27");
300 myTrans = transStart();
302 //read object 1(present in local machine)
303 if((h1 = transRead(myTrans, 1)) == NULL){
304 printf("Object not found\n");
306 //read object 2present in local machine)
307 if((h2 = transRead(myTrans, 2)) == NULL) {
308 printf("Object not found\n");
310 //read object 31(present in d-1 machine)
311 if((h3 = transRead(myTrans, 31)) == NULL) {
312 printf("Object not found\n");
315 //read object 21(present in d-2 machine)
316 if((h4 = transRead(myTrans, 21)) == NULL) {
317 printf("Object not found\n");
320 // Commit transaction
321 transCommit(myTrans);
323 pthread_join(thread_Listen, NULL);
329 unsigned int val, mid;
330 transrecord_t *myTrans;
333 pthread_t thread_Listen;
335 objheader_t *h1, *h2, *h3, *h4, *h5;
338 pthread_attr_init(&attr);
339 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
341 mid = iptoMid("128.200.9.27"); //d-2.eecs.uci.edu
342 //Inserting into lhashtable
343 lhashInsert(20, mid);
344 lhashInsert(21, mid);
345 lhashInsert(22, mid);
347 mid = iptoMid("128.200.9.26"); //d-1.eecs.uci.edu
348 //Inserting into lhashtable
349 lhashInsert(31, mid);
350 lhashInsert(32, mid);
351 lhashInsert(33, mid);
352 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
353 // pthread_create(&thread_Listen, NULL, dstmListen, NULL);
355 printf("DEBUG -> mid = %d\n", mid);
356 checkServer(mid, "128.200.9.26");
357 mid = iptoMid("128.200.9.27");
358 printf("DEBUG -> mid = %d\n", mid);
359 checkServer(mid, "128.200.9.27");
362 myTrans = transStart();
364 // Create and Insert Oid 1
365 size = sizeof(objheader_t) + classsize[0] ;
366 header = (objheader_t *) objstrAlloc(mainobjstore, size);
367 init_obj(header, 1, 0, 1, 0, NEW);
368 mhashInsert(header->oid, header);
369 mid = iptoMid("128.200.9.10");
370 lhashInsert(header->oid, mid);
372 // Create and Insert Oid 2
373 size = sizeof(objheader_t) + classsize[1] ;
374 header = (objheader_t *) objstrAlloc(mainobjstore, size);
375 init_obj(header, 2, 1, 1, 0, NEW);
376 mhashInsert(header->oid, header);
377 mid = iptoMid("128.200.9.10");
378 lhashInsert(header->oid, mid);
381 // Create and Insert Oid 3
382 size = sizeof(objheader_t) + classsize[2] ;
383 header = (objheader_t *) objstrAlloc(mainobjstore, size);
384 init_obj(header, 3, 2, 1, 0, NEW);
385 mhashInsert(header->oid, header);
386 mid = iptoMid("128.200.9.10");
387 lhashInsert(header->oid, mid);
389 // Create and Insert Oid 4
390 size = sizeof(objheader_t) + classsize[3] ;
391 header = (objheader_t *) objstrAlloc(mainobjstore, size);
392 init_obj(header, 4, 3, 1, 0, NEW);
393 mhashInsert(header->oid, header);
394 mid = iptoMid("128.200.9.10");
395 lhashInsert(header->oid, mid);
397 // Create and Insert Oid 5
398 size = sizeof(objheader_t) + classsize[0] ;
399 header = (objheader_t *) objstrAlloc(mainobjstore, size);
400 init_obj(header, 5, 0, 1, 0, NEW);
401 mhashInsert(header->oid, header);
402 mid = iptoMid("128.200.9.10");
403 lhashInsert(header->oid, mid);
405 // Create and Insert Oid 6
406 size = sizeof(objheader_t) + classsize[1] ;
407 header = (objheader_t *) objstrAlloc(mainobjstore, size);
408 init_obj(header, 6, 1, 1, 0, NEW);
409 mhashInsert(header->oid, header);
410 mid = iptoMid("128.200.9.10");
411 lhashInsert(header->oid, mid);
413 //read object 1(present in local machine)
414 if((h1 = transRead(myTrans, 1)) == NULL){
415 printf("Object not found\n");
417 //read object 2present in local machine)
418 if((h2 = transRead(myTrans, 2)) == NULL) {
419 printf("Object not found\n");
421 //read object 3(present in local machine)
422 if((h3 = transRead(myTrans, 3)) == NULL) {
423 printf("Object not found\n");
425 //read object 31 (present in d-1. eecs)
426 if((h4 = transRead(myTrans, 31)) == NULL) {
427 printf("Object not found\n");
429 //read object 20 (present in d-2. eecs)
430 if((h5 = transRead(myTrans, 20)) == NULL) {
431 printf("Object not found\n");
434 transCommit(myTrans);
436 pthread_join(thread_Listen, NULL);