mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-30 03:30:49 +00:00
tracing: add_query(): change query param to utils::chunked_string
Having to unconditionally linearize the chunked query string when passing it to tracing undoes the work put into reducing large alloctions on the query path. The add_query() is evaluated eagerly on every query, even if tracing is disabled. Defer the linearization to build_parameres_map(), which is only called if tracing is enabled.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "alternator/server.hh"
|
||||
#include "audit/audit.hh"
|
||||
#include "alternator/executor_util.hh"
|
||||
#include "utils/chunked_string.hh"
|
||||
#include "gms/application_state.hh"
|
||||
#include "utils/log.hh"
|
||||
#include <fmt/ranges.h>
|
||||
@@ -543,7 +544,7 @@ static tracing::trace_state_ptr maybe_trace_query(service::client_state& client_
|
||||
if (tracing_instance.trace_next_query() || tracing_instance.slow_query_tracing_enabled()) {
|
||||
trace_state = create_tracing_session(tracing_instance);
|
||||
tracing::add_session_param(trace_state, "alternator_op", op);
|
||||
tracing::add_query(trace_state, truncated_content_view(query, max_users_query_size_in_trace_output).take_as_sstring());
|
||||
tracing::add_query(trace_state, utils::chunked_string(truncated_content_view(query, max_users_query_size_in_trace_output).as_view()));
|
||||
tracing::begin(trace_state, seastar::format("Alternator {}", op), client_state.get_client_address());
|
||||
if (!username.empty()) {
|
||||
tracing::set_username(trace_state, auth::authenticated_user(username));
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "cql3/statements/prepared_statement.hh"
|
||||
#include "tracing/trace_state.hh"
|
||||
#include "mutation/timestamp.hh"
|
||||
#include "utils/chunked_string.hh"
|
||||
|
||||
#include "cql3/values.hh"
|
||||
#include "cql3/query_options.hh"
|
||||
@@ -29,7 +30,7 @@ struct trace_state::params_values {
|
||||
|
||||
std::optional<host_id_vector_replica_set> batchlog_endpoints;
|
||||
std::optional<api::timestamp_type> user_timestamp;
|
||||
std::vector<sstring> queries;
|
||||
std::vector<utils::chunked_string> queries;
|
||||
std::optional<db::consistency_level> cl;
|
||||
std::optional<db::consistency_level> serial_cl;
|
||||
std::optional<int32_t> page_size;
|
||||
@@ -75,14 +76,10 @@ void trace_state::set_response_size(size_t s) noexcept {
|
||||
_records->session_rec.response_size = s;
|
||||
}
|
||||
|
||||
void trace_state::add_query(sstring &&val) {
|
||||
void trace_state::add_query(utils::chunked_string val) {
|
||||
_params_ptr->queries.emplace_back(std::move(val));
|
||||
}
|
||||
|
||||
void trace_state::add_query(std::string_view val) {
|
||||
_params_ptr->queries.emplace_back(sstring{ val });
|
||||
}
|
||||
|
||||
void trace_state::add_session_param(std::string_view key, std::string_view val) {
|
||||
_records->session_rec.parameters.emplace(std::move(key), std::move(val));
|
||||
}
|
||||
@@ -145,11 +142,11 @@ void trace_state::build_parameters_map() {
|
||||
auto& queries = vals.queries;
|
||||
if (!queries.empty()) {
|
||||
if (queries.size() == 1) {
|
||||
params_map.emplace("query", queries[0]);
|
||||
params_map.emplace("query", queries[0].linearize());
|
||||
} else {
|
||||
// BATCH
|
||||
for (size_t i = 0; i < queries.size(); ++i) {
|
||||
params_map.emplace(format("query[{:d}]", i), queries[i]);
|
||||
params_map.emplace(format("query[{:d}]", i), queries[i].linearize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <seastar/core/weak_ptr.hh>
|
||||
#include <seastar/core/checked_ptr.hh>
|
||||
#include "tracing/tracing.hh"
|
||||
#include "utils/chunked_string.hh"
|
||||
#include "gms/inet_address.hh"
|
||||
#include "auth/authenticated_user.hh"
|
||||
#include "db/consistency_level_type.hh"
|
||||
@@ -362,17 +363,7 @@ private:
|
||||
*
|
||||
* @param val the query string
|
||||
*/
|
||||
void add_query(sstring &&val);
|
||||
|
||||
/**
|
||||
* Store a query string.
|
||||
*
|
||||
* This value will eventually be stored in a params<string, string> map of a tracing session
|
||||
* with a 'query' key.
|
||||
*
|
||||
* @param val the query string
|
||||
*/
|
||||
void add_query(std::string_view val);
|
||||
void add_query(utils::chunked_string val);
|
||||
|
||||
/**
|
||||
* Store a custom session parameter.
|
||||
@@ -493,8 +484,7 @@ private:
|
||||
friend void set_request_size(const trace_state_ptr& p, size_t s) noexcept;
|
||||
friend void set_response_size(const trace_state_ptr& p, size_t s) noexcept;
|
||||
friend void set_batchlog_endpoints(const trace_state_ptr& p, const host_id_vector_replica_set& val);
|
||||
friend void add_query(const trace_state_ptr& p, sstring &&val);
|
||||
friend void add_query(const trace_state_ptr& p, std::string_view val);
|
||||
friend void add_query(const trace_state_ptr& p, utils::chunked_string val);
|
||||
friend void add_session_param(const trace_state_ptr& p, std::string_view key, std::string_view val);
|
||||
friend void set_common_query_parameters(const trace_state_ptr& p, db::consistency_level consistency,
|
||||
const std::optional<db::consistency_level>& serial_consistency, api::timestamp_type timestamp);
|
||||
@@ -620,18 +610,12 @@ inline void set_batchlog_endpoints(const trace_state_ptr& p, const host_id_vecto
|
||||
}
|
||||
}
|
||||
|
||||
inline void add_query(const trace_state_ptr& p, sstring &&val) {
|
||||
inline void add_query(const trace_state_ptr& p, utils::chunked_string val) {
|
||||
if (p) {
|
||||
p->add_query(std::move(val));
|
||||
}
|
||||
}
|
||||
|
||||
inline void add_query(const trace_state_ptr& p, std::string_view val) {
|
||||
if (p) {
|
||||
p->add_query(val);
|
||||
}
|
||||
}
|
||||
|
||||
inline void add_session_param(const trace_state_ptr& p, std::string_view key, std::string_view val) {
|
||||
if (p) {
|
||||
p->add_session_param(std::move(key), std::move(val));
|
||||
|
||||
@@ -1603,7 +1603,7 @@ future<std::unique_ptr<cql_server::response>> cql_server::connection::process_pr
|
||||
auto query = std::move(query_result).assume_value();
|
||||
auto dialect = get_dialect();
|
||||
|
||||
tracing::add_query(trace_state, query.linearize());
|
||||
tracing::add_query(trace_state, query);
|
||||
tracing::begin(trace_state, "Preparing CQL3 query", client_state.get_client_address());
|
||||
|
||||
return _server._query_processor.invoke_on_others([query, &client_state, dialect] (auto& qp) mutable {
|
||||
@@ -1671,7 +1671,7 @@ process_execute_internal(service::client_state& client_state, sharded<cql3::quer
|
||||
|
||||
if (init_trace) {
|
||||
tracing::set_page_size(trace_state, options.get_page_size());
|
||||
tracing::add_query(trace_state, sstring(prepared->statement->raw_cql_statement.linearize()));
|
||||
tracing::add_query(trace_state, prepared->statement->raw_cql_statement);
|
||||
tracing::add_prepared_statement(trace_state, prepared);
|
||||
tracing::set_common_query_parameters(trace_state, options.get_consistency(),
|
||||
options.get_serial_consistency(), options.get_specific_options().timestamp);
|
||||
@@ -1777,7 +1777,7 @@ process_batch_internal(service::client_state& client_state, sharded<cql3::query_
|
||||
needs_authorization = pending_authorization_entries.emplace(std::move(cache_key), ps->checked_weak_from_this()).second;
|
||||
}
|
||||
if (init_trace) {
|
||||
tracing::add_query(trace_state, sstring(ps->statement->raw_cql_statement.linearize()));
|
||||
tracing::add_query(trace_state, ps->statement->raw_cql_statement);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user