From: Howard Chu Date: Wed, 3 Aug 2011 00:59:37 +0000 (-0700) Subject: Start DB restructuring X-Git-Tag: OPENLDAP_REL_ENG_2_4_27~148^2~151 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=cb4519179303fd54f282d3e4dcb477befbfca48d;p=openldap Start DB restructuring --- diff --git a/libraries/libmdb/mdb.c b/libraries/libmdb/mdb.c index 20be7eadb0..8a1f3518f6 100644 --- a/libraries/libmdb/mdb.c +++ b/libraries/libmdb/mdb.c @@ -188,9 +188,9 @@ SLIST_HEAD(page_stack, MDB_ppage); #define CURSOR_PUSH(c,p) SLIST_INSERT_HEAD(&(c)->mc_stack, p, mp_entry) struct MDB_cursor { - MDB_db *mc_db; MDB_txn *mc_txn; struct page_stack mc_stack; /* stack of parent pages */ + MDB_dbi mc_dbi; short mc_initialized; /* 1 if initialized */ short mc_eof; /* 1 if end is reached */ }; @@ -211,6 +211,24 @@ typedef struct MDB_node { char mn_data[1]; } MDB_node; +typedef struct MDB_dbx { + char *md_name; + MDB_cmp_func *md_cmp; /* user compare function */ + MDB_rel_func *md_rel; /* user relocate function */ + MDB_db *md_parent; /* parent tree */ +} MDB_dbx; + +typedef struct MDB_db { + uint32_t md_pad; + uint16_t md_flags; + uint16_t md_depth; + ULONG md_branch_pages; + ULONG md_leaf_pages; + ULONG md_overflow_pages; + ULONG md_entries; + pgno_t md_root; +} MDB_db; + struct MDB_txn { pgno_t mt_root; /* current / new root page */ pgno_t mt_next_pgno; /* next unallocated page */ @@ -222,29 +240,16 @@ struct MDB_txn { struct dirty_queue *dirty_queue; /* modified pages */ MDB_reader *reader; } mt_u; + MDB_dbx *mt_dbxs; /* array */ + MDB_db **mt_dbs; /* array of ptrs */ + unsigned int mt_numdbs; + #define MDB_TXN_RDONLY 0x01 /* read-only transaction */ #define MDB_TXN_ERROR 0x02 /* an error has occurred */ #define MDB_TXN_METOGGLE 0x04 /* used meta page 1 */ unsigned int mt_flags; }; -struct MDB_db { - MDB_db *md_next; - char *md_name; - MDB_cmp_func *md_cmp; /* user compare function */ - MDB_rel_func *md_rel; /* user relocate function */ - MDB_db *md_parent; /* parent tree */ - MDB_env *md_env; - uint32_t md_pad; - uint16_t md_flags; - uint16_t md_depth; - ULONG md_branch_pages; - ULONG md_leaf_pages; - ULONG md_overflow_pages; - ULONG md_entries; - pgno_t md_root; -}; - struct MDB_env { int me_fd; int me_lfd; @@ -253,7 +258,6 @@ struct MDB_env { char *me_path; char *me_map; MDB_txninfo *me_txns; - MDB_db me_db; /* first DB */ MDB_meta me_meta; MDB_txn *me_txn; /* current write transaction */ size_t me_mapsize; @@ -261,6 +265,9 @@ struct MDB_env { pthread_key_t me_txkey; /* thread-key for readers */ MDB_oldpages *me_pghead; MDB_oldpages *me_pgtail; + MDB_dbx *me_dbxs; /* array */ + MDB_db **me_dbs; /* array of ptrs */ + unsigned int me_numdbs; }; #define NODESIZE offsetof(MDB_node, mn_data) @@ -2557,10 +2564,10 @@ mdbenv_stat(MDB_env *env, MDB_stat *arg) return MDB_SUCCESS; } -int mdb_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_db **db) +int mdb_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi) { if (!name) { - *db = (MDB_db *)&txn->mt_env->me_db; + *dbi = 0; return MDB_SUCCESS; } return EINVAL; diff --git a/libraries/libmdb/mdb.h b/libraries/libmdb/mdb.h index 4a9403d06a..14ee901c18 100644 --- a/libraries/libmdb/mdb.h +++ b/libraries/libmdb/mdb.h @@ -5,14 +5,14 @@ struct MDB_cursor; struct MDB_txn; -struct MDB_db; struct MDB_env; typedef struct MDB_cursor MDB_cursor; typedef struct MDB_txn MDB_txn; -typedef struct MDB_db MDB_db; typedef struct MDB_env MDB_env; +typedef unsigned int MDB_dbi; + typedef struct MDB_val { void *mv_data; size_t mv_size; @@ -64,26 +64,25 @@ int mdbenv_set_mapsize(MDB_env *env, size_t size); int mdbenv_set_maxreaders(MDB_env *env, int readers); int mdbenv_get_maxreaders(MDB_env *env, int *readers); int mdbenv_sync(MDB_env *env); -int mdbenv_compact(MDB_env *env); int mdb_txn_begin(MDB_env *env, int rdonly, MDB_txn **txn); int mdb_txn_commit(MDB_txn *txn); void mdb_txn_abort(MDB_txn *txn); -int mdb_open(MDB_env *env, MDB_txn *txn, const char *name, unsigned int flags, MDB_db **db); -int mdb_stat(MDB_db *db, MDB_stat *stat); -void mdb_close(MDB_db *db); +int mdb_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi); +int mdb_stat(MDB_txn *txn, MDB_dbi dbi, MDB_stat *stat); +void mdb_close(MDB_txn *txn, MDB_dbi dbi); -int mdb_get(MDB_db *db, MDB_txn *txn, MDB_val *key, MDB_val *data); -int mdb_put(MDB_db *db, MDB_txn *txn, MDB_val *key, MDB_val *data, +int mdb_get(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data); +int mdb_put(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data, unsigned int flags); -int mdb_del(MDB_db *db, MDB_txn *txn, MDB_val *key, MDB_val *data); +int mdb_del(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data); -int mdb_cursor_open(MDB_db *db, MDB_txn *txn, MDB_cursor **cursor); +int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor); void mdb_cursor_close(MDB_cursor *cursor); int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op op); -int mdb_cmp(MDB_db *db, const MDB_val *a, const MDB_val *b); +int mdb_cmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b); #endif /* _MDB_H_ */