Commit 04d6f310 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Get rid of a bunch of unused code. For example, no longer relies on random. Addresses #162.

git-svn-id: file:///svn/tokudb@1065 c7de825b-a66e-492c-adef-691d508d4ae1
parent e251c5cb
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "test.h" #include "test.h"
#include "trace.h" #include "trace.h"
enum mode { static enum mode {
MODE_DEFAULT, MODE_MORE MODE_DEFAULT, MODE_MORE
} mode; } mode;
...@@ -20,14 +20,9 @@ enum mode { ...@@ -20,14 +20,9 @@ enum mode {
/* Primary is a map from a UID which consists of a random number followed by the current time. */ /* Primary is a map from a UID which consists of a random number followed by the current time. */
typedef struct timestamp { typedef unsigned char TIMESTAMP;
unsigned int tv_sec; /* in network order */
unsigned int tv_usec; /* in network order */
} TIMESTAMP;
struct primary_key { struct primary_key {
int rand; /* in network order */
TIMESTAMP ts; TIMESTAMP ts;
}; };
...@@ -42,34 +37,25 @@ struct primary_data { ...@@ -42,34 +37,25 @@ struct primary_data {
struct name_key name; struct name_key name;
}; };
void free_pd (struct primary_data *pd) { static void free_pd (struct primary_data *pd) {
free(pd->name.name); free(pd->name.name);
free(pd); free(pd);
} }
void write_uchar_to_dbt (DBT *dbt, const unsigned char c) { static void write_uchar_to_dbt (DBT *dbt, const unsigned char c) {
assert(dbt->size+1 <= dbt->ulen); assert(dbt->size+1 <= dbt->ulen);
((char*)dbt->data)[dbt->size++]=c; ((char*)dbt->data)[dbt->size++]=c;
} }
void write_uint_to_dbt (DBT *dbt, const unsigned int v) { static void write_timestamp_to_dbt (DBT *dbt, const TIMESTAMP ts) {
write_uchar_to_dbt(dbt, (v>>24)&0xff); write_uchar_to_dbt(dbt, ts);
write_uchar_to_dbt(dbt, (v>>16)&0xff);
write_uchar_to_dbt(dbt, (v>> 8)&0xff);
write_uchar_to_dbt(dbt, (v>> 0)&0xff);
}
void write_timestamp_to_dbt (DBT *dbt, const TIMESTAMP ts) {
write_uint_to_dbt(dbt, ts.tv_sec);
write_uint_to_dbt(dbt, ts.tv_usec);
} }
void write_pk_to_dbt (DBT *dbt, const struct primary_key *pk) { static void write_pk_to_dbt (DBT *dbt, const struct primary_key *pk) {
write_uint_to_dbt(dbt, pk->rand);
write_timestamp_to_dbt(dbt, pk->ts); write_timestamp_to_dbt(dbt, pk->ts);
} }
void write_name_to_dbt (DBT *dbt, const struct name_key *nk) { static void write_name_to_dbt (DBT *dbt, const struct name_key *nk) {
int i; int i;
for (i=0; 1; i++) { for (i=0; 1; i++) {
write_uchar_to_dbt(dbt, nk->name[i]); write_uchar_to_dbt(dbt, nk->name[i]);
...@@ -77,33 +63,23 @@ void write_name_to_dbt (DBT *dbt, const struct name_key *nk) { ...@@ -77,33 +63,23 @@ void write_name_to_dbt (DBT *dbt, const struct name_key *nk) {
} }
} }
void write_pd_to_dbt (DBT *dbt, const struct primary_data *pd) { static void write_pd_to_dbt (DBT *dbt, const struct primary_data *pd) {
write_timestamp_to_dbt(dbt, pd->creationtime); write_timestamp_to_dbt(dbt, pd->creationtime);
write_timestamp_to_dbt(dbt, pd->expiretime); write_timestamp_to_dbt(dbt, pd->expiretime);
write_uchar_to_dbt(dbt, pd->doesexpire); write_uchar_to_dbt(dbt, pd->doesexpire);
write_name_to_dbt(dbt, &pd->name); write_name_to_dbt(dbt, &pd->name);
} }
void read_uchar_from_dbt (const DBT *dbt, int *off, unsigned char *uchar) { static void read_uchar_from_dbt (const DBT *dbt, int *off, unsigned char *uchar) {
assert(*off < dbt->size); assert(*off < dbt->size);
*uchar = ((unsigned char *)dbt->data)[(*off)++]; *uchar = ((unsigned char *)dbt->data)[(*off)++];
} }
void read_uint_from_dbt (const DBT *dbt, int *off, unsigned int *uint) { static void read_timestamp_from_dbt (const DBT *dbt, int *off, TIMESTAMP *ts) {
unsigned char a,b,c,d; read_uchar_from_dbt(dbt, off, ts);
read_uchar_from_dbt(dbt, off, &a);
read_uchar_from_dbt(dbt, off, &b);
read_uchar_from_dbt(dbt, off, &c);
read_uchar_from_dbt(dbt, off, &d);
*uint = (a<<24)+(b<<16)+(c<<8)+d;
}
void read_timestamp_from_dbt (const DBT *dbt, int *off, TIMESTAMP *ts) {
read_uint_from_dbt(dbt, off, &ts->tv_sec);
read_uint_from_dbt(dbt, off, &ts->tv_usec);
} }
void read_name_from_dbt (const DBT *dbt, int *off, struct name_key *nk) { static void read_name_from_dbt (const DBT *dbt, int *off, struct name_key *nk) {
unsigned char buf[1000]; unsigned char buf[1000];
int i; int i;
for (i=0; 1; i++) { for (i=0; 1; i++) {
...@@ -113,18 +89,19 @@ void read_name_from_dbt (const DBT *dbt, int *off, struct name_key *nk) { ...@@ -113,18 +89,19 @@ void read_name_from_dbt (const DBT *dbt, int *off, struct name_key *nk) {
nk->name=(unsigned char*)(strdup((char*)buf)); nk->name=(unsigned char*)(strdup((char*)buf));
} }
void read_pd_from_dbt (const DBT *dbt, int *off, struct primary_data *pd) { static void read_pd_from_dbt (const DBT *dbt, int *off, struct primary_data *pd) {
read_timestamp_from_dbt(dbt, off, &pd->creationtime); read_timestamp_from_dbt(dbt, off, &pd->creationtime);
read_timestamp_from_dbt(dbt, off, &pd->expiretime); read_timestamp_from_dbt(dbt, off, &pd->expiretime);
read_uchar_from_dbt(dbt, off, &pd->doesexpire); read_uchar_from_dbt(dbt, off, &pd->doesexpire);
read_name_from_dbt(dbt, off, &pd->name); read_name_from_dbt(dbt, off, &pd->name);
} }
int name_offset_in_pd_dbt (void) { static int name_offset_in_pd_dbt (void) {
return 17; assert(sizeof(TIMESTAMP)==1);
return 1+2*sizeof(TIMESTAMP);
} }
int name_callback (DB *secondary __attribute__((__unused__)), const DBT *key, const DBT *data, DBT *result) { static int name_callback (DB *secondary __attribute__((__unused__)), const DBT *key, const DBT *data, DBT *result) {
struct primary_data *pd = malloc(sizeof(*pd)); struct primary_data *pd = malloc(sizeof(*pd));
int off=0; int off=0;
read_pd_from_dbt(data, &off, pd); read_pd_from_dbt(data, &off, pd);
...@@ -138,7 +115,7 @@ int name_callback (DB *secondary __attribute__((__unused__)), const DBT *key, co ...@@ -138,7 +115,7 @@ int name_callback (DB *secondary __attribute__((__unused__)), const DBT *key, co
return 0; return 0;
} }
int expire_callback (DB *secondary __attribute__((__unused__)), const DBT *key, const DBT *data, DBT *result) { static int expire_callback (DB *secondary __attribute__((__unused__)), const DBT *key, const DBT *data, DBT *result) {
struct primary_data *d = data->data; struct primary_data *d = data->data;
if (d->doesexpire) { if (d->doesexpire) {
result->flags=0; result->flags=0;
...@@ -152,20 +129,20 @@ int expire_callback (DB *secondary __attribute__((__unused__)), const DBT *key, ...@@ -152,20 +129,20 @@ int expire_callback (DB *secondary __attribute__((__unused__)), const DBT *key,
// The expire_key is simply a timestamp. // The expire_key is simply a timestamp.
DB_ENV *dbenv; static DB_ENV *dbenv;
DB *dbp,*namedb,*expiredb; static DB *dbp,*namedb,*expiredb;
DB_TXN * const null_txn=0; static DB_TXN * const null_txn=0;
DBC *delete_cursor=0, *name_cursor=0; static DBC *delete_cursor=0, *name_cursor=0;
// We use a cursor to count the names. // We use a cursor to count the names.
int cursor_count_n_items=0; // The number of items the cursor saw as it scanned over. static int cursor_count_n_items=0; // The number of items the cursor saw as it scanned over.
int calc_n_items=0; // The number of items we expect the cursor to acount static int calc_n_items=0; // The number of items we expect the cursor to acount
int count_all_items=0; // The total number of items static int count_all_items=0; // The total number of items
DBT nc_key,nc_data; static DBT nc_key,nc_data;
void create_databases (void) { static void create_databases (void) {
int r; int r;
r = db_env_create(&dbenv, 0); CKERR(r); r = db_env_create(&dbenv, 0); CKERR(r);
...@@ -184,7 +161,7 @@ void create_databases (void) { ...@@ -184,7 +161,7 @@ void create_databases (void) {
r = dbp->associate(dbp, NULL, expiredb, expire_callback, 0); CKERR(r); r = dbp->associate(dbp, NULL, expiredb, expire_callback, 0); CKERR(r);
} }
void close_databases (void) { static void close_databases (void) {
int r; int r;
if (delete_cursor) { if (delete_cursor) {
r = delete_cursor->c_close(delete_cursor); CKERR(r); r = delete_cursor->c_close(delete_cursor); CKERR(r);
...@@ -201,76 +178,30 @@ void close_databases (void) { ...@@ -201,76 +178,30 @@ void close_databases (void) {
} }
void gettod (TIMESTAMP *ts) { static void gettod (TIMESTAMP *ts) {
static int counter=0; static int counter=0;
assert(counter<127); assert(counter<127);
ts->tv_sec = 0; *ts = counter++;
ts->tv_usec = counter++;
} }
void setup_for_db_create (void) { static int oppass=0, opnum=0;
// Remove name.db and then rebuild it with associate(... DB_CREATE)
int r=unlink(DIR "/name.db");
assert(r==0);
r = db_env_create(&dbenv, 0); CKERR(r);
r = dbenv->open(dbenv, DIR, DB_PRIVATE|DB_INIT_MPOOL, 0); CKERR(r);
r = db_create(&dbp, dbenv, 0); CKERR(r);
r = dbp->open(dbp, null_txn, "primary.db", NULL, DB_BTREE, 0, 0600); CKERR(r);
r = db_create(&namedb, dbenv, 0); CKERR(r);
r = namedb->open(namedb, null_txn, "name.db", NULL, DB_BTREE, DB_CREATE, 0600); CKERR(r);
r = db_create(&expiredb, dbenv, 0); CKERR(r);
r = expiredb->open(expiredb, null_txn, "expire.db", NULL, DB_BTREE, 0, 0600); CKERR(r);
r = dbp->associate(dbp, NULL, expiredb, expire_callback, 0); CKERR(r);
r = dbp->associate(dbp, NULL, namedb, name_callback, DB_CREATE); CKERR(r);
}
#if 0
static int count_entries (const char *dbcname, DB *db) {
DBC *dbc;
int r = db->cursor(db, null_txn, &dbc, 0); CKERR(r);
DBT key,data;
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
int n_found=0;
for (r = do_cget(dbcname, dbc, &key, &data, DB_FIRST);
r==0;
r = do_cget(dbcname, dbc, &key, &data, DB_NEXT)) {
n_found++;
}
assert(r==DB_NOTFOUND);
r=dbc->c_close(dbc); CKERR(r);
return n_found;
}
#endif
int oppass=0, opnum=0;
static void insert_person (void) { static void insert_person (void) {
int namelen = 5+myrandom()%245; // int namelen = 5+myrandom()%245;
struct primary_key pk; struct primary_key pk;
struct primary_data pd; struct primary_data pd;
char keyarray[1000], dataarray[1000]; char keyarray[1000], dataarray[1000];
char *namearray; char *namearray;
myrandom(); // myrandom();
static int rctr=0;
pk.rand = rctr++;
gettod(&pk.ts); gettod(&pk.ts);
pd.creationtime = pk.ts; pd.creationtime = pk.ts;
pd.expiretime = pk.ts; pd.expiretime = pk.ts;
pd.expiretime.tv_sec += 24*60*60*366; pd.expiretime += 128;
pd.doesexpire = oppass==1 && (opnum==2 || opnum==10 || opnum==22); pd.doesexpire = oppass==1 && (opnum==2 || opnum==10 || opnum==22);
int i; // int i;
for (i=0; i<namelen; i++) { // for (i=0; i<namelen; i++) {
myrandom(); // myrandom();
} // }
// fprintf(stderr, "%d: else if (oppass==%d && opnum==%d) pd.name=\"%s\";\n", __LINE__, oppass, opnum, pd.name.name); // fprintf(stderr, "%d: else if (oppass==%d && opnum==%d) pd.name=\"%s\";\n", __LINE__, oppass, opnum, pd.name.name);
if (oppass==1 && opnum==1) namearray="Hc"; if (oppass==1 && opnum==1) namearray="Hc";
else if (oppass==1 && opnum==2) namearray="Ku"; else if (oppass==1 && opnum==2) namearray="Ku";
...@@ -314,7 +245,7 @@ static void insert_person (void) { ...@@ -314,7 +245,7 @@ static void insert_person (void) {
static void delete_oldest_expired (void) { static void delete_oldest_expired (void) {
int r; int r;
myrandom(); //myrandom();
if (delete_cursor==0) { if (delete_cursor==0) {
r = expiredb->cursor(expiredb, null_txn, &delete_cursor, 0); CKERR(r); r = expiredb->cursor(expiredb, null_txn, &delete_cursor, 0); CKERR(r);
...@@ -373,10 +304,8 @@ static void step_name (void) { ...@@ -373,10 +304,8 @@ static void step_name (void) {
} }
} }
int cursor_load=2; /* Set this to a higher number to do more cursor work for every insertion. Needed to get to the end. */
static void activity (void) { static void activity (void) {
myrandom(); //myrandom();
int do_delete = (oppass==1 && opnum==32) || (oppass==2 && opnum==8); int do_delete = (oppass==1 && opnum==32) || (oppass==2 && opnum==8);
if (do_delete) { if (do_delete) {
// Delete the oldest expired one. Keep the cursor open // Delete the oldest expired one. Keep the cursor open
...@@ -399,7 +328,7 @@ static void activity (void) { ...@@ -399,7 +328,7 @@ static void activity (void) {
|| (oppass==1 && opnum==30) || (oppass==1 && opnum==30)
|| (oppass==2 && opnum==9) || (oppass==2 && opnum==9)
|| (oppass==2 && opnum==15)); || (oppass==2 && opnum==15));
myrandom(); //myrandom();
if (do_insert) { if (do_insert) {
insert_person(); insert_person();
} else { } else {
...@@ -444,8 +373,8 @@ int main (int argc, const char *argv[]) { ...@@ -444,8 +373,8 @@ int main (int argc, const char *argv[]) {
argc--; argv++; argc--; argv++;
} }
fprintf(stderr, "seed=%d\n", useseed); // fprintf(stderr, "seed=%d\n", useseed);
srandom(useseed); // srandom(useseed);
switch (mode) { switch (mode) {
case MODE_DEFAULT: case MODE_DEFAULT:
...@@ -465,11 +394,10 @@ int main (int argc, const char *argv[]) { ...@@ -465,11 +394,10 @@ int main (int argc, const char *argv[]) {
oppass=2; oppass=2;
create_databases(); create_databases();
calc_n_items = count_all_items = 14;//count_entries("dbc", dbp); calc_n_items = count_all_items = 14;//count_entries("dbc", dbp);
fprintf(stderr, "%s:%d n_items initially=%d\n", __FILE__, __LINE__, count_all_items); //fprintf(stderr, "%s:%d n_items initially=%d\n", __FILE__, __LINE__, count_all_items);
{ {
const int n_activities = 100; const int n_activities = 100;
int i; int i;
cursor_load = 8*(1+2*count_all_items/n_activities);
//printf("%s:%d count=%d cursor_load=%d\n", __FILE__, __LINE__, count_all_items, cursor_load); //printf("%s:%d count=%d cursor_load=%d\n", __FILE__, __LINE__, count_all_items, cursor_load);
for (i=0; i<n_activities; i++) { for (i=0; i<n_activities; i++) {
opnum=i; opnum=i;
......
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