diff --git a/test/boost/database_test.cc b/test/boost/database_test.cc index 71b0ac54fc..a78b92421e 100644 --- a/test/boost/database_test.cc +++ b/test/boost/database_test.cc @@ -576,6 +576,12 @@ future<> take_snapshot(cql_test_env& e, sstring ks_name, sstring cf_name, sstrin return take_snapshot(e.db(), false /* skip_flush */, std::move(ks_name), std::move(cf_name), std::move(snapshot_name)); } +// Helper to get directory a table keeps its data in. +// Only suitable for tests, that work with local storage type. +fs::path table_dir(const replica::column_family& cf) { + return std::get(cf.get_storage_options().value).dir; +} + SEASTAR_TEST_CASE(snapshot_works) { return do_with_some_data({"cf"}, [] (cql_test_env& e) { take_snapshot(e).get(); @@ -585,7 +591,7 @@ SEASTAR_TEST_CASE(snapshot_works) { }; auto& cf = e.local_db().find_column_family("ks", "cf"); - lister::scan_dir(fs::path(cf.dir()), lister::dir_entry_types::of(), [&expected] (fs::path parent_dir, directory_entry de) { + lister::scan_dir(table_dir(cf), lister::dir_entry_types::of(), [&expected] (fs::path parent_dir, directory_entry de) { expected.insert(de.name); return make_ready_future<>(); }).get(); @@ -593,7 +599,7 @@ SEASTAR_TEST_CASE(snapshot_works) { BOOST_REQUIRE_GT(expected.size(), 1); // all files were copied and manifest was generated - lister::scan_dir((fs::path(cf.dir()) / sstables::snapshots_dir / "test"), lister::dir_entry_types::of(), [&expected] (fs::path parent_dir, directory_entry de) { + lister::scan_dir((table_dir(cf) / sstables::snapshots_dir / "test"), lister::dir_entry_types::of(), [&expected] (fs::path parent_dir, directory_entry de) { expected.erase(de.name); return make_ready_future<>(); }).get(); @@ -612,7 +618,7 @@ SEASTAR_TEST_CASE(snapshot_skip_flush_works) { }; auto& cf = e.local_db().find_column_family("ks", "cf"); - lister::scan_dir(fs::path(cf.dir()), lister::dir_entry_types::of(), [&expected] (fs::path parent_dir, directory_entry de) { + lister::scan_dir(table_dir(cf), lister::dir_entry_types::of(), [&expected] (fs::path parent_dir, directory_entry de) { expected.insert(de.name); return make_ready_future<>(); }).get(); @@ -621,7 +627,7 @@ SEASTAR_TEST_CASE(snapshot_skip_flush_works) { BOOST_REQUIRE_EQUAL(expected.size(), 1); // all files were copied and manifest was generated - lister::scan_dir((fs::path(cf.dir()) / sstables::snapshots_dir / "test"), lister::dir_entry_types::of(), [&expected] (fs::path parent_dir, directory_entry de) { + lister::scan_dir((table_dir(cf) / sstables::snapshots_dir / "test"), lister::dir_entry_types::of(), [&expected] (fs::path parent_dir, directory_entry de) { expected.erase(de.name); return make_ready_future<>(); }).get(); @@ -643,7 +649,7 @@ SEASTAR_TEST_CASE(snapshot_list_okay) { BOOST_REQUIRE_EQUAL(sd.live, 0); BOOST_REQUIRE_GT(sd.total, 0); - lister::scan_dir(fs::path(cf.dir()), lister::dir_entry_types::of(), [] (fs::path parent_dir, directory_entry de) { + lister::scan_dir(table_dir(cf), lister::dir_entry_types::of(), [] (fs::path parent_dir, directory_entry de) { fs::remove(parent_dir / de.name); return make_ready_future<>(); }).get(); @@ -714,7 +720,7 @@ SEASTAR_TEST_CASE(clear_snapshot) { auto& cf = e.local_db().find_column_family("ks", "cf"); unsigned count = 0; - lister::scan_dir((fs::path(cf.dir()) / sstables::snapshots_dir / "test"), lister::dir_entry_types::of(), [&count] (fs::path parent_dir, directory_entry de) { + lister::scan_dir((table_dir(cf) / sstables::snapshots_dir / "test"), lister::dir_entry_types::of(), [&count] (fs::path parent_dir, directory_entry de) { count++; return make_ready_future<>(); }).get(); @@ -723,7 +729,7 @@ SEASTAR_TEST_CASE(clear_snapshot) { e.local_db().clear_snapshot("test", {"ks"}, "").get(); count = 0; - BOOST_REQUIRE_EQUAL(fs::exists(fs::path(cf.dir()) / sstables::snapshots_dir / "test"), false); + BOOST_REQUIRE_EQUAL(fs::exists(table_dir(cf) / sstables::snapshots_dir / "test"), false); return make_ready_future<>(); }); } @@ -739,8 +745,8 @@ SEASTAR_TEST_CASE(clear_multiple_snapshots) { co_await do_with_some_data({table_name}, [&] (cql_test_env& e) { auto& t = e.local_db().find_column_family(ks_name, table_name); - auto table_dir = fs::path(t.dir()); - auto snapshots_dir = table_dir / sstables::snapshots_dir; + auto tdir = table_dir(t); + auto snapshots_dir = tdir / sstables::snapshots_dir; for (auto i = 0; i < num_snapshots; i++) { testlog.debug("Taking snapshot {} on {}.{}", snapshot_name(i), ks_name, table_name); @@ -791,11 +797,11 @@ SEASTAR_TEST_CASE(clear_multiple_snapshots) { testlog.debug("Clearing all snapshots in {}.{} after it had been dropped", ks_name, table_name); e.local_db().clear_snapshot("", {ks_name}, table_name).get(); - SCYLLA_ASSERT(!fs::exists(table_dir)); + SCYLLA_ASSERT(!fs::exists(tdir)); // after all snapshots had been cleared, // the dropped table directory is expected to be removed. - BOOST_REQUIRE_EQUAL(fs::exists(table_dir), false); + BOOST_REQUIRE_EQUAL(fs::exists(tdir), false); return make_ready_future<>(); }); @@ -836,7 +842,7 @@ SEASTAR_TEST_CASE(test_snapshot_ctl_details) { BOOST_REQUIRE_EQUAL(sc_sd.details.live, sd.live); BOOST_REQUIRE_EQUAL(sc_sd.details.total, sd.total); - lister::scan_dir(fs::path(cf.dir()), lister::dir_entry_types::of(), [] (fs::path parent_dir, directory_entry de) { + lister::scan_dir(table_dir(cf), lister::dir_entry_types::of(), [] (fs::path parent_dir, directory_entry de) { fs::remove(parent_dir / de.name); return make_ready_future<>(); }).get(); @@ -878,7 +884,7 @@ SEASTAR_TEST_CASE(test_snapshot_ctl_true_snapshots_size) { auto sc_live_size = sc.local().true_snapshots_size().get(); BOOST_REQUIRE_EQUAL(sc_live_size, sd.live); - lister::scan_dir(fs::path(cf.dir()), lister::dir_entry_types::of(), [] (fs::path parent_dir, directory_entry de) { + lister::scan_dir(table_dir(cf), lister::dir_entry_types::of(), [] (fs::path parent_dir, directory_entry de) { fs::remove(parent_dir / de.name); return make_ready_future<>(); }).get(); @@ -1334,7 +1340,7 @@ SEASTAR_TEST_CASE(snapshot_with_quarantine_works) { auto& cf = db.local().find_column_family("ks", "cf"); // all files were copied and manifest was generated - co_await lister::scan_dir((fs::path(cf.dir()) / sstables::snapshots_dir / "test"), lister::dir_entry_types::of(), [&expected] (fs::path parent_dir, directory_entry de) { + co_await lister::scan_dir((table_dir(cf) / sstables::snapshots_dir / "test"), lister::dir_entry_types::of(), [&expected] (fs::path parent_dir, directory_entry de) { testlog.debug("Found in snapshots: {}", de.name); expected.erase(de.name); return make_ready_future<>(); @@ -1388,7 +1394,7 @@ static future<> test_drop_table_with_auto_snapshot(bool auto_snapshot) { db_cfg_ptr->auto_snapshot(auto_snapshot); co_await do_with_some_data({table_name}, [&] (cql_test_env& e) -> future<> { - auto cf_dir = e.local_db().find_column_family(ks_name, table_name).dir(); + auto cf_dir = table_dir(e.local_db().find_column_family(ks_name, table_name)).native(); // Pass `with_snapshot=true` to drop_table_on_all // to allow auto_snapshot (based on the configuration above). @@ -1413,7 +1419,7 @@ SEASTAR_TEST_CASE(drop_table_with_no_snapshot) { sstring table_name = "table_with_no_snapshot"; co_await do_with_some_data({table_name}, [&] (cql_test_env& e) -> future<> { - auto cf_dir = e.local_db().find_column_family(ks_name, table_name).dir(); + auto cf_dir = table_dir(e.local_db().find_column_family(ks_name, table_name)).native(); // Pass `with_snapshot=false` to drop_table_on_all // to disallow auto_snapshot. @@ -1432,7 +1438,7 @@ SEASTAR_TEST_CASE(drop_table_with_explicit_snapshot) { co_await do_with_some_data({table_name}, [&] (cql_test_env& e) -> future<> { auto snapshot_tag = format("test-{}", db_clock::now().time_since_epoch().count()); co_await replica::database::snapshot_table_on_all_shards(e.db(), ks_name, table_name, snapshot_tag, db::snapshot_ctl::snap_views::no, false); - auto cf_dir = e.local_db().find_column_family(ks_name, table_name).dir(); + auto cf_dir = table_dir(e.local_db().find_column_family(ks_name, table_name)).native(); // With explicit snapshot and with_snapshot=false // dir should still be kept, regardless of the