mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::db: Add error_to_status conversion for rocksdb::Status.
This commit is contained in:
parent
c280c9cd36
commit
f630c28439
2 changed files with 71 additions and 0 deletions
62
ircd/db.cc
62
ircd/db.cc
|
@ -9,6 +9,7 @@
|
|||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
#include <rocksdb/version.h>
|
||||
#include <rocksdb/status.h>
|
||||
#include <rocksdb/db.h>
|
||||
#include <rocksdb/cache.h>
|
||||
#include <rocksdb/comparator.h>
|
||||
|
@ -6793,6 +6794,67 @@ ircd::db::valid(const rocksdb::Iterator &it)
|
|||
return it.Valid();
|
||||
}
|
||||
|
||||
//
|
||||
// error_to_status
|
||||
//
|
||||
|
||||
ircd::db::error_to_status::error_to_status(const fs::error &e)
|
||||
:error_to_status{e.code}
|
||||
{
|
||||
}
|
||||
|
||||
ircd::db::error_to_status::error_to_status(const std::exception &e)
|
||||
:rocksdb::Status
|
||||
{
|
||||
Status::Aborted(slice(string_view(e.what())))
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
ircd::db::error_to_status::error_to_status(const std::error_code &e)
|
||||
:rocksdb::Status{[&e]
|
||||
{
|
||||
using std::errc;
|
||||
|
||||
switch(e.value())
|
||||
{
|
||||
case 0:
|
||||
return Status::OK();
|
||||
|
||||
case int(errc::no_such_file_or_directory):
|
||||
return Status::NotFound();
|
||||
|
||||
case int(errc::not_supported):
|
||||
return Status::NotSupported();
|
||||
|
||||
case int(errc::invalid_argument):
|
||||
return Status::InvalidArgument();
|
||||
|
||||
case int(errc::io_error):
|
||||
return Status::IOError();
|
||||
|
||||
case int(errc::timed_out):
|
||||
return Status::TimedOut();
|
||||
|
||||
case int(errc::device_or_resource_busy):
|
||||
return Status::Busy();
|
||||
|
||||
case int(errc::resource_unavailable_try_again):
|
||||
return Status::TryAgain();
|
||||
|
||||
case int(errc::no_space_on_device):
|
||||
return Status::NoSpace();
|
||||
|
||||
case int(errc::not_enough_memory):
|
||||
return Status::MemoryLimit();
|
||||
|
||||
default:
|
||||
return Status::Aborted(slice(string_view(e.message())));
|
||||
}
|
||||
}()}
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// throw_on_error
|
||||
//
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
namespace ircd::db
|
||||
{
|
||||
struct throw_on_error;
|
||||
struct error_to_status;
|
||||
|
||||
const auto BLOCKING = rocksdb::ReadTier::kReadAllTier;
|
||||
const auto NON_BLOCKING = rocksdb::ReadTier::kBlockCacheTier;
|
||||
|
@ -100,3 +101,11 @@ struct ircd::db::throw_on_error
|
|||
{
|
||||
throw_on_error(const rocksdb::Status & = rocksdb::Status::OK());
|
||||
};
|
||||
|
||||
struct ircd::db::error_to_status
|
||||
:rocksdb::Status
|
||||
{
|
||||
error_to_status(const std::error_code &);
|
||||
error_to_status(const fs::error &);
|
||||
error_to_status(const std::exception &);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue