The name of the Scylla table backing an Alternator LSI looks like `basename:!lsiname`. Some REST API clients (including Scylla Manager) when they send a "!" character in the REST API request path may decide to "URL encode" it - convert it to `%21`.
Because of a Seastar bug (https://github.com/scylladb/seastar/issues/725) Scylla's REST API server forgets to do the URL decoding on the path part of the request, which leads to the REST API request failing to address the LSI table.
The first patch in this PR fixes the bug by using a new Seastar API introduced in https://github.com/scylladb/seastar/pull/2125 that does the URL decoding as appropriate. The second patch in the PR is a new test for this bug, which fails without the fix, and passes afterwards.
Fixes #5883.
Closes scylladb/scylladb#18286
* github.com:scylladb/scylladb:
test/alternator: test addressing LSI using REST API
REST API: stop using deprecated, buggy, path parameter
(cherry picked from commit 0438febdc9)
Signed-off-by: Nadav Har'El <nyh@scylladb.com>
111 lines
4.4 KiB
C++
111 lines
4.4 KiB
C++
/*
|
|
* Copyright (C) 2022-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#ifndef SCYLLA_BUILD_MODE_RELEASE
|
|
|
|
#include <seastar/core/coroutine.hh>
|
|
|
|
#include "task_manager_test.hh"
|
|
#include "api/api-doc/task_manager_test.json.hh"
|
|
#include "tasks/test_module.hh"
|
|
|
|
namespace api {
|
|
|
|
namespace tmt = httpd::task_manager_test_json;
|
|
using namespace json;
|
|
using namespace seastar::httpd;
|
|
|
|
void set_task_manager_test(http_context& ctx, routes& r) {
|
|
tmt::register_test_module.set(r, [&ctx] (std::unique_ptr<http::request> req) -> future<json::json_return_type> {
|
|
co_await ctx.tm.invoke_on_all([] (tasks::task_manager& tm) {
|
|
auto m = make_shared<tasks::test_module>(tm);
|
|
tm.register_module("test", m);
|
|
});
|
|
co_return json_void();
|
|
});
|
|
|
|
tmt::unregister_test_module.set(r, [&ctx] (std::unique_ptr<http::request> req) -> future<json::json_return_type> {
|
|
co_await ctx.tm.invoke_on_all([] (tasks::task_manager& tm) -> future<> {
|
|
auto module_name = "test";
|
|
auto module = tm.find_module(module_name);
|
|
co_await module->stop();
|
|
});
|
|
co_return json_void();
|
|
});
|
|
|
|
tmt::register_test_task.set(r, [&ctx] (std::unique_ptr<http::request> req) -> future<json::json_return_type> {
|
|
sharded<tasks::task_manager>& tms = ctx.tm;
|
|
auto it = req->query_parameters.find("task_id");
|
|
auto id = it != req->query_parameters.end() ? tasks::task_id{utils::UUID{it->second}} : tasks::task_id::create_null_id();
|
|
it = req->query_parameters.find("shard");
|
|
unsigned shard = it != req->query_parameters.end() ? boost::lexical_cast<unsigned>(it->second) : 0;
|
|
it = req->query_parameters.find("keyspace");
|
|
std::string keyspace = it != req->query_parameters.end() ? it->second : "";
|
|
it = req->query_parameters.find("table");
|
|
std::string table = it != req->query_parameters.end() ? it->second : "";
|
|
it = req->query_parameters.find("entity");
|
|
std::string entity = it != req->query_parameters.end() ? it->second : "";
|
|
it = req->query_parameters.find("parent_id");
|
|
tasks::task_info data;
|
|
if (it != req->query_parameters.end()) {
|
|
data.id = tasks::task_id{utils::UUID{it->second}};
|
|
auto parent_ptr = co_await tasks::task_manager::lookup_task_on_all_shards(ctx.tm, data.id);
|
|
data.shard = parent_ptr->get_status().shard;
|
|
}
|
|
|
|
auto module = tms.local().find_module("test");
|
|
id = co_await module->make_task<tasks::test_task_impl>(shard, id, keyspace, table, entity, data);
|
|
co_await tms.invoke_on(shard, [id] (tasks::task_manager& tm) {
|
|
auto it = tm.get_all_tasks().find(id);
|
|
if (it != tm.get_all_tasks().end()) {
|
|
it->second->start();
|
|
}
|
|
});
|
|
co_return id.to_sstring();
|
|
});
|
|
|
|
tmt::unregister_test_task.set(r, [&ctx] (std::unique_ptr<http::request> req) -> future<json::json_return_type> {
|
|
auto id = tasks::task_id{utils::UUID{req->query_parameters["task_id"]}};
|
|
try {
|
|
co_await tasks::task_manager::invoke_on_task(ctx.tm, id, [] (tasks::task_manager::task_ptr task) -> future<> {
|
|
tasks::test_task test_task{task};
|
|
co_await test_task.unregister_task();
|
|
});
|
|
} catch (tasks::task_manager::task_not_found& e) {
|
|
throw bad_param_exception(e.what());
|
|
}
|
|
co_return json_void();
|
|
});
|
|
|
|
tmt::finish_test_task.set(r, [&ctx] (std::unique_ptr<http::request> req) -> future<json::json_return_type> {
|
|
auto id = tasks::task_id{utils::UUID{req->get_path_param("task_id")}};
|
|
auto it = req->query_parameters.find("error");
|
|
bool fail = it != req->query_parameters.end();
|
|
std::string error = fail ? it->second : "";
|
|
|
|
try {
|
|
co_await tasks::task_manager::invoke_on_task(ctx.tm, id, [fail, error = std::move(error)] (tasks::task_manager::task_ptr task) {
|
|
tasks::test_task test_task{task};
|
|
if (fail) {
|
|
test_task.finish_failed(std::make_exception_ptr(std::runtime_error(error)));
|
|
} else {
|
|
test_task.finish();
|
|
}
|
|
return make_ready_future<>();
|
|
});
|
|
} catch (tasks::task_manager::task_not_found& e) {
|
|
throw bad_param_exception(e.what());
|
|
}
|
|
co_return json_void();
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|