mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-08-02 04:43:16 +00:00
fix: use proper object reference in hashing (#85)
Uses `addr obj[]` instead of `addr obj`, fix tests. Signed-off-by: Giuliano Mega <giuliano.mega@gmail.com>
This commit is contained in:
parent
c2c1f55a22
commit
1d22c62325
@ -1,7 +1,7 @@
|
|||||||
mode = ScriptMode.Verbose
|
mode = ScriptMode.Verbose
|
||||||
|
|
||||||
packageName = "datastore"
|
packageName = "datastore"
|
||||||
version = "0.2.2"
|
version = "0.2.3"
|
||||||
author = "Status Research & Development GmbH"
|
author = "Status Research & Development GmbH"
|
||||||
description = "Simple, unified API for multiple data stores"
|
description = "Simple, unified API for multiple data stores"
|
||||||
license = "Apache License 2.0 or MIT"
|
license = "Apache License 2.0 or MIT"
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import std/os
|
|||||||
import std/strformat
|
import std/strformat
|
||||||
import std/strutils
|
import std/strutils
|
||||||
import std/sets
|
import std/sets
|
||||||
|
import std/sequtils
|
||||||
|
|
||||||
import pkg/leveldbstatic
|
import pkg/leveldbstatic
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
@ -23,7 +24,7 @@ type
|
|||||||
openIterators: HashSet[QueryIter]
|
openIterators: HashSet[QueryIter]
|
||||||
|
|
||||||
proc hash(iter: QueryIter): Hash =
|
proc hash(iter: QueryIter): Hash =
|
||||||
hash(addr iter)
|
hash(addr iter[])
|
||||||
|
|
||||||
method has*(self: LevelDbDatastore, key: Key): Future[?!bool] {.async: (raises: [CancelledError]).} =
|
method has*(self: LevelDbDatastore, key: Key): Future[?!bool] {.async: (raises: [CancelledError]).} =
|
||||||
try:
|
try:
|
||||||
@ -75,7 +76,7 @@ method put*(self: LevelDbDatastore, batch: seq[BatchEntry]): Future[?!void] {.as
|
|||||||
|
|
||||||
method close*(self: LevelDbDatastore): Future[?!void] {.async: (raises: [CancelledError]).} =
|
method close*(self: LevelDbDatastore): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||||
try:
|
try:
|
||||||
for iter in self.openIterators:
|
for iter in self.openIterators.toSeq:
|
||||||
if err =? (await iter.dispose()).errorOption:
|
if err =? (await iter.dispose()).errorOption:
|
||||||
return failure(err.msg)
|
return failure(err.msg)
|
||||||
self.openIterators.clear()
|
self.openIterators.clear()
|
||||||
@ -163,6 +164,9 @@ method modify*(
|
|||||||
if not lock.locked:
|
if not lock.locked:
|
||||||
self.locks.del(key)
|
self.locks.del(key)
|
||||||
|
|
||||||
|
proc openIteratorCount*(self: LevelDbDatastore): int =
|
||||||
|
self.openIterators.len
|
||||||
|
|
||||||
proc new*(
|
proc new*(
|
||||||
T: type LevelDbDatastore, dbName: string): ?!T =
|
T: type LevelDbDatastore, dbName: string): ?!T =
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -195,3 +195,10 @@ suite "LevelDB Query":
|
|||||||
let iter = (await ds.query(q)).tryGet
|
let iter = (await ds.query(q)).tryGet
|
||||||
(await iter.dispose()).tryGet
|
(await iter.dispose()).tryGet
|
||||||
(await iter.dispose()).tryGet
|
(await iter.dispose()).tryGet
|
||||||
|
|
||||||
|
test "should stop tracking iterator objects once those are disposed":
|
||||||
|
let q = Query.init(Key.init("/a/b/c").tryGet)
|
||||||
|
let iter = (await ds.query(q)).tryGet
|
||||||
|
check ds.openIteratorCount == 1
|
||||||
|
(await iter.dispose()).tryGet
|
||||||
|
check ds.openIteratorCount == 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user