From cd2c581c7ca6ae463c8aee7ff0fe35323dc2860c Mon Sep 17 00:00:00 2001 From: Piotr Sarna Date: Tue, 6 Aug 2019 10:38:01 +0200 Subject: [PATCH] alternator: remove a pointer-based workaround for future With libjsoncpp we were forced to work around the problem of non-noexcept constructors by using an intermediate unique pointer. Objects provided by rapidjson have correct noexcept specifiers, so the workaround can be dropped. --- alternator/executor.cc | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/alternator/executor.cc b/alternator/executor.cc index d1862bd3bd..b58b0c3ae3 100644 --- a/alternator/executor.cc +++ b/alternator/executor.cc @@ -1239,7 +1239,7 @@ future executor::batch_get_item(std::string content) { // If got here, all "requests" are valid, so let's start them all // in parallel. The requests object are then immediately destroyed. - std::vector>>> response_futures; + std::vector>>> response_futures; for (const auto& rs : requests) { for (const auto &r : rs.requests) { dht::partition_range_vector partition_ranges{dht::partition_range(dht::global_partitioner().decorate_key(*rs.schema, std::move(r.pk)))}; @@ -1253,18 +1253,11 @@ future executor::batch_get_item(std::string content) { auto selection = cql3::selection::selection::wildcard(rs.schema); auto partition_slice = query::partition_slice(std::move(bounds), {}, std::move(regular_columns), selection->get_query_options()); auto command = ::make_lw_shared(rs.schema->id(), rs.schema->version(), partition_slice, query::max_partitions); - future>> f = _proxy.query(rs.schema, std::move(command), std::move(partition_ranges), rs.cl, service::storage_proxy::coordinator_query_options(db::no_timeout)).then( + future>> f = _proxy.query(rs.schema, std::move(command), std::move(partition_ranges), rs.cl, service::storage_proxy::coordinator_query_options(db::no_timeout)).then( [schema = rs.schema, partition_slice = std::move(partition_slice), selection = std::move(selection), attrs_to_get = rs.attrs_to_get] (service::storage_proxy::coordinator_query_result qr) mutable { std::optional json = describe_single_item(schema, partition_slice, *selection, std::move(qr.query_result), std::move(attrs_to_get)); - // Unfortunately, future> doesn't - // work because rjson::value doesn't have a non-throwing move - // constructor. So we need to convert it to a std::unique_ptr. - std::unique_ptr v; - if (json) { - v = std::make_unique(std::move(*json)); - } - return make_ready_future>>( - std::make_tuple(schema->cf_name(), std::move(v))); + return make_ready_future>>( + std::make_tuple(schema->cf_name(), std::move(json))); }); response_futures.push_back(std::move(f)); } @@ -1278,10 +1271,10 @@ future executor::batch_get_item(std::string content) { // handled it above), but this case does include things like timeouts, // unavailable CL, etc. return when_all_succeed(response_futures.begin(), response_futures.end()).then( - [] (std::vector>> responses) { + [] (std::vector>> responses) { rjson::value response = rjson::empty_object(); rjson::set(response, "Responses", rjson::empty_object()); - for (const auto& t : responses) { + for (auto& t : responses) { if (!response["Responses"].HasMember(std::get<0>(t).c_str())) { rjson::set_with_string_name(response["Responses"], std::get<0>(t), rjson::empty_array()); }