diff options
author | Keith Bostic <keith@wiredtiger.com> | 2012-03-10 11:58:54 -0500 |
---|---|---|
committer | Keith Bostic <keith@wiredtiger.com> | 2012-03-10 11:58:54 -0500 |
commit | 27c0f27a80d85f7152817d30b8bf3fb1572410ef (patch) | |
tree | 095091df59a238baf6407cbd67086d50b1982e7c | |
parent | 4b31f0f7c3289dd6b521c36d84dab02ca1317d1c (diff) | |
download | mongo-27c0f27a80d85f7152817d30b8bf3fb1572410ef.tar.gz |
Add the -S option to the test/thread program, that uses a new session
handle on every operation. This tests issue #178.
-rw-r--r-- | test/thread/run.c | 181 | ||||
-rw-r--r-- | test/thread/t.c | 12 | ||||
-rw-r--r-- | test/thread/thread.h | 1 |
3 files changed, 125 insertions, 69 deletions
diff --git a/test/thread/run.c b/test/thread/run.c index ee9f7b3d8b9..5df0060ce30 100644 --- a/test/thread/run.c +++ b/test/thread/run.c @@ -90,6 +90,32 @@ run(int readers, int writers) } /* + * reader_op -- + * Read operation. + */ +static inline void +reader_op(WT_CURSOR *cursor) +{ + WT_ITEM *key, _key; + u_int keyno; + int ret; + char keybuf[64]; + + key = &_key; + + keyno = r() % nkeys; + if (ftype == ROW) { + key->data = keybuf; + key->size = (uint32_t) + snprintf(keybuf, sizeof(keybuf), "%017u", keyno); + cursor->set_key(cursor, key); + } else + cursor->set_key(cursor, (uint32_t)keyno); + if ((ret = cursor->search(cursor)) != 0 && ret != WT_NOTFOUND) + die("cursor.search", ret); +} + +/* * reader -- * Reader thread start function. */ @@ -98,48 +124,90 @@ reader(void *arg) { STATS *s; WT_CURSOR *cursor; - WT_ITEM *key, _key; WT_SESSION *session; pthread_t tid; u_int i, keyno; int id, ret; - char keybuf[64]; id = (int)(uintptr_t)arg; tid = pthread_self(); printf(" read thread %2d starting: tid: %p\n", id, (void *)tid); sched_yield(); /* Get all the threads created. */ - key = &_key; s = &run_stats[id]; - if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) - die("conn.open_session", ret); - - if ((ret = - session->open_cursor(session, FNAME, NULL, NULL, &cursor)) != 0) - die("session.open_cursor", ret); - - for (i = 0; i < nops; ++i, ++s->reads, sched_yield()) { - keyno = r() % nkeys; - if (ftype == ROW) { - key->data = keybuf; - key->size = (uint32_t) - snprintf(keybuf, sizeof(keybuf), "%017u", keyno); - cursor->set_key(cursor, key); - } else - cursor->set_key(cursor, (uint32_t)keyno); - if ((ret = cursor->search(cursor)) != 0 && ret != WT_NOTFOUND) - die("cursor.search", ret); + if (session_per_op) { + for (i = 0; i < nops; ++i, ++s->reads, sched_yield()) { + if ((ret = conn->open_session( + conn, NULL, NULL, &session)) != 0) + die("conn.open_session", ret); + if ((ret = session->open_cursor( + session, FNAME, NULL, NULL, &cursor)) != 0) + die("session.open_cursor", ret); + reader_op(cursor); + if ((ret = session->close(session, NULL)) != 0) + die("session.close", ret); + } + } else { + if ((ret = conn->open_session( + conn, NULL, NULL, &session)) != 0) + die("conn.open_session", ret); + if ((ret = session->open_cursor( + session, FNAME, NULL, NULL, &cursor)) != 0) + die("session.open_cursor", ret); + for (i = 0; i < nops; ++i, ++s->reads, sched_yield()) + reader_op(cursor); + if ((ret = session->close(session, NULL)) != 0) + die("session.close", ret); } - if ((ret = session->close(session, NULL)) != 0) - die("session.close", ret); - return (NULL); } /* + * writer_op -- + * Write operation. + */ +static inline void +writer_op(WT_CURSOR *cursor, STATS *s) +{ + WT_ITEM *key, _key, *value, _value; + u_int keyno; + int ret; + char keybuf[64], valuebuf[64]; + + key = &_key; + value = &_value; + + keyno = r() % nkeys; + if (ftype == ROW) { + key->data = keybuf; + key->size = (uint32_t) + snprintf(keybuf, sizeof(keybuf), "%017u", keyno); + cursor->set_key(cursor, key); + } else + cursor->set_key(cursor, (uint32_t)keyno); + if (keyno % 5 == 0) { + ++s->remove; + if ((ret = + cursor->remove(cursor)) != 0 && ret != WT_NOTFOUND) + die("cursor.remove", ret); + } else { + ++s->update; + value->data = valuebuf; + if (ftype == FIX) + cursor->set_value(cursor, 0x10); + else { + value->size = (uint32_t)snprintf( + valuebuf, sizeof(valuebuf), "XXX %37u", keyno); + cursor->set_value(cursor, value); + } + if ((ret = cursor->update(cursor)) != 0) + die("cursor.update", ret); + } +} + +/* * writer -- * Writer thread start function. */ @@ -148,62 +216,43 @@ writer(void *arg) { STATS *s; WT_CURSOR *cursor; - WT_ITEM *key, _key, *value, _value; WT_SESSION *session; pthread_t tid; - u_int i, keyno; + u_int i; int id, ret; - char keybuf[64], valuebuf[64]; id = (int)(uintptr_t)arg; tid = pthread_self(); printf("write thread %2d starting: tid: %p\n", id, (void *)tid); sched_yield(); /* Get all the threads created. */ - key = &_key; - value = &_value; s = &run_stats[id]; - if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) - die("conn.open_session", ret); - - if ((ret = - session->open_cursor(session, FNAME, NULL, NULL, &cursor)) != 0) - die("session.open_cursor", ret); - - for (i = 0; i < nops; ++i, sched_yield()) { - keyno = r() % nkeys; - if (ftype == ROW) { - key->data = keybuf; - key->size = (uint32_t) - snprintf(keybuf, sizeof(keybuf), "%017u", keyno); - cursor->set_key(cursor, key); - } else - cursor->set_key(cursor, (uint32_t)keyno); - if (keyno % 5 == 0) { - ++s->remove; - if ((ret = - cursor->remove(cursor)) != 0 && ret != WT_NOTFOUND) - die("cursor.remove", ret); - } else { - ++s->update; - value->data = valuebuf; - if (ftype == FIX) - cursor->set_value(cursor, 0x10); - else { - value->size = (uint32_t) - snprintf(valuebuf, - sizeof(valuebuf), "XXX %37u", keyno); - cursor->set_value(cursor, value); - } - if ((ret = cursor->update(cursor)) != 0) - die("cursor.update", ret); + if (session_per_op) { + for (i = 0; i < nops; ++i, sched_yield()) { + if ((ret = conn->open_session( + conn, NULL, NULL, &session)) != 0) + die("conn.open_session", ret); + if ((ret = session->open_cursor( + session, FNAME, NULL, NULL, &cursor)) != 0) + die("session.open_cursor", ret); + writer_op(cursor, s); + if ((ret = session->close(session, NULL)) != 0) + die("session.close", ret); } + } else { + if ((ret = conn->open_session( + conn, NULL, NULL, &session)) != 0) + die("conn.open_session", ret); + if ((ret = session->open_cursor( + session, FNAME, NULL, NULL, &cursor)) != 0) + die("session.open_cursor", ret); + for (i = 0; i < nops; ++i, sched_yield()) + writer_op(cursor, s); + if ((ret = session->close(session, NULL)) != 0) + die("session.close", ret); } - if ((ret = session->close(session, NULL)) != 0) - die("session.close", ret); - return (NULL); } diff --git a/test/thread/t.c b/test/thread/t.c index 77eacffb8cc..764b6d54261 100644 --- a/test/thread/t.c +++ b/test/thread/t.c @@ -10,6 +10,7 @@ WT_CONNECTION *conn; /* WiredTiger connection */ __ftype ftype; /* File type */ u_int nkeys, nops; /* Keys, Operations */ +int session_per_op; /* New session per operation */ static char *progname; /* Program name */ static FILE *logfp; /* Log file */ @@ -38,9 +39,10 @@ main(int argc, char *argv[]) nops = 10000; readers = 10; runs = 0; + session_per_op = 0; writers = 10; - while ((ch = getopt(argc, argv, "1C:k:l:n:R:r:t:W:")) != EOF) + while ((ch = getopt(argc, argv, "1C:k:l:n:R:r:St:W:")) != EOF) switch (ch) { case '1': /* One run */ runs = 1; @@ -67,6 +69,9 @@ main(int argc, char *argv[]) case 'r': /* runs */ runs = atoi(optarg); break; + case 'S': /* new session per operation */ + session_per_op = 1; + break; case 't': switch (optarg[0]) { case 'f': @@ -223,8 +228,8 @@ usage(void) { fprintf(stderr, "usage: %s " - "[-1] [-C wiredtiger-config]\n " - "[-l log] [-R readers] [-r runs] [-t f|r|v] [-W writers]\n", + "[-1S] [-C wiredtiger-config] [-k keys] [-l log]\n\t" + "[-n ops] [-R readers] [-r runs] [-t f|r|v] [-W writers]\n", progname); fprintf(stderr, "%s", "\t-1 run once\n" @@ -234,6 +239,7 @@ usage(void) "\t-n set number of operations each thread does\n" "\t-R set number of reading threads\n" "\t-r set number of runs\n" + "\t-S open/close a session on every operation\n" "\t-t set a file type (fix | row | var)\n" "\t-W set number of writing threads\n"); return (EXIT_FAILURE); diff --git a/test/thread/thread.h b/test/thread/thread.h index d3c4715be29..62886e5433e 100644 --- a/test/thread/thread.h +++ b/test/thread/thread.h @@ -31,6 +31,7 @@ extern __ftype ftype; extern u_int nkeys; /* Keys to load */ extern u_int nops; /* Operations per thread */ +extern int session_per_op; /* New session per operation */ #if defined (__GNUC__) void die(const char *, int) __attribute__((noreturn)); |