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#] Cancellation, ReadOptions, ReadFlags refactor #668

Merged
merged 12 commits into from
Mar 5, 2022
29 changes: 16 additions & 13 deletions cs/benchmark/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,68 +24,71 @@ public void CheckpointCompletionCallback(int sessionID, string sessionName, Comm

// Read functions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool SingleReader(ref Key key, ref Input input, ref Value value, ref Output dst, ref RecordInfo recordInfo, ref ReadInfo readInfo)
public bool SingleReader(ref Key key, ref Input input, ref Value value, ref Output dst, ref ReadInfo readInfo)
{
dst.value = value;
return true;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ConcurrentReader(ref Key key, ref Input input, ref Value value, ref Output dst, ref RecordInfo recordInfo, ref ReadInfo readInfo)
public bool ConcurrentReader(ref Key key, ref Input input, ref Value value, ref Output dst, ref ReadInfo readInfo)
{
dst.value = value;
return true;
}

public void SingleDeleter(ref Key key, ref Value value, ref RecordInfo recordInfo, ref DeleteInfo deleteInfo) { value = default; }
public bool SingleDeleter(ref Key key, ref Value value, ref DeleteInfo deleteInfo) { value = default; return true; }

public bool ConcurrentDeleter(ref Key key, ref Value value, ref RecordInfo recordInfo, ref DeleteInfo deleteInfo) => true;
public bool ConcurrentDeleter(ref Key key, ref Value value, ref DeleteInfo deleteInfo) => true;

// Upsert functions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, ref UpsertInfo upsertInfo, WriteReason reason)
public bool SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref UpsertInfo upsertInfo, WriteReason reason)
{
dst = src;
return true;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ConcurrentWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, ref UpsertInfo upsertInfo)
public bool ConcurrentWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref UpsertInfo upsertInfo)
{
dst = src;
return true;
}

// RMW functions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void InitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo)
public bool InitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RMWInfo rmwInfo)
{
value.value = input.value;
return true;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool InPlaceUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo)
public bool InPlaceUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RMWInfo rmwInfo)
{
value.value += input.value;
return true;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo)
public bool CopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RMWInfo rmwInfo)
{
newValue.value = input.value + oldValue.value;
return true;
}

public void PostCopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo) { }
public void PostCopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RMWInfo rmwInfo) { }

public bool NeedInitialUpdate(ref Key key, ref Input input, ref Output output, ref RMWInfo rmwInfo) => true;

public void PostInitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo) { }
public void PostInitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RMWInfo rmwInfo) { }

public bool NeedCopyUpdate(ref Key key, ref Input input, ref Value oldValue, ref Output output, ref RMWInfo rmwInfo) => true;

public void PostSingleDeleter(ref Key key, ref RecordInfo recordInfo, ref DeleteInfo deleteInfo) { }
public void PostSingleDeleter(ref Key key, ref DeleteInfo deleteInfo) { }

public void PostSingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, ref UpsertInfo upsertInfo, WriteReason reason) { }
public void PostSingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref UpsertInfo upsertInfo, WriteReason reason) { }

public void DisposeKey(ref Key key) { }

Expand Down
4 changes: 2 additions & 2 deletions cs/playground/AsyncStress/SerializedFasterWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,13 @@ public void Dispose()

public class SpanByteFunctions : SpanByteFunctions<SpanByte, SpanByteAndMemory, Empty>
{
public unsafe override bool SingleReader(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref SpanByteAndMemory dst, ref RecordInfo recordInfo, ref ReadInfo readInfo)
public unsafe override bool SingleReader(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref SpanByteAndMemory dst, ref ReadInfo readInfo)
{
value.CopyTo(ref dst, MemoryPool<byte>.Shared);
return true;
}

public unsafe override bool ConcurrentReader(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref SpanByteAndMemory dst, ref RecordInfo recordInfo, ref ReadInfo readInfo)
public unsafe override bool ConcurrentReader(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref SpanByteAndMemory dst, ref ReadInfo readInfo)
{
value.CopyTo(ref dst, MemoryPool<byte>.Shared);
return true;
Expand Down
4 changes: 2 additions & 2 deletions cs/playground/ClassRecoveryDurability/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ internal void FinalizeRead(ref Status status, ref StoreOutput output)

public sealed class StoreFunctions : FunctionsBase<StoreKey, StoreValue, StoreInput, StoreOutput, StoreContext>
{
public override bool SingleReader(ref StoreKey key, ref StoreInput input, ref StoreValue value, ref StoreOutput dst, ref RecordInfo recordInfo, ref ReadInfo readInfo)
public override bool SingleReader(ref StoreKey key, ref StoreInput input, ref StoreValue value, ref StoreOutput dst, ref ReadInfo readInfo)
{
dst.value = value;
return true;
}

public override bool ConcurrentReader(ref StoreKey key, ref StoreInput input, ref StoreValue value, ref StoreOutput dst, ref RecordInfo recordInfo, ref ReadInfo readInfo)
public override bool ConcurrentReader(ref StoreKey key, ref StoreInput input, ref StoreValue value, ref StoreOutput dst, ref ReadInfo readInfo)
{
dst.value = value;
return true;
Expand Down
155 changes: 78 additions & 77 deletions cs/playground/SumStore/SumStoreTypes.cs
Original file line number Diff line number Diff line change
@@ -1,77 +1,78 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Threading;
using FASTER.core;

namespace SumStore
{
public struct AdId : IFasterEqualityComparer<AdId>
{
public long adId;

public long GetHashCode64(ref AdId key)
{
return Utility.GetHashCode(key.adId);
}
public bool Equals(ref AdId k1, ref AdId k2)
{
return k1.adId == k2.adId;
}
}

public struct Input
{
public AdId adId;
public NumClicks numClicks;
}

public struct NumClicks
{
public long numClicks;
}

public struct Output
{
public NumClicks value;
}

public sealed class Functions : FunctionsBase<AdId, NumClicks, Input, Output, Empty>
{
public override void CheckpointCompletionCallback(int sessionID, string sessionName, CommitPoint commitPoint)
{
Console.WriteLine($"Session {sessionID} ({(sessionName ?? "null")}) reports persistence until {commitPoint.UntilSerialNo}");
}

// Read functions
public override bool SingleReader(ref AdId key, ref Input input, ref NumClicks value, ref Output dst, ref RecordInfo recordInfo, ref ReadInfo readInfo)
{
dst.value = value;
return true;
}

public override bool ConcurrentReader(ref AdId key, ref Input input, ref NumClicks value, ref Output dst, ref RecordInfo recordInfo, ref ReadInfo readInfo)
{
dst.value = value;
return true;
}

// RMW functions
public override void InitialUpdater(ref AdId key, ref Input input, ref NumClicks value, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo)
{
value = input.numClicks;
}

public override bool InPlaceUpdater(ref AdId key, ref Input input, ref NumClicks value, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo)
{
Interlocked.Add(ref value.numClicks, input.numClicks.numClicks);
return true;
}

public override void CopyUpdater(ref AdId key, ref Input input, ref NumClicks oldValue, ref NumClicks newValue, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo)
{
newValue.numClicks = oldValue.numClicks + input.numClicks.numClicks;
}
}
}
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Threading;
using FASTER.core;

namespace SumStore
{
public struct AdId : IFasterEqualityComparer<AdId>
{
public long adId;

public long GetHashCode64(ref AdId key)
{
return Utility.GetHashCode(key.adId);
}
public bool Equals(ref AdId k1, ref AdId k2)
{
return k1.adId == k2.adId;
}
}

public struct Input
{
public AdId adId;
public NumClicks numClicks;
}

public struct NumClicks
{
public long numClicks;
}

public struct Output
{
public NumClicks value;
}

public sealed class Functions : FunctionsBase<AdId, NumClicks, Input, Output, Empty>
{
public override void CheckpointCompletionCallback(int sessionID, string sessionName, CommitPoint commitPoint)
{
Console.WriteLine($"Session {sessionID} ({(sessionName ?? "null")}) reports persistence until {commitPoint.UntilSerialNo}");
}

// Read functions
public override bool SingleReader(ref AdId key, ref Input input, ref NumClicks value, ref Output dst, ref ReadInfo readInfo)
{
dst.value = value;
return true;
}

public override bool ConcurrentReader(ref AdId key, ref Input input, ref NumClicks value, ref Output dst, ref ReadInfo readInfo)
{
dst.value = value;
return true;
}

// RMW functions
public override bool InitialUpdater(ref AdId key, ref Input input, ref NumClicks value, ref Output output, ref RMWInfo rmwInfo)
{
value = input.numClicks;
return true;
}

public override bool InPlaceUpdater(ref AdId key, ref Input input, ref NumClicks value, ref Output output, ref RMWInfo rmwInfo)
{
Interlocked.Add(ref value.numClicks, input.numClicks.numClicks);
return true;
}

public override bool CopyUpdater(ref AdId key, ref Input input, ref NumClicks oldValue, ref NumClicks newValue, ref Output output, ref RMWInfo rmwInfo)
{
newValue.numClicks = oldValue.numClicks + input.numClicks.numClicks;
return true; }
}
}
Expand Down
32 changes: 19 additions & 13 deletions cs/remote/samples/FixedLenServer/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,68 +65,74 @@ public void CheckpointCompletionCallback(int sessionID, string sessionName, Comm

// Read functions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool SingleReader(ref Key key, ref Input input, ref Value value, ref Output dst, ref RecordInfo recordInfo, ref ReadInfo readInfo)
public bool SingleReader(ref Key key, ref Input input, ref Value value, ref Output dst, ref ReadInfo readInfo)
{
dst.value = value;
return true;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ConcurrentReader(ref Key key, ref Input input, ref Value value, ref Output dst, ref RecordInfo recordInfo, ref ReadInfo readInfo)
public bool ConcurrentReader(ref Key key, ref Input input, ref Value value, ref Output dst, ref ReadInfo readInfo)
{
dst.value = value;
return true;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, ref UpsertInfo upsertInfo, WriteReason reason) => dst = src;
public bool SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref UpsertInfo upsertInfo, WriteReason reason)
{
dst = src;
return true;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ConcurrentWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, ref UpsertInfo upsertInfo)
public bool ConcurrentWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref UpsertInfo upsertInfo)
{
dst = src;
return true;
}

// RMW functions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void InitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo)
public bool InitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RMWInfo rmwInfo)
{
value.value = input.value;
output.value = value;
return true;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool InPlaceUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo)
public bool InPlaceUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RMWInfo rmwInfo)
{
Interlocked.Add(ref value.value, input.value);
output.value = value;
return true;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo)
public bool CopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RMWInfo rmwInfo)
{
newValue.value = input.value + oldValue.value;
output.value = newValue;
return true;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PostCopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo) { }
public void PostCopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RMWInfo rmwInfo) { }

public bool NeedInitialUpdate(ref Key key, ref Input input, ref Output output, ref RMWInfo rmwInfo) => true;

public void PostInitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo) { }
public void PostInitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RMWInfo rmwInfo) { }

public bool NeedCopyUpdate(ref Key key, ref Input input, ref Value oldValue, ref Output output, ref RMWInfo rmwInfo) => true;

public void SingleDeleter(ref Key key, ref Value value, ref RecordInfo recordInfo, ref DeleteInfo deleteInfo) { }
public bool SingleDeleter(ref Key key, ref Value value, ref DeleteInfo deleteInfo) => true;

public void PostSingleDeleter(ref Key key, ref RecordInfo recordInfo, ref DeleteInfo deleteInfo) { }
public void PostSingleDeleter(ref Key key, ref DeleteInfo deleteInfo) { }

public void PostSingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, ref UpsertInfo upsertInfo, WriteReason reason) { }
public void PostSingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref UpsertInfo upsertInfo, WriteReason reason) { }

public bool ConcurrentDeleter(ref Key key, ref Value value, ref RecordInfo recordInfo, ref DeleteInfo deleteInfo) => true;
public bool ConcurrentDeleter(ref Key key, ref Value value, ref DeleteInfo deleteInfo) => true;

public void DisposeKey(ref Key key) { }

Expand Down
4 changes: 4 additions & 0 deletions cs/remote/src/FASTER.client/StatusCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ internal enum StatusCode : byte
/// </summary>
NotFound,
/// <summary>
/// The operation was canceled (e.g. by an IFunctions method setting info.CancelOperation).
/// </summary>
Canceled,
/// <summary>
/// Operation went pending (async)
/// </summary>
Pending,
Expand Down
Loading