summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2012-03-14 08:19:16 -0400
committerKeith Bostic <keith@wiredtiger.com>2012-03-14 11:05:19 -0400
commitd5f4d7bccad2558350d167c6d41d457de11f1b68 (patch)
treec9bbe07f6e6873e4f3f9edef8b7fd23683ea49f7 /test
parentba259c3d161a83422a136996a2c29a0e9b1a5fe1 (diff)
downloadmongo-d5f4d7bccad2558350d167c6d41d457de11f1b68.tar.gz
Change operations value WT_ITEMs to use a local buffer, too, not a global
one.
Diffstat (limited to 'test')
-rw-r--r--test/format/format.h2
-rw-r--r--test/format/util.c59
-rw-r--r--test/format/wts_bulk.c11
-rw-r--r--test/format/wts_ops.c70
4 files changed, 73 insertions, 69 deletions
diff --git a/test/format/format.h b/test/format/format.h
index 664a16fe579..6cb20a3c4d5 100644
--- a/test/format/format.h
+++ b/test/format/format.h
@@ -108,7 +108,7 @@ void die(const char *, int);
void key_gen(uint8_t *, uint32_t *, uint64_t, int);
void key_gen_setup(uint8_t **);
void track(const char *, uint64_t);
-void value_gen(void *, uint32_t *, uint64_t);
+void value_gen(uint8_t *, uint32_t *, uint64_t);
int wts_dump(const char *, int);
void wts_load(void);
int wts_ops(void);
diff --git a/test/format/util.c b/test/format/util.c
index 7332e7146fe..31e68caed3a 100644
--- a/test/format/util.c
+++ b/test/format/util.c
@@ -65,12 +65,10 @@ key_gen(uint8_t *key, uint32_t *sizep, uint64_t keyno, int insert)
}
void
-value_gen(void *valuep, uint32_t *sizep, uint64_t keyno)
+val_gen_setup(uint8_t **valp)
{
- static size_t blen = 0;
- static const char *dup_data = "duplicate data item";
- static u_char *buf = NULL;
- size_t i;
+ uint8_t *val;
+ size_t i, len;
/*
* Set initial buffer contents to reconizable text.
@@ -79,17 +77,20 @@ value_gen(void *valuep, uint32_t *sizep, uint64_t keyno)
* into the buffer by a few extra bytes, used to generate different
* data for column-store run-length encoded files.
*/
- if (blen < g.c_value_max + 10) {
- if (buf != NULL) {
- free(buf);
- buf = NULL;
- }
- blen = g.c_value_max + 10;
- if ((buf = malloc(blen)) == NULL)
- die("malloc", errno);
- for (i = 0; i < blen; ++i)
- buf[i] = (u_char)"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i % 26];
- }
+ len = g.c_value_max + 20;
+ if ((val = malloc(len)) == NULL)
+ die("malloc", errno);
+ for (i = 0; i < len; ++i)
+ val[i] = (u_char)"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i % 26];
+
+ *valp = val;
+}
+
+void
+value_gen(uint8_t *val, uint32_t *sizep, uint64_t keyno)
+{
+ static const char *dup_data = "duplicate data item";
+ size_t i;
/*
* Fixed-length records: take the low N bits from the last digit of
@@ -97,16 +98,15 @@ value_gen(void *valuep, uint32_t *sizep, uint64_t keyno)
*/
if (g.c_file_type == FIX) {
switch (g.c_bitcnt) {
- case 8: buf[0] = MMRAND(1, 0xff); break;
- case 7: buf[0] = MMRAND(1, 0x7f); break;
- case 6: buf[0] = MMRAND(1, 0x3f); break;
- case 5: buf[0] = MMRAND(1, 0x1f); break;
- case 4: buf[0] = MMRAND(1, 0x0f); break;
- case 3: buf[0] = MMRAND(1, 0x07); break;
- case 2: buf[0] = MMRAND(1, 0x03); break;
- case 1: buf[0] = 1; break;
+ case 8: val[0] = MMRAND(1, 0xff); break;
+ case 7: val[0] = MMRAND(1, 0x7f); break;
+ case 6: val[0] = MMRAND(1, 0x3f); break;
+ case 5: val[0] = MMRAND(1, 0x1f); break;
+ case 4: val[0] = MMRAND(1, 0x0f); break;
+ case 3: val[0] = MMRAND(1, 0x07); break;
+ case 2: val[0] = MMRAND(1, 0x03); break;
+ case 1: val[0] = 1; break;
}
- *(void **)valuep = buf;
*sizep = 1;
return;
}
@@ -116,7 +116,7 @@ value_gen(void *valuep, uint32_t *sizep, uint64_t keyno)
* test that by inserting a zero-length data item every so often.
*/
if (++keyno % 63 == 0) {
- *(void **)valuep = buf;
+ val[0] = '\0';
*sizep = 0;
return;
}
@@ -132,14 +132,13 @@ value_gen(void *valuep, uint32_t *sizep, uint64_t keyno)
if (g.c_file_type == VAR &&
g.c_repeat_data_pct != 0 &&
(u_int)wts_rand() % 100 > g.c_repeat_data_pct) {
- *(void **)valuep = (void *)dup_data;
+ (void)strcpy(val, dup_data);
*sizep = (uint32_t)strlen(dup_data);
return;
}
- snprintf((char *)buf, blen, "%010" PRIu64, keyno);
- buf[10] = '/';
- *(void **)valuep = buf;
+ sprintf(val, "%010" PRIu64, keyno);
+ val[10] = '/';
*sizep = MMRAND(g.c_value_min, g.c_value_max);
}
diff --git a/test/format/wts_bulk.c b/test/format/wts_bulk.c
index f54491db3dd..cd068775703 100644
--- a/test/format/wts_bulk.c
+++ b/test/format/wts_bulk.c
@@ -12,9 +12,9 @@ wts_load(void)
{
WT_CONNECTION *conn;
WT_CURSOR *cursor;
+ WT_ITEM key, value;
WT_SESSION *session;
- static WT_ITEM key, value;
- uint8_t *keybuf;
+ uint8_t *keybuf, *valbuf;
int ret;
conn = g.wts_conn;
@@ -34,6 +34,8 @@ wts_load(void)
/* Set up the default key buffer. */
memset(&key, 0, sizeof(key));
key_gen_setup(&keybuf);
+ memset(&value, 0, sizeof(value));
+ val_gen_setup(&valbuf);
for (;;) {
if (++g.key_cnt > g.c_rows) {
@@ -45,9 +47,10 @@ wts_load(void)
if (g.key_cnt % 100 == 0)
track("bulk load", g.key_cnt);
- key.data = keybuf;
key_gen(keybuf, &key.size, (uint64_t)g.key_cnt, 0);
- value_gen(&value.data, &value.size, (uint64_t)g.key_cnt);
+ key.data = keybuf;
+ value_gen(valbuf, &value.size, (uint64_t)g.key_cnt);
+ value.data = valbuf;
switch (g.c_file_type) {
case FIX:
diff --git a/test/format/wts_ops.c b/test/format/wts_ops.c
index 55f995786a6..2dec487ef68 100644
--- a/test/format/wts_ops.c
+++ b/test/format/wts_ops.c
@@ -8,14 +8,14 @@
#include "format.h"
static int col_del(WT_CURSOR *, WT_ITEM *, uint64_t, int *);
-static int col_insert(WT_CURSOR *, WT_ITEM *, uint64_t *);
-static int col_put(WT_CURSOR *, WT_ITEM *, uint64_t);
+static int col_insert(WT_CURSOR *, WT_ITEM *, WT_ITEM *, uint64_t *);
+static int col_put(WT_CURSOR *, WT_ITEM *, WT_ITEM *, uint64_t);
static int nextprev(WT_CURSOR *, int, int *);
static int notfound_chk(const char *, int, int, uint64_t);
static void *ops(void *);
static int read_row(WT_CURSOR *, WT_ITEM *, uint64_t);
static int row_del(WT_CURSOR *, WT_ITEM *, uint64_t, int *);
-static int row_put(WT_CURSOR *, WT_ITEM *, uint64_t, int);
+static int row_put(WT_CURSOR *, WT_ITEM *, WT_ITEM *, uint64_t, int);
static void print_item(const char *, WT_ITEM *);
/*
@@ -84,19 +84,21 @@ ops(void *arg)
WT_CONNECTION *conn;
WT_CURSOR *cursor, *cursor_insert;
WT_SESSION *session;
- WT_ITEM key;
+ WT_ITEM key, value;
time_t now;
uint64_t cnt, keyno;
uint32_t op;
u_int np;
int dir, insert, notfound, ret;
- uint8_t *keybuf;
+ uint8_t *keybuf, *valbuf;
conn = arg;
- /* Set up the default key buffer. */
+ /* Set up the default key and value buffers. */
memset(&key, 0, sizeof(key));
key_gen_setup(&keybuf);
+ memset(&value, 0, sizeof(value));
+ val_gen_setup(&valbuf);
/* Open a session. */
if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
@@ -133,8 +135,9 @@ ops(void *arg)
insert = notfound = 0;
- key.data = keybuf;
keyno = MMRAND(1, g.rows);
+ key.data = keybuf;
+ value.data = valbuf;
/*
* Perform some number of operations: the percentage of deletes,
@@ -163,7 +166,7 @@ ops(void *arg)
} else if (op < g.c_delete_pct + g.c_insert_pct) {
switch (g.c_file_type) {
case ROW:
- if (row_put(cursor, &key, keyno, 1))
+ if (row_put(cursor, &key, &value, keyno, 1))
goto err;
break;
case FIX:
@@ -173,7 +176,8 @@ ops(void *arg)
* pages pinned.
*/
cursor->reset(cursor);
- if (col_insert(cursor_insert, &key, &keyno))
+ if (col_insert(
+ cursor_insert, &key, &value, &keyno))
goto err;
insert = 1;
break;
@@ -182,12 +186,12 @@ ops(void *arg)
op < g.c_delete_pct + g.c_insert_pct + g.c_write_pct) {
switch (g.c_file_type) {
case ROW:
- if (row_put(cursor, &key, keyno, 0))
+ if (row_put(cursor, &key, &value, keyno, 0))
goto err;
break;
case FIX:
case VAR:
- if (col_put(cursor, &key, keyno))
+ if (col_put(cursor, &key, &value, keyno))
goto err;
break;
}
@@ -384,7 +388,7 @@ read_row(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno)
static int
nextprev(WT_CURSOR *cursor, int next, int *notfoundp)
{
- static WT_ITEM key, value, bdb_key, bdb_value;
+ WT_ITEM key, value, bdb_key, bdb_value;
WT_SESSION *session;
uint64_t keyno;
int notfound, ret;
@@ -490,16 +494,16 @@ nextprev(WT_CURSOR *cursor, int next, int *notfoundp)
* Update an element in a row-store file.
*/
static int
-row_put(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int insert)
+row_put(
+ WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t keyno, int insert)
{
- static WT_ITEM value;
WT_SESSION *session;
int notfound, ret;
session = cursor->session;
key_gen((uint8_t *)key->data, &key->size, keyno, insert);
- value_gen(&value.data, &value.size, keyno);
+ value_gen((uint8_t *)value->data, &value->size, keyno);
/* Log the operation */
if (g.logging == LOG_OPS)
@@ -507,10 +511,10 @@ row_put(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int insert)
insert ? "insertK" : "putK",
(int)key->size, (char *)key->data,
insert ? "insertV" : "putV",
- (int)value.size, (char *)value.data);
+ (int)value->size, (char *)value->data);
cursor->set_key(cursor, key);
- cursor->set_value(cursor, &value);
+ cursor->set_value(cursor, value);
ret = cursor->insert(cursor);
if (ret != 0 && ret != WT_NOTFOUND) {
fprintf(stderr,
@@ -523,7 +527,7 @@ row_put(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int insert)
if (!SINGLETHREADED)
return (0);
- if (bdb_put(key->data, key->size, value.data, value.size, &notfound))
+ if (bdb_put(key->data, key->size, value->data, value->size, &notfound))
return (1);
NTF_CHK(notfound_chk("row_put", ret, notfound, keyno));
@@ -535,15 +539,14 @@ row_put(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno, int insert)
* Update an element in a column-store file.
*/
static int
-col_put(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno)
+col_put(WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t keyno)
{
- static WT_ITEM value;
WT_SESSION *session;
int notfound, ret;
session = cursor->session;
- value_gen(&value.data, &value.size, keyno);
+ value_gen((uint8_t *)value->data, &value->size, keyno);
/* Log the operation */
if (g.logging == LOG_OPS) {
@@ -551,19 +554,19 @@ col_put(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno)
(void)session->msg_printf(session,
"%-10s%" PRIu64 " {0x%02" PRIx8 "}",
"update", keyno,
- ((uint8_t *)value.data)[0]);
+ ((uint8_t *)value->data)[0]);
else
(void)session->msg_printf(session,
"%-10s%" PRIu64 " {%.*s}",
"update", keyno,
- (int)value.size, (char *)value.data);
+ (int)value->size, (char *)value->data);
}
cursor->set_key(cursor, keyno);
if (g.c_file_type == FIX)
- cursor->set_value(cursor, *(uint8_t *)value.data);
+ cursor->set_value(cursor, *(uint8_t *)value->data);
else
- cursor->set_value(cursor, &value);
+ cursor->set_value(cursor, value);
ret = cursor->insert(cursor);
if (ret != 0 && ret != WT_NOTFOUND) {
fprintf(stderr,
@@ -576,7 +579,7 @@ col_put(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno)
return (0);
key_gen((uint8_t *)key->data, &key->size, keyno, 0);
- if (bdb_put(key->data, key->size, value.data, value.size, &notfound))
+ if (bdb_put(key->data, key->size, value->data, value->size, &notfound))
return (1);
NTF_CHK(notfound_chk("col_put", ret, notfound, keyno));
@@ -588,21 +591,20 @@ col_put(WT_CURSOR *cursor, WT_ITEM *key, uint64_t keyno)
* Insert an element in a column-store file.
*/
static int
-col_insert(WT_CURSOR *cursor, WT_ITEM *key, uint64_t *keynop)
+col_insert(WT_CURSOR *cursor, WT_ITEM *key, WT_ITEM *value, uint64_t *keynop)
{
- static WT_ITEM value;
WT_SESSION *session;
uint64_t keyno;
int notfound, ret;
session = cursor->session;
- value_gen(&value.data, &value.size, g.rows + 1);
+ value_gen((uint8_t *)value->data, &value->size, g.rows + 1);
if (g.c_file_type == FIX)
- cursor->set_value(cursor, *(uint8_t *)value.data);
+ cursor->set_value(cursor, *(uint8_t *)value->data);
else
- cursor->set_value(cursor, &value);
+ cursor->set_value(cursor, value);
ret = cursor->insert(cursor);
if (ret != 0) {
fprintf(stderr, "%s: col_insert: %s\n",
@@ -629,12 +631,12 @@ col_insert(WT_CURSOR *cursor, WT_ITEM *key, uint64_t *keynop)
(void)session->msg_printf(session,
"%-10s%" PRIu64 " {0x%02" PRIx8 "}",
"insert", keyno,
- ((uint8_t *)value.data)[0]);
+ ((uint8_t *)value->data)[0]);
else
(void)session->msg_printf(session,
"%-10s%" PRIu64 " {%.*s}",
"insert", keyno,
- (int)value.size, (char *)value.data);
+ (int)value->size, (char *)value->data);
}
if (!SINGLETHREADED)
@@ -642,7 +644,7 @@ col_insert(WT_CURSOR *cursor, WT_ITEM *key, uint64_t *keynop)
key_gen((uint8_t *)key->data, &key->size, keyno, 0);
return (bdb_put(
- key->data, key->size, value.data, value.size, &notfound) ? 1 : 0);
+ key->data, key->size, value->data, value->size, &notfound) ? 1 : 0);
}
/*