mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 23:40:57 +01:00
ircd::db: Add interface to iterate the database's txn log.
This commit is contained in:
parent
2671f4eb90
commit
83bdb7161c
2 changed files with 55 additions and 0 deletions
|
@ -19,6 +19,11 @@ namespace ircd::db
|
|||
bool until(const txn &, const std::function<bool (const delta &)> &);
|
||||
void for_each(const txn &, const std::function<void (const delta &)> &);
|
||||
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
|
||||
|
|
50
ircd/db.cc
50
ircd/db.cc
|
@ -2248,6 +2248,56 @@ noexcept
|
|||
// 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
|
||||
ircd::db::debug(const txn &t)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue