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

refs #6040 add key_size and val_size parameters to db-update.c

git-svn-id: file:///svn/toku/tokudb@53385 c7de825b-a66e-492c-adef-691d508d4ae1
parent 30a0c91f
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include "db.h" #include "db.h"
static size_t key_size = 8;
static size_t val_size = 8;
static int verbose = 0; static int verbose = 0;
static void db_error(const DB_ENV *env, const char *prefix, const char *msg) { static void db_error(const DB_ENV *env, const char *prefix, const char *msg) {
...@@ -37,12 +39,10 @@ static int my_update_callback(DB *db, const DBT *key, const DBT *old_val, const ...@@ -37,12 +39,10 @@ static int my_update_callback(DB *db, const DBT *key, const DBT *old_val, const
// insert new_val = extra // insert new_val = extra
set_val(extra, set_extra); set_val(extra, set_extra);
} else { } else {
if (verbose) { if (verbose) printf("u");
printf("u"); fflush(stdout);
}
// update new_val = old_val + extra // update new_val = old_val + extra
assert(old_val->size == 8 && extra->size == 8); assert(old_val->size == val_size && extra->size == val_size);
char new_val_buffer[8]; char new_val_buffer[val_size];
memcpy(new_val_buffer, old_val->data, sizeof new_val_buffer); memcpy(new_val_buffer, old_val->data, sizeof new_val_buffer);
int newc = htonl(get_int(old_val->data) + get_int(extra->data)); // newc = oldc + newc int newc = htonl(get_int(old_val->data) + get_int(extra->data)); // newc = oldc + newc
memcpy(new_val_buffer, &newc, sizeof newc); memcpy(new_val_buffer, &newc, sizeof newc);
...@@ -57,14 +57,16 @@ static void insert_and_update(DB_ENV *db_env, DB *db, DB_TXN *txn, int a, int b, ...@@ -57,14 +57,16 @@ static void insert_and_update(DB_ENV *db_env, DB *db, DB_TXN *txn, int a, int b,
int r; int r;
// generate the key // generate the key
char key_buffer[8]; assert(key_size >= 8);
char key_buffer[key_size];
int newa = htonl(a); int newa = htonl(a);
memcpy(key_buffer, &newa, sizeof newa); memcpy(key_buffer, &newa, sizeof newa);
int newb = htonl(b); int newb = htonl(b);
memcpy(key_buffer+4, &newb, sizeof newb); memcpy(key_buffer+4, &newb, sizeof newb);
// generate the value // generate the value
char val_buffer[8]; assert(val_size >= 8);
char val_buffer[val_size];
int newc = htonl(c); int newc = htonl(c);
memcpy(val_buffer, &newc, sizeof newc); memcpy(val_buffer, &newc, sizeof newc);
int newd = htonl(d); int newd = htonl(d);
...@@ -86,6 +88,7 @@ static void insert_and_update(DB_ENV *db_env, DB *db, DB_TXN *txn, int a, int b, ...@@ -86,6 +88,7 @@ static void insert_and_update(DB_ENV *db_env, DB *db, DB_TXN *txn, int a, int b,
assert(r == 0 || r == DB_NOTFOUND); assert(r == 0 || r == DB_NOTFOUND);
if (r == 0) { if (r == 0) {
// update it // update it
if (verbose) printf("U");
int oldc = get_int(oldvalue.data); int oldc = get_int(oldvalue.data);
newc = htonl(oldc + c); // newc = oldc + newc newc = htonl(oldc + c); // newc = oldc + newc
memcpy(val_buffer, &newc, sizeof newc); memcpy(val_buffer, &newc, sizeof newc);
...@@ -155,13 +158,13 @@ int main(int argc, char *argv[]) { ...@@ -155,13 +158,13 @@ int main(int argc, char *argv[]) {
#endif #endif
int db_env_open_flags = DB_CREATE | DB_PRIVATE | DB_INIT_MPOOL | DB_INIT_TXN | DB_INIT_LOCK | DB_INIT_LOG; int db_env_open_flags = DB_CREATE | DB_PRIVATE | DB_INIT_MPOOL | DB_INIT_TXN | DB_INIT_LOCK | DB_INIT_LOG;
char *db_filename = "update.db"; char *db_filename = "update.db";
long rows = 100000000; long rows = 1000000000;
long rows_per_txn = 100; long rows_per_txn = 100;
long rows_per_report = 100000; long rows_per_report = 100000;
int key_range = 100000; int key_range = 1000000;
bool do_update_callback = true; bool do_update_callback = true;
bool do_txn = false; bool do_txn = false;
u_int64_t cachesize = 32000000; u_int64_t cachesize = 1000000000;
u_int32_t pagesize = 0; u_int32_t pagesize = 0;
int i; int i;
...@@ -203,6 +206,14 @@ int main(int argc, char *argv[]) { ...@@ -203,6 +206,14 @@ int main(int argc, char *argv[]) {
do_update_callback = atoi(argv[++i]) != 0; do_update_callback = atoi(argv[++i]) != 0;
continue; continue;
} }
if (strcmp(arg, "--key_size") == 0 && i+1 < argc) {
key_size = atoi(argv[++i]);
continue;
}
if (strcmp(arg, "--val_size") == 0 && i+1 < argc) {
val_size = atoi(argv[++i]);
continue;
}
assert(0); assert(0);
} }
...@@ -221,12 +232,14 @@ int main(int argc, char *argv[]) { ...@@ -221,12 +232,14 @@ int main(int argc, char *argv[]) {
db_env->set_update(db_env, my_update_callback); db_env->set_update(db_env, my_update_callback);
#endif #endif
if (cachesize) { if (cachesize) {
if (verbose) printf("cachesize %llu\n", (unsigned long long)cachesize);
const u_int64_t gig = 1 << 30; 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_cachesize(db_env, cachesize / gig, cachesize % gig, 1); assert(r == 0);
} }
if (!do_txn) if (!do_txn)
db_env_open_flags &= ~(DB_INIT_TXN | DB_INIT_LOG); db_env_open_flags &= ~(DB_INIT_TXN | DB_INIT_LOG);
db_env->set_errcall(db_env, db_error); db_env->set_errcall(db_env, db_error);
if (verbose) printf("env %s\n", db_env_dir);
r = db_env->open(db_env, db_env_dir, db_env_open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); assert(r == 0); 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 // create the db
......
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