Change BulkDelete error handling in transaction
Signed-off-by: Shubham Sharma <shubhash@microsoft.com>
This commit is contained in:
parent
e703874f42
commit
487e8bc089
|
@ -62,3 +62,21 @@ func NewETagError(kind ETagErrorKind, err error) *ETagError {
|
|||
kind: kind,
|
||||
}
|
||||
}
|
||||
|
||||
// BulkDeleteRowMismatchError represents mismatch in rowcount while deleting rows.
|
||||
type BulkDeleteRowMismatchError struct {
|
||||
expected uint64
|
||||
affected uint64
|
||||
}
|
||||
|
||||
func (e *BulkDeleteRowMismatchError) Error() string {
|
||||
return fmt.Sprintf("delete affected only %d rows, expected %d", e.affected, e.expected)
|
||||
}
|
||||
|
||||
// BulkDeleteRowMismatchError returns a BulkDeleteRowMismatchError.
|
||||
func NewBulkDeleteRowMismatchError(expected, affected uint64) *BulkDeleteRowMismatchError {
|
||||
return &BulkDeleteRowMismatchError{
|
||||
expected: expected,
|
||||
affected: affected,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -432,8 +432,9 @@ func (s *SQLServer) executeMulti(sets []state.SetRequest, deletes []state.Delete
|
|||
}
|
||||
|
||||
if len(deletes) > 0 {
|
||||
err = s.executeBulkDelete(tx, deletes)
|
||||
if err != nil {
|
||||
switch err = s.executeBulkDelete(tx, deletes); err.(type) {
|
||||
case nil, *state.BulkDeleteRowMismatchError:
|
||||
default:
|
||||
tx.Rollback()
|
||||
|
||||
return err
|
||||
|
@ -545,7 +546,7 @@ func (s *SQLServer) executeBulkDelete(db dbExecutor, req []state.DeleteRequest)
|
|||
}
|
||||
|
||||
if int(rows) != len(req) {
|
||||
err = fmt.Errorf("delete affected only %d rows, expected %d", rows, len(req))
|
||||
err = state.NewBulkDeleteRowMismatchError(uint64(rows), uint64(len(req)))
|
||||
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue