Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve shard concurrency #3251

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/ripple/nodestore/impl/DatabaseShardImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,9 @@ DatabaseShardImp::import(Database& source)
}

// Copy the ledgers from node store
std::shared_ptr<Ledger> lastStoredLedger;
std::shared_ptr<Ledger> recentStored;
uint256 lastLedgerHash;

while (auto seq = shard->prepare())
{
auto ledger {loadByIndex(*seq, app_, false)};
Expand All @@ -822,31 +824,50 @@ DatabaseShardImp::import(Database& source)
shard->getBackend(),
nullptr,
nullptr,
lastStoredLedger))
recentStored))
{
break;
}

if (!shard->store(ledger))
break;

if (seq == lastLedgerSeq(shardIndex))
lastLedgerHash = ledger->info().hash;

if (shard->isBackendComplete())
{
JLOG(j_.debug()) <<
"shard " << shardIndex << " was successfully imported";
// Store shard final key
miguelportilla marked this conversation as resolved.
Show resolved Hide resolved
Serializer s;
s.add32(Shard::version);
s.add32(firstLedgerSeq(shardIndex));
s.add32(lastLedgerSeq(shardIndex));
s.add256(lastLedgerHash);
auto nObj {NodeObject::createObject(
hotUNKNOWN,
std::move(s.modData()),
Shard::finalKey)};

try
{
shard->getBackend()->store(nObj);
boost::filesystem::remove_all(markerFile);

JLOG(j_.debug()) <<
"shard " << shardIndex <<
" was successfully imported";
}
catch (std::exception const& e)
{
JLOG(j_.error()) <<
"exception " << e.what() <<
" in function " << __func__;
}

break;
}

lastStoredLedger = ledger;
recentStored = ledger;
}

if (shard->isBackendComplete())
Expand Down
14 changes: 7 additions & 7 deletions src/ripple/nodestore/impl/Shard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
namespace ripple {
namespace NodeStore {

uint256 const Shard::finalKey_ {0};
uint256 const Shard::finalKey {0};

Shard::Shard(
Application& app,
Expand Down Expand Up @@ -177,15 +177,15 @@ Shard::open(Scheduler& scheduler, nudb::context& ctx)
{
// A finalized shard or has all ledgers stored in the backend
std::shared_ptr<NodeObject> nObj;
if (backend_->fetch(finalKey_.data(), &nObj) != Status::ok)
if (backend_->fetch(finalKey.data(), &nObj) != Status::ok)
{
legacy_ = true;
return fail("incompatible, missing backend final key");
}

// Check final key's value
SerialIter sIt(nObj->getData().data(), nObj->getData().size());
if (sIt.get32() != version_)
if (sIt.get32() != version)
return fail("invalid version");

if (sIt.get32() != firstSeq_ || sIt.get32() != lastSeq_)
Expand Down Expand Up @@ -422,11 +422,11 @@ Shard::finalize(const bool writeSQLite)
// Check if a final key has been stored
lock.unlock();
miguelportilla marked this conversation as resolved.
Show resolved Hide resolved
if (std::shared_ptr<NodeObject> nObj;
miguelportilla marked this conversation as resolved.
Show resolved Hide resolved
backend_->fetch(finalKey_.data(), &nObj) == Status::ok)
backend_->fetch(finalKey.data(), &nObj) == Status::ok)
{
// Check final key's value
SerialIter sIt(nObj->getData().data(), nObj->getData().size());
if (sIt.get32() != version_)
if (sIt.get32() != version)
return fail("invalid version");

if (sIt.get32() != firstSeq_ || sIt.get32() != lastSeq_)
Expand Down Expand Up @@ -585,14 +585,14 @@ Shard::finalize(const bool writeSQLite)

// Store final key's value, may already be stored
Serializer s;
s.add32(version_);
s.add32(version);
s.add32(firstSeq_);
s.add32(lastSeq_);
s.add256(lastLedgerHash);
auto nObj {NodeObject::createObject(
hotUNKNOWN,
std::move(s.modData()),
finalKey_)};
finalKey)};
try
{
backend_->store(nObj);
Expand Down
8 changes: 4 additions & 4 deletions src/ripple/nodestore/impl/Shard.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ class Shard final
void
stop() {stop_ = true;}

private:
// Current shard version
static constexpr std::uint32_t version_ {2};
static constexpr std::uint32_t version {2};

// The finalKey_ is a hard coded value of zero. It is used to store
// The finalKey is a hard coded value of zero. It is used to store
// finalizing shard data to the backend. The data contains a version,
// last ledger's hash, and the first and last ledger sequences.
static uint256 const finalKey_;
static uint256 const finalKey;

private:
struct AcquireInfo
{
// SQLite database to track information about what has been acquired
Expand Down