shuttler/nessDB — Issue #23: db_get interface doesn't return data length
Author: HarryR
Created: 2011-12-30 16:43:42+00:00
State: open

The current nessdb interface makes it problematic to retrieve binary data (e.g. containing NIL - or even not containing any NILs).

void *db_get(struct nessdb *db, struct slice *sk);

Other DBM/KV databases like BDB, Tokyo Cabinet and LevelDB output the length as part of their 'get' call.
e.g.

size_t data_sz = 0;
char* data = tcbdbget(db, key, key_sz, &data_sz);

and

char *dberr = NULL;
size_t data_sz = 0;
char* data = leveldb_get(db, db_roptions, key, key_sz, &data_sz, &dberr);

One way to implement this is to provide an output slice as the third argument to db_get and return the number of bytes retrieved (with 0 being an error condition)
Example:

struct slice key = {"derp", 4};
struct slice val = {NULL, 0};
if( ! db_get(db, &key, &val) ) {
... db_error(db)