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>
17 #include <sys/types.h>
24 #include <netinet/in.h>
43 struct ubik_dbase *dbase;
47 struct rx_connection *rxconn;
50 struct ubik_trans *tt;
53 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
56 printf("about to set lock\n");
57 /* now set database locks. Must do this or people may read uncommitted
58 * data. Note that we're just setting a lock at position 1, which is
59 * this program's convention for locking the whole database */
60 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
61 printf("now have lock\n");
66 /* sleep for a little while to make it possible for us to test for some
69 tv.tv_sec = sleepTime;
71 IOMGR_Select(0, 0, 0, 0, &tv);
73 /* read the original value */
74 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 */
139 /* end the transaction, automatically releasing locks */
140 code = ubik_EndTrans(tt);
145 SAMPLE_QGet(rxconn, gnumber)
146 struct rx_connection *rxconn;
149 afs_int32 code, temp;
150 struct ubik_trans *tt;
153 /* start with a read transaction, since we're only going to do read
154 * operations in this transaction. */
155 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
158 printf("about to set lock\n");
159 /* obtain a read lock, so we don't read data the other guy is writing */
160 code = ubik_SetLock(tt, 1, 1, LOCKREAD);
161 printf("now have lock\n");
166 /* sleep to allow races */
168 tv.tv_sec = sleepTime;
170 IOMGR_Select(0, 0, 0, 0, &tv);
173 code = ubik_Read(tt, &temp, sizeof(afs_int32));
175 /* premature eof, use 0 */
182 /* end the transaction, automatically releasing locks */
183 code = ubik_EndTrans(tt);
189 struct rx_connection *rxconn;
192 struct ubik_trans *tt;
195 /* truncation operation requires a write transaction, too */
196 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
199 printf("about to set lock\n");
200 /* lock the database */
201 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
202 printf("now have lock\n");
208 tv.tv_sec = sleepTime;
210 IOMGR_Select(0, 0, 0, 0, &tv);
212 /* shrink the file */
213 code = ubik_Truncate(tt, 0);
219 code = ubik_EndTrans(tt);
225 struct rx_connection *rxconn;
227 afs_int32 code, temp;
228 struct ubik_trans *tt;
231 /* first start a new transaction. Must be a write transaction since
232 * we're going to change some data (with ubik_Write) */
233 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
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");
262 ubik_AbortTrans(tt); /* surprise! pretend something went wrong */
267 #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());
317 ubik_ServerInit(myHost, htons(3000), serverList, dbfileName, &dbase);
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?? */