Skip to content

Commit

Permalink
faster retention policy when error and use of detach finalize when ne…
Browse files Browse the repository at this point in the history
…eded (#2966)
  • Loading branch information
Ivansete-status authored Aug 12, 2024
1 parent 5f0fbd7 commit 71d4a11
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions waku/waku_archive/archive.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const

# Retention policy
WakuArchiveDefaultRetentionPolicyInterval* = chronos.minutes(30)
WakuArchiveDefaultRetentionPolicyIntervalWhenError* = chronos.minutes(1)

# Metrics reporting
WakuArchiveDefaultMetricsReportInterval* = chronos.minutes(30)
Expand Down Expand Up @@ -193,6 +194,9 @@ proc periodicRetentionPolicy(self: WakuArchive) {.async.} =
(await policy.execute(self.driver)).isOkOr:
waku_archive_errors.inc(labelValues = [retPolicyFailure])
error "failed execution of retention policy", error = error
await sleepAsync(WakuArchiveDefaultRetentionPolicyIntervalWhenError)
## in case of error, let's try again faster
continue

await sleepAsync(WakuArchiveDefaultRetentionPolicyInterval)

Expand Down
11 changes: 10 additions & 1 deletion waku/waku_archive/driver/postgres_driver/postgres_driver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,16 @@ proc removePartition(
"ALTER TABLE messages DETACH PARTITION " & partitionName & " CONCURRENTLY;"
debug "removeOldestPartition", query = detachPartitionQuery
(await self.performWriteQuery(detachPartitionQuery)).isOkOr:
return err(fmt"error in {detachPartitionQuery}: " & $error)
if ($error).contains("FINALIZE"):
## We assume the database is suggesting to use FINALIZE when detaching a partition
let detachPartitionFinalizeQuery =
"ALTER TABLE messages DETACH PARTITION " & partitionName & " FINALIZE;"
debug "removeOldestPartition detaching with FINALIZE",
query = detachPartitionFinalizeQuery
(await self.performWriteQuery(detachPartitionFinalizeQuery)).isOkOr:
return err(fmt"error in FINALIZE {detachPartitionFinalizeQuery}: " & $error)
else:
return err(fmt"error in {detachPartitionQuery}: " & $error)

## Drop the partition
let dropPartitionQuery = "DROP TABLE " & partitionName
Expand Down

0 comments on commit 71d4a11

Please sign in to comment.