-
Notifications
You must be signed in to change notification settings - Fork 690
refactor: Update inhibited instance removal logic #1548
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
Conversation
89ae48b to
13051e9
Compare
WalkthroughThe Changes
Poem
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
lib/runtime/src/component/client.rs (1)
149-155: Avoid extra allocation – useretainto filterinhibitedin-placeCreating a fresh
HashMap(new_inhibited) every time this code path runs forces an extra allocation and a full copy of the surviving elements. Since the lock oninstance_inhibitedis already held, you can safely mutate the map in-place:-let mut new_inhibited = HashMap::<i64, u64>::new(); -let filtered = instances - .into_iter() - .filter_map(|instance| { +// Remove entries whose instance disappeared OR TTL expired +inhibited.retain(|id, ts| { + instances.iter().any(|i| i.id() == *id) && now.saturating_sub(*ts) <= ETCD_LEASE_TTL +}); + +let filtered = instances.into_iter().filter_map(|instance| {This eliminates the second map and the final assignment (
*inhibited = new_inhibited;) while preserving the logic.
oandreeva-nv
left a comment
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.
LGTM, thanks!
Overview:
Update the logic when filtering stale inhibited instances.
Details:
The previous instance_id is not reused when a failed worker restarts, so the updated logic will ensure the stale instance_id is removed from the hash map, to avoid it from growing linearly with respect to the number of failed workers detected.
Where should the reviewer start?
N/A
Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)
N/A
Summary by CodeRabbit