-
Notifications
You must be signed in to change notification settings - Fork 9
Allow run on candidate #392
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
a3f8173
232180e
19943e8
3942fe8
3dba7d3
b36ca73
2c5a15b
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 |
|---|---|---|
|
|
@@ -90,12 +90,7 @@ class CatalogCcMap | |
| uint32_t ng_id = req.NodeGroupId(); | ||
| if (shard_->IsNative(ng_id) && req.CcOp() == CcOperation::ReadForWrite) | ||
| { | ||
| int64_t ng_term = Sharder::Instance().LeaderTerm(ng_id); | ||
| CcHandlerResult<AcquireAllResult> *hd_res = req.Result(); | ||
| if (ng_term < 0) | ||
| { | ||
| return hd_res->SetError(CcErrorCode::REQUESTED_NODE_NOT_LEADER); | ||
| } | ||
|
|
||
| const CatalogKey *catalog_key = nullptr; | ||
| if (req.Key() != nullptr) | ||
|
|
@@ -199,19 +194,17 @@ class CatalogCcMap | |
| } | ||
| }); | ||
|
|
||
| int64_t ng_term = Sharder::Instance().LeaderTerm(req.NodeGroupId()); | ||
| int64_t ng_term = req.NodeGroupTerm(); | ||
| assert(ng_term > 0); | ||
| CODE_FAULT_INJECTOR("term_CatalogCcMap_Execute_PostWriteAllCc", { | ||
| LOG(INFO) | ||
| << "FaultInject term_CatalogCcMap_Execute_PostWriteAllCc"; | ||
| ng_term = -1; | ||
| FaultInject::Instance().InjectFault( | ||
| "term_CatalogCcMap_Execute_PostWriteAllCc", "remove"); | ||
| }); | ||
| if (ng_term < 0) | ||
| { | ||
| req.Result()->SetError(CcErrorCode::REQUESTED_NODE_NOT_LEADER); | ||
| return true; | ||
| } | ||
| }); | ||
|
|
||
| const CatalogKey *table_key = nullptr; | ||
| if (req.Key() != nullptr) | ||
|
|
@@ -1148,28 +1141,31 @@ class CatalogCcMap | |
| assert(req.IsLocal()); | ||
|
|
||
| uint32_t ng_id = req.NodeGroupId(); | ||
| int64_t ng_term = Sharder::Instance().LeaderTerm(ng_id); | ||
| ng_term = std::max(ng_term, Sharder::Instance().StandbyNodeTerm()); | ||
|
|
||
| if (req.IsInRecovering()) | ||
| int64_t ng_term = req.NodeGroupTerm(); | ||
| if (ng_term < 0) | ||
| { | ||
| ng_term = ng_term > 0 | ||
| ? ng_term | ||
| : Sharder::Instance().CandidateLeaderTerm(ng_id); | ||
| if (req.AllowRunOnCandidate()) | ||
| { | ||
| ng_term = Sharder::Instance().CandidateLeaderTerm(ng_id); | ||
| } | ||
| if (ng_term < 0) | ||
| { | ||
| ng_term = Sharder::Instance().LeaderTerm(ng_id); | ||
| int64_t standby_node_term = | ||
| Sharder::Instance().StandbyNodeTerm(); | ||
| ng_term = std::max(ng_term, standby_node_term); | ||
| } | ||
| } | ||
| assert(ng_term > 0); | ||
|
|
||
|
Comment on lines
1143
to
1160
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. Handle unresolved term after fallback instead of asserting. If the leader/standby/candidate lookup still yields a negative term, the current assert can crash and negative terms can leak into lock metadata in release builds. Return a proper error instead. 🔧 Proposed fix (runtime error on invalid term)- assert(ng_term > 0);
+ if (ng_term <= 0)
+ {
+ req.Result()->SetError(CcErrorCode::REQUESTED_NODE_NOT_LEADER);
+ return true;
+ }🤖 Prompt for AI Agents |
||
| CODE_FAULT_INJECTOR("term_CatalogCcMap_Execute_ReadCc", { | ||
| LOG(INFO) << "FaultInject term_CatalogCcMap_Execute_ReadCc"; | ||
| LOG(INFO) << "FaultInject term_CatalogCcMap_Execute_ReadCc"; | ||
| ng_term = -1; | ||
| FaultInject::Instance().InjectFault( | ||
| "term_CatalogCcMap_Execute_ReadCc", "remove"); | ||
| }); | ||
|
|
||
| if (ng_term < 0) | ||
| { | ||
| req.Result()->SetError(CcErrorCode::REQUESTED_NODE_NOT_LEADER); | ||
| return true; | ||
| } | ||
| }); | ||
|
|
||
| const CatalogKey *table_key = | ||
| static_cast<const CatalogKey *>(req.Key()); | ||
|
|
||
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.
Guard invalid
NodeGroupTerm()instead of assert‑only.If a request arrives with a negative term, this assert can crash debug builds; in release builds the negative term is used downstream. Prefer a runtime error path (optionally mirroring the ReadCc fallback) so invalid terms are rejected cleanly.
🔧 Proposed fix (robust guard + fallback)
📝 Committable suggestion
🤖 Prompt for AI Agents