-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add size retention policy (#2093)
* chore: add retention policy with GB or MB limitation #1885 * chore: add retention policy with GB or MB limitation * chore: updated code post review- retention policy * ci: extract discordNotify to separate file Signed-off-by: Jakub Sokołowski <jakub@status.im> * ci: push images to new wakuorg/nwaku repo Signed-off-by: Jakub Sokołowski <jakub@status.im> * ci: enforce default Docker image tags strictly Signed-off-by: Jakub Sokołowski <jakub@status.im> * ci: push GIT_REF if it looks like a version Signed-off-by: Jakub Sokołowski <jakub@status.im> * fix: update wakuv2 fleet DNS discovery enrtree https://github.com/status-im/infra-misc/issues/171 * chore: resolving DNS IP and publishing it when no extIp is provided (#2030) * feat(coverage): Add simple coverage (#2067) * Add test aggregator to all directories. * Implement coverage script. * fix(ci): fix name of discord notify method Also use absolute path to load Groovy script. Signed-off-by: Jakub Sokołowski <jakub@status.im> * chore(networkmonitor): refactor setConnectedPeersMetrics, make it partially concurrent, add version (#2080) * chore(networkmonitor): refactor setConnectedPeersMetrics, make it partially concurrent, add version * add more metrics, refactor how most metrics are calculated * rework metrics table fillup * reset connErr to make sure we honour successful reconnection * chore(cbindings): Adding cpp example that integrates the 'libwaku' (#2079) * Adding cpp example that integrates the `libwaku` --------- Co-authored-by: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com> * fix(ci): update the dependency list in pre-release WF (#2088) * chore: adding NetConfig test suite (#2091) --------- Signed-off-by: Jakub Sokołowski <jakub@status.im> Co-authored-by: Jakub Sokołowski <jakub@status.im> Co-authored-by: Anton Iakimov <yakimant@gmail.com> Co-authored-by: gabrielmer <101006718+gabrielmer@users.noreply.github.com> Co-authored-by: Álex Cabeza Romero <alex93cabeza@gmail.com> Co-authored-by: Vaclav Pavlin <vaclav@status.im> Co-authored-by: Ivan Folgueira Bande <128452529+Ivansete-status@users.noreply.github.com> Co-authored-by: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com>
- Loading branch information
1 parent
23b49ca
commit 8897ae1
Showing
7 changed files
with
196 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
waku/waku_archive/retention_policy/retention_policy_size.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
when (NimMajor, NimMinor) < (1, 4): | ||
{.push raises: [Defect].} | ||
else: | ||
{.push raises: [].} | ||
|
||
import | ||
std/times, | ||
stew/results, | ||
chronicles, | ||
chronos | ||
import | ||
../driver, | ||
../retention_policy | ||
|
||
logScope: | ||
topics = "waku archive retention_policy" | ||
|
||
# default size is 30 Gb | ||
const DefaultRetentionSize*: float = 30_720 | ||
|
||
# to remove 20% of the outdated data from database | ||
const DeleteLimit = 0.80 | ||
|
||
type | ||
# SizeRetentionPolicy implements auto delete as follows: | ||
# - sizeLimit is the size in megabytes (Mbs) the database can grow upto | ||
# to reduce the size of the databases, remove the rows/number-of-messages | ||
# DeleteLimit is the total number of messages to delete beyond this limit | ||
# when the database size crosses the sizeLimit, then only a fraction of messages are kept, | ||
# rest of the outdated message are deleted using deleteOldestMessagesNotWithinLimit(), | ||
# upon deletion process the fragmented space is retrieve back using Vacuum process. | ||
SizeRetentionPolicy* = ref object of RetentionPolicy | ||
sizeLimit: float | ||
|
||
proc init*(T: type SizeRetentionPolicy, size=DefaultRetentionSize): T = | ||
SizeRetentionPolicy( | ||
sizeLimit: size | ||
) | ||
|
||
method execute*(p: SizeRetentionPolicy, | ||
driver: ArchiveDriver): | ||
Future[RetentionPolicyResult[void]] {.async.} = | ||
## when db size overshoots the database limit, shread 20% of outdated messages | ||
|
||
# to get the size of the database, pageCount and PageSize is required | ||
# get page count in "messages" database | ||
var pageCountRes = await driver.getPagesCount() | ||
if pageCountRes.isErr(): | ||
return err("failed to get Pages count: " & pageCountRes.error) | ||
|
||
var pageCount: int64 = pageCountRes.value | ||
|
||
# get page size of database | ||
let pageSizeRes = await driver.getPagesSize() | ||
var pageSize: int64 = int64(pageSizeRes.valueOr(0) div 1024) | ||
|
||
if pageSize == 0: | ||
return err("failed to get Page size: " & pageSizeRes.error) | ||
|
||
# database size in megabytes (Mb) | ||
var totalSizeOfDB: float = float(pageSize * pageCount)/1024.0 | ||
|
||
# check if current databse size crosses the db size limit | ||
if totalSizeOfDB < p.sizeLimit: | ||
return ok() | ||
|
||
# to shread/delete messsges, get the total row/message count | ||
var numMessagesRes = await driver.getMessagesCount() | ||
if numMessagesRes.isErr(): | ||
return err("failed to get messages count: " & numMessagesRes.error) | ||
var numMessages = numMessagesRes.value | ||
|
||
# 80% of the total messages are to be kept, delete others | ||
let pageDeleteWindow = int(float(numMessages) * DeleteLimit) | ||
|
||
let res = await driver.deleteOldestMessagesNotWithinLimit(limit=pageDeleteWindow) | ||
if res.isErr(): | ||
return err("deleting oldest messages failed: " & res.error) | ||
|
||
# vacuum to get the deleted pages defragments to save storage space | ||
# this will resize the database size | ||
let resVaccum = await driver.performsVacuum() | ||
if resVaccum.isErr(): | ||
return err("vacuumming failed: " & resVaccum.error) | ||
|
||
return ok() |