From 3326063b8b145247efde970b35a4fa4b8383fb48 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Mon, 5 Dec 2022 18:46:05 +0300 Subject: [PATCH] sstable: Move write_toc() to storage This method initiates the sstable creation. Effectively it's the first step in sstable creation transaction implemented on top of rename() call. Thus this method is moved onto storage under respective name. Signed-off-by: Pavel Emelyanov --- sstables/sstables.cc | 22 +++++++++++----------- sstables/sstables.hh | 6 +++--- test/lib/sstable_utils.hh | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sstables/sstables.cc b/sstables/sstables.cc index 7b401885fd..79000ee5c5 100644 --- a/sstables/sstables.cc +++ b/sstables/sstables.cc @@ -928,12 +928,12 @@ future sstable::make_component_file_writer(component_type c, file_o void sstable::open_sstable(const io_priority_class& pc) { generate_toc(); - _storage.touch_temp_dir(*this).get0(); - write_toc(pc); + _storage.open(*this, pc); } -void sstable::write_toc(const io_priority_class& pc) { - auto file_path = filename(component_type::TemporaryTOC); +void sstable::filesystem_storage::open(sstable& sst, const io_priority_class& pc) { + touch_temp_dir(sst).get0(); + auto file_path = sst.filename(component_type::TemporaryTOC); sstlog.debug("Writing TOC file {} ", file_path); @@ -944,29 +944,29 @@ void sstable::write_toc(const io_priority_class& pc) { file_output_stream_options options; options.buffer_size = 4096; options.io_priority_class = pc; - auto w = make_component_file_writer(component_type::TemporaryTOC, std::move(options)).get0(); + auto w = sst.make_component_file_writer(component_type::TemporaryTOC, std::move(options)).get0(); - bool toc_exists = file_exists(filename(component_type::TOC)).get0(); + bool toc_exists = file_exists(sst.filename(component_type::TOC)).get0(); if (toc_exists) { // TOC will exist at this point if write_components() was called with // the generation of a sstable that exists. w.close(); remove_file(file_path).get(); - throw std::runtime_error(format("SSTable write failed due to existence of TOC file for generation {:d} of {}.{}", _generation, _schema->ks_name(), _schema->cf_name())); + throw std::runtime_error(format("SSTable write failed due to existence of TOC file for generation {:d} of {}.{}", sst._generation, sst._schema->ks_name(), sst._schema->cf_name())); } - for (auto&& key : _recognized_components) { + for (auto&& key : sst._recognized_components) { // new line character is appended to the end of each component name. - auto value = sstable_version_constants::get_component_map(_version).at(key) + "\n"; + auto value = sstable_version_constants::get_component_map(sst._version).at(key) + "\n"; bytes b = bytes(reinterpret_cast(value.c_str()), value.size()); - write(_version, w, b); + write(sst._version, w, b); } w.flush(); w.close(); // Flushing parent directory to guarantee that temporary TOC file reached // the disk. - sstable_write_io_check(sync_directory, _storage.dir).get(); + sst.sstable_write_io_check(sync_directory, dir).get(); } future<> sstable::filesystem_storage::seal(const sstable& sst) { diff --git a/sstables/sstables.hh b/sstables/sstables.hh index d7a7c995a4..26241c0757 100644 --- a/sstables/sstables.hh +++ b/sstables/sstables.hh @@ -485,13 +485,14 @@ public: future<> remove_temp_dir(); future<> create_links(const sstable& sst, const sstring& dir) const; future<> create_links_common(const sstable& sst, sstring dst_dir, generation_type dst_gen, mark_for_removal mark_for_removal) const; + future<> touch_temp_dir(const sstable& sst); public: future<> seal(const sstable& sst); future<> snapshot(const sstable& sst, const sstring& dir) const; future<> move(const sstable& sst, sstring new_dir, generation_type generation, delayed_commit_changes* delay); - - future<> touch_temp_dir(const sstable& sst); + // runs in async context + void open(sstable& sst, const io_priority_class& pc); }; private: @@ -605,7 +606,6 @@ private: open_flags oflags = open_flags::wo | open_flags::create | open_flags::exclusive) noexcept; void generate_toc(); - void write_toc(const io_priority_class& pc); void open_sstable(const io_priority_class& pc); future<> read_compression(const io_priority_class& pc); diff --git a/test/lib/sstable_utils.hh b/test/lib/sstable_utils.hh index c8558602ce..d8e7992732 100644 --- a/test/lib/sstable_utils.hh +++ b/test/lib/sstable_utils.hh @@ -201,7 +201,7 @@ public: void rewrite_toc_without_scylla_component() { _sst->_recognized_components.erase(component_type::Scylla); remove_file(_sst->filename(component_type::TOC)).get(); - _sst->write_toc(default_priority_class()); + _sst->_storage.open(*_sst, default_priority_class()); _sst->seal_sstable(false).get(); }