do not call open_file_dma directly

We have an API that wraps open_file_dma which we use in some places, but in
many other places we call the reactor version directly.

This patch changes the latter to match the former. It will have the added benefit
of allowing us to make easier changes to these interfaces if needed.

Signed-off-by: Glauber Costa <glauber@scylladb.com>
Message-Id: <29296e4ec6f5e84361992028fe3f27adc569f139.1451950408.git.glauber@scylladb.com>
This commit is contained in:
Glauber Costa
2016-01-04 18:33:28 -05:00
committed by Avi Kivity
parent e9400dfa96
commit 74fbd8fac0
9 changed files with 31 additions and 31 deletions

View File

@@ -1862,7 +1862,7 @@ seal_snapshot(sstring jsondir) {
dblog.debug("Storing manifest {}", jsonfile);
return recursive_touch_directory(jsondir).then([jsonfile, json = std::move(json)] {
return engine().open_file_dma(jsonfile, open_flags::wo | open_flags::create | open_flags::truncate).then([json](file f) {
return open_file_dma(jsonfile, open_flags::wo | open_flags::create | open_flags::truncate).then([json](file f) {
return do_with(make_file_output_stream(std::move(f)), [json] (output_stream<char>& out) {
return out.write(json.c_str(), json.size()).then([&out] {
return out.flush();

View File

@@ -887,7 +887,7 @@ void db::commitlog::segment_manager::flush_segments(bool force) {
future<db::commitlog::segment_manager::sseg_ptr> db::commitlog::segment_manager::allocate_segment(bool active) {
descriptor d(next_id());
return engine().open_file_dma(cfg.commit_log_location + "/" + d.filename(), open_flags::wo | open_flags::create).then([this, d, active](file f) {
return open_file_dma(cfg.commit_log_location + "/" + d.filename(), open_flags::wo | open_flags::create).then([this, d, active](file f) {
// xfs doesn't like files extended betond eof, so enlarge the file
return f.truncate(max_size).then([this, d, active, f] () mutable {
auto s = make_lw_shared<segment>(this, d, std::move(f), active);
@@ -1215,7 +1215,7 @@ const db::commitlog::config& db::commitlog::active_config() const {
future<std::unique_ptr<subscription<temporary_buffer<char>, db::replay_position>>>
db::commitlog::read_log_file(const sstring& filename, commit_load_reader_func next, position_type off) {
return engine().open_file_dma(filename, open_flags::ro).then([next = std::move(next), off](file f) {
return open_file_dma(filename, open_flags::ro).then([next = std::move(next), off](file f) {
return std::make_unique<subscription<temporary_buffer<char>, replay_position>>(
read_log_file(std::move(f), std::move(next), off));
});

View File

@@ -410,7 +410,7 @@ future<> db::config::read_from_file(file f) {
}
future<> db::config::read_from_file(const sstring& filename) {
return engine().open_file_dma(filename, open_flags::ro).then([this](file f) {
return open_file_dma(filename, open_flags::ro).then([this](file f) {
return read_from_file(std::move(f));
});
}

View File

@@ -41,7 +41,7 @@
namespace locator {
future<bool> gossiping_property_file_snitch::property_file_was_modified() {
return engine().open_file_dma(_prop_file_name, open_flags::ro)
return open_file_dma(_prop_file_name, open_flags::ro)
.then([this](file f) {
return do_with(std::move(f), [] (file& f) {
return f.stat();

View File

@@ -2,7 +2,7 @@
namespace locator {
future<> production_snitch_base::load_property_file() {
return engine().open_file_dma(_prop_file_name, open_flags::ro)
return open_file_dma(_prop_file_name, open_flags::ro)
.then([this] (file f) {
return do_with(std::move(f), [this] (file& f) {
return f.size().then([this, &f] (size_t s) {

View File

@@ -654,7 +654,7 @@ future<> sstable::read_toc() {
sstlog.debug("Reading TOC file {} ", file_path);
return engine().open_file_dma(file_path, open_flags::ro).then([this] (file f) {
return open_file_dma(file_path, open_flags::ro).then([this] (file f) {
auto bufptr = allocate_aligned_buffer<char>(4096, 4096);
auto buf = bufptr.get();
@@ -724,7 +724,7 @@ void sstable::write_toc() {
sstlog.debug("Writing TOC file {} ", file_path);
// Writing TOC content to temporary file.
file f = engine().open_file_dma(file_path, open_flags::wo | open_flags::create | open_flags::truncate).get0();
file f = open_file_dma(file_path, open_flags::wo | open_flags::create | open_flags::truncate).get0();
auto out = file_writer(std::move(f), 4096);
auto w = file_writer(std::move(out));
@@ -764,7 +764,7 @@ void write_crc(const sstring file_path, checksum& c) {
sstlog.debug("Writing CRC file {} ", file_path);
auto oflags = open_flags::wo | open_flags::create | open_flags::exclusive;
file f = engine().open_file_dma(file_path, oflags).get0();
file f = open_file_dma(file_path, oflags).get0();
auto out = file_writer(std::move(f), 4096);
auto w = file_writer(std::move(out));
write(w, c);
@@ -776,7 +776,7 @@ void write_digest(const sstring file_path, uint32_t full_checksum) {
sstlog.debug("Writing Digest file {} ", file_path);
auto oflags = open_flags::wo | open_flags::create | open_flags::exclusive;
auto f = engine().open_file_dma(file_path, oflags).get0();
auto f = open_file_dma(file_path, oflags).get0();
auto out = file_writer(std::move(f), 4096);
auto w = file_writer(std::move(out));
@@ -821,7 +821,7 @@ future<> sstable::read_simple(T& component) {
auto file_path = filename(Type);
sstlog.debug(("Reading " + _component_map[Type] + " file {} ").c_str(), file_path);
return engine().open_file_dma(file_path, open_flags::ro).then([this, &component] (file f) {
return open_file_dma(file_path, open_flags::ro).then([this, &component] (file f) {
auto r = make_lw_shared<file_random_access_reader>(std::move(f), sstable_buffer_size);
auto fut = parse(*r, component);
return fut.finally([r = std::move(r)] {
@@ -842,7 +842,7 @@ template <sstable::component_type Type, typename T>
void sstable::write_simple(T& component) {
auto file_path = filename(Type);
sstlog.debug(("Writing " + _component_map[Type] + " file {} ").c_str(), file_path);
file f = engine().open_file_dma(file_path, open_flags::wo | open_flags::create | open_flags::truncate).get0();
file f = open_file_dma(file_path, open_flags::wo | open_flags::create | open_flags::truncate).get0();
auto out = file_writer(std::move(f), sstable_buffer_size);
auto w = file_writer(std::move(out));
write(w, component);
@@ -879,8 +879,8 @@ void sstable::write_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) {
return when_all(open_file_dma(filename(component_type::Index), open_flags::ro),
open_file_dma(filename(component_type::Data), open_flags::ro)).then([this] (auto files) {
_index_file = std::get<file>(std::get<0>(files).get());
_data_file = std::get<file>(std::get<1>(files).get());
return _data_file.size().then([this] (auto size) {
@@ -900,8 +900,8 @@ future<> sstable::open_data() {
future<> sstable::create_data() {
auto oflags = open_flags::wo | open_flags::create | open_flags::exclusive;
return when_all(engine().open_file_dma(filename(component_type::Index), oflags),
engine().open_file_dma(filename(component_type::Data), oflags)).then([this] (auto files) {
return when_all(open_file_dma(filename(component_type::Index), oflags),
open_file_dma(filename(component_type::Data), oflags)).then([this] (auto files) {
// FIXME: If both files could not be created, the first get below will
// throw an exception, and second get() will not be attempted, and
// we'll get a warning about the second future being destructed

View File

@@ -321,7 +321,7 @@ SEASTAR_TEST_CASE(test_commitlog_reader){
}
static future<> corrupt_segment(sstring seg, uint64_t off, uint32_t value) {
return engine().open_file_dma(seg, open_flags::rw).then([off, value](file f) {
return open_file_dma(seg, open_flags::rw).then([off, value](file f) {
size_t size = align_up<size_t>(off, 4096);
return do_with(std::move(f), [size, off, value](file& f) {
return f.dma_read_exactly<char>(0, size).then([&f, off, value](auto buf) {

View File

@@ -90,7 +90,7 @@ SEASTAR_TEST_CASE(datafile_generation_01) {
auto fname = sstable::filename("tests/sstables/tests-temporary", "ks", "cf", la, 1, big, sstable::component_type::Data);
return sst->write_components(*mt).then([mt, sst, s, fname] {
return engine().open_file_dma(fname, open_flags::ro).then([] (file f) {
return open_file_dma(fname, open_flags::ro).then([] (file f) {
auto bufptr = allocate_aligned_buffer<char>(4096, 4096);
auto fut = f.dma_read(0, bufptr.get(), 4096);
@@ -156,7 +156,7 @@ SEASTAR_TEST_CASE(datafile_generation_02) {
auto fname = sstable::filename("tests/sstables/tests-temporary", "ks", "cf", la, 2, big, sstable::component_type::Data);
return sst->write_components(*mt).then([mt, sst, s, fname] {
return engine().open_file_dma(fname, open_flags::ro).then([] (file f) {
return open_file_dma(fname, open_flags::ro).then([] (file f) {
auto bufptr = allocate_aligned_buffer<char>(4096, 4096);
auto fut = f.dma_read(0, bufptr.get(), 4096);
@@ -224,7 +224,7 @@ SEASTAR_TEST_CASE(datafile_generation_03) {
auto fname = sstable::filename("tests/sstables/tests-temporary", "ks", "cf", la, 3, big, sstable::component_type::Data);
return sst->write_components(*mt).then([mt, sst, s, fname] {
return engine().open_file_dma(fname, open_flags::ro).then([] (file f) {
return open_file_dma(fname, open_flags::ro).then([] (file f) {
auto bufptr = allocate_aligned_buffer<char>(4096, 4096);
auto fut = f.dma_read(0, bufptr.get(), 4096);
@@ -295,7 +295,7 @@ SEASTAR_TEST_CASE(datafile_generation_04) {
auto fname = sstable::filename("tests/sstables/tests-temporary", "ks", "cf", la, 4, big, sstable::component_type::Data);
return sst->write_components(*mt).then([mt, sst, s, fname] {
return engine().open_file_dma(fname, open_flags::ro).then([] (file f) {
return open_file_dma(fname, open_flags::ro).then([] (file f) {
auto bufptr = allocate_aligned_buffer<char>(4096, 4096);
auto fut = f.dma_read(0, bufptr.get(), 4096);
@@ -366,7 +366,7 @@ SEASTAR_TEST_CASE(datafile_generation_05) {
return sst->write_components(*mt).then([mt, sst, s] {
auto fname = sstable::filename("tests/sstables/tests-temporary", "ks", "cf", la, 5, big, sstable::component_type::Data);
return engine().open_file_dma(fname, open_flags::ro).then([] (file f) {
return open_file_dma(fname, open_flags::ro).then([] (file f) {
auto bufptr = allocate_aligned_buffer<char>(4096, 4096);
auto fut = f.dma_read(0, bufptr.get(), 4096);
@@ -438,7 +438,7 @@ SEASTAR_TEST_CASE(datafile_generation_06) {
return sst->write_components(*mt).then([mt, sst, s] {
auto fname = sstable::filename("tests/sstables/tests-temporary", "ks", "cf", la, 6, big, sstable::component_type::Data);
return engine().open_file_dma(fname, open_flags::ro).then([] (file f) {
return open_file_dma(fname, open_flags::ro).then([] (file f) {
auto bufptr = allocate_aligned_buffer<char>(4096, 4096);
auto fut = f.dma_read(0, bufptr.get(), 4096);
@@ -514,7 +514,7 @@ SEASTAR_TEST_CASE(datafile_generation_07) {
return sst->write_components(*mt).then([mt, sst, s] {
auto fname = sstable::filename("tests/sstables/tests-temporary", "ks", "cf", la, 7, big, sstable::component_type::Index);
return engine().open_file_dma(fname, open_flags::ro).then([] (file f) {
return open_file_dma(fname, open_flags::ro).then([] (file f) {
auto bufptr = allocate_aligned_buffer<char>(4096, 4096);
auto fut = f.dma_read(0, bufptr.get(), 4096);
@@ -571,7 +571,7 @@ SEASTAR_TEST_CASE(datafile_generation_08) {
return sst->write_components(*mt).then([mt, sst, s] {
auto fname = sstable::filename("tests/sstables/tests-temporary", "ks", "cf", la, 8, big, sstable::component_type::Summary);
return engine().open_file_dma(fname, open_flags::ro).then([] (file f) {
return open_file_dma(fname, open_flags::ro).then([] (file f) {
auto bufptr = allocate_aligned_buffer<char>(4096, 4096);
auto fut = f.dma_read(0, bufptr.get(), 4096);
@@ -680,7 +680,7 @@ SEASTAR_TEST_CASE(datafile_generation_10) {
return sst->write_components(*mt).then([mt, sst, s] {
auto fname = sstable::filename("tests/sstables/tests-temporary", "ks", "cf", la, 10, big, sstable::component_type::Data);
return engine().open_file_dma(fname, open_flags::ro).then([] (file f) {
return open_file_dma(fname, open_flags::ro).then([] (file f) {
auto bufptr = allocate_aligned_buffer<char>(4096, 4096);
auto fut = f.dma_read(0, bufptr.get(), 4096);
@@ -691,7 +691,7 @@ SEASTAR_TEST_CASE(datafile_generation_10) {
f.close().finally([f]{});
auto fname = sstable::filename("tests/sstables/tests-temporary", "ks", "cf", la, 10, big, sstable::component_type::CRC);
return engine().open_file_dma(fname, open_flags::ro).then([adler] (file f) {
return open_file_dma(fname, open_flags::ro).then([adler] (file f) {
auto bufptr = allocate_aligned_buffer<char>(4096, 4096);
auto fut = f.dma_read(0, bufptr.get(), 4096);
@@ -713,7 +713,7 @@ SEASTAR_TEST_CASE(datafile_generation_10) {
});
}).then([adler] {
auto fname = sstable::filename("tests/sstables/tests-temporary", "ks", "cf", la, 10, big, sstable::component_type::Digest);
return engine().open_file_dma(fname, open_flags::ro).then([adler] (file f) {
return open_file_dma(fname, open_flags::ro).then([adler] (file f) {
auto bufptr = allocate_aligned_buffer<char>(4096, 4096);
auto fut = f.dma_read(0, bufptr.get(), 4096);
@@ -1456,7 +1456,7 @@ SEASTAR_TEST_CASE(datafile_generation_40) {
return sst->write_components(*mt).then([mt, sst, s] {
auto fname = sstable::filename("tests/sstables/tests-temporary", "ks", "cf", la, 40, big, sstable::component_type::Data);
return engine().open_file_dma(fname, open_flags::ro).then([] (file f) {
return open_file_dma(fname, open_flags::ro).then([] (file f) {
auto bufptr = allocate_aligned_buffer<char>(4096, 4096);
auto fut = f.dma_read(0, bufptr.get(), 4096);

View File

@@ -187,7 +187,7 @@ static future<> write_sst_info(sstring dir, unsigned long generation) {
using bufptr_t = std::unique_ptr<char [], free_deleter>;
static future<std::pair<bufptr_t, size_t>> read_file(sstring file_path)
{
return engine().open_file_dma(file_path, open_flags::rw).then([] (file f) {
return open_file_dma(file_path, open_flags::rw).then([] (file f) {
return f.size().then([f] (auto size) mutable {
auto aligned_size = align_up(size, 512UL);
auto buf = allocate_aligned_buffer<char>(aligned_size, 512UL);
@@ -803,7 +803,7 @@ SEASTAR_TEST_CASE(wrong_range) {
static future<>
test_sstable_exists(sstring dir, unsigned long generation, bool exists) {
auto file_path = sstable::filename(dir, "ks", "cf", la, generation, big, sstable::component_type::Data);
return engine().open_file_dma(file_path, open_flags::ro).then_wrapped([exists] (future<file> f) {
return open_file_dma(file_path, open_flags::ro).then_wrapped([exists] (future<file> f) {
if (exists) {
BOOST_CHECK_NO_THROW(f.get0());
} else {