Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Access] Add registerDB pruning module #6397

Open
wants to merge 74 commits into
base: master
Choose a base branch
from

Conversation

UlyanaAndrukhiv
Copy link
Contributor

Closes #6068

In this PR:

  • Implemented pruner module for registerDB which will ensure that unneeded pruned data is removed from the db, freeing up disk space.
  • Integrated pruner into Access and Observer nodes.
  • Added metrics.
  • Added functional tests .

@codecov-commenter
Copy link

codecov-commenter commented Aug 26, 2024

Codecov Report

Attention: Patch coverage is 41.68937% with 214 lines in your changes missing coverage. Please review.

Project coverage is 41.24%. Comparing base (8a3055c) to head (1d0e753).

Files with missing lines Patch % Lines
cmd/observer/node_builder/observer_builder.go 0.00% 66 Missing ⚠️
cmd/access/node_builder/access_node_builder.go 0.00% 62 Missing ⚠️
storage/pebble/registers_pruner.go 70.63% 28 Missing and 9 partials ⚠️
storage/pebble/register_pruner_run.go 69.76% 9 Missing and 4 partials ⚠️
module/metrics/registers_db_pruner.go 0.00% 11 Missing ⚠️
module/mock/register_db_pruner_metrics.go 0.00% 8 Missing ⚠️
storage/pebble/operation/registers.go 0.00% 8 Missing ⚠️
module/metrics/access.go 0.00% 4 Missing ⚠️
integration/testnet/container.go 0.00% 2 Missing ⚠️
module/mock/access_metrics.go 0.00% 2 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6397      +/-   ##
==========================================
- Coverage   41.26%   41.24%   -0.02%     
==========================================
  Files        2061     2067       +6     
  Lines      182702   183019     +317     
==========================================
+ Hits        75384    75485     +101     
- Misses     101010   101211     +201     
- Partials     6308     6323      +15     
Flag Coverage Δ
unittests 41.24% <41.68%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

node.Logger,
builder.RegisterDB,
pstorage.WithPrunerMetrics(builder.RegisterDBPrunerMetrics),
//pstorage.WithPruneThreshold(builder.registerDBPruneThreshold),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WithPruneThreshold is temporarily commented out and will be re-enabled once PR #6345 is merged.

Copy link
Contributor

@peterargue peterargue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work! I haven't finished reviewing everything, but here are my comments so far.

storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
@Guitarheroua Guitarheroua requested review from Guitarheroua and zhangchiqing and removed request for Guitarheroua November 4, 2024 17:02
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/db_pruner.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/testutil.go Outdated Show resolved Hide resolved
storage/pebble/testutil.go Show resolved Hide resolved
storage/pebble/registers_pruner_test.go Outdated Show resolved Hide resolved
}

// Reset batchKeysToRemove to empty slice while retaining capacity
batchKeysToRemove = batchKeysToRemove[:0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could reset before sleeping.

also clear(batchKeysToRemove) would be better

Copy link
Contributor

@peterargue peterargue Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this as well. it turns our clear() called on a slice just sets all of the elements in the array to nil rather than changing the size of slice, so it wouldn't work here

storage/pebble/register_pruner_run.go Outdated Show resolved Hide resolved
storage/pebble/register_pruner_run.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
}()

for _, key := range lookupKeys {
if err := dbBatch.Delete(key, nil); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pebble batch support DeleteRange.

I wonder if it would be more efficient with it.

For instance, if we have the following registers and different height:

registerA-height100
registerA-height99
registerA-height98
registerA-height90

And we'd like to prune by height 100.
Instead of calling:

dbBatch.Delete(registerA-height99, pebble.Sync)
dbBatch.Delete(registerA-height98, pebble.Sync)
dbBatch.Delete(registerA-height90, pebble.Sync)

we could call:

dbBatch.DeleteRange(registerA-height99, registerA-height0, pebble.Sync)

I wonder if that would make a difference?

Copy link
Contributor

@Guitarheroua Guitarheroua Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a lookupKeys variable we could have a mix of keys from different batches. For example:
registerA-height98
registerA-height90
...
registerB-height98
...
registerC-height98
registerC-height97

So, we need to call lookupKeyToRegisterID one extra time to group them, or we should group them on a step when we check the key.

Another Idea could be, to save them as a map of ranges, for example:

[registerA]{registerA-height98, registerA-height90},
[registerB]{registerB-height98, registerB-height98},
[registerC]{registerC-height98, registerC-height97}

storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
storage/pebble/registers_pruner.go Outdated Show resolved Hide resolved
module/metrics/registers_db_pruner.go Outdated Show resolved Hide resolved
storage/pebble/register_pruner_run.go Outdated Show resolved Hide resolved
storage/pebble/register_pruner_run.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Access] Add registerDB pruning module
5 participants