diff --git a/services/horizon/internal/ingest/main.go b/services/horizon/internal/ingest/main.go index a9610805db..5bff414ac3 100644 --- a/services/horizon/internal/ingest/main.go +++ b/services/horizon/internal/ingest/main.go @@ -705,7 +705,7 @@ func (s *system) runStateMachine(cur stateMachineNode) error { } func (s *system) maybeReapHistory(lastIngestedLedger uint32) { - if s.config.ReapConfig.Frequency == 0 || lastIngestedLedger%uint32(s.config.ReapConfig.Frequency) != 0 { + if s.reaper.config.Frequency == 0 || lastIngestedLedger%uint32(s.reaper.config.Frequency) != 0 { return } s.wg.Add(1) diff --git a/services/horizon/internal/ingest/reap_test.go b/services/horizon/internal/ingest/reap_test.go index 6216cc0e4e..c34e94c543 100644 --- a/services/horizon/internal/ingest/reap_test.go +++ b/services/horizon/internal/ingest/reap_test.go @@ -83,6 +83,7 @@ func (t *ReaperTestSuite) SetupTest() { t.reaper = newReaper(ReapConfig{ RetentionCount: 30, BatchSize: 10, + Frequency: 7, }, t.historyQ, t.reapLockQ) t.prevSleep = sleep sleep = 0 @@ -126,6 +127,29 @@ func (t *ReaperTestSuite) TestInProgress() { ) } +func (t *ReaperTestSuite) TestReaperInvokedOnMatchingLedger() { + s := &system{ + ctx: t.ctx, + reaper: t.reaper, + } + assertMocksInOrder( + t.reapLockQ.On("Begin", t.ctx).Return(nil).Once(), + t.reapLockQ.On("TryReaperLock", t.ctx).Return(false, nil).Once(), + t.reapLockQ.On("Rollback").Return(nil).Once(), + ) + s.maybeReapHistory(49) + s.wg.Wait() +} + +func (t *ReaperTestSuite) TestReaperIgnoredOnMismatchingLedger() { + s := &system{ + ctx: t.ctx, + reaper: t.reaper, + } + s.maybeReapHistory(48) + s.wg.Wait() +} + func (t *ReaperTestSuite) TestLatestLedgerTooSmall() { assertMocksInOrder( t.reapLockQ.On("Begin", t.ctx).Return(nil).Once(), diff --git a/services/horizon/internal/ingest/resume_state_test.go b/services/horizon/internal/ingest/resume_state_test.go index 985391883f..5167eb195a 100644 --- a/services/horizon/internal/ingest/resume_state_test.go +++ b/services/horizon/internal/ingest/resume_state_test.go @@ -45,6 +45,7 @@ func (s *ResumeTestTestSuite) SetupTest() { ledgerBackend: s.ledgerBackend, stellarCoreClient: s.stellarCoreClient, runStateVerificationOnLedger: ledgerEligibleForStateVerification(64, 1), + reaper: &Reaper{}, } s.system.initMetrics()