lmdb: Fix storage initialization when config file cannot be loaded

This commit is contained in:
Martchus 2022-01-23 19:47:50 +01:00
parent 26f787fb42
commit 1c820fc2f6
2 changed files with 16 additions and 10 deletions

View File

@ -218,7 +218,7 @@ std::vector<std::shared_ptr<BuildAction>> ServiceSetup::BuildSetup::getBuildActi
return buildActions; return buildActions;
} }
void ServiceSetup::loadConfigFiles(bool restoreStateAndDiscardDatabases) void ServiceSetup::loadConfigFiles(bool doFirstTimeSetup)
{ {
// read config file // read config file
cout << Phrases::InfoMessage << "Reading config file: " << configFilePath << Phrases::EndFlush; cout << Phrases::InfoMessage << "Reading config file: " << configFilePath << Phrases::EndFlush;
@ -264,11 +264,9 @@ void ServiceSetup::loadConfigFiles(bool restoreStateAndDiscardDatabases)
} }
} }
// restore state/cache and discard databases // restore state/cache and discard databases
if (restoreStateAndDiscardDatabases) { if (doFirstTimeSetup) {
restoreState(); initStorage();
config.initStorage(dbPath.data(), maxDbs); doFirstTimeSetup = false;
config.markAllDatabasesToBeDiscarded();
restoreStateAndDiscardDatabases = false;
} }
// read webserver, build and user configuration (partially cached so read it after the cache has been restored to override cached values) // read webserver, build and user configuration (partially cached so read it after the cache has been restored to override cached values)
for (const auto &iniEntry : configIni.data()) { for (const auto &iniEntry : configIni.data()) {
@ -288,9 +286,8 @@ void ServiceSetup::loadConfigFiles(bool restoreStateAndDiscardDatabases)
} }
// restore state/cache and discard databases if not done yet // restore state/cache and discard databases if not done yet
if (restoreStateAndDiscardDatabases) { if (doFirstTimeSetup) {
restoreState(); initStorage();
config.markAllDatabasesToBeDiscarded();
} }
// read pacman config // read pacman config
@ -622,6 +619,14 @@ std::size_t ServiceSetup::saveState()
return size; return size;
} }
void ServiceSetup::initStorage()
{
cout << Phrases::InfoMessage << "Opening LMDB file: " << dbPath << " (max DBs: " << maxDbs << ')' << Phrases::EndFlush;
config.initStorage(dbPath.data(), maxDbs);
restoreState();
config.markAllDatabasesToBeDiscarded();
}
void ServiceSetup::run() void ServiceSetup::run()
{ {
#ifndef CPP_UTILITIES_DEBUG_BUILD #ifndef CPP_UTILITIES_DEBUG_BUILD

View File

@ -144,13 +144,14 @@ struct LIBREPOMGR_EXPORT ServiceSetup : public LibPkg::Lockable {
LockTable m_locksByName; LockTable m_locksByName;
} locks; } locks;
void loadConfigFiles(bool restoreStateAndDiscardDatabases); void loadConfigFiles(bool doFirstTimeSetup);
void printDatabases(); void printDatabases();
std::string_view cacheFilePath() const; std::string_view cacheFilePath() const;
RAPIDJSON_NAMESPACE::Document libraryDependenciesToJson(); RAPIDJSON_NAMESPACE::Document libraryDependenciesToJson();
void restoreLibraryDependenciesFromJson(const std::string &json, ReflectiveRapidJSON::JsonDeserializationErrors *errors); void restoreLibraryDependenciesFromJson(const std::string &json, ReflectiveRapidJSON::JsonDeserializationErrors *errors);
std::size_t restoreState(); std::size_t restoreState();
std::size_t saveState(); std::size_t saveState();
void initStorage();
void run(); void run();
ServiceStatus computeStatus() const; ServiceStatus computeStatus() const;
}; };