Skip to content

Conversation

@drmingdrmer
Copy link
Member

@drmingdrmer drmingdrmer commented Sep 20, 2025

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

refactor: meta-service: compact immutable levels periodically

Add a background task to compact immutable levels into bigger one.
Thus the size of the top writable level won't grow too big before
building a snapshot.

with config compact_immutables_ms = 2000(default enabled: 1000ms), the
snapshot_logs_since_last is allowed to set a larger value, in order to
reduce the rate of building a snapshot.

To reduce cache invalidation, a recommended config is:

compact_immutables_ms = 1000
snapshot_logs_since_last = 55000

I.e., build a snapshot for each 55,000 applied raft-log entries.

compact_immutables_ms is enabled by default with interval 1000 ms,
set to 0 to disable it for testing.

Testing

Add a learner node with databend-meta --join ... --learner
to replciate the data with compact_immutables_ms enabeld, and with a
larger snapshot_logs_since_last value, ensure the last_seq matches
the leaders.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Refactoring

Related Issues


This change is Reviewable

@github-actions github-actions bot added the pr-refactor this PR changes the code base without new features or bugfix label Sep 20, 2025
@drmingdrmer drmingdrmer changed the title refactor: meta-service: simplify state-machine store refactor: meta-service: compact immutable levels periodically Sep 20, 2025
Add a background task to compact immutable levels into bigger one.
Thus the size of the top writable level won't  grow too big before
building a snapshot.

with config `compact_immutables_ms = 2000`(default enabled: 1000ms), the
`snapshot_logs_since_last` is allowed to set a larger value, in order to
reduce the rate of building a snapshot.

To reduce cache invalidation, a recommended config is:
```
compact_immutables_ms = 1000
snapshot_logs_since_last = 55000
```

I.e., build a snapshot for each 55,000 applied raft-log entries.

`compact_immutables_ms` is enabled by default with interval `1000 ms`,
set to `0` to disable it for testing.

#### Testing

Add a learner node with `databend-meta --join ... --learner`
to replciate the data with `compact_immutables_ms` enabeld, and with a
larger `snapshot_logs_since_last` value,  ensure the `last_seq` matches
the leaders.
@drmingdrmer drmingdrmer marked this pull request as ready for review September 20, 2025 14:05
@drmingdrmer drmingdrmer merged commit 5d27114 into databendlabs:main Sep 20, 2025
90 checks passed
@drmingdrmer drmingdrmer deleted the 351-refactor branch September 20, 2025 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-refactor this PR changes the code base without new features or bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant