Skip to content

Commit

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

lastRotated_ = validatedSeq;
clearCaches(validatedSeq);

SavedState savedState;
savedState.writableDb = newBackend->getName();
savedState.archiveDb = dbRotating_->rotateBackends(
std::move(newBackend));
savedState.lastRotated = lastRotated_;
state_db_.setState(savedState);
dbRotating_->rotateWithLock(
[&](std::string const& writableBackendName)
{
SavedState savedState;
savedState.writableDb = newBackend->getName();
savedState.archiveDb = writableBackendName;
savedState.lastRotated = lastRotated_;
state_db_.setState(savedState);

clearCaches(validatedSeq);

return std::move(newBackend);
});

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

/** Returns the name of the rotated backend.
*/
virtual
std::string
rotateBackends(std::shared_ptr<Backend> newBackend) = 0;
void
rotateWithLock(
std::function<std::unique_ptr<NodeStore::Backend>(
std::string const& writableBackendName)> const& f) = 0;
};

} // namespace NodeStore
Expand Down
9 changes: 6 additions & 3 deletions src/ripple/nodestore/impl/DatabaseRotatingImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,17 @@ DatabaseRotatingImp::DatabaseRotatingImp(
setParent(parent);
}

std::string
DatabaseRotatingImp::rotateBackends(std::shared_ptr<Backend> newBackend)
void
DatabaseRotatingImp::rotateWithLock(
std::function<std::unique_ptr<NodeStore::Backend>(
std::string const& writableBackendName)> const& f)
{
std::lock_guard lock(mutex_);

auto newBackend = f(writableBackend_->getName());
archiveBackend_->setDeletePath();
archiveBackend_ = std::move(writableBackend_);
writableBackend_ = std::move(newBackend);
return archiveBackend_->getName();
}

std::string
Expand Down
5 changes: 3 additions & 2 deletions src/ripple/nodestore/impl/DatabaseRotatingImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ class DatabaseRotatingImp : public DatabaseRotating
stopThreads();
}

std::string
rotateBackends(std::shared_ptr<Backend> newBackend) override;
void
rotateWithLock(std::function<std::unique_ptr<NodeStore::Backend>(
std::string const& writableBackendName)> const& f) override;

std::string
getName() const override;
Expand Down

0 comments on commit f66e258

Please sign in to comment.