Adjust resourcetopo directref relation update logic - #106
Open
AnnaYue wants to merge 7 commits into
Open
Conversation
need to split to atomic reference pair to do sort and compare
This commit addresses potential deadlock issues and adds timeout protection for event handlers. Lock Hierarchy Fixes: - Add doc.go with comprehensive lock hierarchy documentation (7 levels) - Fix checkGC(): acquire lock before metaLock, release between - Fix checkLabelUpdateForPostNode(): copy data under lock, release before processing - Fix updateNodeMeta(): release metaLock before acquiring lock - Fix deleteAllRelation(): restructure to follow preNode->postNode lock order - Add storagesLock RWMutex to protect storages map from concurrent access Event Handler Timeout: - Add EventHandlerTimeout config option (default 1s) - Implement timeout in handleNodeEvent() with context cancellation - Implement timeout in handleRelationEvent() with context cancellation - Handlers run sequentially; timeout skips remaining handlers after warning Other Changes: - Change event queue log level from Infof to V(6).Infof - Add threading model documentation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change map get operations to use the two-value lookup pattern (val, ok := map[key]) to explicitly check for key existence. This prevents returning nil values that could cause NPE when callers try to use them. Changes: - manager.go: AddNodeHandler, GetTopoNodeStorage, GetNode now check ok before using value - node_storage.go: getNode and deleteNode check ok for cluster, namespace, and name lookups - GetClusterNode: return nil early if node not found Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract duplicate timeout logic into two helper methods: - executeHandlers(): for NodeHandler with timeout support - executeRelationHandlers(): for RelationHandler with timeout support This reduces code duplication and makes the main event handling logic cleaner. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…, and timeout metrics - Add context.Context to NodeHandler and RelationHandler for cooperative cancellation. When EventHandlerTimeout expires, ctx is cancelled so handlers can select on ctx.Done() and return cleanly (no goroutine leak). - Add defer/recover() to executeHandlers and executeRelationHandlers to catch handler panics and prevent process crashes. Panics are logged and the done channel is always closed. - Add HandlerTimeoutMetrics() returning atomic counters for timed-out node and relation handler callbacks. - Fix checkGC() to use metaLock.RLock() instead of Lock() for a read-only boolean check, matching isObjectExisted(). - Revert GetClusterNode nil-return behavior change to preserve the original API contract for deleted-but-referenced nodes. - Update lock hierarchy docs: swap Level 4 (relationsLock) and Level 5 (lock) to match actual code ordering. - Update doc.go callback threading docs to reflect goroutine + timeout execution model. - Add tests: cooperative handler no-leak, panic recovery, goroutine leak detection, DirectRef delta updates, lock ordering stress. Co-Authored-By: Claude <noreply@anthropic.com>
…ct{} for map set
- Replace executeHandlers/executeRelationHandlers (40-line copy-paste)
with a single generic executeHandlers[H any]() function.
- Change map[nodeMeta]interface{} to map[nodeMeta]struct{} for
idiomatic Go set semantics (zero-value sentinel, zero allocation).
Co-Authored-By: Claude <noreply@anthropic.com>
AnnaYue
force-pushed
the
adjust-resourcetopo-directref-relation-update-logic
branch
from
July 25, 2026 11:27
13dcc94 to
078044d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):
2. What is the scope of this PR (e.g. component or file name):
3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):
4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):
5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:
6. Release note
Please refer to Release Notes Language Style Guide to write a quality release note.