Commit 77f3953c authored by Rich Prohaska's avatar Rich Prohaska

test case for bug 935. addresses #935

git-svn-id: file:///svn/tokudb@4635 c7de825b-a66e-492c-adef-691d508d4ae1
parent 01e53bc1
......@@ -537,8 +537,8 @@ static int brtleaf_split (TOKULOGGER logger, FILENUM filenum, BRT t, BRTNODE nod
*nodea = node;
*nodeb = B;
assert(toku_serialize_brtnode_size(node)<node->nodesize);
assert(toku_serialize_brtnode_size(B) <B->nodesize);
assert(toku_serialize_brtnode_size(node) <= node->nodesize);
assert(toku_serialize_brtnode_size(B) <= B->nodesize);
return 0;
}
......@@ -679,8 +679,8 @@ static int brt_nonleaf_split (BRT t, BRTNODE node, BRTNODE *nodea, BRTNODE *node
*nodea = node;
*nodeb = B;
assert(toku_serialize_brtnode_size(node)<node->nodesize);
assert(toku_serialize_brtnode_size(B)<B->nodesize);
assert(toku_serialize_brtnode_size(node) <= node->nodesize);
assert(toku_serialize_brtnode_size(B) <= B->nodesize);
return 0;
}
......
/* -*- mode: C; c-basic-offset: 4 -*- */
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <db.h>
#include "test.h"
void testit(const int klen, const int vlen, const int n, const int lastvlen) {
if (verbose) printf("testit %d %d %d %d\n", klen, vlen, n, lastvlen);
int r;
// setup test directory
system("rm -rf " ENVDIR);
mkdir(ENVDIR, 0777);
// setup environment
DB_ENV *env;
{
r = db_env_create(&env, 0); assert(r == 0);
r = env->set_data_dir(env, ENVDIR);
r = env->set_lg_dir(env, ENVDIR);
env->set_errfile(env, stdout);
r = env->open(env, 0, DB_INIT_MPOOL + DB_PRIVATE + DB_CREATE, 0777);
assert(r == 0);
}
// setup database
DB *db;
{
DB_TXN *txn = 0;
r = db_create(&db, env, 0); assert(r == 0);
r = db->open(db, txn, "test.db", 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0);
}
// insert to fill up a node
{
void *v = malloc(vlen); assert(v);
DB_TXN *txn = 0;
int i;
for (i=0; i<n; i++) {
int k = htonl(i);
assert(sizeof k == klen);
DBT key, val;
r = db->put(db, txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, v, vlen), 0);
assert(r == 0);
}
if (lastvlen > 0) {
int k = htonl(n);
DBT key, val;
r = db->put(db, txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, v, lastvlen), 0);
assert(r == 0);
}
free(v);
}
// add another one to force a node split
{
void *v = malloc(vlen); assert(v);
DB_TXN *txn = 0;
int k = htonl(n+1);
DBT key, val;
r = db->put(db, txn, dbt_init(&key, &k, sizeof k), dbt_init(&val, v, vlen), 0);
assert(r == 0);
free(v);
}
// close db
r = db->close(db, 0); assert(r == 0);
// close env
r = env->close(env, 0); assert(r == 0);
}
int main(int argc, const char *argv[]) {
parse_args(argc, argv);
const int meg = 1024*1024;
const int headeroverhead = 12*4;
const int numentries = 4;
const int klen = 4;
const int vlen = 4096;
const int leafoverhead = 1+8+4+4;
const int leafentrysize = leafoverhead+klen+vlen;
int n = (meg - headeroverhead - numentries) / leafentrysize;
int left = meg - headeroverhead - numentries - n*leafentrysize;
int lastvlen = left - leafoverhead - klen;
testit(klen, vlen, n, lastvlen-1);
testit(klen, vlen, n, lastvlen-0);
testit(klen, vlen, n, lastvlen+1);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment