Skip to content

Commit da593a6

Browse files
committed
Add overload SetVersionStampedKey(...) where the caller can manually specifiy the offset of the versionstamp
1 parent cecf0e4 commit da593a6

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

FoundationDB.Client/FdbTransactionExtensions.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,10 @@ private static int GetVersionStampOffset(Slice buffer, Slice token, string argNa
458458
return p;
459459
}
460460

461-
//TODO: XML Comments!
461+
/// <summary>Set the <paramref name="value"/> of the <paramref name="key"/> in the database, with the <see cref="VersionStamp"/> replaced by the resolved version at commit time.</summary>
462+
/// <param name="trans">Transaction to use for the operation</param>
463+
/// <param name="key">Name of the key whose value is to be mutated. This key must contain a single <see cref="VersionStamp"/>, whose position will be automatically detected.</param>
464+
/// <param name="value">New value for this key.</param>
462465
public static void SetVersionStampedKey([NotNull] this IFdbTransaction trans, Slice key, Slice value)
463466
{
464467
Contract.NotNull(trans, nameof(trans));
@@ -474,6 +477,25 @@ public static void SetVersionStampedKey([NotNull] this IFdbTransaction trans, Sl
474477
trans.Atomic(writer.ToSlice(), value, FdbMutationType.VersionStampedKey);
475478
}
476479

480+
/// <summary>Set the <paramref name="value"/> of the <paramref name="key"/> in the database, with the <see cref="VersionStamp"/> replaced by the resolved version at commit time.</summary>
481+
/// <param name="trans">Transaction to use for the operation</param>
482+
/// <param name="key">Name of the key whose value is to be mutated. This key must contain a single <see cref="VersionStamp"/>, whose start is defined by <paramref name="stampOffset"/>.</param>
483+
/// <param name="stampOffset">Offset within <paramref name="key"/> of the start of the 80-bit VersionStamp.</param>
484+
/// <param name="value">New value for this key.</param>
485+
public static void SetVersionStampedKey([NotNull] this IFdbTransaction trans, Slice key, int stampOffset, Slice value)
486+
{
487+
Contract.NotNull(trans, nameof(trans));
488+
489+
if (stampOffset > key.Count - 10) throw new ArgumentException("The VersionStamp overflows past the end of the key.", nameof(stampOffset));
490+
if (stampOffset > 0xFFFF) throw new ArgumentException("The offset is too large to fit within 16-bits.");
491+
492+
var writer = new SliceWriter(key.Count + 2);
493+
writer.WriteBytes(key);
494+
writer.WriteFixed16(checked((ushort) stampOffset)); //note: currently stored as 16-bits in Little Endian
495+
496+
trans.Atomic(writer.ToSlice(), value, FdbMutationType.VersionStampedKey);
497+
}
498+
477499
/// <summary>Set the <paramref name="value"/> of the <paramref name="key"/> in the database, with the first 10 bytes overwritten with the transaction's <see cref="VersionStamp"/>.</summary>
478500
/// <param name="trans">Transaction to use for the operation</param>
479501
/// <param name="key">Name of the key whose value is to be mutated.</param>

0 commit comments

Comments
 (0)