config: specialize config_from_string() for sstring

Specialize config_from_string() for sstring to resolve lexical_cast
stream state parsing limitation. This enables correct handling of empty
string configurations, such as setting an empty value in CQL:

```cql
UPDATE system.config SET value='' WHERE
name='allowed_repair_based_node_ops';
```
Previous implementation using boost::lexical_cast would fail due to
EOF stream state, incorrectly rejecting valid empty string conversions.

Fixes scylladb/scylladb#22491
Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes scylladb/scylladb#22492
This commit is contained in:
Kefu Chai
2025-01-26 16:17:55 +08:00
committed by Avi Kivity
parent 4a268362b9
commit d1c222d9bd
3 changed files with 17 additions and 0 deletions

View File

@@ -20,6 +20,7 @@
#include <seastar/core/coroutine.hh>
#include <seastar/core/format.hh>
#include <seastar/core/sstring.hh>
#include <seastar/json/json_elements.hh>
#include <seastar/util/log.hh>
#include <seastar/util/log-cli.hh>
@@ -115,6 +116,12 @@ config_from_string(std::string_view value) {
}
}
template <>
sstring
config_from_string(std::string_view value) {
return sstring(value);
}
template <>
const config_type& config_type_for<bool>() {
static config_type ct("bool", value_to_json<bool>);

View File

@@ -95,6 +95,13 @@ SEASTAR_THREAD_TEST_CASE(test_system_config_table_update) {
}).get();
}
SEASTAR_THREAD_TEST_CASE(test_system_config_table_set_empty) {
do_with_cql_env_thread([] (cql_test_env& env) {
env.execute_cql(format("UPDATE system.config SET value = '' WHERE name = 'allowed_repair_based_node_ops';")).get();
BOOST_REQUIRE_EQUAL(env.local_db().get_config().allowed_repair_based_node_ops(), sstring());
}).get();
}
SEASTAR_THREAD_TEST_CASE(test_system_config_table_no_live_update) {
do_with_cql_env_thread([] (cql_test_env& env) {
BOOST_REQUIRE_THROW(

View File

@@ -27,6 +27,9 @@ T config_from_string(std::string_view string_representation) {
template <>
bool config_from_string(std::string_view string_representation);
template <>
sstring config_from_string(std::string_view string_representation);
}
namespace YAML {