mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 23:04:20 +01:00
inflate2 gets a node size of 15641
git-svn-id: file:///svn/toku/tokudb@12760 c7de825b-a66e-492c-adef-691d508d4ae1
This commit is contained in:
parent
20e019e6c0
commit
5e5a473306
1 changed files with 139 additions and 0 deletions
139
src/tests/inflate2.c
Normal file
139
src/tests/inflate2.c
Normal file
|
@ -0,0 +1,139 @@
|
|||
/* -*- mode: C; c-basic-offset: 4 -*- */
|
||||
|
||||
/* Idea: inflate a node by
|
||||
* create a 2-level tree
|
||||
* Nodes are A B C D E F G H
|
||||
* Fill them up sequentially so they'll all be near 4MB.
|
||||
* Close the file
|
||||
* Insert some more to H (buffered in the root)
|
||||
* Delete stuff from G (so that H merges with G)
|
||||
* Merge first flushes G then merges the nodes, and maybe leaves G too big.
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
|
||||
DB_ENV *env;
|
||||
DB *db;
|
||||
const char dbname[] = "foo.db";
|
||||
const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG;
|
||||
|
||||
static void
|
||||
open_em (void)
|
||||
{
|
||||
int r;
|
||||
r = db_env_create(&env, 0); CKERR(r);
|
||||
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
|
||||
r = db_create(&db, env, 0); CKERR(r);
|
||||
r = db->open(db, NULL, dbname, NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
|
||||
}
|
||||
|
||||
static void
|
||||
close_em (void)
|
||||
{
|
||||
int r;
|
||||
r = db->close(db, 0); CKERR(r);
|
||||
r = env->close(env, 0); CKERR(r);
|
||||
}
|
||||
|
||||
static void
|
||||
reopen_em (void)
|
||||
{
|
||||
close_em();
|
||||
open_em();
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
setup(void)
|
||||
{
|
||||
system("rm -rf " ENVDIR);
|
||||
toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);
|
||||
int r;
|
||||
r = db_env_create(&env, 0); CKERR(r);
|
||||
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
|
||||
r = db_create(&db, env, 0); CKERR(r);
|
||||
r = db->set_pagesize(db, 8192); CKERR(r);
|
||||
r = db->open(db, NULL, dbname, NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
|
||||
}
|
||||
|
||||
char vdata[150];
|
||||
|
||||
static void
|
||||
insert_n (u_int32_t ah) {
|
||||
u_int32_t an = htonl(ah);
|
||||
DBT key = {.size = 4, .data=&an };
|
||||
DBT val = {.size = sizeof(vdata), .data=vdata};
|
||||
int r = db->put(db, NULL, &key, &val, DB_YESOVERWRITE);
|
||||
CKERR(r);
|
||||
}
|
||||
|
||||
static void
|
||||
get_n (u_int32_t ah, int expect_r)
|
||||
{
|
||||
u_int32_t an = htonl(ah);
|
||||
DBT key = {.size = 4, .data=&an };
|
||||
DBT val = {.data=0, .flags = DB_DBT_MALLOC};
|
||||
int r = db->get(db, NULL, &key, &val, 0);
|
||||
assert(r==expect_r);
|
||||
if (r==0) toku_free(val.data);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
delete_n_now (u_int32_t ah)
|
||||
{
|
||||
u_int32_t an = htonl(ah);
|
||||
DBT key = {.size = 4, .data=&an };
|
||||
int r = db->del(db, NULL, &key, DB_DELETE_ANY);
|
||||
#ifdef USE_BDB
|
||||
assert(r==0 || r==DB_NOTFOUND);
|
||||
#else
|
||||
CKERR(r);
|
||||
#endif
|
||||
get_n(ah, DB_NOTFOUND);
|
||||
}
|
||||
|
||||
static void
|
||||
doit (void)
|
||||
{
|
||||
u_int32_t N=46;
|
||||
u_int32_t BIG=1<<16;
|
||||
for (u_int32_t i=0; i<2*N; i++) {
|
||||
insert_n(i);
|
||||
}
|
||||
insert_n(BIG);
|
||||
insert_n(BIG+1);
|
||||
reopen_em();
|
||||
for (u_int32_t i=0; i<N; i++) {
|
||||
insert_n(2*N+i);
|
||||
}
|
||||
delete_n_now(BIG+1);
|
||||
return;
|
||||
for (u_int32_t i=N-1; i<N; i++) {
|
||||
delete_n_now(i<<16);
|
||||
}
|
||||
return;
|
||||
reopen_em();
|
||||
insert_n(N<<16);
|
||||
get_n(N<<16, 0);
|
||||
reopen_em();
|
||||
for (u_int32_t i='J'; i<N+1; i++) {
|
||||
delete_n_now(i<<16);
|
||||
}
|
||||
reopen_em();
|
||||
reopen_em();
|
||||
for (u_int32_t j=0; j<46; j++) {
|
||||
insert_n(('.'<<16) + 1 +j +46);
|
||||
}
|
||||
for (u_int32_t i=0; i<13; i++) {
|
||||
delete_n_now((73 - i)<< 16);
|
||||
}
|
||||
reopen_em(); // now a node is 9143 bytes
|
||||
}
|
||||
|
||||
int test_main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
|
||||
setup();
|
||||
doit();
|
||||
close_em();
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue