From a3febe2ae07c5804cf6831fcf18970865d1f09c7 Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Mon, 9 Mar 2015 13:05:03 -0300 Subject: [PATCH] sstable: open data and index files. Because we're expected to go to those files many times, it doesn't make sense to keep opening them. Upon sstable load, we will open those files and then move the reference to the sstable main structure. From this point on, we can just seek to the position we want. Signed-off-by: Glauber Costa --- sstables/sstables.cc | 10 ++++++++++ sstables/sstables.hh | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/sstables/sstables.cc b/sstables/sstables.cc index 1cbfc88d63..0f97db0e24 100644 --- a/sstables/sstables.cc +++ b/sstables/sstables.cc @@ -438,6 +438,14 @@ future<> sstable::read_statistics() { return read_simple(); } +future<> sstable::open_data() { + return when_all(engine().open_file_dma(filename(component_type::Index), open_flags::ro), + engine().open_file_dma(filename(component_type::Data), open_flags::ro)).then([this] (auto files) { + _index_file = make_lw_shared(std::move(std::get(std::get<0>(files).get()))); + _data_file = make_lw_shared(std::move(std::get(std::get<1>(files).get()))); + }); +} + future<> sstable::load() { return read_toc().then([this] { return read_statistics(); @@ -447,6 +455,8 @@ future<> sstable::load() { return read_filter(); }).then([this] {; return read_summary(); + }).then([this] { + return open_data(); }); } diff --git a/sstables/sstables.hh b/sstables/sstables.hh index 7a621951b7..3f1df8f749 100644 --- a/sstables/sstables.hh +++ b/sstables/sstables.hh @@ -6,6 +6,7 @@ #pragma once #include "core/file.hh" +#include "core/fstream.hh" #include "core/future.hh" #include "core/sstring.hh" #include "core/enum.hh" @@ -52,6 +53,8 @@ private: filter _filter; summary _summary; statistics _statistics; + lw_shared_ptr _index_file; + lw_shared_ptr _data_file; sstring _dir; unsigned long _epoch = 0; @@ -74,6 +77,7 @@ private: return read_simple(); } future<> read_statistics(); + future<> open_data(); public: sstable(sstring dir, unsigned long epoch, version_types v, format_types f) : _dir(dir), _epoch(epoch), _version(v), _format(f) {}