Skip to content

Commit b3b4963

Browse files
authored
Fix kv wrong last sequence exception (#895)
* Add error code for wrong-last-sequence in KV * Fix KV wrong last revision exception * Retry create on revision errors * Revert "Retry create on revision errors" This reverts commit a3c16cb.
1 parent c78d24d commit b3b4963

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/NATS.Client.KeyValueStore/NatsKVException.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NATS.Client.JetStream;
2+
using NATS.Client.JetStream.Models;
23

34
namespace NATS.Client.KeyValueStore;
45

@@ -38,10 +39,11 @@ public NatsKVKeyDeletedException(ulong revision)
3839

3940
public class NatsKVWrongLastRevisionException : NatsKVException
4041
{
41-
public NatsKVWrongLastRevisionException()
42-
: base("Wrong last revision")
43-
{
44-
}
42+
public NatsKVWrongLastRevisionException(ApiError error)
43+
: base("Wrong last revision") =>
44+
Error = error;
45+
46+
public ApiError Error { get; }
4547
}
4648

4749
public class NatsKVCreateException : NatsKVException

src/NATS.Client.KeyValueStore/NatsKVStore.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,9 @@ private async ValueTask<NatsResult<ulong>> TryUpdateInternalAsync<T>(string key,
664664
if (publishResult.Success)
665665
{
666666
var ack = publishResult.Value;
667-
if (ack.Error is { ErrCode: 10071, Code: 400, Description: not null } && ack.Error.Description.StartsWith("wrong last sequence", StringComparison.OrdinalIgnoreCase))
667+
if (ack.Error is { ErrCode: 10071, Code: 400, Description: not null } or { ErrCode: 10164, Code: 400, Description: not null } && ack.Error.Description.StartsWith("wrong last sequence", StringComparison.OrdinalIgnoreCase))
668668
{
669-
return new NatsKVWrongLastRevisionException();
669+
return new NatsKVWrongLastRevisionException(ack.Error);
670670
}
671671
else if (ack.Error != null)
672672
{
@@ -725,9 +725,9 @@ private async ValueTask<NatsResult> TryDeleteInternalAsync(string key, TimeSpan
725725
if (publishResult.Success)
726726
{
727727
var ack = publishResult.Value;
728-
if (ack.Error is { ErrCode: 10071, Code: 400, Description: not null } && ack.Error.Description.StartsWith("wrong last sequence", StringComparison.OrdinalIgnoreCase))
728+
if (ack.Error is { ErrCode: 10071, Code: 400, Description: not null } or { ErrCode: 10164, Code: 400, Description: not null } && ack.Error.Description.StartsWith("wrong last sequence", StringComparison.OrdinalIgnoreCase))
729729
{
730-
return new NatsKVWrongLastRevisionException();
730+
return new NatsKVWrongLastRevisionException(ack.Error);
731731
}
732732
else if (ack.Error != null)
733733
{

0 commit comments

Comments
 (0)