nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

commit 8ee1dc79057ababc8f2bb0ef44e63116f615b965
parent f73c9a3a4f26d01b20185c709f915450b36ef01f
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 11 Sep 2023 08:43:27 -0700

log: fix log error messages

Diffstat:
Mnostrdb.c | 18+++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/nostrdb.c b/nostrdb.c @@ -61,9 +61,15 @@ enum ndb_dbs { NDB_DB_PROFILE, NDB_DB_NOTE_ID, NDB_DB_PROFILE_PK, + NDB_DB_NDB_META, NDB_DBS, }; +// keys used for storing data in the NDB metadata database (NDB_DB_NDB_META) +enum ndb_meta_key { + NDB_DB_VERSION = 1 +}; + struct ndb_json_parser { const char *json; int json_len; @@ -962,7 +968,7 @@ static int ndb_init_lmdb(const char *filename, struct ndb_lmdb *lmdb, size_t map } if ((rc = mdb_env_set_maxdbs(lmdb->env, NDB_DBS))) { - fprintf(stderr, "mdb_env_set_mapsize failed, error %d\n", rc); + fprintf(stderr, "mdb_env_set_maxdbs failed, error %d\n", rc); return 0; } @@ -995,6 +1001,12 @@ static int ndb_init_lmdb(const char *filename, struct ndb_lmdb *lmdb, size_t map return 0; } + // ndb metadata (db version, etc) + if ((rc = mdb_dbi_open(txn, "ndb_meta", MDB_CREATE | MDB_INTEGERKEY, &lmdb->dbs[NDB_DB_NDB_META]))) { + fprintf(stderr, "mdb_dbi_open ndb_meta failed, error %d\n", rc); + return 0; + } + // id+ts index flags unsigned int tsid_flags = MDB_CREATE | MDB_DUPSORT | MDB_DUPFIXED; @@ -1036,12 +1048,12 @@ int ndb_init(struct ndb **pndb, const char *filename, size_t mapsize, int ingest return 0; if (!ndb_writer_init(&ndb->writer, &ndb->lmdb)) { - fprintf(stderr, "ndb_writer_init failed"); + fprintf(stderr, "ndb_writer_init failed\n"); return 0; } if (!ndb_ingester_init(&ndb->ingester, &ndb->writer, ingester_threads)) { - fprintf(stderr, "failed to initialize %d ingester thread(s)", + fprintf(stderr, "failed to initialize %d ingester thread(s)\n", ingester_threads); return 0; }