tools/scylla-nodetool: implement enableautocompaction command

This commit is contained in:
Botond Dénes
2023-11-03 10:38:31 -04:00
parent 0e0401a5c5
commit 7ff7cdc86a
2 changed files with 69 additions and 0 deletions

View File

@@ -45,3 +45,42 @@ def test_disableautocompaction_none_existent_keyspace(nodetool):
{"expected_requests": [expected_request("GET", "/storage_service/keyspaces", response=["ks1", "ks2"])]},
["nodetool: Keyspace [non_existent_ks] does not exist.",
"error processing arguments: keyspace non_existent_ks does not exist"])
def test_enableautocompaction(nodetool):
nodetool("enableautocompaction", expected_requests=[
expected_request("GET", "/storage_service/keyspaces", response=["ks1", "ks2"],
multiple=expected_request.MULTIPLE),
expected_request("POST", "/storage_service/auto_compaction/ks1"),
expected_request("POST", "/storage_service/auto_compaction/ks2")
])
def test_enableautocompaction_one_keyspace(nodetool):
nodetool("enableautocompaction", "ks1", expected_requests=[
expected_request("GET", "/storage_service/keyspaces", response=["ks1", "ks2"]),
expected_request("POST", "/storage_service/auto_compaction/ks1")
])
def test_enableautocompaction_one_table(nodetool):
nodetool("enableautocompaction", "ks1", "tbl1", expected_requests=[
expected_request("GET", "/storage_service/keyspaces", response=["ks1", "ks2"]),
expected_request("POST", "/storage_service/auto_compaction/ks1", params={"cf": "tbl1"})
])
def test_enableautocompaction_two_tables(nodetool):
nodetool("enableautocompaction", "ks1", "tbl1", "tbl2", expected_requests=[
expected_request("GET", "/storage_service/keyspaces", response=["ks1", "ks2"]),
expected_request("POST", "/storage_service/auto_compaction/ks1", params={"cf": "tbl1,tbl2"})
])
def test_enableautocompaction_none_existent_keyspace(nodetool):
utils.check_nodetool_fails_with(
nodetool,
("enableautocompaction", "non_existent_ks"),
{"expected_requests": [expected_request("GET", "/storage_service/keyspaces", response=["ks1", "ks2"])]},
["nodetool: Keyspace [non_existent_ks] does not exist.",
"error processing arguments: keyspace non_existent_ks does not exist"])

View File

@@ -370,6 +370,21 @@ void drain_operation(scylla_rest_client& client, const bpo::variables_map& vm) {
client.post("/storage_service/drain");
}
void enableautocompaction_operation(scylla_rest_client& client, const bpo::variables_map& vm) {
if (!vm.count("keyspace")) {
for (const auto& keyspace : get_keyspaces(client)) {
client.post(format("/storage_service/auto_compaction/{}", keyspace));
}
} else {
const auto [keyspace, tables] = parse_keyspace_and_tables(client, vm);
std::unordered_map<sstring, sstring> params;
if (!tables.empty()) {
params["cf"] = fmt::to_string(fmt::join(tables.begin(), tables.end(), ","));
}
client.post(format("/storage_service/auto_compaction/{}", keyspace), std::move(params));
}
}
void enablebackup_operation(scylla_rest_client& client, const bpo::variables_map& vm) {
client.post("/storage_service/incremental_backups", {{"value", "true"}});
}
@@ -806,6 +821,21 @@ Fore more information, see: https://opensource.docs.scylladb.com/stable/operatin
},
drain_operation
},
{
{
"enableautocompaction",
"Enables automatic compaction for the given keyspace and table(s)",
R"(
Fore more information, see: https://opensource.docs.scylladb.com/stable/operating-scylla/nodetool-commands/enableautocompaction.html
)",
{ },
{
typed_option<sstring>("keyspace", "The keyspace to enable automatic compaction for", 1),
typed_option<std::vector<sstring>>("table", "The table(s) to enable automatic compaction for", -1),
}
},
enableautocompaction_operation
},
{
{
"enablebackup",