Merge '[Backport 6.0] replica: fix copy constructor of tablet_sstable_set' from ScyllaDB
Commit9f93dd9fa3changed `tablet_sstable_set::_sstable_sets` to be a `absl::flat_hash_map` and in addition, `std::set<size_t> _sstable_set_ids` was added. `_sstable_set_ids` is set up in the `tablet_sstable_set(schema_ptr s, const storage_group_manager& sgm, const locator::tablet_map& tmap)` constructor, but it is not copied in `tablet_sstable_set(const tablet_sstable_set& o)`. This affects the `tablet_sstable_set::tablet_sstable_set` method as it depends on the copy constructor. Since sstable set can be cloned when a new sstable set is added, the issue will cause ids not being copied into the new sstable set. It's healed only after compaction, since the sstable set is rebuilt from scratch there. This PR fixes this issue by removing the existing copy constructor of `tablet_sstable_set` to enable the implicit default copy constructor. Fixes #19519 (cherry picked from commit44583eed9e) (cherry picked from commitec47b50859) Refs #20115 Closes scylladb/scylladb#20204 * github.com:scylladb/scylladb: boost/sstable_set_test: add testcase to test tablet_sstable_set copy constructor replica: fix copy constructor of tablet_sstable_set
This commit is contained in:
@@ -378,14 +378,6 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
tablet_sstable_set(const tablet_sstable_set& o)
|
||||
: _schema(o._schema)
|
||||
, _tablet_map(o._tablet_map.tablet_count())
|
||||
, _sstable_sets(o._sstable_sets)
|
||||
, _size(o._size)
|
||||
, _bytes_on_disk(o._bytes_on_disk)
|
||||
{}
|
||||
|
||||
static lw_shared_ptr<sstables::sstable_set> make(schema_ptr s, const storage_group_manager& sgm, const locator::tablet_map& tmap) {
|
||||
return make_lw_shared<sstables::sstable_set>(std::make_unique<tablet_sstable_set>(std::move(s), sgm, tmap));
|
||||
}
|
||||
|
||||
@@ -9,10 +9,15 @@
|
||||
|
||||
#include "test/lib/scylla_test_case.hh"
|
||||
|
||||
#include <fmt/ranges.h>
|
||||
#include "db/config.hh"
|
||||
#include "locator/tablets.hh"
|
||||
#include "sstables/sstable_set_impl.hh"
|
||||
#include "sstables/shared_sstable.hh"
|
||||
#include "sstables/sstable_set.hh"
|
||||
#include "sstables/sstables.hh"
|
||||
#include "sstable_test.hh"
|
||||
#include "test/lib/cql_test_env.hh"
|
||||
#include "test/lib/simple_schema.hh"
|
||||
#include "test/lib/sstable_utils.hh"
|
||||
#include "readers/from_mutations_v2.hh"
|
||||
@@ -167,3 +172,28 @@ SEASTAR_TEST_CASE(test_partitioned_sstable_set_bytes_on_disk) {
|
||||
BOOST_REQUIRE_EQUAL(sst_set->bytes_on_disk(), ss1->bytes_on_disk() + ss2->bytes_on_disk());
|
||||
});
|
||||
}
|
||||
|
||||
SEASTAR_TEST_CASE(test_tablet_sstable_set_copy_ctor) {
|
||||
// enable tablets, to get access to tablet_storage_group_manager
|
||||
cql_test_config cfg;
|
||||
cfg.db_config->enable_tablets(true);
|
||||
|
||||
return do_with_cql_env_thread([&](cql_test_env& env) {
|
||||
env.execute_cql("CREATE KEYSPACE test_tablet_sstable_set_copy_ctor"
|
||||
" WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1};").get();
|
||||
env.execute_cql("CREATE TABLE test_tablet_sstable_set_copy_ctor.test (pk int PRIMARY KEY);").get();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
env.execute_cql(fmt::format("INSERT INTO test_tablet_sstable_set_copy_ctor.test (pk) VALUES ({})", i)).get();
|
||||
}
|
||||
auto& cf = env.local_db().find_column_family("test_tablet_sstable_set_copy_ctor", "test");
|
||||
auto& sgm = column_family_test::get_storage_group_manager(cf);
|
||||
sgm->split_all_storage_groups().get();
|
||||
|
||||
auto tablet_sstable_set = replica::make_tablet_sstable_set(cf.schema(), *sgm.get(), locator::tablet_map(8));
|
||||
auto tablet_sstable_set_copy = *tablet_sstable_set.get();
|
||||
BOOST_REQUIRE(*tablet_sstable_set->all() == *tablet_sstable_set_copy.all());
|
||||
BOOST_REQUIRE_EQUAL(tablet_sstable_set->size(), tablet_sstable_set_copy.size());
|
||||
BOOST_REQUIRE_EQUAL(tablet_sstable_set->bytes_on_disk(), tablet_sstable_set_copy.bytes_on_disk());
|
||||
|
||||
}, std::move(cfg));
|
||||
}
|
||||
|
||||
@@ -53,6 +53,10 @@ public:
|
||||
static sstables::generation_type calculate_generation_for_new_table(replica::column_family& cf) {
|
||||
return cf.calculate_generation_for_new_table();
|
||||
}
|
||||
|
||||
static const std::unique_ptr<replica::storage_group_manager>& get_storage_group_manager(replica::column_family& cf) {
|
||||
return cf._sg_manager;
|
||||
}
|
||||
};
|
||||
|
||||
namespace sstables {
|
||||
|
||||
Reference in New Issue
Block a user