2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #include <sys/types.h>
23 #include <netinet/in.h>
42 struct ubik_dbase *dbase;
46 struct rx_connection *rxconn;
49 struct ubik_trans *tt;
52 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
55 printf("about to set lock\n");
56 /* now set database locks. Must do this or people may read uncommitted
57 data. Note that we're just setting a lock at position 1, which is
58 this program's convention for locking the whole database */
59 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
60 printf("now have lock\n");
65 /* sleep for a little while to make it possible for us to test for some
68 tv.tv_sec = sleepTime;
70 IOMGR_Select(0, 0, 0, 0, &tv);
72 /* read the original value */
73 code = ubik_Read(tt, &temp, sizeof(afs_int32));
82 temp++; /* bump the value here */
83 /* reset the file pointer back to where it was before the read */
84 code = ubik_Seek(tt, 0, 0);
89 /* write the data back */
90 code = ubik_Write(tt, &temp, sizeof(afs_int32));
95 /* finally, we commit the transaction */
96 code = ubik_EndTrans(tt);
102 SAMPLE_Get(rxconn, gnumber)
103 struct rx_connection *rxconn;
106 afs_int32 code, temp;
107 struct ubik_trans *tt;
110 /* start with a read transaction, since we're only going to do read
111 operations in this transaction. */
112 code = ubik_BeginTrans(dbase, UBIK_READTRANS, &tt);
115 printf("about to set lock\n");
116 /* obtain a read lock, so we don't read data the other guy is writing */
117 code = ubik_SetLock(tt, 1, 1, LOCKREAD);
118 printf("now have lock\n");
123 /* sleep to allow races */
125 tv.tv_sec = sleepTime;
127 IOMGR_Select(0, 0, 0, 0, &tv);
130 code = ubik_Read(tt, &temp, sizeof(afs_int32));
132 /* premature eof, use 0 */
140 /* end the transaction, automatically releasing locks */
141 code = ubik_EndTrans(tt);
146 SAMPLE_QGet(rxconn, gnumber)
147 struct rx_connection *rxconn;
150 afs_int32 code, temp;
151 struct ubik_trans *tt;
154 /* start with a read transaction, since we're only going to do read
155 operations in this transaction. */
156 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
159 printf("about to set lock\n");
160 /* obtain a read lock, so we don't read data the other guy is writing */
161 code = ubik_SetLock(tt, 1, 1, LOCKREAD);
162 printf("now have lock\n");
167 /* sleep to allow races */
169 tv.tv_sec = sleepTime;
171 IOMGR_Select(0, 0, 0, 0, &tv);
174 code = ubik_Read(tt, &temp, sizeof(afs_int32));
176 /* premature eof, use 0 */
184 /* end the transaction, automatically releasing locks */
185 code = ubik_EndTrans(tt);
191 struct rx_connection *rxconn;
194 struct ubik_trans *tt;
197 /* truncation operation requires a write transaction, too */
198 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
199 if (code) return code;
200 printf("about to set lock\n");
201 /* lock the database */
202 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
203 printf("now have lock\n");
209 tv.tv_sec = sleepTime;
211 IOMGR_Select(0, 0, 0, 0, &tv);
213 /* shrink the file */
214 code = ubik_Truncate(tt, 0);
220 code = ubik_EndTrans(tt);
226 struct rx_connection *rxconn;
228 afs_int32 code, temp;
229 struct ubik_trans *tt;
232 /* first start a new transaction. Must be a write transaction since
233 we're going to change some data (with ubik_Write) */
234 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
235 if (code) return code;
236 printf("about to set lock\n");
237 /* now set database locks. Must do this or people may read uncommitted
238 data. Note that we're just setting a lock at position 1, which is
239 this program's convention for locking the whole database */
240 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
241 printf("now have lock\n");
246 /* sleep for a little while to make it possible for us to test for some
249 tv.tv_sec = sleepTime;
251 IOMGR_Select(0, 0, 0, 0, &tv);
253 /* read the original value */
254 code = ubik_Read(tt, &temp, sizeof(afs_int32));
256 printf("short read, using 0\n");
263 ubik_AbortTrans(tt); /* surprise! pretend something went wrong */
268 #include "AFS_component_version_number.c"
273 register afs_int32 code, i;
274 afs_int32 serverList[MAXSERVERS];
276 struct rx_service *tservice;
277 struct rx_securityClass *sc[2];
278 extern int SAMPLE_ExecuteRequest();
279 char dbfileName[128];
282 printf("usage: userver -servers <serverlist> {-sleep <sleeptime>}\n");
286 /* initialize winsock */
287 if (afs_winsockInit()<0)
290 /* parse our own local arguments */
292 for(i=1;i<argc;i++) {
293 if (strcmp(argv[i], "-sleep")==0) {
295 printf("missing time in -sleep argument\n");
298 sleepTime = atoi(argv[i+1]);
302 /* call routine to parse command line -servers switch, filling in
303 myHost and serverList arrays appropriately */
304 code = ubik_ParseServerList(argc, argv, &myHost, serverList);
306 printf("could not parse server list, code %d\n", code);
309 /* call ServerInit with the values from ParseServerList. Also specify the
310 * name to use for the database files (/tmp/testdb), and the port (3000)
311 * for RPC requests. ServerInit returns a pointer to the database (in
312 * dbase), which is required for creating new transactions */
314 sprintf(dbfileName, "%s/testdb", gettmpdir());
316 code = ubik_ServerInit (myHost, htons(3000), serverList, dbfileName,
320 printf("ubik init failed with code %d\n", code);
324 sc[0] = rxnull_NewServerSecurityObject();
326 sc[1] = rxvab_NewServerSecurityObject("applexx", 0);
328 tservice = rx_NewService(0, USER_SERVICE_ID, "Sample", sc, 1/*2*/,
329 SAMPLE_ExecuteRequest);
330 if (tservice == (struct rx_service *)0) {
331 printf("Could not create SAMPLE rx service\n");
334 rx_SetMinProcs(tservice, 2);
335 rx_SetMaxProcs(tservice, 3);
337 rx_StartServer(1); /* Why waste this idle process?? */