Commit d13076d2 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Simplify further. Addresses #162.

git-svn-id: file:///svn/tokudb@1068 c7de825b-a66e-492c-adef-691d508d4ae1
parent 07c01e89
...@@ -31,17 +31,11 @@ struct name_key { ...@@ -31,17 +31,11 @@ struct name_key {
}; };
struct primary_data { struct primary_data {
TIMESTAMP creationtime;
TIMESTAMP expiretime; /* not valid if doesexpire==0 */ TIMESTAMP expiretime; /* not valid if doesexpire==0 */
unsigned char doesexpire; unsigned char doesexpire;
struct name_key name; struct name_key name;
}; };
static void free_pd (struct primary_data *pd) {
free(pd->name.name);
free(pd);
}
static 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;
...@@ -64,57 +58,30 @@ static void write_name_to_dbt (DBT *dbt, const struct name_key *nk) { ...@@ -64,57 +58,30 @@ static void write_name_to_dbt (DBT *dbt, const struct name_key *nk) {
} }
static 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_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);
} }
static void read_uchar_from_dbt (const DBT *dbt, int *off, unsigned char *uchar) {
assert(*off < dbt->size);
*uchar = ((unsigned char *)dbt->data)[(*off)++];
}
static void read_timestamp_from_dbt (const DBT *dbt, int *off, TIMESTAMP *ts) {
read_uchar_from_dbt(dbt, off, ts);
}
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++) {
read_uchar_from_dbt(dbt, off, &buf[i]);
if (buf[i]==0) break;
}
nk->name=(unsigned char*)(strdup((char*)buf));
}
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);
}
static int name_offset_in_pd_dbt (void) { static int name_offset_in_pd_dbt (void) {
assert(sizeof(TIMESTAMP)==1); assert(sizeof(TIMESTAMP)==1);
return 1+2*sizeof(TIMESTAMP); return 1+sizeof(TIMESTAMP);
} }
static 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)); /* This one does work. */
int off=0; static char buf[1000];
read_pd_from_dbt(data, &off, pd); char *rdata = ((char*)data->data)+name_offset_in_pd_dbt();
static int buf[1000]; int rsize = data->size-name_offset_in_pd_dbt();
memset(result, 0, sizeof(*result));
result->ulen=1000; result->size = rsize;
result->data=buf; result->data = buf;
result->size=0; memcpy(buf, rdata, rsize);
write_name_to_dbt(result, &pd->name); //result->data=rdata; /* This breaks bdb */
free_pd(pd);
return 0; return 0;
} }
static 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) {
...@@ -192,9 +159,7 @@ static void insert_person (void) { ...@@ -192,9 +159,7 @@ static void insert_person (void) {
char keyarray[1000], dataarray[1000]; char keyarray[1000], dataarray[1000];
char *namearray; char *namearray;
gettod(&pk.ts); gettod(&pk.ts);
pd.creationtime = pk.ts;
pd.expiretime = pk.ts; pd.expiretime = pk.ts;
pd.expiretime += 128;
pd.doesexpire = oppass==1 && (opnum==2 || opnum==10 || opnum==22); pd.doesexpire = oppass==1 && (opnum==2 || opnum==10 || opnum==22);
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";
......
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