Skip to content

Commit

Permalink
[FOLD] Address seelabs feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelportilla committed Apr 17, 2020
1 parent fc00054 commit e7c76c4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
13 changes: 7 additions & 6 deletions src/ripple/app/misc/SHAMapStoreImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,14 @@ SHAMapStoreImp::run()
}

lastRotated_ = validatedSeq;
state_db_.setState(SavedState {
newBackend->getName(),
dbRotating_->getName(),
lastRotated_});

clearCaches(validatedSeq);
dbRotating_->rotateBackends(std::move(newBackend));

SavedState savedState;
savedState.writableDb = newBackend->getName();
savedState.archiveDb = dbRotating_->rotateBackends(
std::move(newBackend));
savedState.lastRotated = lastRotated_;
state_db_.setState(savedState);

JLOG(journal_.warn()) << "finished rotation " << validatedSeq;
}
Expand Down
4 changes: 3 additions & 1 deletion src/ripple/nodestore/DatabaseRotating.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ class DatabaseRotating : public Database
TaggedCache<uint256, NodeObject> const&
getPositiveCache() = 0;

/** Returns the name of the rotated backend.
*/
virtual
void
std::string
rotateBackends(std::shared_ptr<Backend> newBackend) = 0;
};

Expand Down
19 changes: 10 additions & 9 deletions src/ripple/nodestore/impl/DatabaseRotatingImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ DatabaseRotatingImp::DatabaseRotatingImp(
setParent(parent);
}

void
std::string
DatabaseRotatingImp::rotateBackends(std::shared_ptr<Backend> newBackend)
{
std::lock_guard lock(mutex_);
archiveBackend_->setDeletePath();
archiveBackend_ = std::move(writableBackend_);
writableBackend_ = std::move(newBackend);
return archiveBackend_->getName();
}

std::string
Expand Down Expand Up @@ -148,27 +149,27 @@ DatabaseRotatingImp::sweep()
std::shared_ptr<NodeObject>
DatabaseRotatingImp::fetchFrom(uint256 const& hash, std::uint32_t seq)
{
auto backends = [&] {
auto [writable, archive] = [&] {
std::lock_guard lock(mutex_);
return std::make_pair(writableBackend_, archiveBackend_);
}();

// Try to fetch from the writable backend
auto nObj = fetchInternal(hash, backends.first);
auto nObj = fetchInternal(hash, writable);
if (! nObj)
{
// Otherwise try to fetch from the archive backend
nObj = fetchInternal(hash, backends.second);
nObj = fetchInternal(hash, archive);
if (nObj)
{
{
// Refresh the writable backend pointer
std::lock_guard lock(mutex_);
backends.first = writableBackend_;
writable = writableBackend_;
}

// Update writable backend with data from the archive backend
backends.first->store(nObj);
writable->store(nObj);
nCache_->erase(hash);
}
}
Expand All @@ -179,16 +180,16 @@ void
DatabaseRotatingImp::for_each(
std::function <void(std::shared_ptr<NodeObject>)> f)
{
auto const backends = [&] {
auto [writable, archive] = [&] {
std::lock_guard lock(mutex_);
return std::make_pair(writableBackend_, archiveBackend_);
}();

// Iterate the writable backend
backends.first->for_each(f);
writable->for_each(f);

// Iterate the archive backend
backends.second->for_each(f);
archive->for_each(f);
}


Expand Down
2 changes: 1 addition & 1 deletion src/ripple/nodestore/impl/DatabaseRotatingImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DatabaseRotatingImp : public DatabaseRotating
stopThreads();
}

void
std::string
rotateBackends(std::shared_ptr<Backend> newBackend) override;

std::string
Expand Down

0 comments on commit e7c76c4

Please sign in to comment.