Add reclaim to the fcli_db prune cmd (#2122)
This commit is contained in:
parent
2cbc16be8b
commit
6c2c99a9ae
|
@ -359,6 +359,13 @@ proc deleteContentOutOfRadius*(db: ContentDB, localId: UInt256, radius: UInt256)
|
||||||
"SQL query OK"
|
"SQL query OK"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
proc reclaimAndTruncate*(db: ContentDB) =
|
||||||
|
notice "Reclaiming unused pages"
|
||||||
|
db.reclaimSpace()
|
||||||
|
if db.manualCheckpoint:
|
||||||
|
notice "Truncating WAL file"
|
||||||
|
db.backend.checkpoint(SqStoreCheckpointKind.truncate)
|
||||||
|
|
||||||
proc forcePrune*(db: ContentDB, localId: UInt256, radius: UInt256) =
|
proc forcePrune*(db: ContentDB, localId: UInt256, radius: UInt256) =
|
||||||
## Force prune the database to a statically set radius. This will also run
|
## Force prune the database to a statically set radius. This will also run
|
||||||
## the reclaimSpace (vacuum) to free unused pages. As side effect this will
|
## the reclaimSpace (vacuum) to free unused pages. As side effect this will
|
||||||
|
@ -369,11 +376,7 @@ proc forcePrune*(db: ContentDB, localId: UInt256, radius: UInt256) =
|
||||||
## skipped.
|
## skipped.
|
||||||
notice "Starting the pruning of content"
|
notice "Starting the pruning of content"
|
||||||
db.deleteContentOutOfRadius(localId, radius)
|
db.deleteContentOutOfRadius(localId, radius)
|
||||||
notice "Reclaiming unused pages"
|
db.reclaimAndTruncate()
|
||||||
db.reclaimSpace()
|
|
||||||
if db.manualCheckpoint:
|
|
||||||
notice "Truncating WAL file"
|
|
||||||
db.backend.checkpoint(SqStoreCheckpointKind.truncate)
|
|
||||||
notice "Finished database pruning"
|
notice "Finished database pruning"
|
||||||
|
|
||||||
proc put*(
|
proc put*(
|
||||||
|
|
|
@ -167,7 +167,9 @@ proc run(config: PortalConf) {.raises: [CatchableError].} =
|
||||||
# TODO I: Perhaps we want to add an offset to counter the latter.
|
# TODO I: Perhaps we want to add an offset to counter the latter.
|
||||||
# TODO II: Perhaps for dynamical radius, we want to also apply the vacuum
|
# TODO II: Perhaps for dynamical radius, we want to also apply the vacuum
|
||||||
# without the forcePrune flag and purely by checking the amount of free
|
# without the forcePrune flag and purely by checking the amount of free
|
||||||
# space versus the pruning fraction.
|
# space versus the pruning fraction. The problem with this is that the
|
||||||
|
# vacuum will temporarily double the space usage (WAL + DB) and thus to do
|
||||||
|
# this automatically without user requesting it could be dangerous.
|
||||||
# TODO III: Adding Radius metadata to the db could be yet another way to
|
# TODO III: Adding Radius metadata to the db could be yet another way to
|
||||||
# decide whether or not to force prune, instead of this flag.
|
# decide whether or not to force prune, instead of this flag.
|
||||||
db.forcePrune(d.localNode.id, radius)
|
db.forcePrune(d.localNode.id, radius)
|
||||||
|
|
|
@ -52,7 +52,11 @@ type
|
||||||
name: "content-amount"
|
name: "content-amount"
|
||||||
.}: uint64
|
.}: uint64
|
||||||
of DbCmd.prune:
|
of DbCmd.prune:
|
||||||
discard
|
reclaimOnly* {.
|
||||||
|
desc: "Only reclaim space from the database, don't actually prune it",
|
||||||
|
defaultValue: true,
|
||||||
|
name: "reclaim-only"
|
||||||
|
.}: bool
|
||||||
of DbCmd.validate:
|
of DbCmd.validate:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
@ -117,6 +121,19 @@ proc cmdBench(conf: DbConf) =
|
||||||
|
|
||||||
printTimers(timers)
|
printTimers(timers)
|
||||||
|
|
||||||
|
proc cmdPrune(conf: DbConf) =
|
||||||
|
if conf.reclaimOnly:
|
||||||
|
let db = ContentDB.new(
|
||||||
|
conf.databaseDir.string,
|
||||||
|
storageCapacity = 1_000_000, # Doesn't matter if only space reclaiming is done
|
||||||
|
manualCheckpoint = true,
|
||||||
|
)
|
||||||
|
|
||||||
|
db.reclaimAndTruncate()
|
||||||
|
else:
|
||||||
|
notice "Functionality not yet implemented"
|
||||||
|
quit QuitSuccess
|
||||||
|
|
||||||
proc controlCHook() {.noconv.} =
|
proc controlCHook() {.noconv.} =
|
||||||
notice "Shutting down after having received SIGINT."
|
notice "Shutting down after having received SIGINT."
|
||||||
quit QuitSuccess
|
quit QuitSuccess
|
||||||
|
@ -138,6 +155,6 @@ when isMainModule:
|
||||||
of DbCmd.generate:
|
of DbCmd.generate:
|
||||||
cmdGenerate(conf)
|
cmdGenerate(conf)
|
||||||
of DbCmd.prune:
|
of DbCmd.prune:
|
||||||
notice "Functionality not yet implemented"
|
cmdPrune(conf)
|
||||||
of DbCmd.validate:
|
of DbCmd.validate:
|
||||||
notice "Functionality not yet implemented"
|
notice "Functionality not yet implemented"
|
||||||
|
|
Loading…
Reference in New Issue