FDB1003: Byte-order atomic on a value that is not a little-endian number
| Analyzer | FoundationDB.Client |
| Severity | Warning (correctness) |
| Code fix | Yes |
Message
AtomicMax compares little-endian integers, and '{0}' is not one, so the stored value can be wrong. Use tr.Atomic(key, value, FdbMutationType.ByteMax) for a byte-order comparison (API level 520 or higher).
Why
AtomicMax and AtomicMin compare the stored value and the parameter as little-endian integers, padded or truncated to the parameter's length. Text, tuples, JSON, and UUIDs compare byte by byte, from the first byte, so the integer comparison picks the wrong winner and nothing fails: the database keeps the wrong value. FdbMutationType.ByteMax and ByteMin compare byte by byte, which is what these encodings need.
The rule reports the value argument when it is FdbValue.ToTextUtf8, ToTextUtf16, FromTuple, ToJson, ToUuid128, or Slice.FromString, FromStringUtf8, FromStringAscii, FromGuid, FromUuid128, FromUuid64, FromUuid96, FromUuid80, FromUuid48.
Bad
tr.AtomicMax(subspace.Key("name"), FdbValue.ToTextUtf8(name));
Good
tr.Atomic(subspace.Key("name"), FdbValue.ToTextUtf8(name), FdbMutationType.ByteMax);
Code fix
The fix rewrites the call to tr.Atomic(key, value, FdbMutationType.ByteMax) (ByteMin for AtomicMin). Atomic has no overload for a Slice key with a typed value such as FdbValue.ToTextUtf8(...); that shape is reported without a fix, and a typed key (subspace.Key(...)) or a Slice value takes the fix.
Suppress
#pragma warning disable FDB1003 // reason
or, for a whole project, in .editorconfig:
dotnet_diagnostic.FDB1003.severity = none