simplify quadrable instance creation

This commit is contained in:
Doug Hoyte
2023-02-07 11:22:52 -05:00
parent 67d11ced30
commit 67331a6e6f
12 changed files with 34 additions and 57 deletions

2
golpe

Submodule golpe updated: c95388c461...e938a71c0d

View File

@ -1,5 +1,4 @@
appName: strfry
quadrable: true
onAppStartup: true
useGlobalH: true
customLMDBSetup: true

View File

@ -42,11 +42,9 @@ void RelayServer::cleanupOldEvents() {
}
if (expiredLevIds.size() > 0) {
auto txn = env.txn_rw();
auto qdb = getQdbInstance();
quadrable::Quadrable qdb;
qdb.init(txn);
qdb.checkout("events");
auto txn = env.txn_rw();
uint64_t numDeleted = 0;
auto changes = qdb.change();
@ -67,12 +65,7 @@ void RelayServer::cleanupOldEvents() {
}
void RelayServer::garbageCollect() {
quadrable::Quadrable qdb;
{
auto txn = env.txn_ro();
qdb.init(txn);
}
qdb.checkout("events");
auto qdb = getQdbInstance();
quadrableGarbageCollect(qdb, 1);
}

View File

@ -2,12 +2,7 @@
void RelayServer::runWriter(ThreadPool<MsgWriter>::Thread &thr) {
quadrable::Quadrable qdb;
{
auto txn = env.txn_ro();
qdb.init(txn);
}
qdb.checkout("events");
auto qdb = getQdbInstance();
while(1) {
auto newMsgs = thr.inbox.pop_all();

View File

@ -6,12 +6,7 @@
void RelayServer::runYesstr(ThreadPool<MsgYesstr>::Thread &thr) {
quadrable::Quadrable qdb;
{
auto txn = env.txn_ro();
qdb.init(txn);
}
auto qdb = getQdbInstance();
struct SyncState {
quadrable::MemStore m;

View File

@ -58,12 +58,7 @@ struct WriterPipeline {
writerThread = std::thread([&]() {
setThreadName("Writer");
quadrable::Quadrable qdb;
{
auto txn = env.txn_ro();
qdb.init(txn);
}
qdb.checkout("events");
auto qdb = getQdbInstance();
while (1) {
// Debounce

View File

@ -32,12 +32,7 @@ void cmd_compact(const std::vector<std::string> &subArgs) {
env.copy_fd(::fileno(f));
}
} else if (args["quad-gc"].asBool()) {
quadrable::Quadrable qdb;
{
auto txn = env.txn_ro();
qdb.init(txn);
}
qdb.checkout("events");
auto qdb = getQdbInstance();
quadrableGarbageCollect(qdb, 2);
}

View File

@ -23,12 +23,7 @@ void cmd_import(const std::vector<std::string> &subArgs) {
if (noVerify) LW << "not verifying event IDs or signatures!";
quadrable::Quadrable qdb;
{
auto txn = env.txn_ro();
qdb.init(txn);
}
qdb.checkout("events");
auto qdb = getQdbInstance();
auto txn = env.txn_rw();

View File

@ -14,12 +14,7 @@ R"(
void cmd_info(const std::vector<std::string> &subArgs) {
std::map<std::string, docopt::value> args = docopt::docopt(USAGE, subArgs, true, "");
quadrable::Quadrable qdb;
{
auto txn = env.txn_ro();
qdb.init(txn);
}
qdb.checkout("events");
auto qdb = getQdbInstance();
auto txn = env.txn_ro();

View File

@ -133,20 +133,12 @@ void cmd_sync(const std::vector<std::string> &subArgs) {
std::unique_ptr<SyncController> controller;
WriterPipeline writer;
WSConnection ws(url);
quadrable::Quadrable qdb;
{
auto txn = env.txn_ro();
qdb.init(txn);
}
qdb.checkout("events");
auto qdb = getQdbInstance();
ws.reconnect = false;
if (filterStr.size()) {
std::vector<uint64_t> levIds;

View File

@ -4,3 +4,9 @@
#include <parallel_hashmap/btree.h>
using namespace phmap;
#include <quadrable.h>
quadrable::Quadrable getQdbInstance(lmdb::txn &txn);
quadrable::Quadrable getQdbInstance();

View File

@ -67,7 +67,24 @@ static void setRLimits() {
if (setrlimit(RLIMIT_NOFILE, &curr)) throw herr("Failed setting NOFILES limit to ", cfg().relay__nofiles, ": ", strerror(errno));
}
quadrable::Quadrable getQdbInstance(lmdb::txn &txn) {
quadrable::Quadrable qdb;
qdb.init(txn);
qdb.checkout("events");
return qdb;
}
quadrable::Quadrable getQdbInstance() {
auto txn = env.txn_ro();
return getQdbInstance(txn);
}
void onAppStartup(lmdb::txn &txn, const std::string &cmd) {
dbCheck(txn, cmd);
setRLimits();
(void)getQdbInstance(txn);
}