mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-28 04:55:33 +00:00
Aristo+Kvt: Let destructor crash when nil
argument is given (#2080)
why: Ignoring `nil` objects was handy for a while but eventually led to lazy programming which in turn led to double destructor calls for the rocks-db.
This commit is contained in:
parent
90622c0915
commit
5379302ce9
@ -98,10 +98,9 @@ proc finish*(db: AristoDbRef; flush = false) =
|
|||||||
##
|
##
|
||||||
## This distructor may be used on already *destructed* descriptors.
|
## This distructor may be used on already *destructed* descriptors.
|
||||||
##
|
##
|
||||||
if not db.isNil:
|
if not db.backend.isNil:
|
||||||
if not db.backend.isNil:
|
db.backend.closeFn flush
|
||||||
db.backend.closeFn flush
|
discard db.getCentre.forgetOthers()
|
||||||
discard db.getCentre.forgetOthers()
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
|
@ -73,10 +73,9 @@ proc finish*(db: KvtDbRef; flush = false) =
|
|||||||
##
|
##
|
||||||
## This distructor may be used on already *destructed* descriptors.
|
## This distructor may be used on already *destructed* descriptors.
|
||||||
##
|
##
|
||||||
if not db.isNil:
|
if not db.backend.isNil:
|
||||||
if not db.backend.isNil:
|
db.backend.closeFn flush
|
||||||
db.backend.closeFn flush
|
discard db.getCentre.forgetOthers()
|
||||||
discard db.getCentre.forgetOthers()
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
|
@ -183,8 +183,8 @@ proc storagesRunner(
|
|||||||
|
|
||||||
proc aristoMain*(noisy = defined(debug)) =
|
proc aristoMain*(noisy = defined(debug)) =
|
||||||
noisy.miscRunner()
|
noisy.miscRunner()
|
||||||
noisy.accountsRunner(persistent=false)
|
noisy.accountsRunner()
|
||||||
noisy.storagesRunner(persistent=false)
|
noisy.storagesRunner()
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
const
|
const
|
||||||
|
@ -202,8 +202,10 @@ proc dbTriplet(w: LeafQuartet; rdbPath: string): Result[DbTriplet,AristoError] =
|
|||||||
|
|
||||||
# ----------------------
|
# ----------------------
|
||||||
|
|
||||||
proc cleanUp(dx: DbTriplet) =
|
proc cleanUp(dx: var DbTriplet) =
|
||||||
dx[0].finish(flush=true)
|
if not dx[0].isNil:
|
||||||
|
dx[0].finish(flush=true)
|
||||||
|
dx.reset
|
||||||
|
|
||||||
proc isDbEq(a, b: FilterRef; db: AristoDbRef; noisy = true): bool =
|
proc isDbEq(a, b: FilterRef; db: AristoDbRef; noisy = true): bool =
|
||||||
## Verify that argument filter `a` has the same effect on the
|
## Verify that argument filter `a` has the same effect on the
|
||||||
@ -559,7 +561,7 @@ proc testDistributedAccess*(
|
|||||||
block:
|
block:
|
||||||
|
|
||||||
# Clause (8) from `aristo/README.md` example
|
# Clause (8) from `aristo/README.md` example
|
||||||
let
|
var
|
||||||
dx = block:
|
dx = block:
|
||||||
let rc = dbTriplet(w, rdbPath)
|
let rc = dbTriplet(w, rdbPath)
|
||||||
xCheckRc rc.error == 0
|
xCheckRc rc.error == 0
|
||||||
@ -612,7 +614,7 @@ proc testDistributedAccess*(
|
|||||||
|
|
||||||
# Work through clauses (12)..(15) from `aristo/README.md` example
|
# Work through clauses (12)..(15) from `aristo/README.md` example
|
||||||
block:
|
block:
|
||||||
let
|
var
|
||||||
dy = block:
|
dy = block:
|
||||||
let rc = dbTriplet(w, rdbPath)
|
let rc = dbTriplet(w, rdbPath)
|
||||||
xCheckRc rc.error == 0
|
xCheckRc rc.error == 0
|
||||||
|
@ -108,13 +108,15 @@ proc randomisedLeafs(
|
|||||||
lvp2[n].swap lvp2[r]
|
lvp2[n].swap lvp2[r]
|
||||||
ok lvp2
|
ok lvp2
|
||||||
|
|
||||||
proc innerCleanUp(db: AristoDbRef): bool {.discardable.} =
|
proc innerCleanUp(db: var AristoDbRef): bool {.discardable.} =
|
||||||
## Defer action
|
## Defer action
|
||||||
let rx = db.txTop()
|
if not db.isNil:
|
||||||
if rx.isOk:
|
let rx = db.txTop()
|
||||||
let rc = rx.value.collapse(commit=false)
|
if rx.isOk:
|
||||||
xCheckRc rc.error == 0
|
let rc = rx.value.collapse(commit=false)
|
||||||
db.finish(flush=true)
|
xCheckRc rc.error == 0
|
||||||
|
db.finish(flush=true)
|
||||||
|
db = AristoDbRef(nil)
|
||||||
|
|
||||||
proc schedStow(
|
proc schedStow(
|
||||||
db: AristoDbRef; # Database
|
db: AristoDbRef; # Database
|
||||||
@ -334,10 +336,11 @@ proc testTxMergeAndDeleteOneByOne*(
|
|||||||
): bool =
|
): bool =
|
||||||
var
|
var
|
||||||
prng = PrngDesc.init 42
|
prng = PrngDesc.init 42
|
||||||
db = AristoDbRef()
|
db = AristoDbRef(nil)
|
||||||
fwdRevVfyToggle = true
|
fwdRevVfyToggle = true
|
||||||
defer:
|
defer:
|
||||||
db.finish(flush=true)
|
if not db.isNil:
|
||||||
|
db.finish(flush=true)
|
||||||
|
|
||||||
for n,w in list:
|
for n,w in list:
|
||||||
# Start with brand new persistent database.
|
# Start with brand new persistent database.
|
||||||
@ -439,10 +442,10 @@ proc testTxMergeAndDeleteSubTree*(
|
|||||||
): bool =
|
): bool =
|
||||||
var
|
var
|
||||||
prng = PrngDesc.init 42
|
prng = PrngDesc.init 42
|
||||||
db = AristoDbRef()
|
db = AristoDbRef(nil)
|
||||||
|
|
||||||
defer:
|
defer:
|
||||||
db.finish(flush=true)
|
if not db.isNil:
|
||||||
|
db.finish(flush=true)
|
||||||
|
|
||||||
for n,w in list:
|
for n,w in list:
|
||||||
# Start with brand new persistent database.
|
# Start with brand new persistent database.
|
||||||
@ -524,7 +527,7 @@ proc testTxMergeProofAndKvpList*(
|
|||||||
let
|
let
|
||||||
oopsTab = oops.toTable
|
oopsTab = oops.toTable
|
||||||
var
|
var
|
||||||
db = AristoDbRef()
|
db = AristoDbRef(nil)
|
||||||
tx = AristoTxRef(nil)
|
tx = AristoTxRef(nil)
|
||||||
rootKey: Hash256
|
rootKey: Hash256
|
||||||
count = 0
|
count = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user