|
| DBD * | dbif_init (const char *envhome, const char *dbname) |
| int | dbif_env_open (DBD *dbd, struct db_param *dbp, uint32_t dbenv_oflags) |
| int | dbif_open (DBD *dbd, struct db_param *dbp, int reindex) |
| int | dbif_close (DBD *dbd) |
| int | dbif_env_remove (const char *path) |
| int | dbif_get (DBD *, const int, DBT *, DBT *, uint32_t) |
| int | dbif_pget (DBD *, const int, DBT *, DBT *, DBT *, uint32_t) |
| int | dbif_put (DBD *, const int, DBT *, DBT *, uint32_t) |
| int | dbif_del (DBD *, const int, DBT *, uint32_t) |
| int | dbif_count (DBD *, const int, uint32_t *) |
| int | dbif_search (DBD *dbd, DBT *key, char *resbuf, uint32_t offset, bool *more) |
| | Paginated substring cursor scan over the name index.
|
| int | dbif_copy_rootinfokey (DBD *srcdbd, DBD *destdbd) |
| int | dbif_txn_begin (DBD *) |
| int | dbif_txn_commit (DBD *) |
| int | dbif_txn_abort (DBD *) |
| int | dbif_txn_close (DBD *dbd, int ret) |
| | Close a transaction based on ret code.
|
| int | dbif_txn_checkpoint (DBD *, uint32_t, uint32_t, uint32_t) |
| int | dbif_dump (DBD *dbd, int dumpindexes) |
| int | dbif_idwalk (DBD *dbd, cnid_t *cnid, int close) |
| | Iterates over dbd, returning cnids.
|
CNID DBD (Database Daemon) Backend interface definitions.
API usage
Initialization
- Provide storage for a DBD * handle: DBD *dbd;
- Call dbif_init with a filename to receive a DBD handle: dbd = dbif_init("cnid2.db"); Pass NULL to create an in-memory db. Note: the DBD type is NOT from BerkeleyDB ! We've defined it.
- Call dbif_env_open to open an dbd environment if you called dbif_init with a filename. Pass a db_param here for on-disk databases.
- Call dbif_open to finally open the CNID database itself. Pass db_param here for in-memory database.
Querying the CNID database
Call dbif_[get|pget|put|del]. They map to the corresponding BerkeleyDB calls with the same names.
Transactions
We use AUTO_COMMIT for the BDB database accesses. This avoids explicit transactions for every bdb access which speeds up reads. But in order to be able to rollback in case of errors we start a transaction once we encounter the first write from dbif_put or dbif_del. Thus you shouldn't call dbif_txn_[begin|abort|commit], they're used internally.
Checkpoiting
Call dbif_txn_checkpoint.
Closing
Call dbif_close.
Silent Upgrade Support
On cnid_dbd shutdown we reopen the environment with recovery, close and then remove it. This enables an upgraded netatalk installation possibly linked against a newer bdb lib to succesfully open/create an environment and then silently upgrade the database itself. How nice!
| int dbif_search |
( |
DBD * | dbd, |
|
|
DBT * | key, |
|
|
char * | resbuf, |
|
|
uint32_t | offset, |
|
|
bool * | more ) |
Paginated substring cursor scan over the name index.
Skips offset matching entries before emitting up to DBD_MAX_SRCH_RSLTS results into resbuf. After the buffer fills, continues until the next matching entry to decide whether further matches exist; reports the result via more.
The caller MUST keep a separate backup of the original name bytes because BDB takes ownership of key->data after each pget() call.
- Parameters
-
| [in] | dbd | database handle |
| [in] | key | initialised with the search name (key->data, key->size) |
| [out] | resbuf | buffer for matching CNIDs in network byte order, must have capacity for DBD_MAX_SRCH_RSLTS * sizeof(cnid_t) bytes |
| [in] | offset | number of leading matches to skip, range 0..DBD_SEARCH_MAX_OFFSET |
| [out] | more | set to true iff a (offset + DBD_MAX_SRCH_RSLTS + 1)-th matching entry exists in the index, false otherwise. MUST be non-NULL. |
- Returns
- -1 on BDB engine error, else the number of matches written to
resbuf (0..DBD_MAX_SRCH_RSLTS)