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 @@
#include "test.h"
#include "trace.h"
enum mode {
static enum mode {
MODE_DEFAULT, MODE_MORE
} 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. */
typedef struct timestamp {
unsigned int tv_sec; /* in network order */
unsigned int tv_usec; /* in network order */
} TIMESTAMP;
typedef unsigned char TIMESTAMP;
struct primary_key {
int rand; /* in network order */
TIMESTAMP ts;
};
......@@ -42,34 +37,25 @@ struct primary_data {
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);
}
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);
((char*)dbt->data)[dbt->size++]=c;
}
void write_uint_to_dbt (DBT *dbt, const unsigned int v) {
write_uchar_to_dbt(dbt, (v>>24)&0xff);
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);
static void write_timestamp_to_dbt (DBT *dbt, const TIMESTAMP ts) {
write_uchar_to_dbt(dbt, ts);
}
void write_pk_to_dbt (DBT *dbt, const struct primary_key *pk) {
write_uint_to_dbt(dbt, pk->rand);
static void write_pk_to_dbt (DBT *dbt, const struct primary_key *pk) {
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;
for (i=0; 1; 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) {
}
}
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->expiretime);
write_uchar_to_dbt(dbt, pd->doesexpire);
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);
*uchar = ((unsigned char *)dbt->data)[(*off)++];
}
void read_uint_from_dbt (const DBT *dbt, int *off, unsigned int *uint) {
unsigned char a,b,c,d;
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);
static void read_timestamp_from_dbt (const DBT *dbt, int *off, TIMESTAMP *ts) {
read_uchar_from_dbt(dbt, off, ts);
}
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];
int i;
for (i=0; 1; i++) {
......@@ -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));
}
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->expiretime);
read_uchar_from_dbt(dbt, off, &pd->doesexpire);
read_name_from_dbt(dbt, off, &pd->name);
}
int name_offset_in_pd_dbt (void) {
return 17;
static int name_offset_in_pd_dbt (void) {
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));
int off=0;
read_pd_from_dbt(data, &off, pd);
......@@ -138,7 +115,7 @@ int name_callback (DB *secondary __attribute__((__unused__)), const DBT *key, co
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;
if (d->doesexpire) {
result->flags=0;
......@@ -152,20 +129,20 @@ int expire_callback (DB *secondary __attribute__((__unused__)), const DBT *key,
// The expire_key is simply a timestamp.
DB_ENV *dbenv;
DB *dbp,*namedb,*expiredb;
static DB_ENV *dbenv;
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.
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
int count_all_items=0; // The total number of items
DBT nc_key,nc_data;
static int cursor_count_n_items=0; // The number of items the cursor saw as it scanned over.
static int calc_n_items=0; // The number of items we expect the cursor to acount
static int count_all_items=0; // The total number of items
static DBT nc_key,nc_data;
void create_databases (void) {
static void create_databases (void) {
int r;
r = db_env_create(&dbenv, 0); CKERR(r);
......@@ -184,7 +161,7 @@ void create_databases (void) {
r = dbp->associate(dbp, NULL, expiredb, expire_callback, 0); CKERR(r);
}
void close_databases (void) {
static void close_databases (void) {
int r;
if (delete_cursor) {
r = delete_cursor->c_close(delete_cursor); CKERR(r);
......@@ -201,76 +178,30 @@ void close_databases (void) {
}
void gettod (TIMESTAMP *ts) {
static void gettod (TIMESTAMP *ts) {
static int counter=0;
assert(counter<127);
ts->tv_sec = 0;
ts->tv_usec = counter++;
*ts = counter++;
}
void setup_for_db_create (void) {
// 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 int oppass=0, opnum=0;
static void insert_person (void) {
int namelen = 5+myrandom()%245;
// int namelen = 5+myrandom()%245;
struct primary_key pk;
struct primary_data pd;
char keyarray[1000], dataarray[1000];
char *namearray;
myrandom();
static int rctr=0;
pk.rand = rctr++;
// myrandom();
gettod(&pk.ts);
pd.creationtime = 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);
int i;
for (i=0; i<namelen; i++) {
myrandom();
}
// int i;
// for (i=0; i<namelen; i++) {
// myrandom();
// }
// 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";
else if (oppass==1 && opnum==2) namearray="Ku";
......@@ -314,7 +245,7 @@ static void insert_person (void) {
static void delete_oldest_expired (void) {
int r;
myrandom();
//myrandom();
if (delete_cursor==0) {
r = expiredb->cursor(expiredb, null_txn, &delete_cursor, 0); CKERR(r);
......@@ -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) {
myrandom();
//myrandom();
int do_delete = (oppass==1 && opnum==32) || (oppass==2 && opnum==8);
if (do_delete) {
// Delete the oldest expired one. Keep the cursor open
......@@ -399,7 +328,7 @@ static void activity (void) {
|| (oppass==1 && opnum==30)
|| (oppass==2 && opnum==9)
|| (oppass==2 && opnum==15));
myrandom();
//myrandom();
if (do_insert) {
insert_person();
} else {
......@@ -444,8 +373,8 @@ int main (int argc, const char *argv[]) {
argc--; argv++;
}
fprintf(stderr, "seed=%d\n", useseed);
srandom(useseed);
// fprintf(stderr, "seed=%d\n", useseed);
// srandom(useseed);
switch (mode) {
case MODE_DEFAULT:
......@@ -465,11 +394,10 @@ int main (int argc, const char *argv[]) {
oppass=2;
create_databases();
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;
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);
for (i=0; i<n_activities; 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