Skip to content

Commit

Permalink
- Remove ConcurrencyControlMode.NoLock. Oh, and while I'm at it, just…
Browse files Browse the repository at this point in the history
… remove ConcurrencyControlMode. (microsoft#448)

- Clean up ILockTable, OverflowBucketLockTable, InternalLock.cs, and LockableContext.cs to streamline the locking calls and clarify the current use of Transient vs. Manual

Co-authored-by: Badrish Chandramouli <[email protected]>
  • Loading branch information
TedHartMS and badrishc authored Jun 6, 2024
1 parent fcf880a commit 0acff38
Show file tree
Hide file tree
Showing 44 changed files with 348 additions and 1,904 deletions.
4 changes: 2 additions & 2 deletions libs/storage/Tsavorite/cs/benchmark/FixedLenYcsbBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ internal Tsavorite_YcsbBenchmark(Key[] i_keys_, Key[] t_keys_, TestLoader testLo
if (testLoader.Options.UseSmallMemoryLog)
store = new TsavoriteKV<Key, Value>
(testLoader.GetHashTableSize(), new LogSettings { LogDevice = device, PreallocateLog = true, PageSizeBits = 25, SegmentSizeBits = 30, MemorySizeBits = 28 },
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, concurrencyControlMode: testLoader.Options.ConcurrencyControlMode, revivificationSettings: revivificationSettings);
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, revivificationSettings: revivificationSettings);
else
store = new TsavoriteKV<Key, Value>
(testLoader.GetHashTableSize(), new LogSettings { LogDevice = device, PreallocateLog = true },
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, concurrencyControlMode: testLoader.Options.ConcurrencyControlMode, revivificationSettings: revivificationSettings);
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, revivificationSettings: revivificationSettings);
}

internal void Dispose()
Expand Down
8 changes: 1 addition & 7 deletions libs/storage/Tsavorite/cs/benchmark/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ class Options
"\n (Checkpoints are stored in directories under " + TestLoader.DataPath + " in directories named by distribution, ycsb vs. synthetic data, and key counts)")]
public bool BackupAndRestore { get; set; }

[Option('z', "locking", Required = false, Default = ConcurrencyControlMode.None,
HelpText = "Locking Implementation:" +
$"\n {nameof(ConcurrencyControlMode.None)} = No Locking (default)" +
$"\n {nameof(ConcurrencyControlMode.LockTable)} = Locking using main HashTable buckets")]
public ConcurrencyControlMode ConcurrencyControlMode { get; set; }

[Option('i', "iterations", Required = false, Default = 1,
HelpText = "Number of iterations of the test to run")]
public int IterationCount { get; set; }
Expand Down Expand Up @@ -118,7 +112,7 @@ public string GetOptionsString()
{
static string boolStr(bool value) => value ? "y" : "n";
return $"b: {Benchmark}; d: {DistributionName.ToLower()}; n: {NumaStyle}; rumd: {string.Join(',', RumdPercents)}; reviv: {RevivificationLevel}; revivbinrecs: {RevivBinRecordCount};"
+ $" revivfrac {RevivifiableFraction}; t: {ThreadCount}; z: {ConcurrencyControlMode}; i: {IterationCount}; hp: {HashPacking};"
+ $" revivfrac {RevivifiableFraction}; t: {ThreadCount}; i: {IterationCount}; hp: {HashPacking};"
+ $" sd: {boolStr(UseSmallData)}; sm: {boolStr(UseSmallMemoryLog)}; sy: {boolStr(UseSyntheticData)}; safectx: {boolStr(UseSafeContext)};"
+ $" chkptms: {PeriodicCheckpointMilliseconds}; chkpttype: {(PeriodicCheckpointMilliseconds > 0 ? PeriodicCheckpointType.ToString() : "None")};"
+ $" chkptincr: {boolStr(PeriodicCheckpointTryIncremental)}";
Expand Down
4 changes: 2 additions & 2 deletions libs/storage/Tsavorite/cs/benchmark/SpanByteYcsbBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ internal SpanByteYcsbBenchmark(KeySpanByte[] i_keys_, KeySpanByte[] t_keys_, Tes
if (testLoader.Options.UseSmallMemoryLog)
store = new TsavoriteKV<SpanByte, SpanByte>
(testLoader.GetHashTableSize(), new LogSettings { LogDevice = device, PreallocateLog = true, PageSizeBits = 22, SegmentSizeBits = 26, MemorySizeBits = 26 },
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, concurrencyControlMode: testLoader.Options.ConcurrencyControlMode, revivificationSettings: revivificationSettings);
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, revivificationSettings: revivificationSettings);
else
store = new TsavoriteKV<SpanByte, SpanByte>
(testLoader.GetHashTableSize(), new LogSettings { LogDevice = device, PreallocateLog = true, MemorySizeBits = 35 },
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, concurrencyControlMode: testLoader.Options.ConcurrencyControlMode, revivificationSettings: revivificationSettings);
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, revivificationSettings: revivificationSettings);
}

internal void Dispose()
Expand Down
31 changes: 4 additions & 27 deletions libs/storage/Tsavorite/cs/src/core/ClientSession/ClientSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,8 @@ internal ClientSession(
{
bContext = new(this);
uContext = new(this);

if (store.LockTable.IsEnabled)
{
lContext = new(this);
luContext = new(this);
}
lContext = new(this);
luContext = new(this);

this.loggerFactory = loggerFactory;
logger = loggerFactory?.CreateLogger($"ClientSession-{GetHashCode():X8}");
Expand Down Expand Up @@ -146,28 +142,12 @@ public void Dispose()
/// <summary>
/// Return a new interface to Tsavorite operations that supports manual locking and epoch control.
/// </summary>
public LockableUnsafeContext<Key, Value, Input, Output, Context, Functions> LockableUnsafeContext
{
get
{
if (!store.LockTable.IsEnabled)
throw new TsavoriteException($"LockableUnsafeContext requires {nameof(ConcurrencyControlMode.LockTable)}");
return luContext;
}
}
public LockableUnsafeContext<Key, Value, Input, Output, Context, Functions> LockableUnsafeContext => luContext;

/// <summary>
/// Return a session wrapper that supports manual locking.
/// </summary>
public LockableContext<Key, Value, Input, Output, Context, Functions> LockableContext
{
get
{
if (!store.LockTable.IsEnabled)
throw new TsavoriteException($"LockableContext requires {nameof(ConcurrencyControlMode.LockTable)}");
return lContext;
}
}
public LockableContext<Key, Value, Input, Output, Context, Functions> LockableContext => lContext;

/// <summary>
/// Return a session wrapper struct that passes through to client session
Expand Down Expand Up @@ -212,9 +192,6 @@ internal void ResetModified<TSessionFunctionsWrapper>(TSessionFunctionsWrapper s
}
}

/// <inheritdoc/>
public bool NeedKeyHash => store.LockTable.IsEnabled && store.LockTable.NeedKeyHash;

/// <inheritdoc/>
public int CompareKeyHashes<TLockableKey>(TLockableKey key1, TLockableKey key2) where TLockableKey : ILockableKey => store.LockTable.CompareKeyHashes(key1, key2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ public interface ILockableContext<TKey>
/// </summary>
void EndLockable();

/// <summary>
/// If true, then keys must use one of the <see cref="ITsavoriteContext{TKey}.GetKeyHash(ref TKey)"/> overloads to obtain a code by which groups of keys will be sorted for manual locking, to avoid deadlocks.
/// </summary>
/// <remarks>Whether this returns true depends on the <see cref="ConcurrencyControlMode"/> on <see cref="TsavoriteKVSettings{Key, Value}"/>, or passed to the TsavoriteKV constructor.</remarks>
bool NeedKeyHash { get; }

/// <summary>
/// Compare two structures that implement ILockableKey.
/// </summary>
Expand Down
Loading

0 comments on commit 0acff38

Please sign in to comment.