-
Notifications
You must be signed in to change notification settings - Fork 502
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: Reap history object tables when ingestion is idle #4518
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6a7cec6
services/horizon: Reap history object tables when ingestion is idle
bartekn 3e86e93
Register a new metric
bartekn 2539cc4
Start a DB tx in maybeReapLookupTables
bartekn c58063d
Better logging
bartekn 0d98106
Remove accounts and assets because no indexes
bartekn 733748a
Fix tests
bartekn da58f01
Fix, add tests
bartekn fe94271
Merge branch 'master' into reap-history-objects
bartekn f2a1438
revert maybeVerifyState fix
bartekn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package history_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stellar/go/services/horizon/internal/db2/history" | ||
"github.com/stellar/go/services/horizon/internal/ledger" | ||
"github.com/stellar/go/services/horizon/internal/reap" | ||
"github.com/stellar/go/services/horizon/internal/test" | ||
) | ||
|
||
func TestReapLookupTables(t *testing.T) { | ||
tt := test.Start(t) | ||
defer tt.Finish() | ||
ledgerState := &ledger.State{} | ||
ledgerState.SetStatus(tt.Scenario("kahuna")) | ||
|
||
db := tt.HorizonSession() | ||
|
||
sys := reap.New(0, db, ledgerState) | ||
|
||
var ( | ||
prevLedgers, curLedgers int | ||
prevClaimableBalances, curClaimableBalances int | ||
prevLiquidityPools, curLiquidityPools int | ||
) | ||
|
||
// Prev | ||
{ | ||
err := db.GetRaw(tt.Ctx, &prevLedgers, `SELECT COUNT(*) FROM history_ledgers`) | ||
tt.Require.NoError(err) | ||
err = db.GetRaw(tt.Ctx, &prevClaimableBalances, `SELECT COUNT(*) FROM history_claimable_balances`) | ||
tt.Require.NoError(err) | ||
err = db.GetRaw(tt.Ctx, &prevLiquidityPools, `SELECT COUNT(*) FROM history_liquidity_pools`) | ||
tt.Require.NoError(err) | ||
} | ||
|
||
ledgerState.SetStatus(tt.LoadLedgerStatus()) | ||
sys.RetentionCount = 1 | ||
err := sys.DeleteUnretainedHistory(tt.Ctx) | ||
tt.Require.NoError(err) | ||
|
||
q := &history.Q{tt.HorizonSession()} | ||
|
||
err = q.Begin() | ||
tt.Require.NoError(err) | ||
|
||
newOffsets, err := q.ReapLookupTables(tt.Ctx, nil) | ||
tt.Require.NoError(err) | ||
|
||
err = q.Commit() | ||
tt.Require.NoError(err) | ||
|
||
// cur | ||
{ | ||
err := db.GetRaw(tt.Ctx, &curLedgers, `SELECT COUNT(*) FROM history_ledgers`) | ||
tt.Require.NoError(err) | ||
err = db.GetRaw(tt.Ctx, &curClaimableBalances, `SELECT COUNT(*) FROM history_claimable_balances`) | ||
tt.Require.NoError(err) | ||
err = db.GetRaw(tt.Ctx, &curLiquidityPools, `SELECT COUNT(*) FROM history_liquidity_pools`) | ||
tt.Require.NoError(err) | ||
} | ||
|
||
tt.Assert.Equal(61, prevLedgers, "prevLedgers") | ||
tt.Assert.Equal(1, curLedgers, "curLedgers") | ||
tt.Assert.Equal(1, prevClaimableBalances, "prevClaimableBalances") | ||
tt.Assert.Equal(0, curClaimableBalances, "curClaimableBalances") | ||
tt.Assert.Equal(1, prevLiquidityPools, "prevLiquidityPools") | ||
tt.Assert.Equal(0, curLiquidityPools, "curLiquidityPools") | ||
|
||
tt.Assert.Len(newOffsets, 2) | ||
tt.Assert.Equal(int64(0), newOffsets["history_claimable_balances"]) | ||
tt.Assert.Equal(int64(0), newOffsets["history_liquidity_pools"]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting way to determine "age." It creates a dependence between the history tables, right? Is there a reason we don't rely on ledger close time, instead? I guess probably because
history_claimable_balances
doesn't have that row 😞There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really about age. The rows are sorted by
id
which is just a sequence integer value assigned to specific ledger object (like claimable balance). Thelimit ... offset
listing here is just to ensure we iterate over entire table in multiple cycles.