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

Optionally do not throw exception from Touch command when record does not exist #137

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions AerospikeClient/Command/TouchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ protected internal override void ParseResult(IConnection conn)
return;
}

if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR)
{
if (writePolicy.failOnTouchRecordDoesNotExist)
{
throw new AerospikeException(resultCode);
}
return;
}

if (resultCode == ResultCode.FILTERED_OUT)
{
if (writePolicy.failOnFilteredOut)
Expand Down
16 changes: 14 additions & 2 deletions AerospikeClient/Policy/WritePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,18 @@ public sealed class WritePolicy : Policy
/// <para>Default: false (do not tombstone deleted records).</para>
/// </summary>
public bool durableDelete;


/// <summary>
/// Qualify how to handle touches when the record does not exist.
/// If true, throw <see cref="Aerospike.Client.AerospikeException"/>
/// with result code <seealso cref="Aerospike.Client.ResultCode.KEY_NOT_FOUND_ERROR"/>;
/// otherwise, do nothing.
/// <para>
/// Default: true
/// </para>
/// </summary>
public bool failOnTouchRecordDoesNotExist = true;

/// <summary>
/// Copy write policy from another write policy.
/// </summary>
Expand All @@ -113,7 +124,8 @@ public WritePolicy(WritePolicy other)
this.expiration = other.expiration;
this.respondAllOps = other.respondAllOps;
this.durableDelete = other.durableDelete;
}
this.failOnTouchRecordDoesNotExist = other.failOnTouchRecordDoesNotExist;
}

/// <summary>
/// Copy write policy from another policy.
Expand Down
14 changes: 13 additions & 1 deletion AerospikeTest/Sync/Basic/TestTouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ record = client.Get(null, key, bin.name);

record = client.Get(null, key, bin.name);
Assert.IsNull(record);
}

try
{
client.Touch(writePolicy, key);
Assert.Fail("Must throw ResultCode.KEY_NOT_FOUND_ERROR exception.");
}
catch (AerospikeException ex) when (ex.Result == ResultCode.KEY_NOT_FOUND_ERROR)
{
}

writePolicy.failOnTouchRecordDoesNotExist = false;
client.Touch(writePolicy, key);
}
}
}