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 <glommer@cloudius-systems.com>
This commit is contained in:
Glauber Costa
2015-03-09 13:05:03 -03:00
parent cea4825642
commit a3febe2ae0
2 changed files with 14 additions and 0 deletions

View File

@@ -438,6 +438,14 @@ future<> sstable::read_statistics() {
return read_simple<statistics, component_type::Statistics, &sstable::_statistics>();
}
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<file>(std::move(std::get<file>(std::get<0>(files).get())));
_data_file = make_lw_shared<file>(std::move(std::get<file>(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();
});
}

View File

@@ -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<file> _index_file;
lw_shared_ptr<file> _data_file;
sstring _dir;
unsigned long _epoch = 0;
@@ -74,6 +77,7 @@ private:
return read_simple<summary, component_type::Summary, &sstable::_summary>();
}
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) {}