21 #include <ripple/basics/contract.h>
22 #include <ripple/nodestore/Factory.h>
23 #include <ripple/nodestore/Manager.h>
24 #include <ripple/nodestore/impl/codec.h>
25 #include <ripple/nodestore/impl/DecodedBlob.h>
26 #include <ripple/nodestore/impl/EncodedBlob.h>
27 #include <nudb/nudb.hpp>
28 #include <boost/filesystem.hpp>
64 Throw<std::runtime_error> (
65 "nodestore: Missing path in NuDB backend");
72 nudb::context& context,
82 Throw<std::runtime_error> (
83 "nodestore: Missing path in NuDB backend");
98 open(
bool createIfMissing)
override
100 using namespace boost::filesystem;
105 "database is already open";
108 auto const folder = path(
name_);
109 auto const dp = (folder /
"nudb.dat").
string();
110 auto const kp = (folder /
"nudb.key").
string();
111 auto const lp = (folder /
"nudb.log").
string();
115 create_directories(folder);
116 nudb::create<nudb::xxhasher>(dp, kp, lp,
118 nudb::block_size(kp), 0.50, ec);
119 if(ec == nudb::errc::file_exists)
122 Throw<nudb::system_error>(ec);
124 db_.open (dp, kp, lp, ec);
126 Throw<nudb::system_error>(ec);
128 Throw<std::runtime_error>(
129 "nodestore: unknown appnum");
140 Throw<nudb::system_error>(ec);
143 boost::filesystem::remove_all (
name_);
155 [key, pno, &status](
void const* data,
std::size_t size)
157 nudb::detail::buffer bf;
160 DecodedBlob decoded (key, result.first, result.second);
161 if (! decoded.
wasOk ())
169 if(ec == nudb::error::key_not_found)
172 Throw<nudb::system_error>(ec);
185 Throw<std::runtime_error> (
"pure virtual called");
195 nudb::detail::buffer bf;
198 db_.insert (e.
getKey(), result.first, result.second, ec);
199 if(ec && ec != nudb::error::key_exists)
200 Throw<nudb::system_error>(ec);
224 for (
auto const& e : batch)
235 auto const dp =
db_.dat_path();
236 auto const kp =
db_.key_path();
237 auto const lp =
db_.log_path();
242 Throw<nudb::system_error>(ec);
249 nudb::detail::buffer bf;
252 DecodedBlob decoded (key, result.first, result.second);
253 if (! decoded.
wasOk ())
255 ec = make_error_code(nudb::error::missing_value);
259 }, nudb::no_progress{}, ec);
261 Throw<nudb::system_error>(ec);
262 db_.open(dp, kp, lp, ec);
264 Throw<nudb::system_error>(ec);
282 auto const dp =
db_.dat_path();
283 auto const kp =
db_.key_path();
284 auto const lp =
db_.log_path();
288 Throw<nudb::system_error>(ec);
289 nudb::verify_info vi;
290 nudb::verify<nudb::xxhasher>(
291 vi, dp, kp, 0, nudb::no_progress{}, ec);
293 Throw<nudb::system_error>(ec);
294 db_.open (dp, kp, lp, ec);
296 Throw<nudb::system_error>(ec);
334 return std::make_unique <NuDBBackend> (
335 keyBytes, keyValues, scheduler, journal);
343 nudb::context& context,
346 return std::make_unique <NuDBBackend> (
347 keyBytes, keyValues, scheduler, context, journal);
Holds a collection of configuration values.
bool wasOk() const noexcept
Determine if the decoding was successful.
std::pair< void const *, std::size_t > nodeobject_decompress(void const *in, std::size_t in_size, BufferFactory &&bf)
Base class for backend factories.
std::atomic< bool > deletePath_
void store(std::shared_ptr< NodeObject > const &no) override
Store a single object.
std::size_t getSize() const noexcept
void setDeletePath() override
Remove contents on disk upon destruction.
Parsed key/value blob into NodeObject components.
NuDBBackend(size_t keyBytes, Section const &keyValues, Scheduler &scheduler, beast::Journal journal)
virtual void erase(Factory &factory)=0
Remove a factory.
void do_insert(std::shared_ptr< NodeObject > const &no)
static constexpr std::size_t currentType
void close() override
Close the backend.
bool canFetchBatch() override
Return true if batch fetches are optimized.
void const * getData() const noexcept
int fdRequired() const override
Returns the number of file descriptors the backend expects to need.
static NuDBFactory nuDBFactory
virtual void insert(Factory &factory)=0
Add a factory.
std::shared_ptr< NodeObject > createObject()
Create a NodeObject from this data.
std::unique_ptr< Backend > createInstance(size_t keyBytes, Section const &keyValues, Scheduler &scheduler, nudb::context &context, beast::Journal journal) override
Create an instance of this factory's backend.
int getWriteLoad() override
Estimate the number of write operations pending.
A generic endpoint for log messages.
Scheduling for asynchronous backend activity.
void open(bool createIfMissing) override
Open the backend.
Contains information about a batch write operation.
void verify() override
Perform consistency checks on database.
std::string getName() override
Get the human-readable name of this backend.
Status
Return codes from Backend operations.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::vector< std::shared_ptr< NodeObject > > fetchBatch(std::size_t n, void const *const *keys) override
Fetch a batch synchronously.
std::string getName() const override
Retrieve the name of this factory.
std::unique_ptr< Backend > createInstance(size_t keyBytes, Section const &keyValues, Scheduler &scheduler, beast::Journal journal) override
Create an instance of this factory's backend.
T duration_cast(T... args)
NuDBBackend(size_t keyBytes, Section const &keyValues, Scheduler &scheduler, nudb::context &context, beast::Journal journal)
void storeBatch(Batch const &batch) override
Store a group of objects.
std::pair< void const *, std::size_t > nodeobject_compress(void const *in, std::size_t in_size, BufferFactory &&bf)
Utility for producing flattened node objects.
void for_each(std::function< void(std::shared_ptr< NodeObject >)> f) override
Visit every object in the database This is usually called during import.
static Manager & instance()
Returns the instance of the manager singleton.
void const * getKey() const noexcept
std::chrono::milliseconds elapsed
virtual void onBatchWrite(BatchWriteReport const &report)=0
Reports the completion of a batch write Allows the scheduler to monitor the node store's performance.
Status fetch(void const *key, std::shared_ptr< NodeObject > *pno) override
Fetch a single object.
T & get(EitherAmount &amt)
void prepare(std::shared_ptr< NodeObject > const &object)
A backend used for the NodeStore.