diff --git a/codex/codex.nim b/codex/codex.nim index f5d8f5ac..fd36451d 100644 --- a/codex/codex.nim +++ b/codex/codex.nim @@ -44,6 +44,7 @@ import ./utils/addrutils import ./namespaces import ./codextypes import ./logutils +import ../leveldb/leveldbds logScope: topics = "codex node" @@ -232,7 +233,7 @@ proc new*( let discoveryStore = Datastore( - SQLiteDatastore.new(config.dataDir / CodexDhtProvidersNamespace) + LevelDbDatastore.new(config.dataDir / CodexDhtProvidersNamespace) .expect("Should create discovery datastore!")) discovery = Discovery.new( @@ -249,11 +250,10 @@ proc new*( repoData = case config.repoKind of repoFS: Datastore(FSDatastore.new($config.dataDir, depth = 5) .expect("Should create repo file data store!")) - of repoSQLite: Datastore(SQLiteDatastore.new($config.dataDir) + of repoSQLite: Datastore(LevelDbDatastore.new($config.dataDir) .expect("Should create repo SQLite data store!")) - metadataStore = Datastore(FSDatastore.new($config.metaDir, depth = 5) - .expect("Should create repo metadata store!")) + metadataStore = Datastore(LevelDbDatastore.new($(config.metaDir / "leveldb.ds")).expect("Should create metadata store!")) repoStore = RepoStore.new( repoDs = repoData, diff --git a/leveldb/leveldbds.nim b/leveldb/leveldbds.nim index 35a7e99e..7323b7e2 100644 --- a/leveldb/leveldbds.nim +++ b/leveldb/leveldbds.nim @@ -1,6 +1,7 @@ import std/options import std/tables +import pkg/chronicles import pkg/chronos import pkg/questionable import pkg/questionable/results @@ -14,6 +15,9 @@ import ./src/leveldb push: {.upraises: [].} +logScope: + topics = "LevelDB" + type LevelDbDatastore* = ref object of Datastore db: LevelDb @@ -49,16 +53,18 @@ method delete*(self: Datastore, keys: seq[Key]): Future[?!void] {.async, locks: return success() method get*(self: LevelDbDatastore, key: Key): Future[?!seq[byte]] {.async, locks: "unknown".} = + trace "Get", key try: let str = self.db.get($key) if not str.isSome: - return failure("LevelDbDatastore.get: key not found " & $key) + return failure(newException(DatastoreKeyNotFound, "LevelDbDatastore.get: key not found " & $key)) let bytes = toByteSeq(str.get()) return success(bytes) except LevelDbException as e: return failure("LevelDbDatastore.get exception: " & $e.msg) method put*(self: LevelDbDatastore, key: Key, data: seq[byte]): Future[?!void] {.async, locks: "unknown".} = + trace "Put", key try: let str = toString(data) self.db.put($key, str) @@ -174,6 +180,8 @@ method modify*( proc new*( T: type LevelDbDatastore, dbName: string): ?!T = try: + trace "Opening LevelDB", dbName + let db = leveldb.open(dbName) success T( @@ -181,4 +189,5 @@ proc new*( locks: newTable[Key, AsyncLock]() ) except LevelDbException: + error "That didn't work" return failure("exception open")