satellite/satellitedb: only reject orders if row not found

any database error doesn't mean the order wasn't found. for example
in cockroach it may say that the transaction is aborted. then what?
maybe we get big old row level deadlocks like we've observed? so
instead explicitly check for ErrNoRows to reject the order and bail
out otherwise. the surrounding logic will give it a retry.

Change-Id: I6e1f8f6e6a6def3e45b44f5088cbdc158e1098e4
This commit is contained in:
Jeff Wendling 2020-01-10 19:05:53 -07:00
parent 5a1b2f49f4
commit 4aef0e3823

View File

@ -251,9 +251,11 @@ func (db *ordersDB) processOrdersInTx(requests []*orders.ProcessOrderRequest, st
var serialNumberID int64
var bucketID []byte
if err := row.Scan(&serialNumberID, &bucketID); err != nil {
if err := row.Scan(&serialNumberID, &bucketID); err == sql.ErrNoRows {
rejected[request.OrderLimit.SerialNumber] = true
continue
} else if err != nil {
return nil, Error.Wrap(err)
}
var result sql.Result
@ -304,7 +306,7 @@ func (db *ordersDB) processOrdersInTx(requests []*orders.ProcessOrderRequest, st
}
_, err := tx.Exec(db.db.Rebind(`
INSERT INTO storagenode_bandwidth_rollups
INSERT INTO storagenode_bandwidth_rollups
(storagenode_id, interval_start, interval_seconds, action, allocated, settled)
VALUES (?, ?, ?, ?, ?, ?)
ON CONFLICT (storagenode_id, interval_start, action)
@ -352,7 +354,7 @@ func (db *ordersDB) processOrdersInTx(requests []*orders.ProcessOrderRequest, st
_, err = tx.Exec(db.db.Rebind(`
INSERT INTO bucket_bandwidth_rollups
(bucket_name, project_id, interval_start, interval_seconds, action, inline, allocated, settled)
(bucket_name, project_id, interval_start, interval_seconds, action, inline, allocated, settled)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (bucket_name, project_id, interval_start, action)
DO UPDATE SET settled = bucket_bandwidth_rollups.settled + ?