nodetool: Implement [gs]etcompationthroughput commands

They exist in the original documentation, but are not yet implemented.
Now it's possible to do it.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
This commit is contained in:
Pavel Emelyanov
2024-12-10 13:49:50 +03:00
parent eb29d6f4b0
commit 67089fd5a1
5 changed files with 105 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
================================
Nodetool getcompactionthroughput
================================
**getcompactionthroughput** - Print the throughput cap for compaction in the system
If zero is printed, it means throughput is uncapped
Syntax
-------
.. code-block:: console
nodetool [options] getcompactionthroughput
See also
* :doc:`setcompactionthroughput <setcompactionthroughput>`
.. include:: nodetool-index.rst

View File

@@ -0,0 +1,19 @@
================================
Nodetool setcompactionthroughput
================================
**setcompactionthroughput** - Print the throughput cap for compaction in the system
Setting zero throughput disables capping
Syntax
-------
.. code-block:: console
nodetool [options] setcompactionthroughput <value_in_mib>
See also
* :doc:`getcompactionthroughput <getcompactionthroughput>`
.. include:: nodetool-index.rst

View File

@@ -60,6 +60,8 @@ Nodetool
nodetool-commands/upgradesstables
nodetool-commands/viewbuildstatus
nodetool-commands/version
nodetool-commands/getcompactionthroughput
nodetool-commands/setcompactionthroughput
The ``nodetool`` utility provides a simple command-line interface to the following exposed operations and attributes.
@@ -132,5 +134,7 @@ Operations that are not listed below are currently not available.
* :doc:`upgradesstables </operating-scylla/nodetool-commands/upgradesstables>` - Upgrades each table that is not running the latest ScyllaDB version, by rewriting SSTables.
* :doc:`viewbuildstatus </operating-scylla/nodetool-commands/viewbuildstatus/>` - Shows the progress of a materialized view build.
* :doc:`version </operating-scylla/nodetool-commands/version>` - Print the DB version.
* :doc:`getcompactionthroughput </operating-scylla/nodetool-commands/getcompactionthroughput>` - Print the throughput cap for compaction in the system
* :doc:`setcompactionthroughput </operating-scylla/nodetool-commands/setcompactionthroughput>` - Set the throughput cap for compaction in the system

View File

@@ -0,0 +1,19 @@
#
# Copyright 2024-present ScyllaDB
#
# SPDX-License-Identifier: AGPL-3.0-or-later
#
from test.nodetool.rest_api_mock import expected_request
import pytest
def test_get_compaction_throughput(nodetool, scylla_only):
res = nodetool("getcompactionthroughput", expected_requests = [
expected_request("GET", "/storage_service/compaction_throughput", response=0)
])
assert res.stdout == '0\n'
def test_set_compaction_throughput(nodetool, scylla_only):
nodetool("setcompactionthroughput", "100", expected_requests = [
expected_request("POST", "/storage_service/compaction_throughput", params={"value": "100"})
])

View File

@@ -3249,6 +3249,22 @@ void version_operation(scylla_rest_client& client, const bpo::variables_map& vm)
fmt::print(std::cout, "ReleaseVersion: {}\n", rjson::to_string_view(version_json));
}
void getcompactionthroughput_operation(scylla_rest_client& client, const bpo::variables_map& vm) {
auto res = client.get("/storage_service/compaction_throughput");
uint32_t compaction_throughput_mb_per_sec = res.GetInt();
fmt::print("{}\n", compaction_throughput_mb_per_sec);
}
void setcompactionthroughput_operation(scylla_rest_client& client, const bpo::variables_map& vm) {
std::unordered_map<sstring, sstring> params;
if (vm.contains("mbs")) {
params["value"] = fmt::to_string(vm["mbs"].as<uint32_t>());
} else {
throw std::invalid_argument(fmt::format("The throughput value must be specified"));
}
client.post("/storage_service/compaction_throughput", std::move(params));
}
const std::vector<operation_option> global_options{
typed_option<sstring>("host,h", "localhost", "the hostname or ip address of the ScyllaDB node"),
typed_option<uint16_t>("port,p", 10000, "the port of the REST API of the ScyllaDB node"),
@@ -4451,6 +4467,34 @@ For more information, see: {}"
version_operation
}
},
{
{
"getcompactionthroughput",
"Get compaction IO throughput",
R"(
Print the MiB/s throughput cap for compaction in the system
)",
},
{
getcompactionthroughput_operation
}
},
{
{
"setcompactionthroughput",
"Set compaction IO throughput",
R"(
Set the MiB/s throughput for compaction, or 0 to disable throttling
)",
{},
{
typed_option<uint32_t>("mbs", "Value in MiB, 0 to disable throttling ", 1),
},
},
{
setcompactionthroughput_operation
}
},
};
return operations_with_func;