Skip to content

Commit

Permalink
[FOLD] Fix introduced shard state bug
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelportilla committed Dec 3, 2020
1 parent 52c7e94 commit 7e8e116
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
30 changes: 19 additions & 11 deletions src/ripple/nodestore/impl/Shard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,16 +638,16 @@ Shard::finalize(
{
uint256 hash{0};
std::uint32_t ledgerSeq{0};
auto fail =
[j = j_, index = index_, &hash, &ledgerSeq](std::string const& msg) {
JLOG(j.fatal())
<< "shard " << index << ". " << msg
<< (hash.isZero() ? "" : ". Ledger hash " + to_string(hash))
<< (ledgerSeq == 0
? ""
: ". Ledger sequence " + std::to_string(ledgerSeq));
return false;
};
auto fail = [&](std::string const& msg) {
JLOG(j_.fatal()) << "shard " << index_ << ". " << msg
<< (hash.isZero() ? ""
: ". Ledger hash " + to_string(hash))
<< (ledgerSeq == 0 ? ""
: ". Ledger sequence " +
std::to_string(ledgerSeq));
state_ = finalizing;
return false;
};

auto const scopedCount{makeBackendCount()};
if (!scopedCount)
Expand Down Expand Up @@ -863,11 +863,13 @@ Shard::finalize(
remove_all(dir_ / AcquireShardDBName);
}

lastAccess_ = std::chrono::steady_clock::now();
state_ = final;

if (!initSQLite(lock))
return fail("failed to initialize SQLite databases");

setFileStats(lock);
lastAccess_ = std::chrono::steady_clock::now();
}
catch (std::exception const& e)
{
Expand Down Expand Up @@ -1044,6 +1046,12 @@ Shard::initSQLite(std::lock_guard<std::mutex> const&)

try
{
if (lgrSQLiteDB_)
lgrSQLiteDB_.reset();

if (txSQLiteDB_)
txSQLiteDB_.reset();

if (state_ == final)
{
lgrSQLiteDB_ = std::make_unique<DatabaseCon>(
Expand Down
1 change: 0 additions & 1 deletion src/ripple/nodestore/impl/Shard.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <nudb/nudb.hpp>

#include <atomic>
#include <tuple>

namespace ripple {
namespace NodeStore {
Expand Down

0 comments on commit 7e8e116

Please sign in to comment.