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-3253: Throw exception when MRT commit called, but transaction was already aborted. Throw exception when MRT abort called, but transaction was already committed. #143

Merged
merged 1 commit into from
Jan 9, 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
8 changes: 3 additions & 5 deletions AerospikeClient/Async/AsyncClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 Aerospike, Inc.
* Copyright 2012-2025 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
Expand Down Expand Up @@ -183,8 +183,7 @@ public void Commit(CommitListener listener, Txn txn)
break;

case Txn.TxnState.ABORTED:
listener.OnSuccess(CommitStatus.CommitStatusType.ALREADY_ABORTED);
break;
throw new AerospikeException(ResultCode.TXN_ALREADY_ABORTED, "Transaction already aborted");

}
}
Expand Down Expand Up @@ -227,8 +226,7 @@ public void Abort(AbortListener listener, Txn txn)
break;

case Txn.TxnState.COMMITTED:
listener.OnSuccess(AbortStatus.AbortStatusType.ALREADY_COMMITTED);
break;
throw new AerospikeException(ResultCode.TXN_ALREADY_COMMITTED, "Transaction already committed");

case Txn.TxnState.ABORTED:
listener.OnSuccess(AbortStatus.AbortStatusType.ALREADY_ABORTED);
Expand Down
4 changes: 1 addition & 3 deletions AerospikeClient/Main/AbortStatus.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 Aerospike, Inc.
* Copyright 2012-2025 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
Expand All @@ -25,7 +25,6 @@ public static class AbortStatus
public enum AbortStatusType
{
OK,
ALREADY_COMMITTED,
ALREADY_ABORTED,
ROLL_BACK_ABANDONED,
CLOSE_ABANDONED
Expand All @@ -36,7 +35,6 @@ public static string AbortErrorToString(AbortStatusType status)
return status switch
{
AbortStatusType.OK => "Abort succeeded.",
AbortStatusType.ALREADY_COMMITTED => "Already committed.",
AbortStatusType.ALREADY_ABORTED => "Already aborted.",
AbortStatusType.ROLL_BACK_ABANDONED => "MRT client roll back abandoned. Server will eventually abort the MRT.",
AbortStatusType.CLOSE_ABANDONED => "MRT has been rolled back, but MRT client close was abandoned. Server will eventually close the MRT.",
Expand Down
8 changes: 4 additions & 4 deletions AerospikeClient/Main/AerospikeClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 Aerospike, Inc.
* Copyright 2012-2025 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
Expand Down Expand Up @@ -516,7 +516,7 @@ public CommitStatus.CommitStatusType Commit(Txn txn)
return CommitStatus.CommitStatusType.ALREADY_COMMITTED;

case Txn.TxnState.ABORTED:
return CommitStatus.CommitStatusType.ALREADY_ABORTED;
throw new AerospikeException(ResultCode.TXN_ALREADY_ABORTED, "Transaction already aborted");
}
}

Expand All @@ -540,8 +540,8 @@ public AbortStatus.AbortStatusType Abort(Txn txn)
return tr.Abort(txnRollPolicyDefault);

case Txn.TxnState.COMMITTED:
return AbortStatus.AbortStatusType.ALREADY_COMMITTED;
throw new AerospikeException(ResultCode.TXN_ALREADY_COMMITTED, "Transaction already committed");

case Txn.TxnState.ABORTED:
return AbortStatus.AbortStatusType.ALREADY_ABORTED;
}
Expand Down
4 changes: 1 addition & 3 deletions AerospikeClient/Main/CommitStatus.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 Aerospike, Inc.
* Copyright 2012-2025 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
Expand Down Expand Up @@ -28,7 +28,6 @@ public enum CommitStatusType
{
OK,
ALREADY_COMMITTED,
ALREADY_ABORTED,
ROLL_FORWARD_ABANDONED,
CLOSE_ABANDONED
}
Expand All @@ -39,7 +38,6 @@ public static string CommitErrorToString(CommitStatusType status)
{
CommitStatusType.OK => "Commit succeeded.",
CommitStatusType.ALREADY_COMMITTED => "Already committed.",
CommitStatusType.ALREADY_ABORTED => "Already aborted.",
CommitStatusType.ROLL_FORWARD_ABANDONED => "MRT client roll forward abandoned. Server will eventually commit the MRT.",
CommitStatusType.CLOSE_ABANDONED => "MRT has been rolled forward, but MRT client close was abandoned. Server will eventually close the MRT.",
_ => "Unexpected AbortStatusType."
Expand Down
24 changes: 21 additions & 3 deletions AerospikeClient/Main/ResultCode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 Aerospike, Inc.
* Copyright 2012-2025 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
Expand All @@ -22,7 +22,19 @@ namespace Aerospike.Client
/// Database operation error codes.
/// </summary>
public sealed class ResultCode
{
{
/// <summary>
/// Multi-record transaction commit called, but the transaction was already aborted.
/// Value: -19
/// </summary>
public const int TXN_ALREADY_ABORTED = -19;

/// <summary>
/// Multi-record transaction abort called, but the transaction was already committed.
/// Value: -18
/// </summary>
public const int TXN_ALREADY_COMMITTED = -18;

/// <summary>
/// Multi-record transaction failed.
/// Value: -17
Expand Down Expand Up @@ -592,7 +604,13 @@ public static bool KeepConnection(int resultCode)
public static string GetResultString(int resultCode)
{
switch (resultCode)
{
{
case TXN_ALREADY_ABORTED:
return "Multi-record transaction already aborted";

case TXN_ALREADY_COMMITTED:
return "Multi-record transaction already committed";

case TXN_FAILED:
return "Multi-record transaction failed";

Expand Down
20 changes: 17 additions & 3 deletions AerospikeTest/Async/TestAsyncTxn.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 Aerospike, Inc.
* Copyright 2012-2025 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
Expand Down Expand Up @@ -357,7 +357,7 @@ public void AsyncTxnWriteCommitAbort()
new Put(txn, key, "val2"),
new Commit(txn),
new GetExpect(null, key, "val2"),
new Abort(txn, AbortStatus.AbortStatusType.ALREADY_COMMITTED)
new Abort(txn, ResultCode.TXN_ALREADY_COMMITTED)
};

Execute(cmds);
Expand Down Expand Up @@ -578,6 +578,7 @@ public class Abort : Runner
{
private readonly Txn txn;
private readonly AbortStatusType status;
private readonly int resultCode = 0;

public Abort(Txn txn)
{
Expand All @@ -591,9 +592,22 @@ public Abort(Txn txn, AbortStatusType abortStatus)
this.status = abortStatus;
}

public Abort(Txn txn, int resultCode)
{
this.txn = txn;
this.resultCode = resultCode;
}

public void Run(TestAsyncTxn parent, Listener listener)
{
client.Abort(new AbortHandler(listener, status), txn);
try
{
client.Abort(new AbortHandler(listener, status), txn);
}
catch (Exception e)
{
parent.OnError(e, resultCode);
}
}

private class AbortHandler : AbortListener
Expand Down
15 changes: 12 additions & 3 deletions AerospikeTest/Sync/Basic/TestTxn.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 Aerospike, Inc.
* Copyright 2012-2025 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
Expand Down Expand Up @@ -498,8 +498,17 @@ public void TxnWriteCommitAbort()
record = client.Get(null, key);
AssertBinEqual(key, record, binName, "val2");

var abortStatus = client.Abort(txn);
Assert.AreEqual(AbortStatus.AbortStatusType.ALREADY_COMMITTED, abortStatus);
try
{
var abortStatus = client.Abort(txn);
}
catch (AerospikeException ae)
{
if (ae.Result != ResultCode.TXN_ALREADY_COMMITTED)
{
throw;
}
}
}

[TestMethod]
Expand Down
Loading