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) {
54 transrecord_t *myTrans;
55 pthread_t thread_Listen;
58 pthread_create(&thread_Listen, NULL, dstmListen, NULL);
60 myTrans = transStart();
62 printf("Creating Transaction\n");
64 if((val = createObjects(myTrans, 0)) != 0) {
65 printf("Error transCreateObj1");
68 if((val = createObjects(myTrans, 1)) != 0) {
69 printf("Error transCreateObj2");
72 if((val = createObjects(myTrans, 2)) != 0) {
73 printf("Error transCreateObj3");
76 if((val = createObjects(myTrans, 3)) != 0) {
77 printf("Error transCreateObj4");
80 if((val = createObjects(myTrans, 0)) != 0) {
81 printf("Error transCreateObj5");
84 if((val = createObjects(myTrans, 1)) != 0) {
85 printf("Error transCreateObj6");
87 pthread_join(thread_Listen, NULL);
93 unsigned int val, mid;
94 transrecord_t *myTrans;
95 pthread_t thread_Listen;
98 mid = iptoMid("128.200.9.27"); //d-2.eecs.uci.edu
99 //Inserting into lhashtable
100 lhashInsert(20, mid);
101 lhashInsert(21, mid);
102 lhashInsert(22, mid);
103 lhashInsert(23, mid);
104 lhashInsert(30, mid);
105 lhashInsert(28, mid);
106 lhashInsert(29, mid);
107 pthread_create(&thread_Listen, NULL, dstmListen, NULL);
109 myTrans = transStart();
111 printf("Creating Transaction\n");
113 if((val = createObjects(myTrans, 0)) != 0) {
114 printf("Error transCreateObj1");
117 if((val = createObjects(myTrans, 1)) != 0) {
118 printf("Error transCreateObj2");
121 if((val = createObjects(myTrans, 2)) != 0) {
122 printf("Error transCreateObj3");
125 if((val = createObjects(myTrans, 3)) != 0) {
126 printf("Error transCreateObj4");
129 if((val = createObjects(myTrans, 0)) != 0) {
130 printf("Error transCreateObj5");
133 if((val = createObjects(myTrans, 1)) != 0) {
134 printf("Error transCreateObj6");
136 pthread_join(thread_Listen, NULL);
141 unsigned int val, mid;
142 transrecord_t *myTrans;
145 pthread_t thread_Listen;
147 objheader_t *h1, *h2, *h3, *h4, *h5;
150 pthread_attr_init(&attr);
151 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
153 mid = iptoMid("128.200.9.27"); //d-2.eecs.uci.edu
154 //Inserting into lhashtable
155 lhashInsert(20, mid);
156 lhashInsert(21, mid);
157 lhashInsert(22, mid);
159 mid = iptoMid("128.200.9.26"); //d-1.eecs.uci.edu
160 //Inserting into lhashtable
161 lhashInsert(31, mid);
162 lhashInsert(32, mid);
163 lhashInsert(33, mid);
164 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
165 // pthread_create(&thread_Listen, NULL, dstmListen, NULL);
167 printf("DEBUG -> mid = %d\n", mid);
168 checkServer(mid, "128.200.9.26");
169 mid = iptoMid("128.200.9.27");
170 printf("DEBUG -> mid = %d\n", mid);
171 checkServer(mid, "128.200.9.27");
174 myTrans = transStart();
177 if((val = createObjects(myTrans, 0)) != 0) {
178 printf("Error transCreateObj1");
181 if((val = createObjects(myTrans, 1)) != 0) {
182 printf("Error transCreateObj2");
185 if((val = createObjects(myTrans, 2)) != 0) {
186 printf("Error transCreateObj3");
189 if((val = createObjects(myTrans, 3)) != 0) {
190 printf("Error transCreateObj4");
193 if((val = createObjects(myTrans, 0)) != 0) {
194 printf("Error transCreateObj5");
197 if((val = createObjects(myTrans, 1)) != 0) {
198 printf("Error transCreateObj6");
202 // Create and Insert Oid 1
203 size = sizeof(objheader_t) + classsize[0] ;
204 header = (objheader_t *) objstrAlloc(mainobjstore, size);
205 init_obj(header, 1, 0, 1, 0, NEW);
206 mhashInsert(header->oid, header);
207 mid = iptoMid("128.200.9.10");
208 lhashInsert(header->oid, mid);
210 // Create and Insert Oid 2
211 size = sizeof(objheader_t) + classsize[1] ;
212 header = (objheader_t *) objstrAlloc(mainobjstore, size);
213 init_obj(header, 2, 1, 1, 0, NEW);
214 mhashInsert(header->oid, header);
215 mid = iptoMid("128.200.9.10");
216 lhashInsert(header->oid, mid);
219 // Create and Insert Oid 3
220 size = sizeof(objheader_t) + classsize[2] ;
221 header = (objheader_t *) objstrAlloc(mainobjstore, size);
222 init_obj(header, 3, 2, 1, 0, NEW);
223 mhashInsert(header->oid, header);
224 mid = iptoMid("128.200.9.10");
225 lhashInsert(header->oid, mid);
227 // Create and Insert Oid 4
228 size = sizeof(objheader_t) + classsize[3] ;
229 header = (objheader_t *) objstrAlloc(mainobjstore, size);
230 init_obj(header, 4, 3, 1, 0, NEW);
231 mhashInsert(header->oid, header);
232 mid = iptoMid("128.200.9.10");
233 lhashInsert(header->oid, mid);
235 // Create and Insert Oid 5
236 size = sizeof(objheader_t) + classsize[0] ;
237 header = (objheader_t *) objstrAlloc(mainobjstore, size);
238 init_obj(header, 5, 0, 1, 0, NEW);
239 mhashInsert(header->oid, header);
240 mid = iptoMid("128.200.9.10");
241 lhashInsert(header->oid, mid);
243 // Create and Insert Oid 6
244 size = sizeof(objheader_t) + classsize[1] ;
245 header = (objheader_t *) objstrAlloc(mainobjstore, size);
246 init_obj(header, 6, 1, 1, 0, NEW);
247 mhashInsert(header->oid, header);
248 mid = iptoMid("128.200.9.10");
249 lhashInsert(header->oid, mid);
251 //read object 1(present in local machine)
252 if((h1 = transRead(myTrans, 1)) == NULL){
253 printf("Object not found\n");
255 //read object 2present in local machine)
256 if((h2 = transRead(myTrans, 2)) == NULL) {
257 printf("Object not found\n");
259 //read object 3(present in local machine)
260 if((h3 = transRead(myTrans, 3)) == NULL) {
261 printf("Object not found\n");
263 //read object 31 (present in d-1. eecs)
264 if((h4 = transRead(myTrans, 31)) == NULL) {
265 printf("Object not found\n");
267 //read object 20 (present in d-2. eecs)
268 if((h5 = transRead(myTrans, 20)) == NULL) {
269 printf("Object not found\n");
272 transCommit(myTrans);
274 pthread_join(thread_Listen, NULL);