From 67089fd5a184e746d68fba935f4c19b19fea2bb5 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 10 Dec 2024 13:49:50 +0300 Subject: [PATCH] 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 --- .../getcompactionthroughput.rst | 19 ++++++++ .../setcompactionthroughput.rst | 19 ++++++++ docs/operating-scylla/nodetool.rst | 4 ++ test/nodetool/test_compaction_throughput.py | 19 ++++++++ tools/scylla-nodetool.cc | 44 +++++++++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 docs/operating-scylla/nodetool-commands/getcompactionthroughput.rst create mode 100644 docs/operating-scylla/nodetool-commands/setcompactionthroughput.rst create mode 100644 test/nodetool/test_compaction_throughput.py diff --git a/docs/operating-scylla/nodetool-commands/getcompactionthroughput.rst b/docs/operating-scylla/nodetool-commands/getcompactionthroughput.rst new file mode 100644 index 0000000000..c885c203cd --- /dev/null +++ b/docs/operating-scylla/nodetool-commands/getcompactionthroughput.rst @@ -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 ` + +.. include:: nodetool-index.rst + diff --git a/docs/operating-scylla/nodetool-commands/setcompactionthroughput.rst b/docs/operating-scylla/nodetool-commands/setcompactionthroughput.rst new file mode 100644 index 0000000000..887bda9408 --- /dev/null +++ b/docs/operating-scylla/nodetool-commands/setcompactionthroughput.rst @@ -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 + +See also + +* :doc:`getcompactionthroughput ` + +.. include:: nodetool-index.rst + diff --git a/docs/operating-scylla/nodetool.rst b/docs/operating-scylla/nodetool.rst index c0cc73ea78..675bfb4a56 100644 --- a/docs/operating-scylla/nodetool.rst +++ b/docs/operating-scylla/nodetool.rst @@ -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 ` - Upgrades each table that is not running the latest ScyllaDB version, by rewriting SSTables. * :doc:`viewbuildstatus ` - Shows the progress of a materialized view build. * :doc:`version ` - Print the DB version. +* :doc:`getcompactionthroughput ` - Print the throughput cap for compaction in the system +* :doc:`setcompactionthroughput ` - Set the throughput cap for compaction in the system diff --git a/test/nodetool/test_compaction_throughput.py b/test/nodetool/test_compaction_throughput.py new file mode 100644 index 0000000000..f53f46006b --- /dev/null +++ b/test/nodetool/test_compaction_throughput.py @@ -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"}) + ]) diff --git a/tools/scylla-nodetool.cc b/tools/scylla-nodetool.cc index b85210f043..2d88598208 100644 --- a/tools/scylla-nodetool.cc +++ b/tools/scylla-nodetool.cc @@ -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 params; + if (vm.contains("mbs")) { + params["value"] = fmt::to_string(vm["mbs"].as()); + } 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 global_options{ typed_option("host,h", "localhost", "the hostname or ip address of the ScyllaDB node"), typed_option("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("mbs", "Value in MiB, 0 to disable throttling ", 1), + }, + }, + { + setcompactionthroughput_operation + } + }, }; return operations_with_func;