4 extern objstr_t *mainobjstore;
5 int classsize[]={sizeof(int),sizeof(char),sizeof(short), sizeof(void *)};
15 void init_obj(objheader_t *h, unsigned int oid, unsigned short type, \
16 unsigned short version,\
17 unsigned short rcount, char status) {
26 //Test case to create objects and do nothing else
28 unsigned int val, mid;
30 transrecord_t *myTrans;
32 pthread_t thread_Listen;
36 pthread_attr_init(&attr);
37 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
39 //Create and Insert Oid 31
40 size = sizeof(objheader_t) + classsize[2] ;
41 header = (objheader_t *) objstrAlloc(mainobjstore, size);
42 init_obj(header, 31, 2, 1, 0, NEW);
43 mhashInsert(header->oid, header);
44 mid = iptoMid("128.195.175.69");
45 lhashInsert(header->oid, mid);
47 //Create and Insert Oid 32
48 size = sizeof(objheader_t) + classsize[1] ;
49 header = (objheader_t *) objstrAlloc(mainobjstore, size);
50 init_obj(header, 32, 1, 1, 0, NEW);
51 mhashInsert(header->oid, header);
52 mid = iptoMid("128.195.175.69");
53 lhashInsert(header->oid, mid);
55 //Create and Insert Oid 33
56 size = sizeof(objheader_t) + classsize[0] ;
57 header = (objheader_t *) objstrAlloc(mainobjstore, size);
58 init_obj(header, 33, 0, 1, 0, NEW);
59 mhashInsert(header->oid, header);
60 mid = iptoMid("128.195.175.69");
61 lhashInsert(header->oid, mid);
63 //Inserting into lhashtable into d-3.eecs
64 mid = iptoMid("128.200.9.29"); //d-3.eecs.uci.edu
69 mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
70 //Inserting into lhashtable of demsky.eecs
76 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
77 //Check if machine demsky is up and running
78 checkServer(mid, "128.200.9.10");
79 mid = iptoMid("128.200.9.29");
80 //Check if machine d-3 is up and running
81 checkServer(mid, "128.200.9.29");
83 pthread_join(thread_Listen, NULL);
88 //Read objects from remote and local machines ; NOTE objects are all available
91 unsigned int val, mid;
93 transrecord_t *myTrans;
94 objheader_t *header, *h1, *h2, *h3, *h4;
95 pthread_t thread_Listen;
99 pthread_attr_init(&attr);
100 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
102 //Create and Insert Oid 31
103 size = sizeof(objheader_t) + classsize[2] ;
104 header = (objheader_t *) objstrAlloc(mainobjstore, size);
105 init_obj(header, 31, 2, 1, 0, NEW);
106 mhashInsert(header->oid, header);
107 mid = iptoMid("128.195.175.69");
108 lhashInsert(header->oid, mid);
110 //Create and Insert Oid 32
111 size = sizeof(objheader_t) + classsize[1] ;
112 header = (objheader_t *) objstrAlloc(mainobjstore, size);
113 init_obj(header, 32, 1, 1, 0, NEW);
114 mhashInsert(header->oid, header);
115 mid = iptoMid("128.195.175.69");
116 lhashInsert(header->oid, mid);
118 //Create and Insert Oid 33
119 size = sizeof(objheader_t) + classsize[0] ;
120 header = (objheader_t *) objstrAlloc(mainobjstore, size);
121 init_obj(header, 33, 0, 1, 0, NEW);
122 mhashInsert(header->oid, header);
123 mid = iptoMid("128.195.175.69");
124 lhashInsert(header->oid, mid);
126 //Inserting into lhashtable into d-3.eecs
127 mid = iptoMid("128.200.9.29"); //d-3.eecs.uci.edu
128 lhashInsert(20, mid);
129 lhashInsert(21, mid);
130 lhashInsert(22, mid);
132 mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
133 //Inserting into lhashtable of demsky.eecs
139 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
141 //Check if machine demsky is up and running
142 checkServer(mid, "128.200.9.10");
143 mid = iptoMid("128.200.9.29");
144 //Check if machine d-2 is up and running
145 checkServer(mid, "128.200.9.29");
148 myTrans = transStart();
150 //read object 1 (found on demksy)
151 if((h1 = transRead(myTrans, 1)) == NULL){
152 printf("Object not found\n");
155 //read object 33 (found on local)
156 if((h2 = transRead(myTrans, 33)) == NULL){
157 printf("Object not found\n");
160 //read object 21 (found on d-3)
161 if((h3 = transRead(myTrans, 21)) == NULL){
162 printf("Object not found\n");
165 //read object 32 (found on local)
166 if((h4 = transRead(myTrans, 32)) == NULL){
167 printf("Object not found\n");
170 pthread_join(thread_Listen, NULL);
177 unsigned int val, mid;
179 transrecord_t *myTrans;
180 objheader_t *header, *h1, *h2, *h3;
181 pthread_t thread_Listen;
185 pthread_attr_init(&attr);
186 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
188 //Create and Insert Oid 31
189 size = sizeof(objheader_t) + classsize[2] ;
190 header = (objheader_t *) objstrAlloc(mainobjstore, size);
191 init_obj(header, 31, 2, 1, 0, NEW);
192 mhashInsert(header->oid, header);
193 mid = iptoMid("128.195.175.69");
194 lhashInsert(header->oid, mid);
196 //Create and Insert Oid 32
197 size = sizeof(objheader_t) + classsize[1] ;
198 header = (objheader_t *) objstrAlloc(mainobjstore, size);
199 init_obj(header, 32, 1, 1, 0, NEW);
200 mhashInsert(header->oid, header);
201 mid = iptoMid("128.195.175.69");
202 lhashInsert(header->oid, mid);
204 //Create and Insert Oid 33
205 size = sizeof(objheader_t) + classsize[0] ;
206 header = (objheader_t *) objstrAlloc(mainobjstore, size);
207 init_obj(header, 33, 0, 1, 0, NEW);
208 mhashInsert(header->oid, header);
209 mid = iptoMid("128.195.175.69");
210 lhashInsert(header->oid, mid);
212 //Inserting into lhashtable into d-3.eecs
213 mid = iptoMid("128.200.9.29"); //d-3.eecs.uci.edu
214 lhashInsert(20, mid);
215 lhashInsert(21, mid);
216 lhashInsert(22, mid);
218 mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
219 //Inserting into lhashtable of demsky.eecs
225 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
227 //Check if machine demsky is up and running
228 checkServer(mid, "128.200.9.10");
229 mid = iptoMid("128.200.9.29");
230 //Check if machine d-3 is up and running
231 checkServer(mid, "128.200.9.29");
234 myTrans = transStart();
236 //read object 4 (found on demksy)
237 if((h1 = transRead(myTrans, 4)) == NULL){
238 printf("Object not found\n");
240 //read object 33 (found on local)
241 if((h2 = transRead(myTrans, 33)) == NULL){
242 printf("Object not found\n");
244 //read object 20 (found on d-3)
245 if((h3 = transRead(myTrans, 20)) == NULL){
246 printf("Object not found\n");
250 transCommit(myTrans);
252 pthread_join(thread_Listen, NULL);
256 //Commit transaction for some objects that are available and some that are
257 //not available anywhere
259 unsigned int val, mid;
261 transrecord_t *myTrans;
262 objheader_t *header, *h1, *h2, *h3, *h4;
263 pthread_t thread_Listen;
267 pthread_attr_init(&attr);
268 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
270 //Create and Insert Oid 31
271 size = sizeof(objheader_t) + classsize[2] ;
272 header = (objheader_t *) objstrAlloc(mainobjstore, size);
273 init_obj(header, 31, 2, 1, 0, NEW);
274 mhashInsert(header->oid, header);
275 mid = iptoMid("128.195.175.69");
276 lhashInsert(header->oid, mid);
278 //Create and Insert Oid 32
279 size = sizeof(objheader_t) + classsize[1] ;
280 header = (objheader_t *) objstrAlloc(mainobjstore, size);
281 init_obj(header, 32, 1, 1, 0, NEW);
282 mhashInsert(header->oid, header);
283 mid = iptoMid("128.195.175.69");
284 lhashInsert(header->oid, mid);
286 //Create and Insert Oid 33
287 size = sizeof(objheader_t) + classsize[0] ;
288 header = (objheader_t *) objstrAlloc(mainobjstore, size);
289 init_obj(header, 33, 0, 1, 0, NEW);
290 mhashInsert(header->oid, header);
291 mid = iptoMid("128.195.175.69");
292 lhashInsert(header->oid, mid);
294 //Inserting into lhashtable into d-3.eecs
295 mid = iptoMid("128.200.9.29"); //d-3.eecs.uci.edu
296 lhashInsert(20, mid);
297 lhashInsert(21, mid);
298 lhashInsert(22, mid);
300 mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
301 //Inserting into lhashtable of demsky.eecs
307 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
309 //Check if machine demsky is up and running
310 checkServer(mid, "128.200.9.10");
311 mid = iptoMid("128.200.9.29");
312 //Check if machine d-2 is up and running
313 checkServer(mid, "128.200.9.29");
316 myTrans = transStart();
318 //read object 4 (found on demksy)
319 if((h1 = transRead(myTrans, 4)) == NULL){
320 printf("Object not found\n");
322 //read object 33 (found on local)
323 if((h2 = transRead(myTrans, 33)) == NULL){
324 printf("Object not found\n");
326 //read object 24 (found nowhere)
327 if((h3 = transRead(myTrans, 24)) == NULL){
328 printf("Object not found\n");
330 //read object 50 (found nowhere)
331 if((h4 = transRead(myTrans, 50)) == NULL){
332 printf("Object not found\n");
336 if((h1 != NULL) && (h2 != NULL) && (h3 != NULL) && (h4 !=NULL))
337 transCommit(myTrans);
339 printf("Cannot complete this transaction\n");
341 pthread_join(thread_Listen, NULL);