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 c2541ad
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
19 changes: 12 additions & 7 deletions src/ripple/app/misc/SHAMapStoreImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,19 @@ 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
10 changes: 6 additions & 4 deletions src/ripple/nodestore/DatabaseRotating.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ class DatabaseRotating : public Database
virtual TaggedCache<uint256, NodeObject> const&
getPositiveCache() = 0;

/** Returns the name of the rotated backend.
/** Rotates the backends.
@param f A function executed before the rotation and under the same lock
*/
virtual
std::string
rotateBackends(std::shared_ptr<Backend> newBackend) = 0;
virtual void
rotateWithLock(std::function<std::unique_ptr<NodeStore::Backend>(
std::string const& writableBackendName)> const& f) = 0;
};

} // namespace NodeStore
Expand Down
24 changes: 11 additions & 13 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 Expand Up @@ -99,11 +102,7 @@ DatabaseRotatingImp::storeLedger(std::shared_ptr<Ledger const> const& srcLedger)
}();

return Database::storeLedger(
*srcLedger,
backend,
pCache_,
nCache_,
nullptr);
*srcLedger, backend, pCache_, nCache_, nullptr);
}

void
Expand Down Expand Up @@ -168,7 +167,7 @@ DatabaseRotatingImp::fetchFrom(uint256 const& hash, std::uint32_t seq)

// Try to fetch from the writable backend
auto nObj = fetchInternal(hash, writable);
if (! nObj)
if (!nObj)
{
// Otherwise try to fetch from the archive backend
nObj = fetchInternal(hash, archive);
Expand All @@ -190,7 +189,7 @@ DatabaseRotatingImp::fetchFrom(uint256 const& hash, std::uint32_t seq)

void
DatabaseRotatingImp::for_each(
std::function <void(std::shared_ptr<NodeObject>)> f)
std::function<void(std::shared_ptr<NodeObject>)> f)
{
auto [writable, archive] = [&] {
std::lock_guard lock(mutex_);
Expand All @@ -204,6 +203,5 @@ DatabaseRotatingImp::for_each(
archive->for_each(f);
}


} // NodeStore
} // ripple
} // namespace NodeStore
} // namespace ripple
8 changes: 5 additions & 3 deletions src/ripple/nodestore/impl/DatabaseRotatingImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ 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 Expand Up @@ -125,7 +127,7 @@ class DatabaseRotatingImp : public DatabaseRotating
fetchFrom(uint256 const& hash, std::uint32_t seq) override;

void
for_each(std::function <void(std::shared_ptr<NodeObject>)> f) override;
for_each(std::function<void(std::shared_ptr<NodeObject>)> f) override;
};

} // namespace NodeStore
Expand Down

0 comments on commit c2541ad

Please sign in to comment.