16-FEB-2011: A simple "append-only" database r1 (See the current copy)
A proposed API and implementation for an append-only database
- Journal (multiple concurrent writers) -- all writes go here, acts as a buffer
- Database (flat text file, looks like a log file) -- written to by single thread reading from Journal; order of inserts is not guaranteed to be the same as order of inserts into journal
- Index (binary tree of keys) -- values are kept in sorted order with a count of the number of values; values are pointers to offsets in the Database
Support disabling the journal or the index at run-time by not specifying them during an amdb_open() call
Journal format:
- [Magic (32-bits)]
- [Header Size (HDR_SZ; 32-bits)]
- [Header (HDR_SZ * 8-bits)]:
- Tag-Length-Value
- [Tracks (NUM_TRACKS * TRACK_SIZE * 8-bits)]
API:
- void *amdb_open(const char *db, const char *journal, const char *index);
- All parameters are strings containing the pathnames to files to store their respective components
- void amdb_insert(void *handle, time_t date, ...);
- All additional arguments are required to be strings in pairs, the first of the pair being the field name and the second being the field contents
- Terminate with NULL
- void amdb_consumejournal(void *handle);
- Starts a process that consumes entries from the journal and writes to database and index files.