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>
37 struct ubik_dbase *dbase;
41 struct rx_connection *rxconn;
44 struct ubik_trans *tt;
47 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
50 printf("about to set lock\n");
51 /* now set database locks. Must do this or people may read uncommitted
52 * data. Note that we're just setting a lock at position 1, which is
53 * this program's convention for locking the whole database */
54 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
55 printf("now have lock\n");
60 /* sleep for a little while to make it possible for us to test for some
63 tv.tv_sec = sleepTime;
65 IOMGR_Select(0, 0, 0, 0, &tv);
67 /* read the original value */
68 code = ubik_Read(tt, &temp, sizeof(afs_int32));
76 temp++; /* bump the value here */
77 /* reset the file pointer back to where it was before the read */
78 code = ubik_Seek(tt, 0, 0);
83 /* write the data back */
84 code = ubik_Write(tt, &temp, sizeof(afs_int32));
89 /* finally, we commit the transaction */
90 code = ubik_EndTrans(tt);
96 SAMPLE_Get(rxconn, gnumber)
97 struct rx_connection *rxconn;
100 afs_int32 code, temp;
101 struct ubik_trans *tt;
104 /* start with a read transaction, since we're only going to do read
105 * operations in this transaction. */
106 code = ubik_BeginTrans(dbase, UBIK_READTRANS, &tt);
109 printf("about to set lock\n");
110 /* obtain a read lock, so we don't read data the other guy is writing */
111 code = ubik_SetLock(tt, 1, 1, LOCKREAD);
112 printf("now have lock\n");
117 /* sleep to allow races */
119 tv.tv_sec = sleepTime;
121 IOMGR_Select(0, 0, 0, 0, &tv);
124 code = ubik_Read(tt, &temp, sizeof(afs_int32));
126 /* premature eof, use 0 */
133 /* end the transaction, automatically releasing locks */
134 code = ubik_EndTrans(tt);
139 SAMPLE_QGet(rxconn, gnumber)
140 struct rx_connection *rxconn;
143 afs_int32 code, temp;
144 struct ubik_trans *tt;
147 /* start with a read transaction, since we're only going to do read
148 * operations in this transaction. */
149 code = ubik_BeginTransReadAny(dbase, UBIK_READTRANS, &tt);
152 printf("about to set lock\n");
153 /* obtain a read lock, so we don't read data the other guy is writing */
154 code = ubik_SetLock(tt, 1, 1, LOCKREAD);
155 printf("now have lock\n");
160 /* sleep to allow races */
162 tv.tv_sec = sleepTime;
164 IOMGR_Select(0, 0, 0, 0, &tv);
167 code = ubik_Read(tt, &temp, sizeof(afs_int32));
169 /* premature eof, use 0 */
176 /* end the transaction, automatically releasing locks */
177 code = ubik_EndTrans(tt);
183 struct rx_connection *rxconn;
186 struct ubik_trans *tt;
189 /* truncation operation requires a write transaction, too */
190 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
193 printf("about to set lock\n");
194 /* lock the database */
195 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
196 printf("now have lock\n");
202 tv.tv_sec = sleepTime;
204 IOMGR_Select(0, 0, 0, 0, &tv);
206 /* shrink the file */
207 code = ubik_Truncate(tt, 0);
213 code = ubik_EndTrans(tt);
219 struct rx_connection *rxconn;
221 afs_int32 code, temp;
222 struct ubik_trans *tt;
225 /* first start a new transaction. Must be a write transaction since
226 * we're going to change some data (with ubik_Write) */
227 code = ubik_BeginTrans(dbase, UBIK_WRITETRANS, &tt);
230 printf("about to set lock\n");
231 /* now set database locks. Must do this or people may read uncommitted
232 * data. Note that we're just setting a lock at position 1, which is
233 * this program's convention for locking the whole database */
234 code = ubik_SetLock(tt, 1, 1, LOCKWRITE);
235 printf("now have lock\n");
240 /* sleep for a little while to make it possible for us to test for some
243 tv.tv_sec = sleepTime;
245 IOMGR_Select(0, 0, 0, 0, &tv);
247 /* read the original value */
248 code = ubik_Read(tt, &temp, sizeof(afs_int32));
250 printf("short read, using 0\n");
256 ubik_AbortTrans(tt); /* surprise! pretend something went wrong */
261 #include "AFS_component_version_number.c"
267 register afs_int32 code, i;
268 afs_int32 serverList[MAXSERVERS];
270 struct rx_service *tservice;
271 struct rx_securityClass *sc[2];
272 extern int SAMPLE_ExecuteRequest();
273 char dbfileName[128];
276 printf("usage: userver -servers <serverlist> {-sleep <sleeptime>}\n");
280 /* initialize winsock */
281 if (afs_winsockInit() < 0)
284 /* parse our own local arguments */
286 for (i = 1; i < argc; i++) {
287 if (strcmp(argv[i], "-sleep") == 0) {
289 printf("missing time in -sleep argument\n");
292 sleepTime = atoi(argv[i + 1]);
296 /* call routine to parse command line -servers switch, filling in
297 * myHost and serverList arrays appropriately */
298 code = ubik_ParseServerList(argc, argv, &myHost, serverList);
300 printf("could not parse server list, code %d\n", code);
303 /* call ServerInit with the values from ParseServerList. Also specify the
304 * name to use for the database files (/tmp/testdb), and the port (3000)
305 * for RPC requests. ServerInit returns a pointer to the database (in
306 * dbase), which is required for creating new transactions */
308 sprintf(dbfileName, "%s/testdb", gettmpdir());
311 ubik_ServerInit(myHost, htons(3000), serverList, dbfileName, &dbase);
314 printf("ubik init failed with code %d\n", code);
318 sc[0] = rxnull_NewServerSecurityObject();
320 sc[1] = rxvab_NewServerSecurityObject("applexx", 0);
322 tservice = rx_NewService(0, USER_SERVICE_ID, "Sample", sc, 1 /*2 */ ,
323 SAMPLE_ExecuteRequest);
324 if (tservice == (struct rx_service *)0) {
325 printf("Could not create SAMPLE rx service\n");
328 rx_SetMinProcs(tservice, 2);
329 rx_SetMaxProcs(tservice, 3);
331 rx_StartServer(1); /* Why waste this idle process?? */