Metadata id was introduced in CQLv5 to make metadata of prepared statement consistent between driver and database. This commit introduces a protocol extension that allows to use the same mechanism in CQLv4. This change: - Introduce SCYLLA_USE_METADATA_ID protocol extension for CQLv4 - Introduce METADATA_CHANGED flag in RESULT. The flag cames directly from CQLv5 binary protocol. In CQLv4, the bit was never used, so we assume it is safe to reuse it. - Implement handling of metadata_id and METADATA_CHANGED in RESULT rows - Implement returning metadata_id in RESULT prepared - Implement reading metadata_id from EXECUTE - Added description of SCYLLA_USE_METADATA_ID in documentation Metadata_id is wrapped in cql_metadata_id_wrapper because we need to distinguish the following situations: - Metadata_id is not supported by the protocol (e.g. CQLv4 without the extension is used) - Metadata_id is supported by the protocol but not set - e.g. PREPARE query is being handled: it doesn't contain metadata_id in the request but the reply (RESULT prepared) must contain metadata_id - Metadata_id is supported by the protocol and set, any number of bytes >= 0 is allowed, according to the CQLv5 protocol specification Fixes scylladb/scylladb#20860
86 lines
2.7 KiB
C++
86 lines
2.7 KiB
C++
/*
|
|
* Copyright (C) 2016-present ScyllaDB
|
|
*
|
|
* Modified by ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: (LicenseRef-ScyllaDB-Source-Available-1.0 and Apache-2.0)
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "audit/audit.hh"
|
|
|
|
#include <seastar/core/shared_ptr.hh>
|
|
#include <seastar/core/weak_ptr.hh>
|
|
#include <seastar/core/checked_ptr.hh>
|
|
#include <vector>
|
|
|
|
#include "exceptions/exceptions.hh"
|
|
#include "types/types.hh"
|
|
|
|
namespace cql3 {
|
|
|
|
class prepare_context;
|
|
class column_specification;
|
|
class cql_statement;
|
|
|
|
struct cql_metadata_id_type {
|
|
explicit cql_metadata_id_type(bytes&& metadata_id) : _metadata_id(std::move(metadata_id)) {}
|
|
bytes _metadata_id;
|
|
|
|
bool operator==(const cql_metadata_id_type& other) const = default;
|
|
};
|
|
|
|
namespace statements {
|
|
|
|
struct invalidated_prepared_usage_attempt {
|
|
void operator()() const {
|
|
throw exceptions::invalidated_prepared_usage_attempt_exception();
|
|
}
|
|
};
|
|
|
|
class prepared_statement : public seastar::weakly_referencable<prepared_statement> {
|
|
public:
|
|
typedef seastar::checked_ptr<seastar::weak_ptr<const prepared_statement>> checked_weak_ptr;
|
|
|
|
public:
|
|
const seastar::shared_ptr<cql_statement> statement;
|
|
const std::vector<seastar::lw_shared_ptr<column_specification>> bound_names;
|
|
const std::vector<uint16_t> partition_key_bind_indices;
|
|
std::vector<sstring> warnings;
|
|
private:
|
|
cql_metadata_id_type _metadata_id;
|
|
|
|
public:
|
|
prepared_statement(audit::audit_info_ptr&& audit_info, seastar::shared_ptr<cql_statement> statement_, std::vector<seastar::lw_shared_ptr<column_specification>> bound_names_,
|
|
std::vector<uint16_t> partition_key_bind_indices, std::vector<sstring> warnings = {});
|
|
|
|
prepared_statement(audit::audit_info_ptr&& audit_info, seastar::shared_ptr<cql_statement> statement_, const prepare_context& ctx, const std::vector<uint16_t>& partition_key_bind_indices,
|
|
std::vector<sstring> warnings = {});
|
|
|
|
prepared_statement(audit::audit_info_ptr&& audit_info, seastar::shared_ptr<cql_statement> statement_, prepare_context&& ctx, std::vector<uint16_t>&& partition_key_bind_indices);
|
|
|
|
prepared_statement(audit::audit_info_ptr&& audit_info, seastar::shared_ptr<cql_statement>&& statement_, std::vector<sstring> warnings = {});
|
|
|
|
checked_weak_ptr checked_weak_from_this() const {
|
|
return checked_weak_ptr(this->weak_from_this());
|
|
}
|
|
|
|
void calculate_metadata_id();
|
|
|
|
cql_metadata_id_type get_metadata_id() const;
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
template <> struct fmt::formatter<cql3::cql_metadata_id_type> {
|
|
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
|
auto format(const cql3::cql_metadata_id_type& m, fmt::format_context& ctx) const {
|
|
return fmt::format_to(ctx.out(), "{}", m._metadata_id);
|
|
}
|
|
};
|