-
Notifications
You must be signed in to change notification settings - Fork 9
Update datamigration for rangepartition #462
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
base: main
Are you sure you want to change the base?
Changes from all commits
6b5c40e
769953f
d686176
92f2a35
94a5786
48e5817
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6899,10 +6899,11 @@ class TemplateCcMap : public CcMap | |
| uint16_t pause_idx = shard_->core_id_; | ||
| CleanType clean_type = req.GetCleanType(); | ||
| if (clean_type == CleanType::CleanBucketData || | ||
| clean_type == CleanType::CleanRangeData) | ||
| clean_type == CleanType::CleanRangeData || | ||
| clean_type == CleanType::CleanRangeDataForMigration) | ||
| { | ||
| // For clean bucket data and range data, cc req is only sent to 1 | ||
| // core. | ||
| // For clean bucket data and range data (for data migration), cc req | ||
| // is only sent to 1 core. | ||
| pause_idx = 0; | ||
| } | ||
| if (req.ResumeKey(pause_idx)->KeyPtr() != nullptr) | ||
|
|
@@ -6982,6 +6983,14 @@ class TemplateCcMap : public CcMap | |
|
|
||
| if (ccp == &pos_inf_page_ || !(ccp->FirstKey() < *end_key)) | ||
| { | ||
| if (req.GetCleanType() == CleanType::CleanRangeDataForMigration) | ||
| { | ||
| // For data migration, we need to delete the range size info | ||
| // for the range that has been migrated to other node group. | ||
| int32_t partition_id = req.GetPartitionId(); | ||
| assert(partition_id > 0 && partition_id != INT32_MAX); | ||
| RemoveRangeSize(static_cast<uint32_t>(partition_id)); | ||
| } | ||
|
Comment on lines
+6986
to
+6993
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allow partition At Line 6991, Suggested fix- assert(partition_id > 0 && partition_id != INT32_MAX);
+ assert(partition_id >= 0 && partition_id != INT32_MAX);
RemoveRangeSize(static_cast<uint32_t>(partition_id));Based on learnings: during 🤖 Prompt for AI Agents
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🧠 Learnings used |
||
| return req.SetFinish(); | ||
| } | ||
| else | ||
|
|
@@ -11551,6 +11560,14 @@ class TemplateCcMap : public CcMap | |
| return false; | ||
| } | ||
|
|
||
| void RemoveRangeSize(uint32_t partition_id) | ||
| { | ||
| if constexpr (RangePartitioned) | ||
| { | ||
| range_sizes_.erase(partition_id); | ||
| } | ||
| } | ||
|
|
||
| absl::btree_map< | ||
| KeyT, | ||
| std::unique_ptr< | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: eloqdata/tx_service
Length of output: 14477
🏁 Script executed:
Repository: eloqdata/tx_service
Length of output: 5027
🏁 Script executed:
Repository: eloqdata/tx_service
Length of output: 45
🏁 Script executed:
Repository: eloqdata/tx_service
Length of output: 3167
🏁 Script executed:
Repository: eloqdata/tx_service
Length of output: 705
🏁 Script executed:
Repository: eloqdata/tx_service
Length of output: 224
🏁 Script executed:
Repository: eloqdata/tx_service
Length of output: 2167
🏁 Script executed:
Repository: eloqdata/tx_service
Length of output: 2146
Add runtime bounds check before casting partition_id to
uint32_t.At lines 6990–6992, the code directly casts
GetPartitionId()(int32_t) touint32_twithout checking for negative values. The assertion at line 6991 only guards againstINT32_MAXand is disabled in release builds. If a negative value reaches this path (through upstream corruption or a bug), it will wrap to a large positive value when cast, erasing the wrong entry fromrange_sizes_and leaving stale range-size metadata.This pattern already exists defensively in the codebase (e.g.,
local_cc_shards.h:1192,cc_request.h:7836). Add a runtime check consistent with established practice:Suggested fix
if (req.GetCleanType() == CleanType::CleanRangeDataForMigration) { // For data migration, we need to delete the range size info // for the range that has been migrated to other node group. int32_t partition_id = req.GetPartitionId(); - assert(partition_id != INT32_MAX); - RemoveRangeSize(static_cast<uint32_t>(partition_id)); + if (partition_id >= 0 && partition_id != INT32_MAX) + { + RemoveRangeSize(static_cast<uint32_t>(partition_id)); + } + else + { + LOG(ERROR) << "Invalid partition_id in migration cleanup: " + << partition_id; + } }📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The caller will guarantee that this value is non-negative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yi-xmuThanks for the clarification. If the caller guarantees partition_id is non-negative, I’m good to drop the runtime check.Optional tiny follow-up for maintainability: tighten the existing debug assertion to reflect the invariant and leave a brief comment. For example:
If you prefer, I can prep a small patch to do just this (assert + comment) and nothing else.
✏️ Learnings added
🧠 Learnings used