frozen_mutation: introduce consume method

Allowing to consume the frozen_mutation directly
to a stream rather than unfreezing it first
and then consuming the unfrozen mutation.

Streaming directly from the frozen_mutation
saves both cpu and memory, and will make it
easier to be made async as a follow, to allow
yielding, e.g. between rows.

This is used today only in to_data_query_result
which is invoked on the read-repair path.

Refs #10038
Fixes #10021

Test: unit(release)

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
Message-Id: <20220405055807.1834494-1-bhalevy@scylladb.com>
This commit is contained in:
Benny Halevy
2022-04-05 08:58:07 +03:00
committed by Botond Dénes
parent 67e0590bbc
commit abbf5de68c
3 changed files with 187 additions and 5 deletions

View File

@@ -28,6 +28,7 @@
#include "schema_builder.hh"
#include "partition_slice_builder.hh"
#include "readers/from_mutations_v2.hh"
#include "mutation_rebuilder.hh"
using namespace std::literals::chrono_literals;
@@ -558,3 +559,21 @@ SEASTAR_THREAD_TEST_CASE(test_result_size_calculation) {
BOOST_REQUIRE_EQUAL(digest_only_builder.memory_accounter().used_memory(), result_and_digest_builder.memory_accounter().used_memory());
}
SEASTAR_THREAD_TEST_CASE(test_frozen_mutation_consumer) {
random_mutation_generator gen(random_mutation_generator::generate_counters::no);
schema_ptr s = gen.schema();
std::vector<mutation> mutations = gen(1);
const mutation& m = mutations[0];
frozen_mutation fm = freeze(m);
// sanity check unfreeze first
mutation um = fm.unfreeze(s);
BOOST_REQUIRE_EQUAL(um, m);
// Rebuild mutation by consuming from the frozen_mutation
mutation_rebuilder_v2 rebuilder(s);
auto res = fm.consume(s, rebuilder);
BOOST_REQUIRE(res.result);
const auto& rebuilt = *res.result;
BOOST_REQUIRE_EQUAL(rebuilt, m);
}