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#] Merge IAdvancedFunctions into IFunctions #565

Merged
merged 6 commits into from
Oct 14, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ ClientBin/
*.pfx
*.publishsettings
node_modules/
**/log-commits

# RIA/Silverlight projects
Generated_Code/
Expand Down
35 changes: 21 additions & 14 deletions cs/benchmark/Functions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

#pragma warning disable 1591

using System.Runtime.CompilerServices;
using System.Diagnostics;
using FASTER.core;
Expand All @@ -12,18 +10,25 @@ namespace FASTER.benchmark
public struct Functions : IFunctions<Key, Value, Input, Output, Empty>
{
readonly bool locking;
readonly bool postOps;

public Functions(bool locking) => this.locking = locking;
public Functions(bool locking, bool postOps = false)
{
this.locking = locking;
this.postOps = postOps;
}

public void RMWCompletionCallback(ref Key key, ref Input input, ref Output output, Empty ctx, Status status)
public bool SupportsPostOperations => this.postOps;

public void RMWCompletionCallback(ref Key key, ref Input input, ref Output output, Empty ctx, Status status, RecordMetadata recordMetadata)
{
}

public void ReadCompletionCallback(ref Key key, ref Input input, ref Output output, Empty ctx, Status status)
public void ReadCompletionCallback(ref Key key, ref Input input, ref Output output, Empty ctx, Status status, RecordMetadata recordMetadata)
{
}

public void UpsertCompletionCallback(ref Key key, ref Value value, Empty ctx)
public void UpsertCompletionCallback(ref Key key, ref Input input, ref Value value, Empty ctx)
{
}

Expand All @@ -38,54 +43,56 @@ public void CheckpointCompletionCallback(string sessionId, CommitPoint commitPoi

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

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

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

// Upsert functions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SingleWriter(ref Key key, ref Value src, ref Value dst)
public void SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref RecordInfo recordInfo, long address)
{
dst = src;
}

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

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

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool InPlaceUpdater(ref Key key, ref Input input, ref Value value, ref Output output)
public bool InPlaceUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RecordInfo recordInfo, long address)
{
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)
public void CopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RecordInfo recordInfo, long address)
{
newValue.value = input.value + oldValue.value;
}

public bool PostCopyUpdater(ref Key key, ref Input input, ref Value value, ref Output output) => true;
public bool PostCopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RecordInfo recordInfo, long address) => true;

public bool SupportsLocking => locking;

Expand Down
18 changes: 9 additions & 9 deletions cs/playground/AsyncStress/SerializedFasterWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public partial class SerializedFasterWrapper<Key, Value> : IFasterWrapper<Key, V
{
readonly FasterKV<SpanByte, SpanByte> _store;
readonly AsyncPool<ClientSession<SpanByte, SpanByte, SpanByte, SpanByteAndMemory, Empty, SpanByteFunctions>> _sessionPool;
readonly UpsertUpdater upsertUpdater = new UpsertUpdater();
readonly RmwUpdater rmwUpdater = new RmwUpdater();
readonly UpsertUpdater upsertUpdater = new();
readonly RmwUpdater rmwUpdater = new();
readonly bool useOsReadBuffering;
int pendingCount = 0;

Expand Down Expand Up @@ -101,7 +101,7 @@ public void Update<TUpdater, TAsyncResult>(TUpdater updater, Key key, Value valu
where TUpdater : IUpdater<TAsyncResult>
{
if (!_sessionPool.TryGet(out var session))
session = _sessionPool.GetAsync().GetAwaiter().GetResult();
session = _sessionPool.GetAsync().AsTask().GetAwaiter().GetResult();

byte[] keyBytes = MessagePackSerializer.Serialize(key);
byte[] valueBytes = MessagePackSerializer.Serialize(value);
Expand All @@ -128,7 +128,7 @@ public async ValueTask UpdateChunkAsync<TUpdater, TAsyncResult>(TUpdater updater
where TUpdater : IUpdater<TAsyncResult>
{
if (!_sessionPool.TryGet(out var session))
session = _sessionPool.GetAsync().GetAwaiter().GetResult();
session = _sessionPool.GetAsync().AsTask().GetAwaiter().GetResult();

for (var i = 0; i < count; ++i)
{
Expand Down Expand Up @@ -156,7 +156,7 @@ public async ValueTask UpdateChunkAsync<TUpdater, TAsyncResult>(TUpdater updater
public async ValueTask<(Status, Value)> ReadAsync(Key key)
{
if (!_sessionPool.TryGet(out var session))
session = await _sessionPool.GetAsync().ConfigureAwait(false);
session = await _sessionPool.GetAsync().AsTask().ConfigureAwait(false);

byte[] keyBytes = MessagePackSerializer.Serialize(key);
ValueTask<FasterKV<SpanByte, SpanByte>.ReadAsyncResult<SpanByte, SpanByteAndMemory, Empty>> task;
Expand All @@ -181,7 +181,7 @@ public async ValueTask UpdateChunkAsync<TUpdater, TAsyncResult>(TUpdater updater
public ValueTask<(Status, Value)> Read(Key key)
{
if (!_sessionPool.TryGet(out var session))
session = _sessionPool.GetAsync().GetAwaiter().GetResult();
session = _sessionPool.GetAsync().AsTask().GetAwaiter().GetResult();

byte[] keyBytes = MessagePackSerializer.Serialize(key);
(Status, SpanByteAndMemory) result;
Expand Down Expand Up @@ -220,7 +220,7 @@ public async ValueTask UpdateChunkAsync<TUpdater, TAsyncResult>(TUpdater updater
public async ValueTask<(Status, Value)[]> ReadChunkAsync(Key[] chunk, int offset, int count)
{
if (!_sessionPool.TryGet(out var session))
session = _sessionPool.GetAsync().GetAwaiter().GetResult();
session = _sessionPool.GetAsync().AsTask().GetAwaiter().GetResult();

// Reads in chunk are performed serially
(Status, Value)[] result = new (Status, Value)[count];
Expand All @@ -240,13 +240,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)
public unsafe override bool SingleReader(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref SpanByteAndMemory dst, ref RecordInfo recordInfo, long address)
{
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)
public unsafe override bool ConcurrentReader(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref SpanByteAndMemory dst, ref RecordInfo recordInfo, long address)
{
value.CopyTo(ref dst, MemoryPool<byte>.Shared);
return true;
Expand Down
2 changes: 1 addition & 1 deletion cs/playground/CacheStoreConcurrent/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public struct CacheContext
/// </summary>
public class CacheFunctions : SimpleFunctions<CacheKey, CacheValue, CacheContext>
{
public override void ReadCompletionCallback(ref CacheKey key, ref CacheValue input, ref CacheValue output, CacheContext ctx, Status status)
public override void ReadCompletionCallback(ref CacheKey key, ref CacheValue input, ref CacheValue output, CacheContext ctx, Status status, RecordMetadata recordMetadata)
{
if (ctx.type == 0)
{
Expand Down
6 changes: 3 additions & 3 deletions cs/playground/ClassRecoveryDurability/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,19 @@ 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)
public override bool SingleReader(ref StoreKey key, ref StoreInput input, ref StoreValue value, ref StoreOutput dst, ref RecordInfo recordInfo, long address)
{
dst.value = value;
return true;
}

public override bool ConcurrentReader(ref StoreKey key, ref StoreInput input, ref StoreValue value, ref StoreOutput dst)
public override bool ConcurrentReader(ref StoreKey key, ref StoreInput input, ref StoreValue value, ref StoreOutput dst, ref RecordInfo recordInfo, long address)
{
dst.value = value;
return true;
}

public override void ReadCompletionCallback(ref StoreKey key, ref StoreInput input, ref StoreOutput output, StoreContext ctx, Status status)
public override void ReadCompletionCallback(ref StoreKey key, ref StoreInput input, ref StoreOutput output, StoreContext ctx, Status status, RecordMetadata recordMetadata)
{
ctx.Populate(ref status, ref output);
}
Expand Down
10 changes: 5 additions & 5 deletions cs/playground/SumStore/SumStoreTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,31 @@ public override void CheckpointCompletionCallback(string sessionId, CommitPoint
}

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

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

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

public override bool InPlaceUpdater(ref AdId key, ref Input input, ref NumClicks value, ref Output output)
public override bool InPlaceUpdater(ref AdId key, ref Input input, ref NumClicks value, ref Output output, ref RecordInfo recordInfo, long address)
{
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)
public override void CopyUpdater(ref AdId key, ref Input input, ref NumClicks oldValue, ref NumClicks newValue, ref Output output, ref RecordInfo recordInfo, long address)
{
newValue.numClicks = oldValue.numClicks + input.numClicks.numClicks;
}
Expand Down
20 changes: 10 additions & 10 deletions cs/remote/samples/FixedLenServer/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ public struct Output
}


public struct Functions : IAdvancedFunctions<Key, Value, Input, Output, long>
public struct Functions : IFunctions<Key, Value, Input, Output, long>
{
// No locking needed for atomic types such as Value
public bool SupportsLocking => false;

// Callbacks
public void RMWCompletionCallback(ref Key key, ref Input input, ref Output output, long ctx, Status status) { }
public void RMWCompletionCallback(ref Key key, ref Input input, ref Output output, long ctx, Status status, RecordMetadata recordMetadata) { }

public void ReadCompletionCallback(ref Key key, ref Input input, ref Output output, long ctx, Status status, RecordInfo recordInfo) { }
public void ReadCompletionCallback(ref Key key, ref Input input, ref Output output, long ctx, Status status, RecordMetadata recordMetadata) { }

public void UpsertCompletionCallback(ref Key key, ref Value value, long ctx) { }
public void UpsertCompletionCallback(ref Key key, ref Input input, ref Value value, long ctx) { }

public void DeleteCompletionCallback(ref Key key, long ctx) { }

Expand All @@ -72,7 +72,7 @@ public void CheckpointCompletionCallback(string sessionId, CommitPoint commitPoi

// Read functions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool SingleReader(ref Key key, ref Input input, ref Value value, ref Output dst, long address)
public bool SingleReader(ref Key key, ref Input input, ref Value value, ref Output dst, ref RecordInfo recordInfo, long address)
{
dst.value = value;
return true;
Expand All @@ -87,18 +87,18 @@ public bool ConcurrentReader(ref Key key, ref Input input, ref Value value, ref

// Upsert functions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SingleWriter(ref Key key, ref Value src, ref Value dst) => dst = src;
public void SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref RecordInfo recordInfo, long address) => dst = src;

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

// RMW functions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void InitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output)
public void InitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RecordInfo recordInfo, long address)
{
value.value = input.value;
output.value = value;
Expand All @@ -120,12 +120,12 @@ public void CopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Va
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool PostCopyUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RecordInfo recordInfo, long address) => true;
public bool PostCopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RecordInfo recordInfo, long address) => true;

public void Lock(ref RecordInfo recordInfo, ref Key key, ref Value value, LockType lockType, ref long lockContext) { }

public bool Unlock(ref RecordInfo recordInfo, ref Key key, ref Value value, LockType lockType, long lockContext) => true;

public void ConcurrentDeleter(ref Key key, ref Value value, ref RecordInfo recordInfo, long address) { }
public bool ConcurrentDeleter(ref Key key, ref Value value, ref RecordInfo recordInfo, long address) => true;
}
}
2 changes: 1 addition & 1 deletion cs/remote/src/FASTER.server/BinaryServerSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace FASTER.server
{
internal unsafe sealed class BinaryServerSession<Key, Value, Input, Output, Functions, ParameterSerializer>
: FasterKVServerSessionBase<Key, Value, Input, Output, Functions, ParameterSerializer>
where Functions : IAdvancedFunctions<Key, Value, Input, Output, long>
where Functions : IFunctions<Key, Value, Input, Output, long>
where ParameterSerializer : IServerSerializer<Key, Value, Input, Output>
{
readonly HeaderReaderWriter hrw;
Expand Down
2 changes: 1 addition & 1 deletion cs/remote/src/FASTER.server/FasterKVProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace FASTER.server
/// <typeparam name="Functions"></typeparam>
/// <typeparam name="ParameterSerializer"></typeparam>
public sealed class FasterKVProvider<Key, Value, Input, Output, Functions, ParameterSerializer> : ISessionProvider
where Functions : IAdvancedFunctions<Key, Value, Input, Output, long>
where Functions : IFunctions<Key, Value, Input, Output, long>
where ParameterSerializer : IServerSerializer<Key, Value, Input, Output>
{
readonly FasterKV<Key, Value> store;
Expand Down
4 changes: 2 additions & 2 deletions cs/remote/src/FASTER.server/FasterKVServerSessionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace FASTER.server
{
internal abstract class FasterKVServerSessionBase<Key, Value, Input, Output, Functions, ParameterSerializer> : FasterKVServerSessionBase<Output>
where Functions : IAdvancedFunctions<Key, Value, Input, Output, long>
where Functions : IFunctions<Key, Value, Input, Output, long>
where ParameterSerializer : IServerSerializer<Key, Value, Input, Output>
{
protected readonly AdvancedClientSession<Key, Value, Input, Output, long, ServerKVFunctions<Key, Value, Input, Output, Functions>> session;
protected readonly ClientSession<Key, Value, Input, Output, long, ServerKVFunctions<Key, Value, Input, Output, Functions>> session;
protected readonly ParameterSerializer serializer;

public FasterKVServerSessionBase(Socket socket, FasterKV<Key, Value> store, Functions functions,
Expand Down
Loading