Skip to content

feat: introduce reconcile table procedure #6584

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

WenyXu
Copy link
Member

@WenyXu WenyXu commented Jul 24, 2025

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

#6429

What's changed and what's your intention?

Introduce a procedure for reconciling table metadata between metasrv and datanode.

The reconciliation procedure implements a state machine pattern with the following states:

  • ReconciliationStart: Validates table info and prepares for reconciliation
  • ResolveColumnMetadata - resolve column metadata conflicts with configurable strategies
  • ReconcileRegions - Performs region reconciliation operations
  • UpdateTableInfo - Update table info in metasrv if needed
  • ReconciliationEnd

PR Checklist

Please convert it to a draft if some of the following conditions are not met.

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.
  • API changes are backward compatible.
  • Schema or data changes are backward compatible.

@github-actions github-actions bot added size/L docs-not-required This change does not impact docs. labels Jul 24, 2025
@WenyXu WenyXu changed the title chore: introduce reconcile table procedure feat: introduce reconcile table procedure Jul 24, 2025
@WenyXu WenyXu force-pushed the feat/reconcile-table branch from e39bf15 to 5197994 Compare July 24, 2025 09:25
Signed-off-by: WenyXu <wenymedia@gmail.com>
@WenyXu WenyXu force-pushed the feat/reconcile-table branch from 5197994 to 3201a4d Compare July 24, 2025 09:26
Signed-off-by: WenyXu <wenymedia@gmail.com>
@WenyXu WenyXu force-pushed the feat/reconcile-table branch from 3201a4d to f792ebf Compare July 24, 2025 09:44
@WenyXu WenyXu requested a review from fengjiachun July 24, 2025 10:06
@WenyXu WenyXu marked this pull request as ready for review July 24, 2025 10:06
@WenyXu WenyXu requested review from waynexia, v0y4g3r, MichaelScofield and a team as code owners July 24, 2025 10:06
@@ -140,7 +140,7 @@ etcd-client = "0.14"
fst = "0.4.7"
futures = "0.3"
futures-util = "0.3"
greptime-proto = { git = "https://github.com/GreptimeTeam/greptime-proto.git", rev = "7fcaa3e413947a7a28d9af95812af26c1939ce78" }
greptime-proto = { git = "https://github.com/GreptimeTeam/greptime-proto.git", rev = "7be0563739721b69ff78686754c51d542c8fe8db" }
Copy link
Member Author

Choose a reason for hiding this comment

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

let primary_key =
new_primary_keys
.get(name)
.context(InvalidRegionRequestSnafu {
Copy link
Collaborator

Choose a reason for hiding this comment

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

with_context

///
/// It will check the table id and table name consistency.
/// If the table id and table name are not consistent, it will return an error.
pub(crate) async fn validate_table_id_and_name(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why check this? In what situations would id and name be inconsistent?

Copy link
Collaborator

@fengjiachun fengjiachun left a comment

Choose a reason for hiding this comment

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

Rest LGTM

Comment on lines +747 to +757
let new_primary_keys = column_metadatas
.iter()
.filter(|c| c.semantic_type == SemanticType::Tag)
.map(|c| (c.column_schema.name.as_str(), c.column_id))
.collect::<HashMap<_, _>>();

let old_primary_keys = metadata
.column_metadatas
.iter()
.filter(|c| c.semantic_type == SemanticType::Tag)
.map(|c| (c.column_schema.name.as_str(), c.column_id));
Copy link
Contributor

Choose a reason for hiding this comment

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

Primary keys may have a different order than the original column order.

We can create a table with columns (a, b, c) but primary key (c, a).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants