Cette page n'est pas encore traduite. La version anglaise est affichée ci-dessous.
FDB1006: Version-stamped key written with Set
| Analyzer | FoundationDB.Client |
| Severity | Warning (correctness) |
| Code fix | Yes |
Message
The key contains a version stamp placeholder, and Set does not fill in the stamp. Use tr.SetVersionStampedKey(key, value) so the database fills it in at commit.
Why
tr.CreateVersionStamp() and tr.CreateUniqueVersionStamp() return a placeholder: the real stamp is known only when the transaction commits. SetVersionStampedKey tells the database where the placeholder sits in the key, and the database writes the committed version there. Set writes the placeholder bytes as they are, so every such write lands under the same incomplete key.
The rule reports Set when its key argument contains a call to CreateVersionStamp or CreateUniqueVersionStamp on the transaction, directly or through a local of the same method. A placeholder chosen by a condition (unresolved ? tr.CreateVersionStamp() : known, or ??) is not reported: it is in the key on one branch only, and code written that way calls SetVersionStampedKey on that branch and Set on the other.
Bad
var stamp = tr.CreateVersionStamp();
tr.Set(inbox.Key(stamp), payload);
Good
var stamp = tr.CreateVersionStamp();
tr.SetVersionStampedKey(inbox.Key(stamp), payload);
Code fix
The fix renames the call to SetVersionStampedKey.
Suppress
#pragma warning disable FDB1006 // reason
or, for a whole project, in .editorconfig:
dotnet_diagnostic.FDB1006.severity = none