-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dev-codec-coverage
* master: minor refactor for RocksDB (#244)
- Loading branch information
Showing
9 changed files
with
189 additions
and
42 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import rocksdb | ||
import Utils | ||
|
||
public struct Options: ~Copyable, Sendable { | ||
let ptr: SafePointer | ||
|
||
var value: OpaquePointer { ptr.value } | ||
|
||
public init() { | ||
ptr = .init(ptr: rocksdb_options_create(), free: rocksdb_options_destroy) | ||
} | ||
|
||
public func increaseParallelism(cpus: Int) { | ||
rocksdb_options_increase_parallelism(ptr.value, Int32(cpus)) | ||
} | ||
|
||
public func optimizeLevelStyleCompaction(memtableMemoryBudget: UInt64) { | ||
rocksdb_options_optimize_level_style_compaction(ptr.value, memtableMemoryBudget) | ||
} | ||
|
||
public func setCreateIfMissing(_ createIfMissing: Bool) { | ||
rocksdb_options_set_create_if_missing(ptr.value, createIfMissing ? 1 : 0) | ||
} | ||
|
||
public func setLevelCompactionDynamicLevelBytes(levelCompactionDynamicLevelBytes: Bool) { | ||
rocksdb_options_set_level_compaction_dynamic_level_bytes(ptr.value, levelCompactionDynamicLevelBytes ? 1 : 0) | ||
} | ||
} | ||
|
||
public struct WriteOptions: ~Copyable, Sendable { | ||
let ptr: SafePointer | ||
|
||
var value: OpaquePointer { ptr.value } | ||
|
||
public init() { | ||
ptr = .init(ptr: rocksdb_writeoptions_create(), free: rocksdb_writeoptions_destroy) | ||
} | ||
} | ||
|
||
public struct ReadOptions: ~Copyable, Sendable { | ||
let ptr: SafePointer | ||
|
||
var value: OpaquePointer { ptr.value } | ||
|
||
public init() { | ||
ptr = .init(ptr: rocksdb_readoptions_create(), free: rocksdb_readoptions_destroy) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
public struct SafePointer: ~Copyable, Sendable { | ||
let ptr: SendableOpaquePointer | ||
let free: @Sendable (_ ptr: OpaquePointer) -> Void | ||
public let ptr: SendableOpaquePointer | ||
private let free: @Sendable (_ ptr: OpaquePointer) -> Void | ||
|
||
public var value: OpaquePointer { ptr.value } | ||
|
||
public init(ptr: OpaquePointer, free: @Sendable @escaping (OpaquePointer) -> Void) { | ||
self.ptr = ptr.asSendable | ||
self.free = free | ||
} | ||
|
||
deinit { free(ptr.value) } | ||
} |