mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 23:04:20 +01:00
[t:4356] wrote test that truncates and removes during a HOT. it fails.
git-svn-id: file:///svn/toku/tokudb@38574 c7de825b-a66e-492c-adef-691d508d4ae1
This commit is contained in:
parent
6f71ad769d
commit
01e39e136b
1 changed files with 134 additions and 0 deletions
134
src/tests/test4356.c
Normal file
134
src/tests/test4356.c
Normal file
|
@ -0,0 +1,134 @@
|
|||
/* -*- mode: C; c-basic-offset: 4 -*- */
|
||||
#ident "$Id$"
|
||||
#ident "Copyright (c) 2007-2011 Tokutek Inc. All rights reserved."
|
||||
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
|
||||
|
||||
// This test verifies that db->dbremove and db->truncate can be called
|
||||
// during a call to db->hot_optimize without causing problems. See
|
||||
// #4356.
|
||||
|
||||
#include "test.h"
|
||||
|
||||
const size_t VALSIZE = 100;
|
||||
// If a full leaf is 4 MB and a full internal node has 16 children, then
|
||||
// a height 1 tree can have at most 64 MB of data (ish). 100 MB should
|
||||
// easily be enough to force a height 2 tree, which should be enough for
|
||||
// this test.
|
||||
const int NUM_ROWS = 1024 * 1024;
|
||||
|
||||
static DB_ENV *env;
|
||||
static DB *db;
|
||||
|
||||
static void
|
||||
setup(void)
|
||||
{
|
||||
int r;
|
||||
r = system("rm -rf " ENVDIR);
|
||||
CKERR(r);
|
||||
toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);
|
||||
r = db_env_create(&env, 0);
|
||||
CKERR(r);
|
||||
r = env->open(env, ENVDIR, DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_CREATE|DB_PRIVATE, S_IRWXU+S_IRWXG+S_IRWXO);
|
||||
CKERR(r);
|
||||
r = db_create(&db, env, 0);
|
||||
CKERR(r);
|
||||
{
|
||||
DB_TXN *txn;
|
||||
r = env->txn_begin(env, 0, &txn, 0);
|
||||
CKERR(r);
|
||||
r = db->open(db, txn, __FILE__".db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO);
|
||||
CKERR(r);
|
||||
r = txn->commit(txn, 0);
|
||||
CKERR(r);
|
||||
}
|
||||
if (verbose) { printf("Inserting data.\n"); }
|
||||
{
|
||||
DB_TXN *txn;
|
||||
r = env->txn_begin(env, 0, &txn, 0);
|
||||
CKERR(r);
|
||||
{
|
||||
int k;
|
||||
char v[VALSIZE];
|
||||
memset(v, 0, sizeof v);
|
||||
DBT key, val;
|
||||
dbt_init(&key, &k, sizeof k);
|
||||
dbt_init(&val, v, sizeof v);
|
||||
for (k = 0; k < NUM_ROWS; ++k) {
|
||||
r = db->put(db, txn, &key, &val, 0);
|
||||
CKERR(r);
|
||||
}
|
||||
r = txn->commit(txn, 0);
|
||||
CKERR(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
finish(void)
|
||||
{
|
||||
int r;
|
||||
r = db->close(db, 0);
|
||||
CKERR(r);
|
||||
r = env->close(env, 0);
|
||||
CKERR(r);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
REMOVE_4356,
|
||||
TRUNCATE_4356
|
||||
} operation_4356_t;
|
||||
|
||||
struct progress_extra_4356 {
|
||||
operation_4356_t op;
|
||||
bool ran_operation;
|
||||
};
|
||||
|
||||
static int
|
||||
progress_4356(void *extra, float progress)
|
||||
{
|
||||
int r = 0;
|
||||
struct progress_extra_4356 *e = extra;
|
||||
if (!e->ran_operation && progress > 0.5) {
|
||||
if (e->op == REMOVE_4356) {
|
||||
if (verbose) { printf("Running remove.\n"); }
|
||||
r = db->remove(db, __FILE__".db", 0, 0);
|
||||
assert(r != 0); // cannot remove a db with an open handle
|
||||
if (verbose) { printf("Completed remove.\n"); }
|
||||
} else if (e->op == TRUNCATE_4356) {
|
||||
u_int32_t row_count = 0;
|
||||
if (verbose) { printf("Running truncate.\n"); }
|
||||
r = db->truncate(db, 0, &row_count, 0);
|
||||
CKERR(r);
|
||||
if (verbose) { printf("Completed truncate.\n"); }
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static void
|
||||
run_test(operation_4356_t op)
|
||||
{
|
||||
int r;
|
||||
setup();
|
||||
struct progress_extra_4356 extra;
|
||||
extra.op = op;
|
||||
extra.ran_operation = false;
|
||||
if (verbose) { printf("Running HOT.\n"); }
|
||||
r = db->hot_optimize(db, progress_4356, &extra);
|
||||
CKERR(r);
|
||||
if (verbose) { printf("Completed HOT.\n"); }
|
||||
finish();
|
||||
}
|
||||
|
||||
int
|
||||
test_main(int argc, char * const argv[])
|
||||
{
|
||||
parse_args(argc, argv);
|
||||
if (verbose) { printf("Running truncate test.\n"); }
|
||||
run_test(TRUNCATE_4356);
|
||||
if (verbose) { printf("Running remove test.\n"); }
|
||||
run_test(REMOVE_4356);
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue