Skip to content

Commit

Permalink
Fix issue: "Updating cache" prints in log when cache is disabled (#1479)
Browse files Browse the repository at this point in the history
Fixed #1461
  • Loading branch information
cindyyan317 authored Jun 24, 2024
1 parent e65351e commit c7fee02
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/data/BackendInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ BackendInterface::fetchLedgerObject(
return obj;
}

LOG(gLog.trace()) << "Cache miss - " << ripple::strHex(key);
auto dbObj = doFetchLedgerObject(key, sequence, yield);
if (!dbObj) {
LOG(gLog.trace()) << "Missed cache and missed in db";
Expand Down
4 changes: 2 additions & 2 deletions src/data/CassandraBackend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ class BasicCassandraBackend : public BackendInterface {

auto const& result = res.value();
if (not result.hasRows()) {
LOG(log_.error()) << "Could not fetch all transaction hashes - no rows; ledger = "
<< std::to_string(ledgerSequence);
LOG(log_.warn()) << "Could not fetch all transaction hashes - no rows; ledger = "
<< std::to_string(ledgerSequence);
return {};
}

Expand Down
13 changes: 8 additions & 5 deletions src/etl/impl/LedgerPublisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,16 @@ class LedgerPublisher {
LOG(log_.info()) << "Publishing ledger " << std::to_string(lgrInfo.seq);

if (!state_.get().isWriting) {
LOG(log_.info()) << "Updating cache";
LOG(log_.info()) << "Updating ledger range for read node.";

std::vector<data::LedgerObject> const diff = data::synchronousAndRetryOnTimeout([&](auto yield) {
return backend_->fetchLedgerDiff(lgrInfo.seq, yield);
});
if (!cache_.get().isDisabled()) {
std::vector<data::LedgerObject> const diff = data::synchronousAndRetryOnTimeout([&](auto yield) {
return backend_->fetchLedgerDiff(lgrInfo.seq, yield);
});

cache_.get().update(diff, lgrInfo.seq);
}

cache_.get().update(diff, lgrInfo.seq);
backend_->updateRange(lgrInfo.seq);
}

Expand Down
26 changes: 23 additions & 3 deletions tests/unit/etl/LedgerPublisherTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,35 @@ struct ETLLedgerPublisherTest : util::prometheus::WithPrometheus, MockBackendTes
StrictMockSubscriptionManagerSharedPtr mockSubscriptionManagerPtr;
};

TEST_F(ETLLedgerPublisherTest, PublishLedgerHeaderIsWritingFalse)
TEST_F(ETLLedgerPublisherTest, PublishLedgerHeaderIsWritingFalseAndCacheDisabled)
{
SystemState dummyState;
dummyState.isWriting = false;
auto const dummyLedgerHeader = CreateLedgerHeader(LEDGERHASH, SEQ, AGE);
impl::LedgerPublisher publisher(ctx, backend, mockCache, mockSubscriptionManagerPtr, dummyState);
publisher.publish(dummyLedgerHeader);
EXPECT_CALL(mockCache, isDisabled).WillOnce(Return(true));
EXPECT_CALL(*backend, fetchLedgerDiff(SEQ, _)).Times(0);

EXPECT_CALL(*backend, fetchLedgerDiff(SEQ, _)).WillOnce(Return(std::vector<LedgerObject>{}));
// setLastPublishedSequence not in strand, should verify before run
EXPECT_TRUE(publisher.getLastPublishedSequence());
EXPECT_EQ(publisher.getLastPublishedSequence().value(), SEQ);

ctx.run();
EXPECT_TRUE(backend->fetchLedgerRange());
EXPECT_EQ(backend->fetchLedgerRange().value().minSequence, SEQ);
EXPECT_EQ(backend->fetchLedgerRange().value().maxSequence, SEQ);
}

TEST_F(ETLLedgerPublisherTest, PublishLedgerHeaderIsWritingFalseAndCacheEnabled)
{
SystemState dummyState;
dummyState.isWriting = false;
auto const dummyLedgerHeader = CreateLedgerHeader(LEDGERHASH, SEQ, AGE);
impl::LedgerPublisher publisher(ctx, backend, mockCache, mockSubscriptionManagerPtr, dummyState);
publisher.publish(dummyLedgerHeader);
EXPECT_CALL(mockCache, isDisabled).WillOnce(Return(false));
EXPECT_CALL(*backend, fetchLedgerDiff(SEQ, _)).Times(1);

// setLastPublishedSequence not in strand, should verify before run
EXPECT_TRUE(publisher.getLastPublishedSequence());
Expand Down Expand Up @@ -218,7 +238,7 @@ TEST_F(ETLLedgerPublisherTest, PublishLedgerSeqStopIsFalse)

auto const dummyLedgerHeader = CreateLedgerHeader(LEDGERHASH, SEQ, AGE);
EXPECT_CALL(*backend, fetchLedgerBySequence(SEQ, _)).WillOnce(Return(dummyLedgerHeader));

EXPECT_CALL(mockCache, isDisabled).WillOnce(Return(false));
EXPECT_CALL(*backend, fetchLedgerDiff(SEQ, _)).WillOnce(Return(std::vector<LedgerObject>{}));
EXPECT_CALL(mockCache, updateImp);

Expand Down

0 comments on commit c7fee02

Please sign in to comment.