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.29"); //d-3.eecs.uci.edu
188 lhashInsert(20, mid);
189 lhashInsert(21, mid);
190 lhashInsert(22, mid);
192 mid = iptoMid("128.200.9.30"); //d-4.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);
199 //Check if machine d-4 is up and running
200 checkServer(mid, "128.200.9.30");
201 mid = iptoMid("128.200.9.29");
202 //Check if machine d-3 is up and running
203 checkServer(mid, "128.200.9.29");
206 myTrans = transStart();
208 //read object 1(present in local machine)
209 if((h1 = transRead(myTrans, 1)) == NULL){
210 printf("Object not found\n");
212 //read object 2present in local machine)
213 if((h2 = transRead(myTrans, 2)) == NULL) {
214 printf("Object not found\n");
216 //read object 3(present in local machine)
217 if((h3 = transRead(myTrans, 3)) == NULL) {
218 printf("Object not found\n");
221 // Commit transaction
222 transCommit(myTrans);
224 pthread_join(thread_Listen, NULL);
229 //Commit transaction with few locally available objects and other objects from machine d-1
233 unsigned int val, mid;
234 transrecord_t *myTrans;
237 pthread_t thread_Listen;
239 objheader_t *h1, *h2, *h3, *h4;//h1,h2 from local ; h3 from d-1 , h-4 from d-2
242 pthread_attr_init(&attr);
243 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
245 // Create and Insert Oid 1
246 size = sizeof(objheader_t) + classsize[0] ;
247 header = (objheader_t *) objstrAlloc(mainobjstore, size);
248 init_obj(header, 1, 0, 1, 0, NEW);
249 mhashInsert(header->oid, header);
250 mid = iptoMid("128.200.9.10");
251 lhashInsert(header->oid, mid);
253 // Create and Insert Oid 2
254 size = sizeof(objheader_t) + classsize[1] ;
255 header = (objheader_t *) objstrAlloc(mainobjstore, size);
256 init_obj(header, 2, 1, 1, 0, NEW);
257 mhashInsert(header->oid, header);
258 mid = iptoMid("128.200.9.10");
259 lhashInsert(header->oid, mid);
262 // Create and Insert Oid 3
263 size = sizeof(objheader_t) + classsize[2] ;
264 header = (objheader_t *) objstrAlloc(mainobjstore, size);
265 init_obj(header, 3, 2, 1, 0, NEW);
266 mhashInsert(header->oid, header);
267 mid = iptoMid("128.200.9.10");
268 lhashInsert(header->oid, mid);
270 // Create and Insert Oid 4
271 size = sizeof(objheader_t) + classsize[3] ;
272 header = (objheader_t *) objstrAlloc(mainobjstore, size);
273 init_obj(header, 4, 3, 1, 0, NEW);
274 mhashInsert(header->oid, header);
275 mid = iptoMid("128.200.9.10");
276 lhashInsert(header->oid, mid);
278 //Inserting into lhashtable
279 mid = iptoMid("128.200.9.29"); //d-3.eecs.uci.edu
280 lhashInsert(20, mid);
281 lhashInsert(21, mid);
282 lhashInsert(22, mid);
284 mid = iptoMid("128.200.9.30"); //d-4.eecs.uci.edu
285 //Inserting into lhashtable
286 lhashInsert(31, mid);
287 lhashInsert(32, mid);
288 lhashInsert(33, mid);
290 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
291 //Check if machine d-4 is up and running
292 checkServer(mid, "128.200.9.30");
293 mid = iptoMid("128.200.9.29");
294 //Check if machine d-3 is up and running
295 checkServer(mid, "128.200.9.29");
298 myTrans = transStart();
300 //read object 1(present in local machine)
301 if((h1 = transRead(myTrans, 2)) == NULL){
302 printf("Object not found\n");
305 //read object 2present in local machine)
306 if((h2 = transRead(myTrans, 1)) == NULL) {
307 printf("Object not found\n");
309 //read object 31(present in d-4 machine)
310 if((h3 = transRead(myTrans, 31)) == NULL) {
311 printf("Object not found\n");
313 //read object 21(present in d-3 machine)
314 if((h4 = transRead(myTrans, 21)) == NULL) {
315 printf("Object not found\n");
318 // Commit transaction
319 transCommit(myTrans);
321 pthread_join(thread_Listen, NULL);
327 unsigned int val, mid;
328 transrecord_t *myTrans;
331 pthread_t thread_Listen;
333 objheader_t *h1, *h2, *h3, *h4, *h5;
336 pthread_attr_init(&attr);
337 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
339 mid = iptoMid("128.200.9.27"); //d-2.eecs.uci.edu
340 //Inserting into lhashtable
341 lhashInsert(20, mid);
342 lhashInsert(21, mid);
343 lhashInsert(22, mid);
345 mid = iptoMid("128.200.9.26"); //d-1.eecs.uci.edu
346 //Inserting into lhashtable
347 lhashInsert(31, mid);
348 lhashInsert(32, mid);
349 lhashInsert(33, mid);
350 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
352 printf("DEBUG -> mid = %d\n", mid);
353 checkServer(mid, "128.200.9.26");
354 mid = iptoMid("128.200.9.27");
355 printf("DEBUG -> mid = %d\n", mid);
356 checkServer(mid, "128.200.9.27");
359 myTrans = transStart();
361 // Create and Insert Oid 1
362 size = sizeof(objheader_t) + classsize[0] ;
363 header = (objheader_t *) objstrAlloc(mainobjstore, size);
364 init_obj(header, 1, 0, 1, 0, NEW);
365 mhashInsert(header->oid, header);
366 mid = iptoMid("128.200.9.10");
367 lhashInsert(header->oid, mid);
369 // Create and Insert Oid 2
370 size = sizeof(objheader_t) + classsize[1] ;
371 header = (objheader_t *) objstrAlloc(mainobjstore, size);
372 init_obj(header, 2, 1, 1, 0, NEW);
373 mhashInsert(header->oid, header);
374 mid = iptoMid("128.200.9.10");
375 lhashInsert(header->oid, mid);
378 // Create and Insert Oid 3
379 size = sizeof(objheader_t) + classsize[2] ;
380 header = (objheader_t *) objstrAlloc(mainobjstore, size);
381 init_obj(header, 3, 2, 1, 0, NEW);
382 mhashInsert(header->oid, header);
383 mid = iptoMid("128.200.9.10");
384 lhashInsert(header->oid, mid);
386 // Create and Insert Oid 4
387 size = sizeof(objheader_t) + classsize[3] ;
388 header = (objheader_t *) objstrAlloc(mainobjstore, size);
389 init_obj(header, 4, 3, 1, 0, NEW);
390 mhashInsert(header->oid, header);
391 mid = iptoMid("128.200.9.10");
392 lhashInsert(header->oid, mid);
394 // Create and Insert Oid 5
395 size = sizeof(objheader_t) + classsize[0] ;
396 header = (objheader_t *) objstrAlloc(mainobjstore, size);
397 init_obj(header, 5, 0, 1, 0, NEW);
398 mhashInsert(header->oid, header);
399 mid = iptoMid("128.200.9.10");
400 lhashInsert(header->oid, mid);
402 // Create and Insert Oid 6
403 size = sizeof(objheader_t) + classsize[1] ;
404 header = (objheader_t *) objstrAlloc(mainobjstore, size);
405 init_obj(header, 6, 1, 1, 0, NEW);
406 mhashInsert(header->oid, header);
407 mid = iptoMid("128.200.9.10");
408 lhashInsert(header->oid, mid);
410 //read object 1(present in local machine)
411 if((h1 = transRead(myTrans, 1)) == NULL){
412 printf("Object not found\n");
414 //read object 2present in local machine)
415 if((h2 = transRead(myTrans, 2)) == NULL) {
416 printf("Object not found\n");
418 //read object 3(present in local machine)
419 if((h3 = transRead(myTrans, 3)) == NULL) {
420 printf("Object not found\n");
422 //read object 31 (present in d-1. eecs)
423 if((h4 = transRead(myTrans, 31)) == NULL) {
424 printf("Object not found\n");
426 //read object 20 (present in d-2. eecs)
427 if((h5 = transRead(myTrans, 20)) == NULL) {
428 printf("Object not found\n");
431 transCommit(myTrans);
433 pthread_join(thread_Listen, NULL);