Skip to content

Commit ddea7c4

Browse files
authored
Merge branch 'master' into fix-marketplace-block-expiry
2 parents ad9fb7f + 8582334 commit ddea7c4

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

codex/erasure/erasure.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,8 @@ proc encodeData(
419419

420420
trace "Adding parity block", cid = blk.cid, idx
421421
cids[idx] = blk.cid
422-
if isErr (await self.store.putBlock(blk)):
423-
trace "Unable to store block!", cid = blk.cid
422+
if error =? (await self.store.putBlock(blk)).errorOption:
423+
warn "Unable to store block!", cid = blk.cid, msg = error.msg
424424
return failure("Unable to store block!")
425425
idx.inc(params.steps)
426426

@@ -619,8 +619,8 @@ proc decode*(self: Erasure, encoded: Manifest): Future[?!Manifest] {.async.} =
619619
return failure(error)
620620

621621
trace "Recovered block", cid = blk.cid, index = i
622-
if isErr (await self.store.putBlock(blk)):
623-
trace "Unable to store block!", cid = blk.cid
622+
if error =? (await self.store.putBlock(blk)).errorOption:
623+
warn "Unable to store block!", cid = blk.cid, msg = error.msg
624624
return failure("Unable to store block!")
625625

626626
cids[idx] = blk.cid

codex/stores/maintenance.nim

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import ../clock
2323
import ../logutils
2424
import ../systemclock
2525

26+
logScope:
27+
topics = "codex maintenance"
28+
2629
const
2730
DefaultBlockInterval* = 10.minutes
2831
DefaultNumBlocksPerInterval* = 1000
@@ -40,7 +43,7 @@ proc new*(
4043
repoStore: RepoStore,
4144
interval: Duration,
4245
numberOfBlocksPerInterval = 100,
43-
timer = Timer.new(),
46+
timer = Timer.new("maintenance"),
4447
clock: Clock = SystemClock.new(),
4548
): BlockMaintainer =
4649
## Create new BlockMaintainer instance
@@ -59,8 +62,8 @@ proc new*(
5962
proc deleteExpiredBlock(
6063
self: BlockMaintainer, cid: Cid
6164
): Future[void] {.async: (raises: [CancelledError]).} =
62-
if isErr (await self.repoStore.delBlock(cid)):
63-
trace "Unable to delete block from repoStore"
65+
if error =? (await self.repoStore.delBlock(cid)).errorOption:
66+
warn "Unable to delete block from repoStore", error = error.msg
6467

6568
proc processBlockExpiration(
6669
self: BlockMaintainer, be: BlockExpiration
@@ -78,13 +81,13 @@ proc runBlockCheck(
7881
)
7982

8083
without iter =? expirations, err:
81-
trace "Unable to obtain blockExpirations iterator from repoStore"
84+
warn "Unable to obtain blockExpirations iterator from repoStore", err = err.msg
8285
return
8386

8487
var numberReceived = 0
8588
for beFut in iter:
8689
without be =? (await beFut), err:
87-
trace "Unable to obtain blockExpiration from iterator"
90+
warn "Unable to obtain blockExpiration from iterator", err = err.msg
8891
continue
8992
inc numberReceived
9093
await self.processBlockExpiration(be)
@@ -94,6 +97,7 @@ proc runBlockCheck(
9497
# We're at the end of the dataset and should start from 0 next time.
9598
if numberReceived < self.numberOfBlocksPerInterval:
9699
self.offset = 0
100+
trace "Cycle completed"
97101

98102
proc start*(self: BlockMaintainer) =
99103
proc onTimer(): Future[void] {.async: (raises: []).} =

codex/utils/timer.nim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type
2424
name: string
2525
loopFuture: Future[void]
2626

27-
proc new*(T: type Timer, timerName = "Unnamed Timer"): Timer =
27+
proc new*(T: type Timer, timerName: string): Timer =
2828
## Create a new Timer intance with the given name
2929
Timer(name: timerName)
3030

@@ -35,6 +35,9 @@ proc timerLoop(timer: Timer) {.async: (raises: []).} =
3535
await sleepAsync(timer.interval)
3636
except CancelledError:
3737
discard # do not propagate as timerLoop is asyncSpawned
38+
except CatchableError as err:
39+
error "CatchableError in timer loop", name = timer.name, msg = err.msg
40+
info "Timer loop has stopped", name = timer.name
3841

3942
method start*(
4043
timer: Timer, callback: TimerCallback, interval: Duration

tests/codex/utils/testtimer.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ asyncchecksuite "Timer":
3636
timer2.start(lettersCallback, 10.milliseconds)
3737

3838
setup:
39-
timer1 = Timer.new()
40-
timer2 = Timer.new()
39+
timer1 = Timer.new("testtimer1")
40+
timer2 = Timer.new("testtimer2")
4141

4242
output = ""
4343
numbersState = 0

0 commit comments

Comments
 (0)