Commit a68a748b authored by Rich Prohaska's avatar Rich Prohaska

addresses #223

git-svn-id: file:///svn/tokudb@1419 c7de825b-a66e-492c-adef-691d508d4ae1
parent 85af57de
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/stat.h>
#include <db.h>
#include "test.h"
u_int64_t size_from(u_int32_t gbytes, u_int32_t bytes) {
return (gbytes << 30ULL) + bytes;
}
void size_to(u_int64_t s, u_int32_t *gbytes, u_int32_t *bytes) {
*gbytes = s >> 30;
*bytes = s & ((1<<30) - 1);
}
void test_cachesize() {
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3
int r;
DB_ENV *env;
u_int32_t gbytes, bytes; int ncache;
r = db_env_create(&env, 0); assert(r == 0);
r = env->get_cachesize(env, &gbytes, &bytes, &ncache); assert(r == 0);
printf("default %u %u %d\n", gbytes, bytes, ncache);
r = env->set_cachesize(env, 0, 0, 1); assert(r == 0);
r = env->get_cachesize(env, &gbytes, &bytes, &ncache); assert(r == 0);
printf("minimum %u %u %d\n", gbytes, bytes, ncache);
u_int64_t minsize = size_from(gbytes, bytes);
u_int64_t s = 1; size_to(s, &gbytes, &bytes);
while (gbytes <= 32) {
r = env->set_cachesize(env, gbytes, bytes, ncache); assert(r == 0);
r = env->get_cachesize(env, &gbytes, &bytes, &ncache); assert(r == 0);
assert(ncache == 1);
if (s <= minsize)
assert(minsize == size_from(gbytes, bytes));
else
assert(s == size_from(gbytes, bytes));
s *= 2; size_to(s, &gbytes, &bytes);
}
r = env->close(env, 0); assert(r == 0);
#endif
}
int main(int argc, const char *argv[]) {
parse_args(argc, argv);
test_cachesize();
return 0;
}
......@@ -381,6 +381,17 @@ static int toku_db_env_set_cachesize(DB_ENV * env, u_int32_t gbytes, u_int32_t b
return 0;
}
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3
static int toku_db_env_get_cachesize(DB_ENV * env, u_int32_t *gbytes, u_int32_t *bytes, int *ncache) {
*gbytes = env->i->cachetable_size >> 30;
*bytes = env->i->cachetable_size & ((1<<30)-1);
*ncache = 1;
return 0;
}
#endif
static int toku_db_env_set_data_dir(DB_ENV * env, const char *dir) {
u_int32_t i;
int r;
......@@ -532,6 +543,9 @@ int db_env_create(DB_ENV ** envp, u_int32_t flags) {
result->set_lg_dir = toku_db_env_set_lg_dir;
result->set_lg_max = toku_db_env_set_lg_max;
result->set_cachesize = toku_db_env_set_cachesize;
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3
result->get_cachesize = toku_db_env_get_cachesize;
#endif
result->set_lk_detect = toku_db_env_set_lk_detect;
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR <= 4
result->set_lk_max = toku_db_env_set_lk_max;
......
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