Embedded AlchemyDB v0.0.0.0.1

6 views
Skip to first unread message

Jak Sprats

unread,
Aug 31, 2011, 2:33:50 PM8/31/11
to redisql-dev
Hi All,

A client of AlchemyDB needed an Embedded AlchemyDB version and was
nice enough to allow it to be open sourced (AGPL like the rest of
AlchemyDB).

Embedded AlchemyDB is single threaded, so if you are calling it from a
multithreaded application, you will have to ensure that only one
thread calls it at a time (which is not as bad as it sounds because an
in-memory database responds quickly).

Another quirk (and probably a good thing) is SELECTed rows are
returned via a callback and a SELECT can be cancelled midway, if the
callback returns 0.

I do not expect many people to need a single-threaded embedded in-
memory AlchemyDB, so this writeup will be the only announcement.

The test program is here:
https://github.com/JakSprats/Alchemy-Database/blob/master/redis_unstable/src/embedded_test.c

It has some test running functions, but in the end it all comes down
to calling:
eresp_t *e_alchemy_raw(char *sql, select_callback *scb);
https://github.com/JakSprats/Alchemy-Database/blob/master/DB/embed.c#L225-239

The data structures used in e_alchemy_raw() are defined here
https://github.com/JakSprats/Alchemy-Database/blob/master/DB/xdb_common.h#L42-59
& https://github.com/JakSprats/Alchemy-Database/blob/master/DB/embed.h#L35-41
here are the relevant parts:
typedef struct aobj {
char *s;
uint32 len;
uint32 i;
ulong l;
float f;
uchar type;
} aobj;
typedef struct embedded_row_t {
int ncols;
struct aobj **cols;
} erow_t;
typedef bool select_callback(erow_t* erow);
typedef struct embedded_response_t {
int retcode; /* REDIS_OK, REDIS_ERR */
int ncols; /* SELECTed column named count */
char **cnames; /* SELECTed column names */
int nobj; /* number of returned objects */
struct aobj **objs; /* returned objects */
} eresp_t;

Aobj.types are defined here:
https://github.com/JakSprats/Alchemy-Database/blob/master/DB/common.h#L43-47
#define COL_TYPE_INT 0
#define COL_TYPE_LONG 1
#define COL_TYPE_STRING 2
#define COL_TYPE_FLOAT 3
#define COL_TYPE_NONE 4

The test program is the best example of how it works
https://github.com/JakSprats/Alchemy-Database/blob/master/redis_unstable/src/embedded_test.c
I tried to put in enough examples and helpful accessor functions to
explain how embedded AlchemyDB works.

Building the system is done here:
https://github.com/JakSprats/Alchemy-Database/blob/master/redis_unstable/src/Makefile#L219-220
it takes libraries from ./DB & objects from ./redis/src

Alchemy works on most linux flavors. It does not currently work on
32bit systems, but w/ about 2-5 days work it could (it used to, but
bitrot changed that).

Embedded Alchemy is optimised for its SQL calls, but also works w/
redis objects, although redis objects are written to a buffer in redis
protocol and then parsed (as a client would) to populate eresp_t.

- jak
Reply all
Reply to author
Forward
0 new messages