Files
scylladb/test/boost/virtual_table_mutation_source_test.cc
Avi Kivity cbba80914d memtable: move to replica module and namespace
Memtables are a replica-side entity, and so are moved to the
replica module and namespace.

Memtables are also used outside the replica, in two places:
 - in some virtual tables; this is also in some way inside the replica,
   (virtual readers are installed at the replica level, not the
   cooordinator), so I don't consider it a layering violation
 - in many sstable unit tests, as a convenient way to create sstables
   with known input. This is a layering violation.

We could make memtables their own module, but I think this is wrong.
Memtables are deeply tied into replica memory management, and trying
to make them a low-level primitive (at a lower level than sstables) will
be difficult. Not least because memtables use sstables. Instead, we
should have a memtable-like thing that doesn't support merging and
doesn't have all other funky memtable stuff, and instead replace
the uses of memtables in sstable tests with some kind of
make_flat_mutation_reader_from_unsorted_mutations() that does
the sorting that is the reason for the use of memtables in tests (and
live with the layering violation meanwhile).

Test: unit (dev)

Closes #10120
2022-02-23 09:05:16 +02:00

79 lines
3.0 KiB
C++

/*
* Copyright (C) 2021-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include "db/virtual_table.hh"
#include "db/system_keyspace.hh"
#include "schema.hh"
#include "test/lib/mutation_source_test.hh"
#include <seastar/testing/thread_test_case.hh>
class memtable_filling_test_vt : public db::memtable_filling_virtual_table {
std::vector<mutation> _mutations;
public:
memtable_filling_test_vt(schema_ptr s, std::vector<mutation> mutations)
: memtable_filling_virtual_table(s)
, _mutations(std::move(mutations)) {}
future<> execute(std::function<void(mutation)> mutation_sink) override {
return with_timeout(db::no_timeout, do_for_each(_mutations, [mutation_sink = std::move(mutation_sink)] (const mutation& m) { mutation_sink(m); }));
}
};
class streaming_test_vt : public db::streaming_virtual_table {
schema_ptr _s;
std::vector<mutation> _mutations;
public:
streaming_test_vt(schema_ptr s, std::vector<mutation> mutations)
: streaming_virtual_table(s)
, _s(s)
, _mutations(std::move(mutations)) {}
virtual future<> execute(reader_permit permit, db::result_collector& rc) override {
return async([this, permit, &rc] {
auto mt = make_lw_shared<replica::memtable>(_s);
do_for_each(_mutations, [mt] (const mutation& m) {
mt->apply(m);
}).get();
auto rdr = mt->make_flat_reader(_s, permit);
auto close_rdr = deferred_close(rdr);
rdr.consume_pausable([&rc] (mutation_fragment mf) {
return rc.take(std::move(mf)).then([] { return stop_iteration::no; });
}).get();
});
}
};
SEASTAR_THREAD_TEST_CASE(test_memtable_filling_vt_as_mutation_source) {
std::unique_ptr<memtable_filling_test_vt> table; // Used to prolong table's life
run_mutation_source_tests([&table] (schema_ptr s, const std::vector<mutation>& mutations, gc_clock::time_point) -> mutation_source {
table = std::make_unique<memtable_filling_test_vt>(s, mutations);
return table->as_mutation_source();
});
}
SEASTAR_THREAD_TEST_CASE(test_streaming_vt_as_mutation_source) {
std::unique_ptr<streaming_test_vt> table; // Used to prolong table's life
run_mutation_source_tests([&table] (schema_ptr s, const std::vector<mutation>& mutations, gc_clock::time_point) -> mutation_source {
table = std::make_unique<streaming_test_vt>(s, mutations);
return mutation_source([ms = table->as_mutation_source()] (schema_ptr s,
reader_permit permit,
const dht::partition_range& pr,
const query::partition_slice& slice,
const io_priority_class& pc,
tracing::trace_state_ptr trace_state,
streamed_mutation::forwarding stream_fwd,
mutation_reader::forwarding) {
return ms.make_reader(s, permit, pr, slice, pc, trace_state, stream_fwd, mutation_reader::forwarding::no);
});
}, false /* with_partition_range_forwarding */);
}