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

Don't suspend writes based on batch size. Instead, log if it seems to be too big #4762

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/ripple/nodestore/backend/NuDBFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class NuDBBackend : public Backend, public BatchWriter::Callback
void
store(std::shared_ptr<NodeObject> const& no) override
{
batch_.store(no);
batch_.store(no, j_);
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/nodestore/backend/RocksDBFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class RocksDBBackend : public Backend, public BatchWriter::Callback
void
store(std::shared_ptr<NodeObject> const& object) override
{
m_batch.store(object);
m_batch.store(object, m_journal);
}

void
Expand Down
22 changes: 16 additions & 6 deletions src/ripple/nodestore/impl/BatchWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,31 @@ BatchWriter::~BatchWriter()
}

void
BatchWriter::store(std::shared_ptr<NodeObject> const& object)
BatchWriter::store(
std::shared_ptr<NodeObject> const& object,
beast::Journal const& j)
{
std::unique_lock<decltype(mWriteMutex)> sl(mWriteMutex);

// If the batch has reached its limit, we wait
// until the batch writer is finished
while (mWriteSet.size() >= batchWriteLimitSize)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HowardHinnant Here's the logic change.

mWriteCondition.wait(sl);

mWriteSet.push_back(object);

if (!mWritePending)
{
mWritePending = true;

// Log if the write batch size is too big. The trade-off here
// is that new ledgers can't be persisted if a limit is enforced,
// which causes desync. Versus eventual memory exhaustion if
// there are no limits. But we at least stay in sync longer in the
// latter case.
if (mWriteSet.size() >= batchWriteLimitSize)
{
JLOG(j.warn())
<< "Pending write batch size " << mWriteSet.size()
<< " exceeds threshold of " << batchWriteLimitSize
<< ". This may be caused by slow i/o. More memory is consumed "
" as pending write count increases.";
}
m_scheduler.scheduleTask(*this);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/ripple/nodestore/impl/BatchWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef RIPPLE_NODESTORE_BATCHWRITER_H_INCLUDED
#define RIPPLE_NODESTORE_BATCHWRITER_H_INCLUDED

#include <ripple/basics/Log.h>
#include <ripple/nodestore/Scheduler.h>
#include <ripple/nodestore/Task.h>
#include <ripple/nodestore/Types.h>
Expand Down Expand Up @@ -68,7 +69,7 @@ class BatchWriter : private Task
write the batch out.
*/
void
store(std::shared_ptr<NodeObject> const& object);
store(std::shared_ptr<NodeObject> const& object, beast::Journal const& j);

/** Get an estimate of the amount of writing I/O pending. */
int
Expand Down