-
Notifications
You must be signed in to change notification settings - Fork 468
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
storage controller: API + CLI for migrating secondary locations #10284
base: main
Are you sure you want to change the base?
Changes from all commits
0ff780d
a5ef8c3
49a683f
39a98f7
fb96e04
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 |
---|---|---|
|
@@ -936,7 +936,7 @@ def test_storage_controller_debug_apis(neon_env_builder: NeonEnvBuilder): | |
that just hits the endpoints to check that they don't bitrot. | ||
""" | ||
|
||
neon_env_builder.num_pageservers = 2 | ||
neon_env_builder.num_pageservers = 3 | ||
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. 3 pageservers because we need some node that contains neither an attached nor secondary location, in order to migrate a secondary there |
||
env = neon_env_builder.init_start() | ||
|
||
tenant_id = TenantId.generate() | ||
|
@@ -961,7 +961,7 @@ def test_storage_controller_debug_apis(neon_env_builder: NeonEnvBuilder): | |
"GET", f"{env.storage_controller_api}/debug/v1/scheduler" | ||
) | ||
# Two nodes, in a dict of node_id->node | ||
assert len(response.json()["nodes"]) == 2 | ||
assert len(response.json()["nodes"]) == 3 | ||
assert sum(v["shard_count"] for v in response.json()["nodes"].values()) == 3 | ||
assert all(v["may_schedule"] for v in response.json()["nodes"].values()) | ||
|
||
|
@@ -972,13 +972,25 @@ def test_storage_controller_debug_apis(neon_env_builder: NeonEnvBuilder): | |
headers=env.storage_controller.headers(TokenScope.ADMIN), | ||
) | ||
|
||
# Secondary migration API: superficial check that it migrates | ||
secondary_dest = env.pageservers[2].id | ||
env.storage_controller.request( | ||
"PUT", | ||
f"{env.storage_controller_api}/control/v1/tenant/{tenant_id}-0002/migrate_secondary", | ||
headers=env.storage_controller.headers(TokenScope.ADMIN), | ||
json={"tenant_shard_id": f"{tenant_id}-0002", "node_id": secondary_dest}, | ||
) | ||
assert env.storage_controller.tenant_describe(tenant_id)["shards"][0]["node_secondary"] == [ | ||
secondary_dest | ||
] | ||
|
||
# Node unclean drop API | ||
response = env.storage_controller.request( | ||
"POST", | ||
f"{env.storage_controller_api}/debug/v1/node/{env.pageservers[1].id}/drop", | ||
headers=env.storage_controller.headers(TokenScope.ADMIN), | ||
) | ||
assert len(env.storage_controller.node_list()) == 1 | ||
assert len(env.storage_controller.node_list()) == 2 | ||
|
||
# Tenant unclean drop API | ||
response = env.storage_controller.request( | ||
|
@@ -1696,7 +1708,13 @@ def test_storcon_cli(neon_env_builder: NeonEnvBuilder): | |
""" | ||
output_dir = neon_env_builder.test_output_dir | ||
shard_count = 4 | ||
env = neon_env_builder.init_start(initial_tenant_shard_count=shard_count) | ||
neon_env_builder.num_pageservers = 2 | ||
env = neon_env_builder.init_configs() | ||
env.start() | ||
|
||
tenant_id = TenantId.generate() | ||
env.create_tenant(tenant_id, placement_policy='{"Attached":1}', shard_count=shard_count) | ||
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. Switch to explicit tenant creation because the default tenant in NeonEnv doesn't have secondaries. |
||
|
||
base_args = [env.neon_binpath / "storcon_cli", "--api", env.storage_controller_api] | ||
|
||
def storcon_cli(args): | ||
|
@@ -1725,7 +1743,7 @@ def storcon_cli(args): | |
# List nodes | ||
node_lines = storcon_cli(["nodes"]) | ||
# Table header, footer, and one line of data | ||
assert len(node_lines) == 5 | ||
assert len(node_lines) == 7 | ||
assert "localhost" in node_lines[3] | ||
|
||
# Pause scheduling onto a node | ||
|
@@ -1743,42 +1761,88 @@ def storcon_cli(args): | |
storcon_cli(["node-configure", "--node-id", "1", "--availability", "offline"]) | ||
assert "Offline" in storcon_cli(["nodes"])[3] | ||
|
||
# Restore node, verify status changes in CLI output | ||
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. This is necessary because we now have two nodes, so making one unavailable kicks off migrations |
||
env.pageservers[0].start() | ||
|
||
def is_online(): | ||
assert "Offline" not in storcon_cli(["nodes"]) | ||
|
||
wait_until(is_online) | ||
|
||
# Let everything stabilize after node failure to avoid interfering with subsequent steps | ||
env.storage_controller.reconcile_until_idle(timeout_secs=10) | ||
|
||
# List tenants | ||
tenant_lines = storcon_cli(["tenants"]) | ||
assert len(tenant_lines) == 5 | ||
assert str(env.initial_tenant) in tenant_lines[3] | ||
assert str(tenant_id) in tenant_lines[3] | ||
|
||
# Setting scheduling policies intentionally result in warnings, they're for rare use. | ||
env.storage_controller.allowed_errors.extend( | ||
[".*Skipping reconcile for policy.*", ".*Scheduling is disabled by policy.*"] | ||
) | ||
|
||
# Describe a tenant | ||
tenant_lines = storcon_cli(["tenant-describe", "--tenant-id", str(env.initial_tenant)]) | ||
tenant_lines = storcon_cli(["tenant-describe", "--tenant-id", str(tenant_id)]) | ||
assert len(tenant_lines) >= 3 + shard_count * 2 | ||
assert str(env.initial_tenant) in tenant_lines[0] | ||
assert str(tenant_id) in tenant_lines[0] | ||
|
||
# Migrate an attached location | ||
def other_ps_id(current_ps_id): | ||
return ( | ||
env.pageservers[0].id | ||
if current_ps_id == env.pageservers[1].id | ||
else env.pageservers[1].id | ||
) | ||
|
||
storcon_cli( | ||
[ | ||
"tenant-shard-migrate", | ||
"--tenant-shard-id", | ||
f"{tenant_id}-0004", | ||
"--node", | ||
str( | ||
other_ps_id( | ||
env.storage_controller.tenant_describe(tenant_id)["shards"][0]["node_attached"] | ||
) | ||
), | ||
] | ||
) | ||
|
||
# Migrate a secondary location | ||
storcon_cli( | ||
[ | ||
"tenant-shard-migrate-secondary", | ||
"--tenant-shard-id", | ||
f"{tenant_id}-0004", | ||
"--node", | ||
str( | ||
other_ps_id( | ||
env.storage_controller.tenant_describe(tenant_id)["shards"][0][ | ||
"node_secondary" | ||
][0] | ||
) | ||
), | ||
] | ||
) | ||
|
||
# Pause changes on a tenant | ||
storcon_cli(["tenant-policy", "--tenant-id", str(env.initial_tenant), "--scheduling", "stop"]) | ||
storcon_cli(["tenant-policy", "--tenant-id", str(tenant_id), "--scheduling", "stop"]) | ||
assert "Stop" in storcon_cli(["tenants"])[3] | ||
|
||
# Cancel ongoing reconcile on a tenant | ||
storcon_cli( | ||
["tenant-shard-cancel-reconcile", "--tenant-shard-id", f"{env.initial_tenant}-0104"] | ||
) | ||
storcon_cli(["tenant-shard-cancel-reconcile", "--tenant-shard-id", f"{tenant_id}-0104"]) | ||
|
||
# Change a tenant's placement | ||
storcon_cli( | ||
["tenant-policy", "--tenant-id", str(env.initial_tenant), "--placement", "secondary"] | ||
) | ||
storcon_cli(["tenant-policy", "--tenant-id", str(tenant_id), "--placement", "secondary"]) | ||
assert "Secondary" in storcon_cli(["tenants"])[3] | ||
|
||
# Modify a tenant's config | ||
storcon_cli( | ||
[ | ||
"patch-tenant-config", | ||
"--tenant-id", | ||
str(env.initial_tenant), | ||
str(tenant_id), | ||
"--config", | ||
json.dumps({"pitr_interval": "1m"}), | ||
] | ||
|
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.
Deterministic order to enable the storcon CLI test assertions to run reliably with multiple nodes