[PATCH v1 04/11] transport: co-routinize cql_server::connection::process_prepare

0 views
Skip to first unread message

Gleb Natapov

<gleb@scylladb.com>
unread,
Jul 9, 2024, 7:32:26 AM (8 days ago) Jul 9
to scylladb-dev@googlegroups.com
---
transport/server.cc | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/transport/server.cc b/transport/server.cc
index fac3053c1b0..39bb3bc954e 100644
--- a/transport/server.cc
+++ b/transport/server.cc
@@ -1051,17 +1051,16 @@ future<std::unique_ptr<cql_server::response>> cql_server::connection::process_pr
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] (auto& qp) mutable {
- return qp.prepare(std::move(query), client_state).discard_result();
- }).then([this, query, stream, &client_state, trace_state] () mutable {
- tracing::trace(trace_state, "Done preparing on remote shards");
- return _server._query_processor.local().prepare(std::move(query), client_state).then([this, stream, trace_state] (auto msg) {
- tracing::trace(trace_state, "Done preparing on a local shard - preparing a result. ID is [{}]", seastar::value_of([&msg] {
- return messages::result_message::prepared::cql::get_id(msg);
- }));
- return make_result(stream, *msg, trace_state, _version);
- });
+ co_await _server._query_processor.invoke_on_others([query, &client_state] (auto& qp) mutable -> future<> {
+ (void)co_await qp.prepare(std::move(query), client_state);
});
+
+ tracing::trace(trace_state, "Done preparing on remote shards");
+ auto msg = co_await _server._query_processor.local().prepare(std::move(query), client_state);
+ tracing::trace(trace_state, "Done preparing on a local shard - preparing a result. ID is [{}]", seastar::value_of([&msg] {
+ return messages::result_message::prepared::cql::get_id(msg);
+ }));
+ co_return make_result(stream, *msg, trace_state, _version);
}

static future<process_fn_return_type>
--
2.45.2

Avi Kivity

<avi@scylladb.com>
unread,
Jul 9, 2024, 8:28:51 AM (8 days ago) Jul 9
to Gleb Natapov, scylladb-dev@googlegroups.com
On Tue, 2024-07-09 at 14:30 +0300, 'Gleb Natapov' via ScyllaDB development wrote:
---
 transport/server.cc | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/transport/server.cc b/transport/server.cc
index fac3053c1b0..39bb3bc954e 100644
--- a/transport/server.cc
+++ b/transport/server.cc
@@ -1051,17 +1051,16 @@ future<std::unique_ptr<cql_server::response>> cql_server::connection::process_pr
     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] (auto& qp) mutable {
-            return qp.prepare(std::move(query), client_state).discard_result();
-    }).then([this, query, stream, &client_state, trace_state] () mutable {
-        tracing::trace(trace_state, "Done preparing on remote shards");
-        return _server._query_processor.local().prepare(std::move(query), client_state).then([this, stream, trace_state] (auto msg) {
-            tracing::trace(trace_state, "Done preparing on a local shard - preparing a result. ID is [{}]", seastar::value_of([&msg] {
-                return messages::result_message::prepared::cql::get_id(msg);
-            }));
-            return make_result(stream, *msg, trace_state, _version);
-        });
+    co_await _server._query_processor.invoke_on_others([query, &client_state] (auto& qp) mutable -> future<> {
+            (void)co_await qp.prepare(std::move(query), client_state);


The cast to void isn't necessary. Before the coroutine it was, since future<whatever> doesn't convert to future<>, but the whatever isn't [[nodiscard]] so it can be dropped.

Gleb Natapov

<gleb@scylladb.com>
unread,
Jul 9, 2024, 8:51:48 AM (8 days ago) Jul 9
to Avi Kivity, scylladb-dev@googlegroups.com
Before the coroutine there was no void, there was discard_result(). Void
here is unnecessary, but it shows that the result is discarded.

> >      });
> > +
> > +    tracing::trace(trace_state, "Done preparing on remote shards");
> > +    auto msg = co_await
> > _server._query_processor.local().prepare(std::move(query),
> > client_state);
> > +    tracing::trace(trace_state, "Done preparing on a local shard -
> > preparing a result. ID is [{}]", seastar::value_of([&msg] {
> > +        return messages::result_message::prepared::cql::get_id(msg);
> > +    }));
> > +    co_return make_result(stream, *msg, trace_state, _version);
> >  }
> >  
> >  static future<process_fn_return_type>
> > --
> > 2.45.2
> >
>

--
Gleb.
Reply all
Reply to author
Forward
0 new messages