From 4aef0e38238d99347d8160c219981b58e4d04bb2 Mon Sep 17 00:00:00 2001 From: Jeff Wendling Date: Fri, 10 Jan 2020 19:05:53 -0700 Subject: [PATCH] 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 --- satellite/satellitedb/orders.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/satellite/satellitedb/orders.go b/satellite/satellitedb/orders.go index 0f54f775c..61c7c6681 100644 --- a/satellite/satellitedb/orders.go +++ b/satellite/satellitedb/orders.go @@ -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 + ?