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

TT-12780 prevent sql pump to panic when sharding enabled and skip api id is set #860

Merged
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
2 changes: 1 addition & 1 deletion pumps/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
endIndex := dataLen
// We iterate dataLen +1 times since we're writing the data after the date change on sharding_table:true
for i := 0; i <= dataLen; i++ {
if c.SQLConf.TableSharding {
if c.SQLConf.TableSharding && startIndex < len(typedData) {

Check failure on line 215 in pumps/sql.go

View workflow job for this annotation

GitHub Actions / golangci-lint

215-237 lines are duplicate of `pumps/sql.go:288-310` (dupl)
recDate := typedData[startIndex].TimeStamp.Format("20060102")
var nextRecDate string
// if we're on i == dataLen iteration, it means that we're out of index range. We're going to use the last record date.
Expand Down
20 changes: 20 additions & 0 deletions pumps/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,26 @@ func TestSQLWriteDataSharded(t *testing.T) {
assert.Equal(t, data.RowsLen, len(dbRecords))
})
}

t.Run("empty_keys", func(t *testing.T) {
emptyKeys := make([]interface{}, 0)
errWrite := pmp.WriteData(context.Background(), emptyKeys)
if errWrite != nil {
t.Fatal("SQL Pump couldn't write records with err:", errWrite)
}

// Check if any table has been created for the empty input case
tables := []string{
analytics.SQLTable + "_" + now.Format("20060102"),
analytics.SQLTable + "_" + nowPlus1.Format("20060102"),
analytics.SQLTable + "_" + nowPlus2.Format("20060102"),
}
for _, table := range tables {
t.Run("checking_"+table, func(t *testing.T) {
assert.Equal(t, false, pmp.db.Migrator().HasTable(table)) // No table should exist
})
}
})
}

func TestSQLWriteUptimeData(t *testing.T) {
Expand Down
Loading