mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd::db: Assert synchronization for sequential file operations; update offset on PositionedRead().
This commit is contained in:
parent
c1d915db7a
commit
e8088ce52a
2 changed files with 47 additions and 4 deletions
|
@ -24,6 +24,7 @@ struct ircd::db::database::env::sequential_file final
|
|||
static const fs::fd::opts default_opts;
|
||||
|
||||
database &d;
|
||||
ctx::mutex mutex;
|
||||
fs::fd::opts opts;
|
||||
fs::fd fd;
|
||||
size_t _buffer_align;
|
||||
|
|
50
ircd/db.cc
50
ircd/db.cc
|
@ -5980,6 +5980,20 @@ ircd::db::database::env::sequential_file::Read(size_t length,
|
|||
noexcept try
|
||||
{
|
||||
const ctx::uninterruptible::nothrow ui;
|
||||
const std::unique_lock<decltype(mutex)> lock
|
||||
{
|
||||
mutex, std::try_to_lock
|
||||
};
|
||||
|
||||
// RocksDB sez that this call requires "External synchronization" i.e the
|
||||
// caller, not this class is responsible for exclusion. We assert anyway.
|
||||
if(unlikely(!bool(lock)))
|
||||
throw assertive
|
||||
{
|
||||
"'%s': Unexpected concurrent access to seqfile %p",
|
||||
d.name,
|
||||
this
|
||||
};
|
||||
|
||||
assert(result);
|
||||
assert(scratch);
|
||||
|
@ -6001,13 +6015,13 @@ noexcept try
|
|||
scratch, length
|
||||
};
|
||||
|
||||
const auto read
|
||||
const const_buffer read
|
||||
{
|
||||
fs::read(fd, buf, offset)
|
||||
};
|
||||
|
||||
*result = slice(read);
|
||||
offset += length;
|
||||
this->offset += size(read);
|
||||
return Status::OK();
|
||||
}
|
||||
catch(const fs::error &e)
|
||||
|
@ -6051,15 +6065,28 @@ ircd::db::database::env::sequential_file::PositionedRead(uint64_t offset,
|
|||
noexcept try
|
||||
{
|
||||
const ctx::uninterruptible::nothrow ui;
|
||||
const std::unique_lock<decltype(mutex)> lock
|
||||
{
|
||||
mutex, std::try_to_lock
|
||||
};
|
||||
|
||||
if(unlikely(!bool(lock)))
|
||||
throw assertive
|
||||
{
|
||||
"'%s': Unexpected concurrent access to seqfile %p",
|
||||
d.name,
|
||||
this
|
||||
};
|
||||
|
||||
assert(result);
|
||||
assert(scratch);
|
||||
#ifdef RB_DEBUG_DB_ENV
|
||||
log::debug
|
||||
{
|
||||
log, "'%s': seqfile:%p positioned read:%p offset:%zu length:%zu scratch:%p",
|
||||
log, "'%s': seqfile:%p offset:%zu positioned read:%p offset:%zu length:%zu scratch:%p",
|
||||
d.name,
|
||||
this,
|
||||
this->offset,
|
||||
result,
|
||||
offset,
|
||||
length,
|
||||
|
@ -6072,12 +6099,13 @@ noexcept try
|
|||
scratch, length
|
||||
};
|
||||
|
||||
const auto read
|
||||
const const_buffer read
|
||||
{
|
||||
fs::read(fd, buf, offset)
|
||||
};
|
||||
|
||||
*result = slice(read);
|
||||
this->offset = std::max(this->offset, off_t(offset + size(read)));
|
||||
return Status::OK();
|
||||
}
|
||||
catch(const fs::error &e)
|
||||
|
@ -6118,6 +6146,20 @@ ircd::db::database::env::sequential_file::Skip(uint64_t size)
|
|||
noexcept
|
||||
{
|
||||
const ctx::uninterruptible::nothrow ui;
|
||||
const std::unique_lock<decltype(mutex)> lock
|
||||
{
|
||||
mutex, std::try_to_lock
|
||||
};
|
||||
|
||||
// RocksDB sez that this call requires "External synchronization" i.e the
|
||||
// caller, not this class is responsible for exclusion. We assert anyway.
|
||||
if(unlikely(!bool(lock)))
|
||||
throw assertive
|
||||
{
|
||||
"'%s': Unexpected concurrent access to seqfile %p",
|
||||
d.name,
|
||||
this
|
||||
};
|
||||
|
||||
#ifdef RB_DEBUG_DB_ENV
|
||||
log::debug
|
||||
|
|
Loading…
Reference in a new issue