From 9d17a4e6da58df81fd5b193fef569bc28675511d Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 18 Mar 2015 09:30:17 +0200 Subject: [PATCH 1/3] transport: Use constant for CQL version There's a CQL version constant in query processor. Use it when advertising CQL version to clients. Signed-off-by: Pekka Enberg --- cql3/query_processor.cc | 2 ++ cql3/query_processor.hh | 4 ++-- transport/server.cc | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cql3/query_processor.cc b/cql3/query_processor.cc index 4ac8d2017e..aaa472112e 100644 --- a/cql3/query_processor.cc +++ b/cql3/query_processor.cc @@ -38,6 +38,8 @@ using namespace transport::messages; thread_local logging::logger log("query_processor"); +const sstring query_processor::CQL_VERSION = "3.2.0"; + future<::shared_ptr> query_processor::process(const sstring_view& query_string, service::query_state& query_state, query_options& options) { diff --git a/cql3/query_processor.hh b/cql3/query_processor.hh index 1f964ea7a5..3500d3bdf7 100644 --- a/cql3/query_processor.hh +++ b/cql3/query_processor.hh @@ -45,9 +45,9 @@ private: public: query_processor(service::storage_proxy& proxy, distributed& db) : _proxy(proxy), _db(db) {} -#if 0 - public static final SemanticVersion CQL_VERSION = new SemanticVersion("3.2.0"); + static const sstring CQL_VERSION; +#if 0 public static final QueryProcessor instance = new QueryProcessor(); #endif private: diff --git a/transport/server.cc b/transport/server.cc index 05101add23..eade7b76bf 100644 --- a/transport/server.cc +++ b/transport/server.cc @@ -506,8 +506,7 @@ future<> cql_server::connection::write_ready(int16_t stream) future<> cql_server::connection::write_supported(int16_t stream) { std::multimap opts; - opts.insert({"CQL_VERSION", "3.0.0"}); - opts.insert({"CQL_VERSION", "3.2.0"}); + opts.insert({"CQL_VERSION", cql3::query_processor::CQL_VERSION}); opts.insert({"COMPRESSION", "snappy"}); auto response = make_shared(stream, cql_binary_opcode::SUPPORTED); response->write_string_multimap(opts); From 61f97541432aa8097a1cfd852457e22fc76bedcb Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Thu, 19 Mar 2015 17:55:56 +0200 Subject: [PATCH 2/3] transport: Unify CQL binary protocol error codes Use exceptions::error_code in transport/server.cc and remove duplicated enum. Signed-off-by: Pekka Enberg --- transport/server.cc | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/transport/server.cc b/transport/server.cc index eade7b76bf..e498ce3621 100644 --- a/transport/server.cc +++ b/transport/server.cc @@ -82,24 +82,6 @@ enum class cql_binary_opcode : uint8_t { AUTH_SUCCESS = 16, }; -enum class cql_binary_error { - SERVER_ERROR = 0x0000, - PROTOCOL_ERROR = 0x000A, - BAD_CREDENTIALS = 0x0100, - UNAVAILABLE = 0x1000, - OVERLOADED = 0x1001, - IS_BOOTSTRAPPING = 0x1002, - TRUNCATE_ERROR = 0x1003, - WRITE_TIMEOUT = 0x1100, - READ_TIMEOUT = 0x1200, - SYNTAX_ERROR = 0x2000, - UNAUTHORIZED = 0x2100, - INVALID = 0x2200, - CONFIG_ERROR = 0x2300, - ALREADY_EXISTS = 0x2400, - UNPREPARED = 0x2500, -}; - inline db::consistency_level wire_to_consistency(int16_t v) { switch (v) { @@ -180,7 +162,7 @@ private: future<> process_batch(uint16_t stream, temporary_buffer buf); future<> process_register(uint16_t stream, temporary_buffer buf); - future<> write_error(int16_t stream, cql_binary_error err, sstring msg); + future<> write_error(int16_t stream, exceptions::exception_code err, sstring msg); future<> write_ready(int16_t stream); future<> write_supported(int16_t stream); future<> write_result(int16_t stream, shared_ptr msg); @@ -377,9 +359,9 @@ future<> cql_server::connection::process_request() { try { f.get(); } catch (std::exception& ex) { - write_error(stream, cql_binary_error::SERVER_ERROR, ex.what()); + write_error(stream, exceptions::exception_code::SERVER_ERROR, ex.what()); } catch (...) { - write_error(stream, cql_binary_error::SERVER_ERROR, "unknown error"); + write_error(stream, exceptions::exception_code::SERVER_ERROR, "unknown error"); } }); }); @@ -489,7 +471,7 @@ future<> cql_server::connection::process_register(uint16_t stream, temporary_buf return write_ready(stream); } -future<> cql_server::connection::write_error(int16_t stream, cql_binary_error err, sstring msg) +future<> cql_server::connection::write_error(int16_t stream, exceptions::exception_code err, sstring msg) { auto response = make_shared(stream, cql_binary_opcode::ERROR); response->write_int(static_cast(err)); From 0e3140af8748140ff0d1d5a882781dea9a518489 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Thu, 19 Mar 2015 18:59:31 +0200 Subject: [PATCH 3/3] cql3: Optimize constants::marker::bind() Suggested by Tomek. Signed-off-by: Pekka Enberg --- cql3/constants.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cql3/constants.hh b/cql3/constants.hh index b1e705b862..cb941f9a42 100644 --- a/cql3/constants.hh +++ b/cql3/constants.hh @@ -185,7 +185,7 @@ public: if (!bytes) { return ::shared_ptr{}; } - return ::make_shared(bytes); + return ::make_shared(std::move(bytes)); } };