0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-18 07:50:57 +01:00

ircd::db: Add interface to iterate the database's txn log.

This commit is contained in:
Jason Volk 2018-03-22 20:49:11 -07:00
parent 2671f4eb90
commit 83bdb7161c
2 changed files with 55 additions and 0 deletions

View file

@ -19,6 +19,11 @@ namespace ircd::db
bool until(const txn &, const std::function<bool (const delta &)> &); bool until(const txn &, const std::function<bool (const delta &)> &);
void for_each(const txn &, const std::function<void (const delta &)> &); void for_each(const txn &, const std::function<void (const delta &)> &);
std::string debug(const txn &); std::string debug(const txn &);
using seq_closure_bool = std::function<bool (txn &, uint64_t)>;
using seq_closure = std::function<void (txn &, uint64_t)>;
bool for_each(database &d, const uint64_t &seq, const seq_closure_bool &);
void for_each(database &d, const uint64_t &seq, const seq_closure &);
} }
struct ircd::db::txn struct ircd::db::txn

View file

@ -2248,6 +2248,56 @@ noexcept
// db/txn.h // db/txn.h
// //
void
ircd::db::for_each(database &d,
const uint64_t &seq,
const seq_closure &closure)
{
for_each(d, seq, seq_closure_bool{[&closure]
(txn &txn, const uint64_t &seq)
{
closure(txn, seq);
return true;
}});
}
bool
ircd::db::for_each(database &d,
const uint64_t &seq,
const seq_closure_bool &closure)
{
std::unique_ptr<rocksdb::TransactionLogIterator> tit;
throw_on_error
{
d.d->GetUpdatesSince(seq, &tit)
};
assert(bool(tit));
for(; tit->Valid(); tit->Next())
{
auto batchres
{
tit->GetBatch()
};
throw_on_error
{
tit->status()
};
db::txn txn
{
d, std::move(batchres.writeBatchPtr)
};
assert(bool(txn.wb));
if(!closure(txn, batchres.sequence))
return false;
}
return true;
}
std::string std::string
ircd::db::debug(const txn &t) ircd::db::debug(const txn &t)
{ {