Skip to content

Commit 32d04e6

Browse files
authored
[C#] Replace LockingMode with ConcurrencyControlMode (#867)
* Replace LockingMode with ConcurrencyControlMode * Fix 'Remote' solution build
1 parent 4d5412b commit 32d04e6

38 files changed

+165
-165
lines changed

cs/benchmark/FasterSpanByteYcsbBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ internal FasterSpanByteYcsbBenchmark(KeySpanByte[] i_keys_, KeySpanByte[] t_keys
8080
if (testLoader.Options.UseSmallMemoryLog)
8181
store = new FasterKV<SpanByte, SpanByte>
8282
(testLoader.MaxKey / testLoader.Options.HashPacking, new LogSettings { LogDevice = device, PreallocateLog = true, PageSizeBits = 22, SegmentSizeBits = 26, MemorySizeBits = 26 },
83-
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, lockingMode: testLoader.LockingMode);
83+
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, concurrencyControlMode: testLoader.ConcurrencyControlMode);
8484
else
8585
store = new FasterKV<SpanByte, SpanByte>
8686
(testLoader.MaxKey / testLoader.Options.HashPacking, new LogSettings { LogDevice = device, PreallocateLog = true, MemorySizeBits = 35 },
87-
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, lockingMode: testLoader.LockingMode);
87+
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, concurrencyControlMode: testLoader.ConcurrencyControlMode);
8888
}
8989

9090
internal void Dispose()

cs/benchmark/FasterYcsbBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ internal FASTER_YcsbBenchmark(Key[] i_keys_, Key[] t_keys_, TestLoader testLoade
8080
if (testLoader.Options.UseSmallMemoryLog)
8181
store = new FasterKV<Key, Value>
8282
(testLoader.MaxKey / testLoader.Options.HashPacking, new LogSettings { LogDevice = device, PreallocateLog = true, PageSizeBits = 25, SegmentSizeBits = 30, MemorySizeBits = 28 },
83-
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, lockingMode: testLoader.LockingMode);
83+
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, concurrencyControlMode: testLoader.ConcurrencyControlMode);
8484
else
8585
store = new FasterKV<Key, Value>
8686
(testLoader.MaxKey / testLoader.Options.HashPacking, new LogSettings { LogDevice = device, PreallocateLog = true },
87-
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, lockingMode: testLoader.LockingMode);
87+
new CheckpointSettings { CheckpointDir = testLoader.BackupPath }, concurrencyControlMode: testLoader.ConcurrencyControlMode);
8888
}
8989

9090
internal void Dispose()

cs/benchmark/Options.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class Options
3636
[Option('z', "locking", Required = false, Default = 0,
3737
HelpText = "Locking Implementation:" +
3838
"\n 0 = None (default)" +
39-
"\n 1 = Mixed-mode locking using main HashTable buckets")]
40-
public int LockingMode { get; set; }
39+
"\n 1 = LockTable using main HashTable buckets")]
40+
public int ConcurrencyControlMode { get; set; }
4141

4242
[Option('i', "iterations", Required = false, Default = 1,
4343
HelpText = "Number of iterations of the test to run")]
@@ -100,7 +100,7 @@ class Options
100100
public string GetOptionsString()
101101
{
102102
static string boolStr(bool value) => value ? "y" : "n";
103-
return $"d: {DistributionName.ToLower()}; n: {NumaStyle}; rumd: {string.Join(',', RumdPercents)}; t: {ThreadCount}; z: {LockingMode}; i: {IterationCount}; hp: {HashPacking}"
103+
return $"d: {DistributionName.ToLower()}; n: {NumaStyle}; rumd: {string.Join(',', RumdPercents)}; t: {ThreadCount}; z: {ConcurrencyControlMode}; i: {IterationCount}; hp: {HashPacking}"
104104
+ $" sd: {boolStr(UseSmallData)}; sm: {boolStr(UseSmallMemoryLog)}; sy: {boolStr(this.UseSyntheticData)}; safectx: {boolStr(this.UseSafeContext)};"
105105
+ $" chkptms: {this.PeriodicCheckpointMilliseconds}; chkpttype: {(this.PeriodicCheckpointMilliseconds > 0 ? this.PeriodicCheckpointType.ToString() : "None")};"
106106
+ $" chkptincr: {boolStr(this.PeriodicCheckpointTryIncremental)}";

cs/benchmark/TestLoader.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TestLoader
2828
internal KeySpanByte[] txn_span_keys = default;
2929

3030
internal readonly BenchmarkType BenchmarkType;
31-
internal readonly LockingMode LockingMode;
31+
internal readonly ConcurrencyControlMode ConcurrencyControlMode;
3232
internal readonly long InitCount;
3333
internal readonly long TxnCount;
3434
internal readonly int MaxKey;
@@ -61,13 +61,13 @@ static bool verifyOption(bool isValid, string name, string info = null)
6161
if (!verifyOption(Options.NumaStyle >= 0 && Options.NumaStyle <= 1, "NumaStyle"))
6262
return;
6363

64-
this.LockingMode = Options.LockingMode switch
64+
this.ConcurrencyControlMode = Options.ConcurrencyControlMode switch
6565
{
66-
0 => LockingMode.None,
67-
1 => LockingMode.Standard,
68-
_ => throw new InvalidOperationException($"Unknown Locking mode int: {Options.LockingMode}")
66+
0 => ConcurrencyControlMode.None,
67+
1 => ConcurrencyControlMode.LockTable,
68+
_ => throw new InvalidOperationException($"Unknown Locking mode int: {Options.ConcurrencyControlMode}")
6969
};
70-
if (!verifyOption(Enum.IsDefined(typeof(LockingMode), this.LockingMode), "LockingMode"))
70+
if (!verifyOption(Enum.IsDefined(typeof(ConcurrencyControlMode), this.ConcurrencyControlMode), "ConcurrencyControlMode"))
7171
return;
7272

7373
if (!verifyOption(Options.IterationCount > 0, "Iteration Count"))

cs/remote/samples/FixedLenServer/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static void Main(string[] args)
3939
builder.SetMinimumLevel(LogLevel.Error);
4040
});
4141

42-
using var server = new FixedLenServer<Key, Value, Input, Output, Functions>(opts.GetServerOptions(), () => new Functions(), lockingMode: LockingMode.Standard);
42+
using var server = new FixedLenServer<Key, Value, Input, Output, Functions>(opts.GetServerOptions(), () => new Functions(), concurrencyControlMode: ConcurrencyControlMode.LockTable);
4343
server.Start();
4444
Console.WriteLine("Started server");
4545

cs/remote/src/FASTER.server/Servers/FixedLenServer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public sealed class FixedLenServer<Key, Value, Input, Output, Functions> : Gener
2323
/// </summary>
2424
/// <param name="opts"></param>
2525
/// <param name="functionsGen"></param>
26-
/// <param name="lockingMode"></param>
26+
/// <param name="concurrencyControlMode"></param>
2727
/// <param name="maxSizeSettings"></param>
2828
/// <param name="loggerFactory"></param>
29-
public FixedLenServer(ServerOptions opts, Func<Functions> functionsGen, LockingMode lockingMode, MaxSizeSettings maxSizeSettings = default, ILoggerFactory loggerFactory = null)
30-
: base(opts, functionsGen, new FixedLenSerializer<Key, Value, Input, Output>(), new FixedLenKeySerializer<Key, Input>(), lockingMode: lockingMode, maxSizeSettings, loggerFactory)
29+
public FixedLenServer(ServerOptions opts, Func<Functions> functionsGen, ConcurrencyControlMode concurrencyControlMode, MaxSizeSettings maxSizeSettings = default, ILoggerFactory loggerFactory = null)
30+
: base(opts, functionsGen, new FixedLenSerializer<Key, Value, Input, Output>(), new FixedLenKeySerializer<Key, Input>(), concurrencyControlMode: concurrencyControlMode, maxSizeSettings, loggerFactory)
3131
{
3232
}
3333
}

cs/remote/src/FASTER.server/Servers/GenericServer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public class GenericServer<Key, Value, Input, Output, Functions, ParameterSerial
3131
/// <param name="functionsGen"></param>
3232
/// <param name="serializer"></param>
3333
/// <param name="keyInputSerializer"></param>
34-
/// <param name="lockingMode"></param>
34+
/// <param name="concurrencyControlMode"></param>
3535
/// <param name="maxSizeSettings"></param>
3636
/// <param name="loggerFactory"></param>
37-
public GenericServer(ServerOptions opts, Func<Functions> functionsGen, ParameterSerializer serializer, IKeyInputSerializer<Key, Input> keyInputSerializer,
38-
LockingMode lockingMode, MaxSizeSettings maxSizeSettings = default, ILoggerFactory loggerFactory = null)
37+
public GenericServer(ServerOptions opts, Func<Functions> functionsGen, ParameterSerializer serializer, IKeyInputSerializer<Key, Input> keyInputSerializer,
38+
ConcurrencyControlMode concurrencyControlMode, MaxSizeSettings maxSizeSettings = default, ILoggerFactory loggerFactory = null)
3939
{
4040
this.opts = opts;
4141

@@ -45,7 +45,7 @@ public GenericServer(ServerOptions opts, Func<Functions> functionsGen, Parameter
4545
if (!Directory.Exists(opts.CheckpointDir))
4646
Directory.CreateDirectory(opts.CheckpointDir);
4747

48-
store = new FasterKV<Key, Value>(indexSize, logSettings, checkpointSettings, lockingMode: lockingMode, loggerFactory: loggerFactory);
48+
store = new FasterKV<Key, Value>(indexSize, logSettings, checkpointSettings, concurrencyControlMode: concurrencyControlMode, loggerFactory: loggerFactory);
4949

5050
if (opts.Recover)
5151
{

cs/remote/src/FASTER.server/Servers/VarLenServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public VarLenServer(ServerOptions opts, ILoggerFactory loggerFactory = null)
3737
if (!Directory.Exists(opts.CheckpointDir))
3838
Directory.CreateDirectory(opts.CheckpointDir);
3939

40-
store = new FasterKV<SpanByte, SpanByte>(indexSize, logSettings, checkpointSettings, lockingMode: LockingMode.Standard, loggerFactory: loggerFactory);
40+
store = new FasterKV<SpanByte, SpanByte>(indexSize, logSettings, checkpointSettings, concurrencyControlMode: ConcurrencyControlMode.LockTable, loggerFactory: loggerFactory);
4141

4242
if (!opts.DisablePubSub)
4343
{

cs/remote/test/FASTER.remote.test/TestUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static FixedLenServer<long, long, long, long, SimpleFunctions<long, long,
3434
Recover = tryRecover,
3535
IndexSize = "1m",
3636
};
37-
return new FixedLenServer<long, long, long, long, SimpleFunctions<long, long, long>>(opts, () => new SimpleFunctions<long, long, long>(merger), lockingMode: LockingMode.Standard);
37+
return new FixedLenServer<long, long, long, long, SimpleFunctions<long, long, long>>(opts, () => new SimpleFunctions<long, long, long>(merger), concurrencyControlMode: ConcurrencyControlMode.LockTable);
3838
}
3939

4040
/// <summary>

cs/samples/StoreVarLenTypes/AsciiSumSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void Run()
2828
// For this test we require record-level locking
2929
using var store = new FasterKV<SpanByte, SpanByte>(
3030
size: 1L << 20,
31-
logSettings: new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 12 }, lockingMode: LockingMode.Standard);
31+
logSettings: new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 12 }, concurrencyControlMode: ConcurrencyControlMode.LockTable);
3232

3333
// Create session for ASCII sums. We require two callback function types to be provided:
3434
// AsciiSumSpanByteFunctions implements RMW callback functions

cs/src/core/ClientSession/ClientSession.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public LockableUnsafeContext<Key, Value, Input, Output, Context, Functions> Lock
241241
get
242242
{
243243
if (!this.fht.LockTable.IsEnabled)
244-
throw new FasterException($"LockableUnsafeContext requires {nameof(LockingMode.Standard)}");
244+
throw new FasterException($"LockableUnsafeContext requires {nameof(ConcurrencyControlMode.LockTable)}");
245245
return luContext;
246246
}
247247
}
@@ -254,7 +254,7 @@ public LockableContext<Key, Value, Input, Output, Context, Functions> LockableCo
254254
get
255255
{
256256
if (!this.fht.LockTable.IsEnabled)
257-
throw new FasterException($"LockableContext requires {nameof(LockingMode.Standard)}");
257+
throw new FasterException($"LockableContext requires {nameof(ConcurrencyControlMode.LockTable)}");
258258
return lContext;
259259
}
260260
}

cs/src/core/ClientSession/ILockableContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface ILockableContext<TKey>
2525
/// <summary>
2626
/// If true, then keys must use one of the <see cref="IFasterContext{TKey}.GetKeyHash(ref TKey)"/> overloads to obtain a code by which groups of keys will be sorted for manual locking, to avoid deadlocks.
2727
/// </summary>
28-
/// <remarks>Whether this returns true depends on the <see cref="LockingMode"/> on <see cref="FasterKVSettings{Key, Value}"/>, or passed to the FasterKV constructor.</remarks>
28+
/// <remarks>Whether this returns true depends on the <see cref="ConcurrencyControlMode"/> on <see cref="FasterKVSettings{Key, Value}"/>, or passed to the FasterKV constructor.</remarks>
2929
bool NeedKeyHash { get; }
3030

3131
/// <summary>

cs/src/core/Index/Common/FasterKVSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public sealed class FasterKVSettings<Key, Value> : IDisposable
2424
/// <summary>
2525
/// How FASTER should do record locking
2626
/// </summary>
27-
public LockingMode LockingMode;
27+
public ConcurrencyControlMode ConcurrencyControlMode;
2828

2929
/// <summary>
3030
/// Device used for main hybrid log
@@ -199,7 +199,7 @@ public override string ToString()
199199
var retStr = $"index: {Utility.PrettySize(IndexSize)}; log memory: {Utility.PrettySize(MemorySize)}; log page: {Utility.PrettySize(PageSize)}; log segment: {Utility.PrettySize(SegmentSize)}";
200200
retStr += $"; log device: {(LogDevice == null ? "null" : LogDevice.GetType().Name)}";
201201
retStr += $"; obj log device: {(ObjectLogDevice == null ? "null" : ObjectLogDevice.GetType().Name)}";
202-
retStr += $"; mutable fraction: {MutableFraction}; locking mode: {this.LockingMode}";
202+
retStr += $"; mutable fraction: {MutableFraction}; locking mode: {this.ConcurrencyControlMode}";
203203
retStr += $"; read cache (rc): {(ReadCacheEnabled ? "yes" : "no")}";
204204
retStr += $"; read copy options: {ReadCopyOptions}";
205205
if (ReadCacheEnabled)

cs/src/core/Index/FASTER/FASTER.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public FasterKV(FasterKVSettings<Key, Value> fasterKVSettings) :
8787
fasterKVSettings.GetIndexSizeCacheLines(), fasterKVSettings.GetLogSettings(),
8888
fasterKVSettings.GetCheckpointSettings(), fasterKVSettings.GetSerializerSettings(),
8989
fasterKVSettings.EqualityComparer, fasterKVSettings.GetVariableLengthStructSettings(),
90-
fasterKVSettings.TryRecoverLatest, fasterKVSettings.LockingMode, null, fasterKVSettings.logger)
90+
fasterKVSettings.TryRecoverLatest, fasterKVSettings.ConcurrencyControlMode, null, fasterKVSettings.logger)
9191
{ }
9292

9393
/// <summary>
@@ -100,14 +100,14 @@ public FasterKV(FasterKVSettings<Key, Value> fasterKVSettings) :
100100
/// <param name="comparer">FASTER equality comparer for key</param>
101101
/// <param name="variableLengthStructSettings"></param>
102102
/// <param name="tryRecoverLatest">Try to recover from latest checkpoint, if any</param>
103-
/// <param name="lockingMode">How FASTER should do record locking</param>
103+
/// <param name="concurrencyControlMode">How FASTER should do record locking</param>
104104
/// <param name="loggerFactory">Logger factory to create an ILogger, if one is not passed in (e.g. from <see cref="FasterKVSettings{Key, Value}"/>).</param>
105105
/// <param name="logger">Logger to use.</param>
106106
/// <param name="lockTableSize">Number of buckets in the lock table</param>
107107
public FasterKV(long size, LogSettings logSettings,
108108
CheckpointSettings checkpointSettings = null, SerializerSettings<Key, Value> serializerSettings = null,
109109
IFasterEqualityComparer<Key> comparer = null,
110-
VariableLengthStructSettings<Key, Value> variableLengthStructSettings = null, bool tryRecoverLatest = false, LockingMode lockingMode = LockingMode.Standard,
110+
VariableLengthStructSettings<Key, Value> variableLengthStructSettings = null, bool tryRecoverLatest = false, ConcurrencyControlMode concurrencyControlMode = ConcurrencyControlMode.LockTable,
111111
ILoggerFactory loggerFactory = null, ILogger logger = null, int lockTableSize = Constants.kDefaultLockTableSize)
112112
{
113113
this.loggerFactory = loggerFactory;
@@ -134,8 +134,8 @@ public FasterKV(long size, LogSettings logSettings,
134134
}
135135
}
136136

137-
this.DoTransientLocking = lockingMode == LockingMode.Standard;
138-
this.DoEphemeralLocking = lockingMode == LockingMode.Ephemeral;
137+
this.DoTransientLocking = concurrencyControlMode == ConcurrencyControlMode.LockTable;
138+
this.DoEphemeralLocking = concurrencyControlMode == ConcurrencyControlMode.RecordIsolation;
139139

140140
if (checkpointSettings is null)
141141
checkpointSettings = new CheckpointSettings();
@@ -238,7 +238,7 @@ public FasterKV(long size, LogSettings logSettings,
238238
sectorSize = (int)logSettings.LogDevice.SectorSize;
239239
Initialize(size, sectorSize);
240240

241-
this.LockTable = new OverflowBucketLockTable<Key, Value>(lockingMode == LockingMode.Standard ? this : null);
241+
this.LockTable = new OverflowBucketLockTable<Key, Value>(concurrencyControlMode == ConcurrencyControlMode.LockTable ? this : null);
242242

243243
systemState = SystemState.Make(Phase.REST, 1);
244244

cs/src/core/Index/FASTER/FASTERIterator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public FasterKVIterator(FasterKV<Key, Value> fht, Functions functions, long unti
104104
}
105105

106106
tempKv = new FasterKV<Key, Value>(fht.IndexSize, new LogSettings { LogDevice = new NullDevice(), ObjectLogDevice = new NullDevice(), MutableFraction = 1 }, comparer: fht.Comparer,
107-
variableLengthStructSettings: variableLengthStructSettings, loggerFactory: loggerFactory, lockingMode: LockingMode.None);
107+
variableLengthStructSettings: variableLengthStructSettings, loggerFactory: loggerFactory, concurrencyControlMode: ConcurrencyControlMode.None);
108108
tempKvSession = tempKv.NewSession<Input, Output, Context, Functions>(functions);
109109
mainKvIter = fht.Log.Scan(fht.Log.BeginAddress, untilAddress);
110110
pushScanIterator = mainKvIter as IPushScanIterator<Key>;

cs/src/core/Index/FASTER/Implementation/Locking/OverflowBucketLockTable.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ internal struct OverflowBucketLockTable<TKey, TValue> : ILockTable<TKey>
1919
internal OverflowBucketLockTable(FasterKV<TKey, TValue> f) => this.fht = f;
2020

2121
[Conditional("DEBUG")]
22-
void AssertLockAllowed() => Debug.Assert(IsEnabled, $"Attempt to do Manual-locking lock when locking mode is not {LockingMode.Standard}");
22+
void AssertLockAllowed() => Debug.Assert(IsEnabled, $"Attempt to do Manual-locking lock when locking mode is not {ConcurrencyControlMode.LockTable}");
2323

2424
[Conditional("DEBUG")]
25-
void AssertUnlockAllowed() => Debug.Assert(IsEnabled, $"Attempt to do Manual-locking unlock when locking mode is not {LockingMode.Standard}");
25+
void AssertUnlockAllowed() => Debug.Assert(IsEnabled, $"Attempt to do Manual-locking unlock when locking mode is not {ConcurrencyControlMode.LockTable}");
2626

2727
[Conditional("DEBUG")]
28-
void AssertQueryAllowed() => Debug.Assert(IsEnabled, $"Attempt to do Manual-locking query when locking mode is not {LockingMode.Standard}");
28+
void AssertQueryAllowed() => Debug.Assert(IsEnabled, $"Attempt to do Manual-locking query when locking mode is not {ConcurrencyControlMode.LockTable}");
2929

3030
internal long GetSize() => fht.state[fht.resizeInfo.version].size_mask;
3131

0 commit comments

Comments
 (0)