diff --git a/waku/waku_archive/archive.nim b/waku/waku_archive/archive.nim index 51d9e6bec..f95865ebd 100644 --- a/waku/waku_archive/archive.nim +++ b/waku/waku_archive/archive.nim @@ -24,6 +24,7 @@ const # Retention policy WakuArchiveDefaultRetentionPolicyInterval* = chronos.minutes(30) + WakuArchiveDefaultRetentionPolicyIntervalWhenError* = chronos.minutes(1) # Metrics reporting WakuArchiveDefaultMetricsReportInterval* = chronos.minutes(30) @@ -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) diff --git a/waku/waku_archive/driver/postgres_driver/postgres_driver.nim b/waku/waku_archive/driver/postgres_driver/postgres_driver.nim index 42c56b5a6..559fd0be3 100644 --- a/waku/waku_archive/driver/postgres_driver/postgres_driver.nim +++ b/waku/waku_archive/driver/postgres_driver/postgres_driver.nim @@ -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