Skip to content

Commit a5c6356

Browse files
committed
Update SetOrderProcessing
1 parent 442e640 commit a5c6356

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

sa/sa.go

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -838,29 +838,22 @@ func (ssa *SQLStorageAuthority) SetOrderProcessing(ctx context.Context, req *sap
838838
if req.Id == 0 {
839839
return nil, errIncompleteRequest
840840
}
841-
_, overallError := db.WithTransaction(ctx, ssa.dbMap, func(tx db.Executor) (interface{}, error) {
842-
result, err := tx.ExecContext(ctx, `
843-
UPDATE orders
844-
SET beganProcessing = ?
845-
WHERE id = ?
846-
AND beganProcessing = ?`,
847-
true,
848-
req.Id,
849-
false)
850-
if err != nil {
851-
return nil, berrors.InternalServerError("error updating order to beganProcessing status")
852-
}
853841

854-
n, err := result.RowsAffected()
855-
if err != nil || n == 0 {
856-
return nil, berrors.OrderNotReadyError("Order was already processing. This may indicate your client finalized the same order multiple times, possibly due to a client bug.")
857-
}
842+
query := `UPDATE orders SET beganProcessing = ? WHERE id = ? AND beganProcessing = ?`
843+
if features.Get().WriteNewOrderSchema && looksLikeRandomID(req.Id, ssa.clk.Now()) {
844+
query = `UPDATE orders2 SET beganProcessing = ? WHERE id = ? AND beganProcessing = ?`
845+
}
858846

859-
return nil, nil
860-
})
861-
if overallError != nil {
862-
return nil, overallError
847+
result, err := ssa.dbMap.ExecContext(ctx, query, true, req.Id, false)
848+
if err != nil {
849+
return nil, berrors.InternalServerError("error updating order to beganProcessing status")
850+
}
851+
852+
n, err := result.RowsAffected()
853+
if err != nil || n == 0 {
854+
return nil, berrors.OrderNotReadyError("Order was already processing. This may indicate your client finalized the same order multiple times, possibly due to a client bug.")
863855
}
856+
864857
return &emptypb.Empty{}, nil
865858
}
866859

0 commit comments

Comments
 (0)