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
45 lines
1.4 KiB
C++
45 lines
1.4 KiB
C++
/*
|
|
* Copyright 2020-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
|
|
*/
|
|
|
|
#include <seastar/core/format.hh>
|
|
#include "transport/cql_protocol_extension.hh"
|
|
#include "cql3/result_set.hh"
|
|
#include "exceptions/exceptions.hh"
|
|
|
|
#include <map>
|
|
|
|
namespace cql_transport {
|
|
|
|
static const std::map<cql_protocol_extension, seastar::sstring> EXTENSION_NAMES = {
|
|
{cql_protocol_extension::LWT_ADD_METADATA_MARK, "SCYLLA_LWT_ADD_METADATA_MARK"},
|
|
{cql_protocol_extension::RATE_LIMIT_ERROR, "SCYLLA_RATE_LIMIT_ERROR"},
|
|
{cql_protocol_extension::TABLETS_ROUTING_V1, "TABLETS_ROUTING_V1"},
|
|
{cql_protocol_extension::USE_METADATA_ID, "SCYLLA_USE_METADATA_ID"}
|
|
};
|
|
|
|
cql_protocol_extension_enum_set supported_cql_protocol_extensions() {
|
|
return cql_protocol_extension_enum_set::full();
|
|
}
|
|
|
|
const seastar::sstring& protocol_extension_name(cql_protocol_extension ext) {
|
|
return EXTENSION_NAMES.at(ext);
|
|
}
|
|
|
|
std::vector<seastar::sstring> additional_options_for_proto_ext(cql_protocol_extension ext) {
|
|
switch (ext) {
|
|
case cql_protocol_extension::LWT_ADD_METADATA_MARK:
|
|
return {format("LWT_OPTIMIZATION_META_BIT_MASK={:d}", cql3::prepared_metadata::LWT_FLAG_MASK)};
|
|
case cql_protocol_extension::RATE_LIMIT_ERROR:
|
|
return {format("ERROR_CODE={}", exceptions::exception_code::RATE_LIMIT_ERROR)};
|
|
default:
|
|
return {};
|
|
}
|
|
}
|
|
|
|
} // namespace cql_transport
|