Skip to content

Commit

Permalink
workaround to fix zero getcount return value.
Browse files Browse the repository at this point in the history
  • Loading branch information
yokofly committed Oct 15, 2024
1 parent 7c50e8a commit b57dc6b
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions core/dbio/database/database_proton.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,15 +456,32 @@ func processProtonInsertRow(columns iop.Columns, row []any) []any {

// GetCount returns count of records
func (conn *ProtonConn) GetCount(tableFName string) (uint64, error) {
// wait for a while before getting count, otherwise newly added row can be 0
time.Sleep(countWaitDuration)
sql := fmt.Sprintf(`select count(*) as cnt from table(%s)`, tableFName)
data, err := conn.Self().Query(sql)
if err != nil {
g.LogError(err, "could not get row number")
return 0, err
var count uint64

// Retry logic to handle occasional zero count, likely due to database latency or transactional delays.
// Temporary workaround while investigating the root cause.
for attempt := 0; attempt < maxRetries; attempt++ {
sql := fmt.Sprintf(`select count(*) as cnt from table(%s)`, tableFName)
data, err := conn.Self().Query(sql)
if err != nil {
g.LogError(err, "could not get row number")
return 0, err
}

count = cast.ToUint64(data.Rows[0][0])
if count > 0 {
return count, nil
}

if attempt < maxRetries-1 {
g.Debug("Got zero count for %s, retrying in %v (attempt %d/%d)",
tableFName, countWaitDuration, attempt+1, maxRetries)
time.Sleep(countWaitDuration)
}
}
return cast.ToUint64(data.Rows[0][0]), nil

// Return 0 after max retries if no valid count is obtained
return count, nil
}

func (conn *ProtonConn) GetNativeType(col iop.Column) (nativeType string, err error) {
Expand Down

0 comments on commit b57dc6b

Please sign in to comment.