Skip to content

Commit

Permalink
avoid dividing by zero when calculating page (#2228)
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex authored Nov 6, 2024
1 parent 0d5d3e3 commit 42e3636
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 7 additions & 2 deletions flow/cmd/mirror_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,15 @@ func (h *FlowRequestHandler) CDCBatches(ctx context.Context, req *protos.GetCDCB
return nil, err
}

var page int32
if req.Limit != 0 {
page = rowsBehind/int32(req.Limit) + 1
}

return &protos.GetCDCBatchesResponse{
CdcBatches: batches,
Total: total,
Page: rowsBehind/int32(req.Limit) + 1,
Page: page,
}, nil
}

Expand Down Expand Up @@ -755,7 +760,7 @@ func (h *FlowRequestHandler) ListMirrorLogs(
}

page := req.Page
if page == 0 {
if page == 0 && req.NumPerPage != 0 {
page = rowsBehind/req.NumPerPage + 1
}

Expand Down
12 changes: 4 additions & 8 deletions flow/connectors/postgres/qrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func (c *PostgresConnector) getNumRowsPartitions(
config *protos.QRepConfig,
last *protos.QRepPartition,
) ([]*protos.QRepPartition, error) {
var err error
numRowsPerPartition := int64(config.NumRowsPerPartition)
quotedWatermarkColumn := QuoteIdentifier(config.WatermarkColumn)

Expand Down Expand Up @@ -116,7 +115,7 @@ func (c *PostgresConnector) getNumRowsPartitions(
}

var totalRows pgtype.Int8
if err = row.Scan(&totalRows); err != nil {
if err := row.Scan(&totalRows); err != nil {
return nil, fmt.Errorf("failed to query for total rows: %w", err)
}

Expand Down Expand Up @@ -177,19 +176,16 @@ func (c *PostgresConnector) getNumRowsPartitions(
return nil, fmt.Errorf("failed to scan row: %w", err)
}

err = partitionHelper.AddPartition(start, end)
if err != nil {
if err := partitionHelper.AddPartition(start, end); err != nil {
return nil, fmt.Errorf("failed to add partition: %w", err)
}
}

err = rows.Err()
if err != nil {
if err := rows.Err(); err != nil {
return nil, fmt.Errorf("failed to read rows: %w", err)
}

err = tx.Commit(ctx)
if err != nil {
if err := tx.Commit(ctx); err != nil {
return nil, fmt.Errorf("failed to commit transaction: %w", err)
}

Expand Down

0 comments on commit 42e3636

Please sign in to comment.