-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
217 additions
and
23 deletions.
There are no files selected for viewing
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
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,51 @@ | ||
# Nim-RocksDB | ||
# Copyright 2024 Status Research & Development GmbH | ||
# Licensed under either of | ||
# | ||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) | ||
# * GPL license, version 2.0, ([LICENSE-GPLv2](LICENSE-GPLv2) or https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html) | ||
# | ||
# at your option. This file may not be copied, modified, or distributed except according to those terms. | ||
|
||
## A `SnapshotRef` represents a view of the state of the database at some point in time. | ||
|
||
{.push raises: [].} | ||
|
||
import ./lib/librocksdb | ||
|
||
type | ||
SnapshotPtr* = ptr rocksdb_snapshot_t | ||
|
||
SnapshotType* = enum | ||
rocksdb | ||
transactiondb | ||
|
||
SnapshotRef* = ref object | ||
cPtr: SnapshotPtr | ||
kind: SnapshotType | ||
|
||
proc newSnapshot*(cPtr: SnapshotPtr, kind: SnapshotType): SnapshotRef = | ||
doAssert not cPtr.isNil() | ||
SnapshotRef(cPtr: cPtr, kind: kind) | ||
|
||
proc isClosed*(snapshot: SnapshotRef): bool {.inline.} = | ||
## Returns `true` if the `SnapshotRef` has been closed and `false` otherwise. | ||
snapshot.cPtr.isNil() | ||
|
||
proc cPtr*(snapshot: SnapshotRef): SnapshotPtr = | ||
## Get the underlying database pointer. | ||
doAssert not snapshot.isClosed() | ||
snapshot.cPtr | ||
|
||
proc kind*(snapshot: SnapshotRef): SnapshotType = | ||
## Get the kind of the `SnapshotRef`. | ||
snapshot.kind | ||
|
||
proc getSequenceNumber*(snapshot: SnapshotRef): uint64 = | ||
## Return the associated sequence number. | ||
doAssert not snapshot.isClosed() | ||
rocksdb_snapshot_get_sequence_number(snapshot.cPtr).uint64 | ||
|
||
proc setClosed*(snapshot: SnapshotRef) = | ||
# The snapshot should be released from `RocksDbRef` or `TransactionDbRef` | ||
snapshot.cPtr = nil |
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
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
Oops, something went wrong.