Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C#] Remove legacy SimpleVersionScheme #806

Merged
merged 2 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 0 additions & 114 deletions cs/src/core/Utilities/SimpleVersionScheme.cs

This file was deleted.

24 changes: 12 additions & 12 deletions cs/test/SimpleVersionSchemeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ internal class SimpleVersionSchemeTest
[Category("FasterLog")]
public void SimpleTest()
{
var tested = new SimpleVersionScheme();
var tested = new EpochProtectedVersionScheme(new LightEpoch());
var protectedVal = 0;
var v = tested.Enter();

Assert.AreEqual(1, v);
tested.TryAdvanceVersion((_, _) => protectedVal = 1);
Assert.AreEqual(1, v.Version);
tested.TryAdvanceVersionWithCriticalSection((_, _) => protectedVal = 1);
Thread.Sleep(10);
// because of ongoing protection, nothing should happen yet
tested.Leave();
Expand All @@ -27,37 +27,37 @@ public void SimpleTest()

// Next thread sees new version
v = tested.Enter();
Assert.AreEqual(v, 2);
Assert.AreEqual(v.Version, 2);
tested.Leave();
}

[Test]
[Category("FasterLog")]
public void SingleThreadTest()
{
var tested = new SimpleVersionScheme();
var tested = new EpochProtectedVersionScheme(new LightEpoch());
var protectedVal = 0;

var v = tested.Enter();
Assert.AreEqual(1, v);
Assert.AreEqual(1, v.Version);
tested.Leave();

tested.TryAdvanceVersion((_, _) => protectedVal = 1);
tested.TryAdvanceVersionWithCriticalSection((_, _) => protectedVal = 1);
Assert.AreEqual(1, protectedVal);

tested.TryAdvanceVersion((_, _) => protectedVal = 2, 4);
tested.TryAdvanceVersionWithCriticalSection((_, _) => protectedVal = 2, 4);
Assert.AreEqual(2, protectedVal);

v = tested.Enter();
Assert.AreEqual(4, v);
Assert.AreEqual(4, v.Version);
tested.Leave();
}

[Test]
[Category("FasterLog")]
public void LargeConcurrentTest()
{
var tested = new SimpleVersionScheme();
var tested = new EpochProtectedVersionScheme(new LightEpoch());
var protectedVal = 1L;
var termination = new ManualResetEventSlim();

Expand All @@ -71,7 +71,7 @@ public void LargeConcurrentTest()
while (!termination.IsSet)
{
var v = tested.Enter();
Assert.AreEqual(v, Interlocked.Read(ref protectedVal));
Assert.AreEqual(v.Version, Interlocked.Read(ref protectedVal));
tested.Leave();
}
});
Expand All @@ -81,7 +81,7 @@ public void LargeConcurrentTest()

for (var i = 0; i < 1000; i++)
{
tested.TryAdvanceVersion((vOld, vNew) =>
tested.TryAdvanceVersionWithCriticalSection((vOld, vNew) =>
{
Assert.AreEqual(vOld, Interlocked.Read(ref protectedVal));
// Flip sign to simulate critical section processing
Expand Down
8 changes: 4 additions & 4 deletions cs/test/SimulatedFlakyDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public class SimulatedFlakyDevice : StorageDeviceBase
private ErrorSimulationOptions options;
private ThreadLocal<Random> random;
private List<long> permanentlyFailedRangesStart, permanentlyFailedRangesEnd;
private SimpleVersionScheme versionScheme;
private EpochProtectedVersionScheme versionScheme;

public SimulatedFlakyDevice(IDevice underlying, ErrorSimulationOptions options) : base(underlying.FileName, underlying.SectorSize, underlying.Capacity)
{
this.underlying = underlying;
this.options = options;
permanentlyFailedRangesStart = new List<long>();
permanentlyFailedRangesEnd = new List<long>();
versionScheme = new SimpleVersionScheme();
versionScheme = new EpochProtectedVersionScheme(new LightEpoch());
random = new ThreadLocal<Random>(() => new Random());
}

Expand Down Expand Up @@ -73,7 +73,7 @@ public override void WriteAsync(IntPtr sourceAddress, int segmentId, ulong desti
else if (random.Value.NextDouble() < options.writePermanentErrorRate)
{
callback(42, numBytesToWrite, context);
versionScheme.TryAdvanceVersion((_, _) =>
versionScheme.TryAdvanceVersionWithCriticalSection((_, _) =>
{
var index = permanentlyFailedRangesStart.BinarySearch(logicalDestStart);
if (index >= 0)
Expand Down Expand Up @@ -129,7 +129,7 @@ public override void ReadAsync(int segmentId, ulong sourceAddress, IntPtr destin
{
callback(42, readLength, context);

versionScheme.TryAdvanceVersion((_, _) =>
versionScheme.TryAdvanceVersionWithCriticalSection((_, _) =>
{
var index = permanentlyFailedRangesStart.BinarySearch(logicalSrcStart);
if (index >= 0)
Expand Down