0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-15 22:41:12 +01:00

ircd::db: Integrate env::sequential_file with AIO.

This commit is contained in:
Jason Volk 2018-08-23 01:10:30 -07:00
parent 1748ff843b
commit 7698759d04
2 changed files with 169 additions and 50 deletions

View file

@ -21,8 +21,12 @@ struct ircd::db::database::env::sequential_file final
using Status = rocksdb::Status; using Status = rocksdb::Status;
using Slice = rocksdb::Slice; using Slice = rocksdb::Slice;
static const fs::fd::opts default_opts;
database &d; database &d;
std::unique_ptr<SequentialFile> defaults; fs::fd::opts opts;
fs::fd fd;
off_t offset;
bool use_direct_io() const noexcept override; bool use_direct_io() const noexcept override;
size_t GetRequiredBufferAlignment() const noexcept override; size_t GetRequiredBufferAlignment() const noexcept override;
@ -31,6 +35,6 @@ struct ircd::db::database::env::sequential_file final
Status Read(size_t n, Slice *result, char *scratch) noexcept override; Status Read(size_t n, Slice *result, char *scratch) noexcept override;
Status Skip(uint64_t size) noexcept override; Status Skip(uint64_t size) noexcept override;
sequential_file(database *const &d, const std::string &name, const EnvOptions &, std::unique_ptr<SequentialFile> defaults); sequential_file(database *const &d, const std::string &name, const EnvOptions &);
~sequential_file() noexcept; ~sequential_file() noexcept;
}; };

View file

@ -1870,25 +1870,22 @@ noexcept
rocksdb::Status rocksdb::Status
ircd::db::database::env::NewSequentialFile(const std::string& name, ircd::db::database::env::NewSequentialFile(const std::string& name,
std::unique_ptr<SequentialFile>* r, std::unique_ptr<SequentialFile> *const r,
const EnvOptions& options) const EnvOptions &options)
noexcept noexcept
{ {
#ifdef RB_DEBUG_DB_ENV #ifdef RB_DEBUG_DB_ENV
log.debug("'%s': new sequential file '%s' options:%p", log::debug
{
log, "'%s': new sequential file '%s' options:%p",
d.name, d.name,
name, name,
&options); &options
};
#endif #endif
std::unique_ptr<SequentialFile> defaults; *r = std::make_unique<sequential_file>(&d, name, options);
const auto ret return Status::OK();
{
this->defaults.NewSequentialFile(name, &defaults, options)
};
*r = std::make_unique<sequential_file>(&d, name, options, std::move(defaults));
return ret;
} }
rocksdb::Status rocksdb::Status
@ -2841,36 +2838,113 @@ noexcept
// sequential_file // sequential_file
// //
decltype(ircd::db::database::env::sequential_file::default_opts)
ircd::db::database::env::sequential_file::default_opts{[]
{
ircd::fs::fd::opts ret{std::ios_base::in};
ret.direct = false;
return ret;
}()};
ircd::db::database::env::sequential_file::sequential_file(database *const &d, ircd::db::database::env::sequential_file::sequential_file(database *const &d,
const std::string &name, const std::string &name,
const EnvOptions &opts, const EnvOptions &env_opts)
std::unique_ptr<SequentialFile> defaults) :d
:d{*d}
,defaults{std::move(defaults)}
{ {
*d
}
,opts{[&env_opts]
{
fs::fd::opts ret{default_opts};
ret.direct = env_opts.use_direct_reads;
return ret;
}()}
,fd
{
name, this->opts
}
,offset
{
0
}
{
#ifdef RB_DEBUG_DB_ENV
log::debug
{
log, "'%s': opened seqfile:%p fd:%d '%s'",
d->name,
this,
int(fd),
name
};
#endif
} }
ircd::db::database::env::sequential_file::~sequential_file() ircd::db::database::env::sequential_file::~sequential_file()
noexcept noexcept
{ {
#ifdef RB_DEBUG_DB_ENV
log::debug
{
log, "'%s': close seqfile:%p fd:%d",
d.name,
this,
int(fd)
};
#endif
} }
rocksdb::Status rocksdb::Status
ircd::db::database::env::sequential_file::Read(size_t length, ircd::db::database::env::sequential_file::Read(size_t length,
Slice *result, Slice *result,
char *scratch) char *scratch)
noexcept noexcept try
{ {
const ctx::uninterruptible::nothrow ui;
assert(result);
#ifdef RB_DEBUG_DB_ENV #ifdef RB_DEBUG_DB_ENV
log.debug("'%s': seqfile:%p read:%p length:%zu scratch:%p", log::debug
{
log, "'%s': seqfile:%p read:%p offset:%zu length:%zu scratch:%p",
d.name, d.name,
this, this,
result, result,
offset,
length, length,
scratch); scratch
};
#endif #endif
return defaults->Read(length, result, scratch); const mutable_buffer buf
{
scratch, length
};
const auto read
{
fs::read(fd, buf, offset)
};
*result = slice(read);
offset += length;
return Status::OK();
}
catch(const std::exception &e)
{
log::error
{
log, "'%s': seqfile:%p read:%p offset:%zu length:%zu scratch:%p :%s",
d.name,
this,
result,
offset,
length,
scratch,
e.what()
};
return Status::InvalidArgument();
} }
rocksdb::Status rocksdb::Status
@ -2878,19 +2952,52 @@ ircd::db::database::env::sequential_file::PositionedRead(uint64_t offset,
size_t length, size_t length,
Slice *result, Slice *result,
char *scratch) char *scratch)
noexcept noexcept try
{ {
const ctx::uninterruptible::nothrow ui;
assert(result);
#ifdef RB_DEBUG_DB_ENV #ifdef RB_DEBUG_DB_ENV
log.debug("'%s': seqfile:%p read:%p length:%zu offset:%zu scratch:%p", log::debug
{
log, "'%s': seqfile:%p positioned read:%p offset:%zu length:%zu scratch:%p",
d.name, d.name,
this, this,
result, result,
length,
offset, offset,
scratch); length,
scratch
};
#endif #endif
return defaults->PositionedRead(offset, length, result, scratch); const mutable_buffer buf
{
scratch, length
};
const auto read
{
fs::read(fd, buf, offset)
};
*result = slice(read);
return Status::OK();
}
catch(const std::exception &e)
{
log::error
{
log, "'%s': seqfile:%p positioned read:%p offset:%zu length:%zu scratch:%p :%s",
d.name,
this,
result,
offset,
length,
scratch,
e.what()
};
return Status::InvalidArgument();
} }
rocksdb::Status rocksdb::Status
@ -2898,13 +3005,18 @@ ircd::db::database::env::sequential_file::Skip(uint64_t size)
noexcept noexcept
{ {
#ifdef RB_DEBUG_DB_ENV #ifdef RB_DEBUG_DB_ENV
log.debug("'%s': seqfile:%p skip:%zu", log::debug
{
"'%s': seqfile:%p offset:zu skip:%zu",
d.name, d.name,
this, this,
size); offset,
size
};
#endif #endif
return defaults->Skip(size); offset += size;
return Status::OK();
} }
rocksdb::Status rocksdb::Status
@ -2913,28 +3025,31 @@ ircd::db::database::env::sequential_file::InvalidateCache(size_t offset,
noexcept noexcept
{ {
#ifdef RB_DEBUG_DB_ENV #ifdef RB_DEBUG_DB_ENV
log.debug("'%s': seqfile:%p invalidate cache offset:%zu length:%zu", log::debug
{
"'%s': seqfile:%p invalidate cache offset:%zu length:%zu",
d.name, d.name,
this, this,
offset, offset,
length); length
};
#endif #endif
return defaults->InvalidateCache(offset, length); return Status::OK();
} }
bool bool
ircd::db::database::env::sequential_file::use_direct_io() ircd::db::database::env::sequential_file::use_direct_io()
const noexcept const noexcept
{ {
return defaults->use_direct_io(); return opts.direct;
} }
size_t size_t
ircd::db::database::env::sequential_file::GetRequiredBufferAlignment() ircd::db::database::env::sequential_file::GetRequiredBufferAlignment()
const noexcept const noexcept
{ {
return defaults->GetRequiredBufferAlignment(); return ircd::info::page_size;
} }
// //