Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Added DBMain::RecoverSystem() for loading the database back in from t…
Browse files Browse the repository at this point in the history
…he WAL. This is currently broken because it tries to recreate the catalogs from the WAL but the catalog obviously already exists...
  • Loading branch information
apavlo committed Apr 17, 2021
1 parent db769b5 commit bece91f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/include/main/db_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class DBMain {
*/
void Run();

/**
* Attempt to recover the system from the WAL.
*/
void RecoverSystem();

/**
* Shuts down the server.
* It is worth noting that in normal cases, noisepage will shut down and return from Run().
Expand Down
26 changes: 26 additions & 0 deletions src/main/db_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#undef __SETTING_GFLAGS_DEFINE__ // NOLINT

#include "execution/execution_util.h"
#include "storage/recovery/disk_log_provider.h"
#include "storage/recovery/replication_log_provider.h"

namespace noisepage {
Expand All @@ -30,6 +31,31 @@ void DBMain::Run() {
}
}

void DBMain::RecoverSystem() {
NOISEPAGE_ASSERT(settings_manager_ != DISABLED, "Trying to recover system without SettingsManager.");

// Skip if logging is disabled
if (settings_manager_->GetBool(settings::Param::wal_enable) == false) {
return;
}

// Skip if the file does not exist
auto wal_file_path = settings_manager_->GetString(settings::Param::wal_file_path);
if (std::filesystem::exists(wal_file_path) == false) {
return;
}

// Instantiate recovery manager and recover the tables
storage::DiskLogProvider log_provider(wal_file_path);
storage::RecoveryManager recovery_manager(common::ManagedPointer<storage::AbstractLogProvider>(&log_provider),
catalog_layer_->GetCatalog(), txn_layer_->GetTransactionManager(),
txn_layer_->GetDeferredActionManager(), GetReplicationManager(),
GetThreadRegistry(), storage_layer_->GetBlockStore());

recovery_manager.StartRecovery();
recovery_manager.WaitForRecoveryToFinish();
}

void DBMain::ForceShutdown() {
if (replication_manager_ != DISABLED) {
GetLogManager()->EndReplication();
Expand Down
1 change: 1 addition & 0 deletions src/main/noisepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ int main(int argc, char *argv[]) {

db_main_handler_ptr = db_main.get();

db_main->RecoverSystem();
db_main->Run();

noisepage::LoggersUtil::ShutDown();
Expand Down

0 comments on commit bece91f

Please sign in to comment.