Skip to content

Conversation

KafkaCat
Copy link

@KafkaCat KafkaCat commented Sep 5, 2025

Summary

This PR will be the first part of a larger effort to add the centralized manifest metadata service for tonbo. More PR is coming along with way.

What changes are included in this PR?

  • Add bootstrap.sql to model version snapshot. DDL script is idempotent
  • Implement current() and update() for ManifestStorage<R> trait that read the latest version snapshot and write a new version snapshot by applying the version edits

Concerns

  • I believe the centralized manifest metadata service should belongs to a separate repository rather than the public tonbo repo.
  • I found there is a testcase of VersionEdit::recover() which is specific to reading from version log file. Current data model doesn't support this usecase. I will need to talk to someone to find out whether/how to support it.
  • Deletion of old, non-active version snapshots data in database are not done yet. This is required to maintain database scale so that query won't took long.

TODOs

  • Part2:
    • Flush deleted sst/wal files into database. Add clean() method to remove actual files and send clean tag
    • Add a daemon process to look up database regularly and cleanup unused rows based on active transaction timestamps.
    • Implement rewrite() and destroy() interface
  • Part3:
    • Add multi-tenant support: Upon creation of db register self to centralized metadata service.
    • Revise data model to include S3 location entity. Upon initialization of db also persist file system/location into database
    • Revise query to use db_id to get version snapshot for specific tenant

Are these changes tested?

Run cargo test -- metadata::mds::tests --ignored require-docker

NOTE: The test is actually integration test. We need a better story for running integration test

@jonathanc-n jonathanc-n requested a review from ethe September 5, 2025 23:03
@jonathanc-n jonathanc-n self-assigned this Sep 5, 2025
@ethe ethe requested a review from jonathanc-n September 6, 2025 04:54
@jonathanc-n jonathanc-n removed their assignment Sep 6, 2025
Copy link

codecov bot commented Sep 7, 2025

Codecov Report

❌ Patch coverage is 0% with 328 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/metadata/mds.rs 0.00% 308 Missing ⚠️
src/version/mod.rs 0.00% 17 Missing ⚠️
src/version/timestamp.rs 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

scope_id INTEGER REFERENCES scopes(id) ON DELETE RESTRICT,
PRIMARY KEY (version_snapshot_id, row_index, col_index),

CONSTRAINT valid_row_index CHECK (row_index >= 0 AND row_index <= 7), -- harded coded MAX_LEVEL
Copy link
Member

@ethe ethe Sep 7, 2025

Choose a reason for hiding this comment

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

the max level num is 6 I think, we hard code leveled compaction as 7 levels, which are level0 to level6, so I think row_index < 7 would be correct

r#"
SELECT id, timestamp, log_length
FROM version_snapshots
ORDER BY created_at DESC
Copy link
Member

Choose a reason for hiding this comment

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

the ordering column is different with https://github.com/tonbo-io/tonbo/pull/481/files#diff-f2ac089b8c9efebe62753973e425342ec1abbb4a4dee365daa6babca6e8a35deR140, it would be clear if we always use the same column to get/set the current timestamp

// Non recovery mode will persist the log length
if !is_recover {
version_edits.push(VersionEdit::NewLogLength { len: edit_len });
eprint!("I'm here to push: {edit_len}")
Copy link
Member

Choose a reason for hiding this comment

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

return Error here would be better

Copy link
Author

Choose a reason for hiding this comment

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

opps. It was for my testing but apparently I missed this. Will fix

@ethe
Copy link
Member

ethe commented Sep 7, 2025

sqlx does not support WASM target platform, which means we can not support running Tonbo cloud instance on FaaS based on Deno (it would be better to support this), are there any alternatives?

@ethe
Copy link
Member

ethe commented Sep 7, 2025

I found there is a testcase of VersionEdit::recover() which is specific to reading from version log file.

IMO recover() should be a behavior of a specific metadata storage implementations, we should not expose this method to storage trait level or beyond, because for remote metadata server, it does not need to call recover and reconstruct the full in-mem version set status, every editting and reading should always request remote service.

What do you think? cc @jonathanc-n @KafkaCat

@ethe
Copy link
Member

ethe commented Sep 7, 2025

Deletion of old, non-active version snapshots data in database are not done yet. This is required to maintain database scale so that query won't took long.

Yes, this also relates to GC in major compaction.

@ethe
Copy link
Member

ethe commented Sep 7, 2025

I think remote metadata service implmentation would be better to be an external independent crate (maybe a workspace member in this repository), not inline in Tonbo core, it keeps Tonbo core lean, and lets the backend evolve independently.

option: Arc<DbOption>,
) -> Result<Self, MetadataServiceError> {
let pool = PgPoolOptions::new()
.idle_timeout(Some(Duration::from_secs(10 * 60)))
Copy link
Member

Choose a reason for hiding this comment

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

It would be better to add a todo comment here: make it configurable would be better.

[const { Vec::new() }; MAX_LEVEL],
option.clone(),
clean_sender.clone(),
Arc::new(AtomicU32::new(0)),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Arc::new(AtomicU32::new(0)),
timestamp,

@KafkaCat
Copy link
Author

KafkaCat commented Sep 7, 2025

I think remote metadata service implmentation would be better to be an external independent crate (maybe a workspace member in this repository), not inline in Tonbo core, it keeps Tonbo core lean, and lets the backend evolve independently.

I can make metadata service into a separate workspace for this PR. But I strongly believe it should belongs to a separate repository to maintain boundary between managed service and core edge use case

@KafkaCat
Copy link
Author

KafkaCat commented Sep 7, 2025

I found there is a testcase of VersionEdit::recover() which is specific to reading from version log file.

IMO recover() should be a behavior of a specific metadata storage implementations, we should not expose this method to storage trait level or beyond, because for remote metadata server, it does not need to call recover and reconstruct the full in-mem version set status, every editting and reading should always request remote service.

Yeah I think the existing interface is not abstract enough. The interface in my mind is: 1. current(&self, db_id:DbId)->VersionRef<R> 2. update(&self, db_id: DbId, version_edits: Vec<VersionEdits<_>>)->() 3. compact(&self, db_id: DbId) 4. destroy(&self, db_id: DbId)

All implementation should keep an in-memory representation of VersionRef and call update to flush the version edits into persistence. Rewrite is used to compact past set of version edits into a cleaner version (relational model need to revised to only record the version edits delta instead of keeping writing new version every time)

@KafkaCat
Copy link
Author

KafkaCat commented Sep 7, 2025

sqlx does not support WASM target platform, which means we can not support running Tonbo cloud instance on FaaS based on Deno (it would be better to support this), are there any alternatives?

Good question! Sqlx is a widely recognized crate for data access layer so I just use it. I haven't thought of WASM compatibility. Let's talk offline on usecase of supporting javascript runtime. I think there is some knowledge gap for me to fill.

Meanwhile let me research if there is any other crate support WASM target If I switch to SQLite eco-system then there is diesel ORM with sqlite wasm support It also makes testing story a little easier since sqlite crate can spawn in-memory instance. Maybe that's the approach forward if WASM support is a hard requirement.

@KafkaCat
Copy link
Author

KafkaCat commented Sep 8, 2025

Synced with ethe@ offline. Notes:

  • We will start a new repository and move this implementation to there to keep core tonbo clean
  • I will define a new ManifestStorage interface that works for both log-based and db-based approach
  • I will investigate the change log approach that only persists the version edits delta and keep an in-memory presentation of Version. This way it's fast to read from database
  • I will also migrate to sqlite eco-system to better support wasm use case

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.

3 participants