Commit bb4d2433 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

#3462 test case with large rows that crash the brt loader refs[t:3462]

git-svn-id: file:///svn/toku/tokudb@30306 c7de825b-a66e-492c-adef-691d508d4ae1
parent 0f68894c
// verify that the loader can deal with blobs larger than the node size
#include "test.h"
static int my_bt_compare(DB *db, const DBT *a, const DBT *b) {
db = db;
assert(a->size == 8 && b->size == 8);
return memcmp(a->data, b->data, 8);
}
static int my_row_generate(DB *dest_db, DB *src_db, DBT *dest_key, DBT *dest_val, const DBT *src_key, const DBT *src_val) {
dest_db = dest_db; src_db = src_db; dest_key = dest_key; dest_val = dest_val; src_key = src_key; src_val = src_val;
assert(dest_key->flags == DB_DBT_REALLOC);
dest_key->data = toku_realloc(dest_key->data, src_key->size);
memcpy(dest_key->data, src_key->data, src_key->size);
dest_key->size = src_key->size;
assert(dest_val->flags == DB_DBT_REALLOC);
dest_val->data = toku_realloc(dest_val->data, src_val->size);
memcpy(dest_val->data, src_val->data, src_val->size);
dest_val->size = src_val->size;
return 0;
}
static void insert(DB_LOADER *loader, int k, int val_size) {
int r;
// generate the key
char key_buffer[8];
int newa = htonl(k);
memcpy(key_buffer, &newa, sizeof newa);
// generate the value
char *val_buffer = toku_malloc(val_size); assert(val_buffer);
memset(val_buffer, 0, val_size);
DBT key = { .data = key_buffer, .size = sizeof key_buffer };
DBT value = { .data = val_buffer, .size = val_size };
r = loader->put(loader, &key, &value); assert(r == 0);
toku_free(val_buffer);
}
int test_main(int argc, char * const argv[]) {
#if defined(TOKUDB)
char *db_env_dir = "blobs.leafsplit.env.tokudb";
#else
char *db_env_dir = "blobs.leafsplit.env.bdb";
#endif
int db_env_open_flags = DB_CREATE | DB_PRIVATE | DB_INIT_MPOOL | DB_INIT_TXN | DB_INIT_LOCK | DB_INIT_LOG;
char *db_filename = "blobs.db";
int do_txn = 1;
u_int64_t cachesize = 0;
u_int32_t pagesize = 0;
int i;
for (i = 1; i < argc; i++) {
char *arg = argv[i];
if (strcmp(arg, "-v") == 0 || strcmp(arg, "--verbose") == 0) {
verbose++;
continue;
}
if (strcmp(arg, "-q") == 0) {
if (verbose > 0) verbose--;
continue;
}
if (strcmp(arg, "--txn") == 0 && i+1 < argc) {
do_txn = atoi(argv[++i]);
continue;
}
if (strcmp(arg, "--pagesize") == 0 && i+1 < argc) {
pagesize = atoi(argv[++i]);
continue;
}
if (strcmp(arg, "--cachesize") == 0 && i+1 < argc) {
cachesize = atol(argv[++i]);
continue;
}
assert(0);
}
int r;
char rm_cmd[strlen(db_env_dir) + strlen("rm -rf ") + 1];
snprintf(rm_cmd, sizeof(rm_cmd), "rm -rf %s", db_env_dir);
r = system(rm_cmd); assert(r == 0);
r = toku_os_mkdir(db_env_dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); assert(r == 0);
// create and open the env
DB_ENV *db_env = NULL;
r = db_env_create(&db_env, 0); assert(r == 0);
if (cachesize) {
const u_int64_t gig = 1 << 30;
r = db_env->set_cachesize(db_env, cachesize / gig, cachesize % gig, 1); assert(r == 0);
}
r = db_env->set_generate_row_callback_for_put(db_env, my_row_generate); assert(r == 0);
r = db_env->set_default_bt_compare(db_env, my_bt_compare); assert(r == 0);
if (!do_txn)
db_env_open_flags &= ~(DB_INIT_TXN | DB_INIT_LOG);
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
// create the db
DB *db = NULL;
r = db_create(&db, db_env, 0); assert(r == 0);
DB_TXN *create_txn = NULL;
if (do_txn) {
r = db_env->txn_begin(db_env, NULL, &create_txn, 0); assert(r == 0);
}
if (pagesize) {
r = db->set_pagesize(db, pagesize); assert(r == 0);
}
r = db->open(db, create_txn, db_filename, NULL, DB_BTREE, DB_CREATE, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0);
DB_LOADER *loader = NULL;
uint32_t db_flags = 0;
uint32_t dbt_flags = 0;
r = db_env->create_loader(db_env, create_txn, &loader, db, 1, &db, &db_flags, &dbt_flags, 0); assert(r == 0);
insert(loader, 1, 8000000);
insert(loader, 2, 1);
r = loader->close(loader); assert(r == 0);
if (do_txn) {
r = create_txn->commit(create_txn, 0); assert(r == 0);
}
// shutdown
r = db->close(db, 0); assert(r == 0); db = NULL;
r = db_env->close(db_env, 0); assert(r == 0); db_env = NULL;
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