Files
scylladb/test/boost/sstable_set_test.cc
Avi Kivity fdc1449392 treewide: rename flat_mutation_reader_v2 to mutation_reader
flat_mutation_reader_v2 was introduced in a pair of commits in 2021:

  e3309322c3 "Clone flat_mutation_reader related classes into v2 variants"
  08b5773c12 "Adapt flat_mutation_reader_v2 to the new version of the API"

as a replacement for flat_mutation_reader, using range_tombstone_change
instead of range_tombstone to represent represent range tombstones. See
those commits for more information.

The transition was incremental; the last use of the original
flat_mutation_reader was removed in 2022 in commit

  026f8cc1e7 "db: Use mutation_partition_v2 in mvcc"

In turn, flat_mutation_reader was introduced in 2017 in commit

  748205ca75 "Introduce flat_mutation_reader"

To transition from a mutation_reader that nested rows within
a partition in a separate stream, to a flat reader that streamed
partitions and rows in the same stream.

Here, we reclaim the original name and rename the awkward
flat_mutation_reader_v2 to mutation_reader.

Note that mutation_fragment_v2 remains since we still use the original
for compatibilty, sometimes.

Some notes about the transition:

 - files were also renamed. In one case (flat_mutation_reader_test.cc), the
   rename target already existed, so we rename to
    mutation_reader_another_test.cc.

 - a namespace 'mutation_reader' with two definitions existed (in
   mutation_reader_fwd.hh). Its contents was folded into the mutation_reader
   class. As a result, a few #includes had to be adjusted.

Closes scylladb/scylladb#19356
2024-06-21 07:12:06 +03:00

170 lines
6.8 KiB
C++

/*
* Copyright (C) 2021-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include "test/lib/scylla_test_case.hh"
#include "sstables/sstable_set_impl.hh"
#include "sstables/shared_sstable.hh"
#include "sstables/sstable_set.hh"
#include "sstables/sstables.hh"
#include "test/lib/simple_schema.hh"
#include "test/lib/sstable_utils.hh"
#include "readers/from_mutations_v2.hh"
using namespace sstables;
static sstables::sstable_set make_sstable_set(schema_ptr schema, lw_shared_ptr<sstable_list> all = {}, bool use_level_metadata = true) {
auto ret = sstables::sstable_set(std::make_unique<partitioned_sstable_set>(schema, use_level_metadata));
for (auto& sst : *all) {
ret.insert(sst);
}
return ret;
}
SEASTAR_TEST_CASE(test_sstables_sstable_set_read_modify_write) {
return test_env::do_with_async([] (test_env& env) {
simple_schema ss;
auto s = ss.schema();
auto pk = tests::generate_partition_key(s);
auto mut = mutation(s, pk);
ss.add_row(mut, ss.make_ckey(0), "val");
auto mr = make_mutation_reader_from_mutations_v2(s, env.make_reader_permit(), mut);
sstable_writer_config cfg = env.manager().configure_writer("");
auto sst1 = make_sstable_easy(env, std::move(mr), cfg);
auto ss1 = make_lw_shared<sstables::sstable_set>(make_sstable_set(ss.schema(), make_lw_shared<sstable_list>({sst1})));
BOOST_REQUIRE_EQUAL(ss1->all()->size(), 1);
// Test that a random sstable_origin is stored and retrieved properly.
mr = make_mutation_reader_from_mutations_v2(s, env.make_reader_permit(), mut);
auto sst2 = make_sstable_easy(env, std::move(mr), cfg);
auto ss2 = make_lw_shared<sstables::sstable_set>(*ss1);
ss2->insert(sst2);
BOOST_REQUIRE_EQUAL(ss2->all()->size(), 2);
BOOST_REQUIRE_EQUAL(ss1->all()->size(), 1);
});
}
SEASTAR_TEST_CASE(test_time_series_sstable_set_read_modify_write) {
return test_env::do_with_async([] (test_env& env) {
simple_schema ss;
auto s = ss.schema();
auto pk = tests::generate_partition_key(s);
auto mut = mutation(s, pk);
ss.add_row(mut, ss.make_ckey(0), "val");
sstable_writer_config cfg = env.manager().configure_writer("");
auto mr = make_mutation_reader_from_mutations_v2(s, env.make_reader_permit(), mut);
auto sst1 = make_sstable_easy(env, std::move(mr), cfg);
auto ss1 = make_lw_shared<time_series_sstable_set>(ss.schema(), true);
ss1->insert(sst1);
BOOST_REQUIRE_EQUAL(ss1->all()->size(), 1);
// Test that a random sstable_origin is stored and retrieved properly.
mr = make_mutation_reader_from_mutations_v2(s, env.make_reader_permit(), mut);
auto sst2 = make_sstable_easy(env, std::move(mr), cfg);
auto ss2 = make_lw_shared<time_series_sstable_set>(*ss1);
ss2->insert(sst2);
BOOST_REQUIRE_EQUAL(ss2->all()->size(), 2);
BOOST_REQUIRE_EQUAL(ss1->all()->size(), 1);
std::set<sstables::shared_sstable> in_set;
ss2->for_each_sstable_gently_until([&] (sstables::shared_sstable sst) {
in_set.insert(sst);
return make_ready_future<stop_iteration>(false);
}).get();
BOOST_REQUIRE(in_set == std::set<sstables::shared_sstable>({sst1, sst2}));
auto lookup_sst = [&] (sstables::shared_sstable sst) {
bool found = false;
ss2->for_each_sstable_gently_until([&] (sstables::shared_sstable cur) {
found = (cur == sst);
return make_ready_future<stop_iteration>(found);
}).get();
return found;
};
BOOST_REQUIRE(lookup_sst(sst1));
BOOST_REQUIRE(lookup_sst(sst2));
});
}
SEASTAR_TEST_CASE(test_time_series_sstable_set_bytes_on_disk) {
return test_env::do_with_async([] (test_env& env) {
simple_schema ss;
auto s = ss.schema();
auto pk = tests::generate_partition_key(s);
auto mut = mutation(s, pk);
ss.add_row(mut, ss.make_ckey(0), "val");
sstable_writer_config cfg = env.manager().configure_writer("");
auto mr = make_mutation_reader_from_mutations_v2(s, env.make_reader_permit(), mut);
auto sst1 = make_sstable_easy(env, std::move(mr), cfg);
auto size1 = sst1->bytes_on_disk();
auto ss1 = make_lw_shared<sstable_set>(std::make_unique<time_series_sstable_set>(ss.schema(), true));
ss1->insert(sst1);
BOOST_REQUIRE_EQUAL(ss1->bytes_on_disk(), size1);
// Test that a random sstable_origin is stored and retrieved properly.
mr = make_mutation_reader_from_mutations_v2(s, env.make_reader_permit(), mut);
auto sst2 = make_sstable_easy(env, std::move(mr), cfg);
auto size2 = sst2->bytes_on_disk();
auto ss2 = make_lw_shared<sstable_set>(*ss1);
BOOST_REQUIRE_EQUAL(ss2->bytes_on_disk(), ss1->bytes_on_disk());
ss2->insert(sst2);
BOOST_REQUIRE_EQUAL(ss2->bytes_on_disk(), size1 + size2);
std::vector<lw_shared_ptr<sstable_set>> sets = {ss1, ss2};
auto sst_set = make_lw_shared<sstable_set>(std::make_unique<compound_sstable_set>(s, std::move(sets)));
BOOST_REQUIRE_EQUAL(sst_set->bytes_on_disk(), ss1->bytes_on_disk() + ss2->bytes_on_disk());
});
}
SEASTAR_TEST_CASE(test_partitioned_sstable_set_bytes_on_disk) {
return test_env::do_with_async([] (test_env& env) {
simple_schema ss;
auto s = ss.schema();
auto pk = tests::generate_partition_key(s);
auto mut = mutation(s, pk);
ss.add_row(mut, ss.make_ckey(0), "val");
sstable_writer_config cfg = env.manager().configure_writer("");
auto mr = make_mutation_reader_from_mutations_v2(s, env.make_reader_permit(), mut);
auto sst1 = make_sstable_easy(env, std::move(mr), cfg);
auto size1 = sst1->bytes_on_disk();
auto ss1 = make_lw_shared<sstable_set>(std::make_unique<partitioned_sstable_set>(ss.schema(), true));
ss1->insert(sst1);
BOOST_REQUIRE_EQUAL(ss1->bytes_on_disk(), size1);
// Test that a random sstable_origin is stored and retrieved properly.
mr = make_mutation_reader_from_mutations_v2(s, env.make_reader_permit(), mut);
auto sst2 = make_sstable_easy(env, std::move(mr), cfg);
auto size2 = sst2->bytes_on_disk();
auto ss2 = make_lw_shared<sstable_set>(*ss1);
BOOST_REQUIRE_EQUAL(ss2->bytes_on_disk(), ss1->bytes_on_disk());
ss2->insert(sst2);
BOOST_REQUIRE_EQUAL(ss2->bytes_on_disk(), size1 + size2);
std::vector<lw_shared_ptr<sstable_set>> sets = {ss1, ss2};
auto sst_set = make_lw_shared<sstable_set>(std::make_unique<compound_sstable_set>(s, std::move(sets)));
BOOST_REQUIRE_EQUAL(sst_set->bytes_on_disk(), ss1->bytes_on_disk() + ss2->bytes_on_disk());
});
}