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#] Add WriteReason parameter to SingleWriter #630

Merged
merged 6 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 2 additions & 8 deletions cs/benchmark/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ 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 Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
{
dst = src;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CopyWriter(ref Key key, ref Value src, ref Value dst, ref RecordInfo recordInfo, long address)
public void SingleWriter(WriteReason reason, ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
badrishc marked this conversation as resolved.
Show resolved Hide resolved
{
dst = src;
}
Expand Down Expand Up @@ -99,7 +93,7 @@ public void PostInitialUpdater(ref Key key, ref Input input, ref Value value, re

public void PostSingleDeleter(ref Key key, ref RecordInfo recordInfo, long address) { }

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

public void DisposeKey(ref Key key) { }

Expand Down
8 changes: 2 additions & 6 deletions cs/remote/samples/FixedLenServer/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,8 @@ public bool ConcurrentReader(ref Key key, ref Input input, ref Value value, ref
return true;
}

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

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address) => dst = src;
public void SingleWriter(WriteReason reason, ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address) => dst = src;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ConcurrentWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
Expand Down Expand Up @@ -132,7 +128,7 @@ public void SingleDeleter(ref Key key, ref Value value, ref RecordInfo recordInf

public void PostSingleDeleter(ref Key key, ref RecordInfo recordInfo, long address) { }

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

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

Expand Down
9 changes: 3 additions & 6 deletions cs/remote/src/FASTER.server/ServerKVFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,10 @@ public void RMWCompletionCallback(ref Key key, ref Input input, ref Output outpu
public bool SingleReader(ref Key key, ref Input input, ref Value value, ref Output dst, ref RecordInfo recordInfo, long address)
=> functions.SingleReader(ref key, ref input, ref value, ref dst, ref recordInfo, address);

public void SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
=> functions.SingleWriter(ref key, ref input, ref src, ref dst, ref output, ref recordInfo, address);
public void SingleWriter(WriteReason reason, ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
=> functions.SingleWriter(reason, ref key, ref input, ref src, ref dst, ref output, ref recordInfo, address);

public void PostSingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address) { }

public void CopyWriter(ref Key key, ref Value src, ref Value dst, ref RecordInfo recordInfo, long address)
=> functions.CopyWriter(ref key, ref src, ref dst, ref recordInfo, address);
public void PostSingleWriter(WriteReason reason, ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address) { }

public void UpsertCompletionCallback(ref Key key, ref Input input, ref Value value, long ctx)
=> functions.UpsertCompletionCallback(ref key, ref input, ref value, ctx);
Expand Down
2 changes: 1 addition & 1 deletion cs/samples/MemOnlyCache/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override bool ConcurrentWriter(ref CacheKey key, ref CacheValue input, re
return true;
}

public override void SingleWriter(ref CacheKey key, ref CacheValue input, ref CacheValue src, ref CacheValue dst, ref CacheValue output, ref RecordInfo recordInfo, long address)
public override void PostSingleWriter(WriteReason reason, ref CacheKey key, ref CacheValue input, ref CacheValue src, ref CacheValue dst, ref CacheValue output, ref RecordInfo recordInfo, long address)
{
dst = src;
sizeTracker.AddTrackedSize(key.GetSize + src.GetSize);
Expand Down
60 changes: 42 additions & 18 deletions cs/src/core/ClientSession/ClientSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,21 @@ public async ValueTask WaitForCommitAsync(CancellationToken token = default)
/// <param name="compactUntilAddress">Compact log until this address</param>
/// <param name="compactionType">Compaction type (whether we lookup records or scan log for liveness checking)</param>
/// <returns>Address until which compaction was done</returns>
public long Compact(long compactUntilAddress, CompactionType compactionType = CompactionType.Scan)
public long Compact(long compactUntilAddress, CompactionType compactionType = CompactionType.Scan)
=> Compact(compactUntilAddress, compactionType, default(DefaultCompactionFunctions<Key, Value>));

/// <summary>
/// Compact the log until specified address, moving active records to the tail of the log. BeginAddress is shifted, but the physical log
/// is not deleted from disk. Caller is responsible for truncating the physical log on disk by taking a checkpoint or calling Log.Truncate
/// </summary>
/// <param name="input">Input for SingleWriter</param>
/// <param name="output">Output from SingleWriter; it will be called all records that are moved, before Compact() returns, so the user must supply buffering or process each output completely</param>
/// <param name="compactUntilAddress">Compact log until this address</param>
/// <param name="compactionType">Compaction type (whether we lookup records or scan log for liveness checking)</param>
/// <returns>Address until which compaction was done</returns>
public long Compact(ref Input input, ref Output output, long compactUntilAddress, CompactionType compactionType = CompactionType.Scan)
=> Compact(ref input, ref output, compactUntilAddress, compactionType, default(DefaultCompactionFunctions<Key, Value>));

/// <summary>
/// Compact the log until specified address, moving active records to the tail of the log. BeginAddress is shifted, but the physical log
/// is not deleted from disk. Caller is responsible for truncating the physical log on disk by taking a checkpoint or calling Log.Truncate
Expand All @@ -703,7 +715,29 @@ public long Compact(long compactUntilAddress, CompactionType compactionType = Co
/// <returns>Address until which compaction was done</returns>
public long Compact<CompactionFunctions>(long untilAddress, CompactionType compactionType, CompactionFunctions compactionFunctions)
where CompactionFunctions : ICompactionFunctions<Key, Value>
=> fht.Compact<Input, Output, Context, Functions, CompactionFunctions>(functions, compactionFunctions, untilAddress, compactionType, new SessionVariableLengthStructSettings<Value, Input> { valueLength = variableLengthStruct, inputLength = inputVariableLengthStruct });
{
Input input = default;
Output output = default;
return fht.Compact<Input, Output, Context, Functions, CompactionFunctions>(functions, compactionFunctions, ref input, ref output, untilAddress, compactionType,
new SessionVariableLengthStructSettings<Value, Input> { valueLength = variableLengthStruct, inputLength = inputVariableLengthStruct });
}

/// <summary>
/// Compact the log until specified address, moving active records to the tail of the log. BeginAddress is shifted, but the physical log
/// is not deleted from disk. Caller is responsible for truncating the physical log on disk by taking a checkpoint or calling Log.Truncate
/// </summary>
/// <param name="input">Input for SingleWriter</param>
/// <param name="output">Output from SingleWriter; it will be called all records that are moved, before Compact() returns, so the user must supply buffering or process each output completely</param>
/// <param name="untilAddress">Compact log until this address</param>
/// <param name="compactionType">Compaction type (whether we lookup records or scan log for liveness checking)</param>
/// <param name="compactionFunctions">User provided compaction functions (see <see cref="ICompactionFunctions{Key, Value}"/>).</param>
/// <returns>Address until which compaction was done</returns>
public long Compact<CompactionFunctions>(ref Input input, ref Output output, long untilAddress, CompactionType compactionType, CompactionFunctions compactionFunctions)
where CompactionFunctions : ICompactionFunctions<Key, Value>
{
return fht.Compact<Input, Output, Context, Functions, CompactionFunctions>(functions, compactionFunctions, ref input, ref output, untilAddress, compactionType,
new SessionVariableLengthStructSettings<Value, Input> { valueLength = variableLengthStruct, inputLength = inputVariableLengthStruct });
}

/// <summary>
/// Copy key and value to tail, succeed only if key is known to not exist in between expectedLogicalAddress and tail.
Expand All @@ -714,12 +748,12 @@ public long Compact<CompactionFunctions>(long untilAddress, CompactionType compa
/// <param name="desiredValue"></param>
/// <param name="expectedLogicalAddress">Address of existing key (or upper bound)</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal OperationStatus CopyToTail(ref Key key, ref Input input, ref Value desiredValue, ref Output output, long expectedLogicalAddress)
internal OperationStatus CompactionCopyToTail(ref Key key, ref Input input, ref Value desiredValue, ref Output output, long expectedLogicalAddress)
{
if (SupportAsync) UnsafeResumeThread();
try
{
return fht.InternalCopyToTail(ref key, ref input, ref desiredValue, ref output, expectedLogicalAddress, FasterSession, ctx, noReadCache: true);
return fht.InternalCopyToTail(ref key, ref input, ref desiredValue, ref output, expectedLogicalAddress, FasterSession, ctx, WriteReason.Compaction);
}
finally
{
Expand Down Expand Up @@ -863,22 +897,12 @@ public void ReadCompletionCallback(ref Key key, ref Input input, ref Output outp

#region IFunctions - Upserts
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
=> _clientSession.functions.SingleWriter(ref key, ref input, ref src, ref dst, ref output, ref recordInfo, address);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PostSingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
=> _clientSession.functions.PostSingleWriter(ref key, ref input, ref src, ref dst, ref output, ref recordInfo, address);
public void SingleWriter(WriteReason reason, ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
=> _clientSession.functions.SingleWriter(reason, ref key, ref input, ref src, ref dst, ref output, ref recordInfo, address);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CopyWriter(ref Key key, ref Value src, ref Value dst, ref RecordInfo recordInfo, long address)
=> _clientSession.functions.CopyWriter(ref key, ref src, ref dst, ref recordInfo, address);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PostCopyWriter(ref Key key, ref Value src, ref Value dst, ref RecordInfo recordInfo, long address)
{
// TODO: Placeholder for indexing
}
public void PostSingleWriter(WriteReason reason, ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
=> _clientSession.functions.PostSingleWriter(reason, ref key, ref input, ref src, ref dst, ref output, ref recordInfo, address);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ConcurrentWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address, out bool lockFailed)
Expand Down
18 changes: 4 additions & 14 deletions cs/src/core/ClientSession/LockableUnsafeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,22 +509,12 @@ public void ReadCompletionCallback(ref Key key, ref Input input, ref Output outp

#region IFunctions - Upserts
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
=> _clientSession.functions.SingleWriter(ref key, ref input, ref src, ref dst, ref output, ref recordInfo, address);
public void SingleWriter(WriteReason reason, ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
=> _clientSession.functions.SingleWriter(reason, ref key, ref input, ref src, ref dst, ref output, ref recordInfo, address);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PostSingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
=> _clientSession.functions.PostSingleWriter(ref key, ref input, ref src, ref dst, ref output, ref recordInfo, address);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CopyWriter(ref Key key, ref Value src, ref Value dst, ref RecordInfo recordInfo, long address)
=> _clientSession.functions.CopyWriter(ref key, ref src, ref dst, ref recordInfo, address);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PostCopyWriter(ref Key key, ref Value src, ref Value dst, ref RecordInfo recordInfo, long address)
{
// TODO: Placeholder for indexing
}
public void PostSingleWriter(WriteReason reason, ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
=> _clientSession.functions.PostSingleWriter(reason, ref key, ref input, ref src, ref dst, ref output, ref recordInfo, address);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ConcurrentWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address, out bool lockFailed)
Expand Down
18 changes: 4 additions & 14 deletions cs/src/core/ClientSession/UnsafeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,22 +429,12 @@ public void ReadCompletionCallback(ref Key key, ref Input input, ref Output outp

#region IFunctions - Upserts
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
=> _clientSession.functions.SingleWriter(ref key, ref input, ref src, ref dst, ref output, ref recordInfo, address);
public void SingleWriter(WriteReason reason, ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
=> _clientSession.functions.SingleWriter(reason, ref key, ref input, ref src, ref dst, ref output, ref recordInfo, address);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PostSingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
=> _clientSession.functions.PostSingleWriter(ref key, ref input, ref src, ref dst, ref output, ref recordInfo, address);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CopyWriter(ref Key key, ref Value src, ref Value dst, ref RecordInfo recordInfo, long address)
=> _clientSession.functions.CopyWriter(ref key, ref src, ref dst, ref recordInfo, address);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PostCopyWriter(ref Key key, ref Value src, ref Value dst, ref RecordInfo recordInfo, long address)
{
// TODO: Placeholder for indexing
}
public void PostSingleWriter(WriteReason reason, ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address)
=> _clientSession.functions.PostSingleWriter(reason, ref key, ref input, ref src, ref dst, ref output, ref recordInfo, address);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ConcurrentWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, long address, out bool lockFailed)
Expand Down
Loading