Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Dec 4, 2024
1 parent 5cafabc commit 36863dc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Database/Sources/Database/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
}

Expand All @@ -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)
}
}
10 changes: 6 additions & 4 deletions Database/Sources/Database/RocksDB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
27 changes: 27 additions & 0 deletions Database/Sources/Database/RocksDBBackend.swift
Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit 36863dc

Please sign in to comment.