Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLIENT-3241] Throw exceptions when an MRT commit is called but transaction was already aborted and when an MRT abort is called but a transaction was already committed. #707

Merged
merged 8 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions aerospike-stubs/aerospike.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -295,17 +295,15 @@ QUERY_DURATION_LONG_RELAX_AP: Literal[2]

MRT_COMMIT_OK: Literal[0]
MRT_COMMIT_ALREADY_COMMITTED: Literal[1]
MRT_COMMIT_ALREADY_ABORTED: Literal[2]
MRT_COMMIT_VERIFY_FAILED: Literal[3]
MRT_COMMIT_MARK_ROLL_FORWARD_ABANDONED: Literal[4]
MRT_COMMIT_ROLL_FORWARD_ABANDONED: Literal[5]
MRT_COMMIT_CLOSE_ABANDONED: Literal[6]
MRT_COMMIT_VERIFY_FAILED: Literal[2]
MRT_COMMIT_MARK_ROLL_FORWARD_ABANDONED: Literal[3]
MRT_COMMIT_ROLL_FORWARD_ABANDONED: Literal[4]
MRT_COMMIT_CLOSE_ABANDONED: Literal[5]

MRT_ABORT_OK: Literal[0]
MRT_ABORT_ALREADY_COMMITTED: Literal[1]
MRT_ABORT_ALREADY_ABORTED: Literal[2]
MRT_ABORT_ROLL_BACK_ABANDONED: Literal[3]
MRT_ABORT_CLOSE_ABANDONED: Literal[4]
MRT_ABORT_ALREADY_ABORTED: Literal[1]
MRT_ABORT_ROLL_BACK_ABANDONED: Literal[2]
MRT_ABORT_CLOSE_ABANDONED: Literal[3]

MRT_STATE_OPEN: Literal[0]
MRT_STATE_VERIFIED: Literal[1]
Expand Down
9 changes: 9 additions & 0 deletions aerospike-stubs/exception.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ class InvalidHostError(ClientError):
class ParamError(ClientError):
pass

class TransactionFailed(ClientError):
pass

class TransactionAlreadyAborted(ClientError):
pass

class TransactionAlreadyCommitted(ClientError):
pass

class ServerError(AerospikeError):
pass

Expand Down
8 changes: 0 additions & 8 deletions doc/aerospike.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1589,10 +1589,6 @@ MRT Commit Status

Transaction has already been committed.

.. data:: MRT_COMMIT_ALREADY_ABORTED

Transaction has already been aborted.

.. data:: MRT_COMMIT_VERIFY_FAILED

Transaction verify failed. Transaction will be aborted.
Expand Down Expand Up @@ -1620,10 +1616,6 @@ MRT Abort Status

Abort succeeded.

.. data:: MRT_ABORT_ALREADY_COMMITTED

Transaction has already been committed.

.. data:: MRT_ABORT_ALREADY_ABORTED

Transaction has already been aborted.
Expand Down
24 changes: 24 additions & 0 deletions doc/exception.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,30 @@ Client Errors

Subclass of :py:exc:`~aerospike.exception.ClientError`.

.. py:exception:: TransactionFailed

Multi-record transaction failed.

Error code: ``-17``

Subclass of :py:exc:`~aerospike.exception.ClientError`.

.. py:exception:: TransactionAlreadyCommitted

Multi-record transaction abort called, but the transaction was already committed.

Error code: ``-18``

Subclass of :py:exc:`~aerospike.exception.ClientError`.

.. py:exception:: TransactionAlreadyAborted

Multi-record transaction commit called, but the transaction was already aborted.

Error code: ``-19``

Subclass of :py:exc:`~aerospike.exception.ClientError`.

Server Errors
-------------

Expand Down
3 changes: 0 additions & 3 deletions src/main/aerospike.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ static struct module_constant_name_to_value module_constants[] = {
{"MRT_COMMIT_OK", .value.integer = AS_COMMIT_OK},
{"MRT_COMMIT_ALREADY_COMMITTED",
.value.integer = AS_COMMIT_ALREADY_COMMITTED},
{"MRT_COMMIT_ALREADY_ABORTED", .value.integer = AS_COMMIT_ALREADY_ABORTED},
{"MRT_COMMIT_VERIFY_FAILED", .value.integer = AS_COMMIT_VERIFY_FAILED},
{"MRT_COMMIT_MARK_ROLL_FORWARD_ABANDONED",
.value.integer = AS_COMMIT_MARK_ROLL_FORWARD_ABANDONED},
Expand All @@ -513,8 +512,6 @@ static struct module_constant_name_to_value module_constants[] = {
{"MRT_COMMIT_CLOSE_ABANDONED", .value.integer = AS_COMMIT_CLOSE_ABANDONED},

{"MRT_ABORT_OK", .value.integer = AS_ABORT_OK},
{"MRT_ABORT_ALREADY_COMMITTED",
.value.integer = AS_ABORT_ALREADY_COMMITTED},
{"MRT_ABORT_ALREADY_ABORTED", .value.integer = AS_ABORT_ALREADY_ABORTED},
{"MRT_ABORT_ROLL_BACK_ABANDONED",
.value.integer = AS_ABORT_ROLL_BACK_ABANDONED},
Expand Down
7 changes: 6 additions & 1 deletion src/main/exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,13 @@ struct exception_def exception_defs[] = {
AEROSPIKE_ERR_ASYNC_CONNECTION, NULL),
EXCEPTION_DEF("ClientAbortError", CLIENT_ERR_EXCEPTION_NAME,
AEROSPIKE_ERR_CLIENT_ABORT, NULL),
EXCEPTION_DEF("TranactionFailed", CLIENT_ERR_EXCEPTION_NAME,
EXCEPTION_DEF("TransactionFailed", CLIENT_ERR_EXCEPTION_NAME,
AEROSPIKE_TXN_FAILED, NULL),
EXCEPTION_DEF("TransactionAlreadyCommitted", CLIENT_ERR_EXCEPTION_NAME,
AEROSPIKE_TXN_ALREADY_COMMITTED, NULL),
EXCEPTION_DEF("TransactionAlreadyAborted", CLIENT_ERR_EXCEPTION_NAME,
AEROSPIKE_TXN_ALREADY_ABORTED, NULL),

// Server errors
EXCEPTION_DEF("InvalidRequest", SERVER_ERR_EXCEPTION_NAME,
AEROSPIKE_ERR_REQUEST_INVALID, NULL),
Expand Down
8 changes: 4 additions & 4 deletions test/new_tests/test_mrt_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def test_commit_fail(self):
}
self.as_connection.put(self.keys[0], {self.bin_name: 1}, policy=policy)
self.as_connection.abort(mrt)
status = self.as_connection.commit(mrt)
assert status == aerospike.MRT_COMMIT_ALREADY_ABORTED
with pytest.raises(e.TransactionAlreadyAborted):
self.as_connection.commit(mrt)

# Test case 10: Issue abort after issung commit. (P1)
def test_abort_fail(self):
Expand All @@ -100,5 +100,5 @@ def test_abort_fail(self):
}
self.as_connection.put(self.keys[0], {self.bin_name: 1}, policy=policy)
self.as_connection.commit(mrt)
status = self.as_connection.abort(mrt)
assert status == aerospike.MRT_ABORT_ALREADY_COMMITTED
with pytest.raises(e.TransactionAlreadyCommitted):
self.as_connection.abort(mrt)
Loading