forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 16
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
[VirtualCluster] Clean up after removing node instances from a virtual cluster #441
+298
−42
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c09c43d
Fix with pub msg
Chong-Li 44e1062
Fix compile
Chong-Li aa48d00
Fix and UT
Chong-Li afaf22b
Fix
Chong-Li 6124603
Format
Chong-Li 7ca6fa7
Fix
Chong-Li 2aa203f
Fix and format
Chong-Li 55da609
Merge remote-tracking branch 'origin/main' into fix_drain
Chong-Li 5951036
Format
Chong-Li File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -29,23 +29,37 @@ bool VirtualClusterManager::UpdateVirtualCluster( | |||||
return false; | ||||||
} | ||||||
|
||||||
const auto &virtual_cluster_id = virtual_cluster_data.id(); | ||||||
auto it = virtual_clusters_.find(virtual_cluster_id); | ||||||
if (it == virtual_clusters_.end()) { | ||||||
virtual_clusters_[virtual_cluster_id] = std::move(virtual_cluster_data); | ||||||
} else { | ||||||
if (it->second.revision() > virtual_cluster_data.revision()) { | ||||||
RAY_LOG(WARNING) | ||||||
<< "The revision of the received virtual cluster is outdated, ignore it."; | ||||||
return false; | ||||||
// The virtual cluster id of the input data. | ||||||
const auto &input_virtual_cluster_id = virtual_cluster_data.id(); | ||||||
|
||||||
if (virtual_cluster_data.is_removed()) { | ||||||
if (virtual_cluster_id_ == input_virtual_cluster_id) { | ||||||
virtual_cluster_id_.clear(); | ||||||
// The virtual cluster is removed, we have to clean up | ||||||
// the local tasks (it is a no-op in most cases). | ||||||
local_node_cleanup_fn_(); | ||||||
} | ||||||
virtual_clusters_.erase(input_virtual_cluster_id); | ||||||
} else { | ||||||
// Whether the local node in the input data. | ||||||
bool local_node_in_data = | ||||||
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.
Suggested change
|
||||||
virtual_cluster_data.node_instances().contains(local_node_instance_id_); | ||||||
|
||||||
if (virtual_cluster_data.is_removed()) { | ||||||
virtual_clusters_.erase(it); | ||||||
return true; | ||||||
// The local node is removed from its current virtual cluster. | ||||||
if (virtual_cluster_id_ == input_virtual_cluster_id && !local_node_in_data) { | ||||||
virtual_cluster_id_.clear(); | ||||||
// Clean up the local tasks (it is a no-op in most cases). | ||||||
local_node_cleanup_fn_(); | ||||||
} else if (virtual_cluster_id_ != input_virtual_cluster_id && | ||||||
local_node_in_data) { // The local node is added to a new virtual cluster. | ||||||
virtual_cluster_id_ = input_virtual_cluster_id; | ||||||
// There are chances that the pub message (removing the local node from a virtual | ||||||
// cluster) was lost in the past, so we also have to clean up when adding the local | ||||||
// node to a new virtual cluster (it is a no-op in most cases). | ||||||
local_node_cleanup_fn_(); | ||||||
} | ||||||
|
||||||
it->second = std::move(virtual_cluster_data); | ||||||
virtual_clusters_[input_virtual_cluster_id] = std::move(virtual_cluster_data); | ||||||
} | ||||||
return true; | ||||||
} | ||||||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,10 @@ namespace raylet { | |
|
||
class VirtualClusterManager { | ||
public: | ||
VirtualClusterManager() = default; | ||
VirtualClusterManager(const NodeID &node_id, | ||
std::function<void()> local_node_cleanup_fn) | ||
: local_node_instance_id_(node_id.Hex()), | ||
local_node_cleanup_fn_(local_node_cleanup_fn) {} | ||
|
||
/// Update the virtual cluster. | ||
/// | ||
|
@@ -47,6 +50,11 @@ class VirtualClusterManager { | |
private: | ||
/// The virtual clusters. | ||
absl::flat_hash_map<std::string, rpc::VirtualClusterTableData> virtual_clusters_; | ||
/// The local node instance id. | ||
std::string local_node_instance_id_; | ||
std::function<void()> local_node_cleanup_fn_; | ||
/// The (indivisible) virtual cluster to which the local node belongs. | ||
std::string virtual_cluster_id_; | ||
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. local_virtual_cluster_id_ |
||
}; | ||
|
||
} // namespace raylet | ||
|
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.
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.
invoke
subscribe
directly.