1
0
Fork 0
forked from blue/lmdbal

a method to get the size of the storage with opened transaction, tests for readAll, and some test for transactions

This commit is contained in:
Blue 2023-04-01 17:45:20 +03:00
parent 17fb37075c
commit a4bb7e6269
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
6 changed files with 168 additions and 22 deletions

View file

@ -59,25 +59,31 @@ void LMDBAL::iStorage::ensureOpened(const std::string& methodName) const {
throw Closed(methodName, db->name, name);
}
uint32_t LMDBAL::iStorage::count() const {
LMDBAL::SizeType LMDBAL::iStorage::count() const {
ensureOpened(countMethodName);
MDB_txn *txn;
TransactionID txn = beginReadOnlyTransaction();
SizeType amount;
try {
amount = count(txn);
} catch (...) {
abortTransaction(txn);
throw;
}
abortTransaction(txn);
return amount;
}
LMDBAL::SizeType LMDBAL::iStorage::count(TransactionID txn) const {
MDB_stat stat;
int rc = mdb_txn_begin(db->environment, NULL, MDB_RDONLY, &txn);
int rc = mdb_stat(txn, dbi, &stat);
if (rc) {
mdb_txn_abort(txn);
throw Unknown(db->name, mdb_strerror(rc), name);
}
rc = mdb_stat(txn, dbi, &stat);
if (rc) {
mdb_txn_abort(txn);
throw Unknown(db->name, mdb_strerror(rc), name);
}
uint32_t amount = stat.ms_entries;
mdb_txn_abort(txn);
return amount;
return stat.ms_entries;
}
void LMDBAL::iStorage::throwDuplicateOrUnknown(int rc, TransactionID txn, const std::string& key) const {

View file

@ -24,8 +24,12 @@
namespace LMDBAL {
typedef uint32_t SizeType;
class iStorage {
friend class Base;
public:
protected:
iStorage(const std::string& name, Base* parent);
virtual ~iStorage();
@ -48,7 +52,8 @@ protected:
public:
virtual void drop();
virtual uint32_t count() const;
virtual SizeType count() const;
virtual SizeType count(TransactionID txn) const;
TransactionID beginReadOnlyTransaction() const;
TransactionID beginTransaction() const;