-
Notifications
You must be signed in to change notification settings - Fork 47
[feat] Filter SimpleStorage nodes by custom resource #151
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
Merged
0oshowero0
merged 2 commits into
Ascend:main
from
nataliekung:feat/simple-storage-node-resource
Aug 12, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| # Copyright 2025 The TransferQueue Team | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
| from omegaconf import OmegaConf | ||
|
|
||
| from transfer_queue.storage.bootstrap import simple_storage_bootstrap | ||
| from transfer_queue.utils import common | ||
|
|
||
| _NODE_A = "01" * 28 | ||
| _NODE_B = "02" * 28 | ||
| _NODE_C = "03" * 28 | ||
| _NODE_D = "04" * 28 | ||
|
|
||
|
|
||
| def _node(node_id: str, *, alive: bool = True, resources: dict[str, float] | None = None) -> dict: | ||
| return {"NodeID": node_id, "Alive": alive, "Resources": resources or {}} | ||
|
|
||
|
|
||
| def _node_ids(strategies) -> list[str]: | ||
| return [strategy.node_id for strategy in strategies] | ||
|
|
||
|
|
||
| def test_round_robin_uses_all_alive_nodes_by_default(monkeypatch): | ||
| nodes = [_node(_NODE_B), _node(_NODE_C, alive=False), _node(_NODE_A)] | ||
| monkeypatch.setattr(common.ray, "nodes", lambda: nodes) | ||
|
|
||
| strategies = common.get_node_round_robin_scheduling_strategies(5) | ||
|
|
||
| assert _node_ids(strategies) == [_NODE_A, _NODE_B, _NODE_A, _NODE_B, _NODE_A] | ||
|
|
||
|
|
||
| def test_node_resource_filters_nodes_and_zero_capacity(monkeypatch): | ||
| nodes = [ | ||
| _node(_NODE_C, resources={"storage_pool": 2}), | ||
| _node(_NODE_B, resources={"storage_pool": 0}), | ||
| _node(_NODE_A, resources={"storage_pool": 1}), | ||
| _node(_NODE_D, resources={"compute_pool": 1}), | ||
| ] | ||
| monkeypatch.setattr(common.ray, "nodes", lambda: nodes) | ||
|
|
||
| strategies = common.get_node_round_robin_scheduling_strategies(4, node_resource="storage_pool") | ||
|
|
||
| assert _node_ids(strategies) == [_NODE_A, _NODE_C, _NODE_A, _NODE_C] | ||
|
|
||
|
|
||
| def test_node_resource_excludes_dead_nodes(monkeypatch): | ||
| nodes = [ | ||
| _node(_NODE_A, alive=False, resources={"storage_pool": 1}), | ||
| _node(_NODE_B, resources={"storage_pool": 1}), | ||
| ] | ||
| monkeypatch.setattr(common.ray, "nodes", lambda: nodes) | ||
|
|
||
| strategies = common.get_node_round_robin_scheduling_strategies(2, node_resource="storage_pool") | ||
|
|
||
| assert _node_ids(strategies) == [_NODE_B, _NODE_B] | ||
|
|
||
|
|
||
| def test_node_resource_raises_when_no_alive_node_matches(monkeypatch): | ||
| nodes = [ | ||
| _node(_NODE_A, resources={"storage_pool": 0}), | ||
| _node(_NODE_B, alive=False, resources={"storage_pool": 1}), | ||
| ] | ||
| monkeypatch.setattr(common.ray, "nodes", lambda: nodes) | ||
|
|
||
| with pytest.raises(ValueError, match="No alive Ray nodes provide custom resource 'storage_pool'"): | ||
| common.get_node_round_robin_scheduling_strategies(1, node_resource="storage_pool") | ||
|
|
||
|
|
||
| def test_default_no_alive_node_error_is_unchanged(monkeypatch): | ||
| monkeypatch.setattr(common.ray, "nodes", lambda: []) | ||
|
|
||
| with pytest.raises(RuntimeError, match="No alive Ray nodes found. Is Ray initialized?"): | ||
| common.get_node_round_robin_scheduling_strategies(1) | ||
|
|
||
|
|
||
| def test_simple_storage_initialization_forwards_node_resource(monkeypatch): | ||
| strategy = MagicMock(node_id=_NODE_A) | ||
| get_strategies = MagicMock(return_value=[strategy]) | ||
| storage_unit = MagicMock() | ||
| storage_handle = MagicMock() | ||
| storage_unit.options.return_value.remote.return_value = storage_handle | ||
|
|
||
| monkeypatch.setattr(simple_storage_bootstrap, "get_node_round_robin_scheduling_strategies", get_strategies) | ||
| monkeypatch.setattr(simple_storage_bootstrap, "SimpleStorageUnit", storage_unit) | ||
| monkeypatch.setattr(simple_storage_bootstrap, "process_zmq_server_info", lambda _: {}) | ||
|
|
||
| conf = OmegaConf.create( | ||
| { | ||
| "backend": { | ||
| "storage_backend": "SimpleStorage", | ||
| "SimpleStorage": { | ||
| "num_data_storage_units": 1, | ||
| "total_storage_size": None, | ||
| "node_resource": "storage_pool", | ||
| }, | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| handles = simple_storage_bootstrap.initialize_simple_storage(conf) | ||
|
|
||
| get_strategies.assert_called_once_with(1, node_resource="storage_pool") | ||
| assert handles == {"TransferQueueStorageUnit#0": storage_handle} |
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
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
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
Oops, something went wrong.
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.
I suggest we rename the config as
required_node_resourceThere 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.
Renamed it to
required_node_resourcethroughout the config, implementation, error message, and tests. Thanks for the suggestion.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.
Renamed it to required_node_resource throughout the config, implementation, error message, and tests. Thanks for the suggestion.