diff --git a/Database/Sources/Database/Options.swift b/Database/Sources/Database/Options.swift index 8312a58e..8c67d8f2 100644 --- a/Database/Sources/Database/Options.swift +++ b/Database/Sources/Database/Options.swift @@ -7,7 +7,7 @@ public struct Options: ~Copyable, Sendable { var value: OpaquePointer { ptr.value } public init() { - ptr = .init(rocksdb_options_create(), free: rocksdb_options_destroy) + ptr = .init(ptr: rocksdb_options_create(), free: rocksdb_options_destroy) } public func increaseParallelism(cpus: Int) { @@ -33,7 +33,7 @@ public struct WriteOptions: ~Copyable, Sendable { var value: OpaquePointer { ptr.value } public init() { - ptr = .init(rocksdb_writeoptions_create(), free: rocksdb_writeoptions_destroy) + ptr = .init(ptr: rocksdb_writeoptions_create(), free: rocksdb_writeoptions_destroy) } } @@ -43,6 +43,6 @@ public struct ReadOptions: ~Copyable, Sendable { var value: OpaquePointer { ptr.value } public init() { - ptr = .init(rocksdb_readoptions_create(), free: rocksdb_readoptions_destroy) + ptr = .init(ptr: rocksdb_readoptions_create(), free: rocksdb_readoptions_destroy) } } diff --git a/Database/Sources/Database/RocksDB.swift b/Database/Sources/Database/RocksDB.swift index ac5860a8..f98d2d34 100644 --- a/Database/Sources/Database/RocksDB.swift +++ b/Database/Sources/Database/RocksDB.swift @@ -23,7 +23,7 @@ public final class RocksDB: Sendable { private let db: SendableOpaquePointer public init(path: URL) throws(Error) { - dbOptions = Options() + let dbOptions = Options() // TODO: starting from options here // https://github.com/paritytech/parity-common/blob/e3787dc768b08e10809834c65419ad3c255b5cac/kvdb-rocksdb/src/lib.rs#L339 @@ -33,15 +33,17 @@ public final class RocksDB: Sendable { dbOptions.optimizeLevelStyleCompaction(memtableMemoryBudget: 512 * 1024 * 1024) // 512 MB dbOptions.setCreateIfMissing(true) - writeOptions = WriteOptions() - readOptions = ReadOptions() - // open DB db = try Self.call { err, _ in rocksdb_open(dbOptions.value, path.path, &err).asSendable } onErr: { message throws(Error) in throw Error.openFailed(message: message) } + + self.dbOptions = dbOptions + + writeOptions = WriteOptions() + readOptions = ReadOptions() } deinit { diff --git a/Database/Sources/Database/RocksDBBackend.swift b/Database/Sources/Database/RocksDBBackend.swift new file mode 100644 index 00000000..78f02e12 --- /dev/null +++ b/Database/Sources/Database/RocksDBBackend.swift @@ -0,0 +1,27 @@ +import Blockchain +import Foundation +import Utils + +public final class RocksDBBackend: StateBackendProtocol { + public init() {} + + public func read(key _: Data) async throws -> Data? { + fatalError("unimplemented") + } + + public func readAll(prefix _: Data, startKey _: Data?, limit _: UInt32?) async throws -> [(key: Data, value: Data)] { + fatalError("unimplemented") + } + + public func batchUpdate(_: [StateBackendOperation]) async throws { + fatalError("unimplemented") + } + + public func readValue(hash _: Data32) async throws -> Data? { + fatalError("unimplemented") + } + + public func gc(callback _: @Sendable (Data) -> Data32?) async throws { + fatalError("unimplemented") + } +}