diff --git a/include/limestone/api/datastore.h b/include/limestone/api/datastore.h index 08d86ff9..27aa2ba2 100644 --- a/include/limestone/api/datastore.h +++ b/include/limestone/api/datastore.h @@ -309,7 +309,7 @@ class datastore { * @param from the location of log files * @attention this function is not thread-safe. */ - void create_snapshot(const std::set& file_names); + void create_snapshot(); epoch_id_type last_durable_epoch_in_dir(); diff --git a/src/limestone/datastore.cpp b/src/limestone/datastore.cpp index 9f3450be..b584794b 100644 --- a/src/limestone/datastore.cpp +++ b/src/limestone/datastore.cpp @@ -104,33 +104,14 @@ void datastore::recover() const noexcept { } void datastore::ready() { - // create filename set for snapshot - std::set detached_pwals = compaction_catalog_->get_detached_pwals(); - - std::set filename_set; - boost::system::error_code error; - boost::filesystem::directory_iterator it(location_, error); - boost::filesystem::directory_iterator end; - if (error) { - LOG_AND_THROW_IO_EXCEPTION("Failed to initialize directory iterator, path: " + location_.string(), error); - } - for (; it != end; it.increment(error)) { - if (error) { - LOG_AND_THROW_IO_EXCEPTION("Failed to access directory entry: , path: " + location_.string(), error); - } - if (boost::filesystem::is_regular_file(it->path())) { - std::string filename = it->path().filename().string(); - if (detached_pwals.find(filename) == detached_pwals.end()) { - filename_set.insert(filename); - } - } - } - - create_snapshot(filename_set); + create_snapshot(); online_compaction_worker_future_ = std::async(std::launch::async, &datastore::online_compaction_worker, this); state_ = state::ready; } + + + std::unique_ptr datastore::get_snapshot() const { check_after_ready(static_cast(__func__)); return std::unique_ptr(new snapshot(location_)); diff --git a/src/limestone/datastore_snapshot.cpp b/src/limestone/datastore_snapshot.cpp index 273c5536..86e59a2e 100644 --- a/src/limestone/datastore_snapshot.cpp +++ b/src/limestone/datastore_snapshot.cpp @@ -27,6 +27,7 @@ #include #include "limestone_exception_helper.h" +#include "compaction_catalog.h" #include "dblog_scan.h" #include "internal.h" #include "log_entry.h" @@ -299,13 +300,42 @@ void create_compact_pwal( } } +std::set assemble_snapshot_input_filenames( + const std::unique_ptr& compaction_catalog, + const boost::filesystem::path& location) { + std::set detached_pwals = compaction_catalog->get_detached_pwals(); + + std::set filename_set; + boost::system::error_code error; + boost::filesystem::directory_iterator it(location, error); + boost::filesystem::directory_iterator end; + if (error) { + LOG_AND_THROW_IO_EXCEPTION("Failed to initialize directory iterator, path: " + location.string(), error); + } + for (; it != end; it.increment(error)) { + if (error) { + LOG_AND_THROW_IO_EXCEPTION("Failed to access directory entry, path: " + location.string(), error); + } + if (boost::filesystem::is_regular_file(it->path())) { + std::string filename = it->path().filename().string(); +// if (detached_pwals.find(filename) == detached_pwals.end() && filename != compaction_catalog::get_compacted_filename()) { + if (detached_pwals.find(filename) == detached_pwals.end()) { + filename_set.insert(filename); + } + } + } + + return filename_set; +} + } namespace limestone::api { using namespace limestone::internal; -void datastore::create_snapshot(const std::set& file_names) { +void datastore::create_snapshot() { const auto& from_dir = location_; + std::set file_names = assemble_snapshot_input_filenames(compaction_catalog_, from_dir); auto [max_appeared_epoch, sctx] = create_sorted_from_wals(from_dir, recover_max_parallelism_, file_names); epoch_id_switched_.store(max_appeared_epoch); epoch_id_informed_.store(max_appeared_epoch);