Update known_gaps table name

This commit is contained in:
Abdul Rabbani 2022-03-31 14:11:57 -04:00
parent 359799dee2
commit 102f874c63
4 changed files with 12 additions and 12 deletions

View File

@ -103,7 +103,7 @@ func (db *DB) InsertIPLDsStm() string {
// InsertKnownGapsStm satisfies the sql.Statements interface
func (db *DB) InsertKnownGapsStm() string {
return `INSERT INTO eth.known_gaps (starting_block_number, ending_block_number, checked_out, processing_key) VALUES ($1, $2, $3, $4)
return `INSERT INTO eth_meta.known_gaps (starting_block_number, ending_block_number, checked_out, processing_key) VALUES ($1, $2, $3, $4)
ON CONFLICT (starting_block_number) DO UPDATE SET (ending_block_number, processing_key) = ($2, $4)
WHERE eth.known_gaps.ending_block_number <= $2`
WHERE eth_meta.known_gaps.ending_block_number <= $2`
}

View File

@ -148,7 +148,7 @@ type LogsModel struct {
Topic3 string `db:"topic3"`
}
// KnownGaps is the data structure for eth.known_gaps
// KnownGaps is the data structure for eth_meta.known_gaps
type KnownGapsModel struct {
StartingBlockNumber string `db:"starting_block_number"`
EndingBlockNumber string `db:"ending_block_number"`

View File

@ -30,10 +30,10 @@ import (
)
var (
knownGapsInsert = "INSERT INTO eth.known_gaps (starting_block_number, ending_block_number, checked_out, processing_key) " +
knownGapsInsert = "INSERT INTO eth_meta.known_gaps (starting_block_number, ending_block_number, checked_out, processing_key) " +
"VALUES ('%s', '%s', %t, %d) " +
"ON CONFLICT (starting_block_number) DO UPDATE SET (ending_block_number, processing_key) = ('%s', %d) " +
"WHERE eth.known_gaps.ending_block_number <= '%s';\n"
"WHERE eth_meta.known_gaps.ending_block_number <= '%s';\n"
dbQueryString = "SELECT MAX(block_number) FROM eth.header_cids"
defaultWriteFilePath = "./known_gaps.sql"
)
@ -191,7 +191,6 @@ func (kg *KnownGapsState) findAndUpdateGaps(latestBlockOnChain *big.Int, expecte
}
// Upserts known gaps to the DB.
// INSERT INTO eth.known_gaps (starting_block_number, ending_block_number, checked_out, processing_key) VALUES ($1, $2, $3, $4)
func (kg *KnownGapsState) upsertKnownGaps(knownGaps models.KnownGapsModel) error {
_, err := kg.db.Exec(context.Background(), kg.db.InsertKnownGapsStm(),
knownGaps.StartingBlockNumber, knownGaps.EndingBlockNumber, knownGaps.CheckedOut, knownGaps.ProcessingKey)
@ -202,6 +201,7 @@ func (kg *KnownGapsState) upsertKnownGaps(knownGaps models.KnownGapsModel) error
return nil
}
// Write upsert statement into a local file.
func (kg *KnownGapsState) upsertKnownGapsFile(knownGaps models.KnownGapsModel) error {
insertStmt := []byte(fmt.Sprintf(knownGapsInsert, knownGaps.StartingBlockNumber, knownGaps.EndingBlockNumber, knownGaps.CheckedOut, knownGaps.ProcessingKey,
knownGaps.EndingBlockNumber, knownGaps.ProcessingKey, knownGaps.EndingBlockNumber))

View File

@ -55,8 +55,8 @@ func testWriteToDb(t *testing.T, tests []gapValues, wipeDbBeforeStart bool) {
// Clear Table first, this is needed because we updated an entry to have a larger endblock number
// so we can't find the original start and endblock pair.
if wipeDbBeforeStart {
t.Log("Cleaning up eth.known_gaps table")
db.Exec(context.Background(), "DELETE FROM eth.known_gaps")
t.Log("Cleaning up eth_meta.known_gaps table")
db.Exec(context.Background(), "DELETE FROM eth_meta.known_gaps")
}
for _, tc := range tests {
@ -89,8 +89,8 @@ func testWriteToFile(t *testing.T, tests []gapValues, wipeDbBeforeStart bool) {
// Clear Table first, this is needed because we updated an entry to have a larger endblock number
// so we can't find the original start and endblock pair.
if wipeDbBeforeStart {
t.Log("Cleaning up eth.known_gaps table")
db.Exec(context.Background(), "DELETE FROM eth.known_gaps")
t.Log("Cleaning up eth_meta.known_gaps table")
db.Exec(context.Background(), "DELETE FROM eth_meta.known_gaps")
}
if _, err := os.Stat(knownGapsFilePath); err == nil {
err := os.Remove(knownGapsFilePath)
@ -133,7 +133,7 @@ func testFindAndUpdateGaps(t *testing.T, wipeDbBeforeStart bool) {
db := setupDb(t)
if wipeDbBeforeStart {
db.Exec(context.Background(), "DELETE FROM eth.known_gaps")
db.Exec(context.Background(), "DELETE FROM eth_meta.known_gaps")
}
knownGaps := KnownGapsState{
processingKey: 1,
@ -188,7 +188,7 @@ func createKnownErrorBlocks(knownErrorBlocks []*big.Int, knownErrorBlocksStart i
// Make sure the upsert was performed correctly
func validateUpsert(t *testing.T, service *Service, startingBlock int64, endingBlock int64) {
t.Logf("Starting to query blocks: %d - %d", startingBlock, endingBlock)
queryString := fmt.Sprintf("SELECT starting_block_number from eth.known_gaps WHERE starting_block_number = %d AND ending_block_number = %d", startingBlock, endingBlock)
queryString := fmt.Sprintf("SELECT starting_block_number from eth_meta.known_gaps WHERE starting_block_number = %d AND ending_block_number = %d", startingBlock, endingBlock)
_, queryErr := service.KnownGaps.queryDb(queryString) // Figure out the string.
t.Logf("Updated Known Gaps table starting from, %d, and ending at, %d", startingBlock, endingBlock)