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

services/horizon: Update cursor when bumping ledger to latest #4150

Merged
merged 1 commit into from
Jan 10, 2022
Merged
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
8 changes: 8 additions & 0 deletions services/horizon/internal/ingest/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,14 @@ func (r resumeState) run(s *system) (transition, error) {
log.WithField("ingestLedger", ingestLedger).
WithField("lastIngestedLedger", lastIngestedLedger).
Info("bumping ingest ledger to next ledger after ingested ledger in db")

// Update cursor if there's more than one ingesting instance: either
Copy link
Contributor

Choose a reason for hiding this comment

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

ingestLedger <= lastIngestedLedger is a state that can only happen due to multiple ingestions instances? just wanted to understand the comment which refers to it, would a single ingestion instance ever get in here, i.e. this is a best effort attempt under any case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, this can only happen if there is more than one ingesting instance. ingestLedger is the currently ingested ledger in this instance, lastIngestedLedger is the last ingested ledger in the cluster. I guess the variable names could be better.

// Captive-Core or DB ingestion connected to another Stellar-Core.
if err = s.updateCursor(lastIngestedLedger); err != nil {
// Don't return updateCursor error.
log.WithError(err).Warn("error updating stellar-core cursor")
}

return retryResume(resumeState{
latestSuccessfullyProcessedLedger: lastIngestedLedger,
}), nil
Expand Down
7 changes: 7 additions & 0 deletions services/horizon/internal/ingest/resume_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ func (s *ResumeTestTestSuite) TestBumpIngestLedger() {
s.historyQ.On("Begin").Return(nil).Once()
s.historyQ.On("GetLastLedgerIngest", s.ctx).Return(uint32(101), nil).Once()

s.stellarCoreClient.On(
"SetCursor",
mock.AnythingOfType("*context.timerCtx"),
defaultCoreCursorName,
int32(101),
).Return(errors.New("my error")).Once()

next, err := resumeState{latestSuccessfullyProcessedLedger: 99}.run(s.system)
s.Assert().NoError(err)
s.Assert().Equal(
Expand Down