Change BulkDelete error handling in transaction

Signed-off-by: Shubham Sharma <shubhash@microsoft.com>
This commit is contained in:
Shubham Sharma 2022-02-21 15:40:58 +05:30
parent e703874f42
commit 487e8bc089
2 changed files with 22 additions and 3 deletions

View File

@ -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,
}
}

View File

@ -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
}