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

first pass at readonly / static cleanup #905

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
46 changes: 23 additions & 23 deletions cs/benchmark/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,91 9,91 @@ namespace FASTER.benchmark
{
public struct Functions : IFunctions<Key, Value, Input, Output, Empty>
{
public void RMWCompletionCallback(ref Key key, ref Input input, ref Output output, Empty ctx, Status status, RecordMetadata recordMetadata)
public readonly 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, RecordMetadata recordMetadata)
public readonly void ReadCompletionCallback(ref Key key, ref Input input, ref Output output, Empty ctx, Status status, RecordMetadata recordMetadata)
{
}

public void CheckpointCompletionCallback(int sessionID, string sessionName, CommitPoint commitPoint)
public readonly void CheckpointCompletionCallback(int sessionID, string sessionName, CommitPoint commitPoint)
{
Debug.WriteLine($"Session {sessionID} ({(sessionName ?? "null")}) reports persistence until {commitPoint.UntilSerialNo}");
}

// Read functions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool SingleReader(ref Key key, ref Input input, ref Value value, ref Output dst, ref ReadInfo readInfo)
public readonly 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 ReadInfo readInfo)
public readonly bool ConcurrentReader(ref Key key, ref Input input, ref Value value, ref Output dst, ref ReadInfo readInfo)
{
dst.value = value;
return true;
}

public bool SingleDeleter(ref Key key, ref Value value, ref DeleteInfo deleteInfo) { value = default; return true; }
public readonly 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 DeleteInfo deleteInfo) => true;
public readonly bool ConcurrentDeleter(ref Key key, ref Value value, ref DeleteInfo deleteInfo) => true;

// Upsert functions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool SingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref UpsertInfo upsertInfo, WriteReason reason)
public readonly 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 UpsertInfo upsertInfo)
public readonly 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 bool InitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RMWInfo rmwInfo)
public readonly 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 RMWInfo rmwInfo)
public readonly 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 bool CopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RMWInfo rmwInfo)
public readonly 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 RMWInfo rmwInfo) { }
public readonly 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 readonly 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 RMWInfo rmwInfo) { }
public readonly 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 readonly 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 DeleteInfo deleteInfo) { }
public readonly 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 UpsertInfo upsertInfo, WriteReason reason) { }
public readonly void PostSingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref UpsertInfo upsertInfo, WriteReason reason) { }

public void DisposeSingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref UpsertInfo upsertInfo, WriteReason reason) { }
public void DisposeCopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RMWInfo rmwInfo) { }
public void DisposeInitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RMWInfo rmwInfo) { }
public void DisposeSingleDeleter(ref Key key, ref Value value, ref DeleteInfo deleteInfo) { }
public void DisposeDeserializedFromDisk(ref Key key, ref Value value) { }
public readonly void DisposeSingleWriter(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref UpsertInfo upsertInfo, WriteReason reason) { }
public readonly void DisposeCopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RMWInfo rmwInfo) { }
public readonly void DisposeInitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RMWInfo rmwInfo) { }
public readonly void DisposeSingleDeleter(ref Key key, ref Value value, ref DeleteInfo deleteInfo) { }
public readonly void DisposeDeserializedFromDisk(ref Key key, ref Value value) { }
}
}
6 changes: 3 additions & 3 deletions cs/benchmark/Key.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 18,19 @@ public struct Key : IFasterEqualityComparer<Key>
public long value;


public override string ToString()
public override readonly string ToString()
{
return "{ " value " }";
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long GetHashCode64(ref Key k)
public readonly long GetHashCode64(ref Key k)
{
return Utility.GetHashCode(k.value);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(ref Key k1, ref Key k2)
public readonly bool Equals(ref Key k1, ref Key k2)
{
return k1.value == k2.value;
}
Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Allocator/AsyncIOContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 71,7 @@ public unsafe struct AsyncIOContext<Key, Value>
/// <summary>
/// Indicates whether this is a default instance with no pending operation
/// </summary>
public bool IsDefault() => this.callbackQueue is null && this.asyncOperation is null && this.completionEvent is null;
public readonly bool IsDefault() => this.callbackQueue is null && this.asyncOperation is null && this.completionEvent is null;

/// <summary>
/// Dispose
Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Allocator/MallocFixedPageSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 93,7 @@ public class MallocFixedPageSize<T> : IDisposable
private int checkpointCallbackCount;
private SemaphoreSlim checkpointSemaphore;

private ConcurrentQueue<long> freeList;
private readonly ConcurrentQueue<long> freeList;

readonly ILogger logger;

Expand Down
1 change: 1 addition & 0 deletions cs/src/core/Async/AsyncOperationInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 62,7 @@ internal sealed class AsyncOperationInternal<Input, Output, Context, TAsyncOpera
ExceptionDispatchInfo _exception;
readonly FasterKV<Key, Value> _fasterKV;
readonly IFasterSession<Key, Value, Input, Output, Context> _fasterSession;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Possible call side-effects?")]
TAsyncOperation _asyncOperation;
PendingContext<Input, Output, Context> _pendingContext;
int CompletionComputeStatus;
Expand Down
12 changes: 6 additions & 6 deletions cs/src/core/Async/DeleteAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 21,10 @@ internal DeleteAsyncOperation(ref DeleteOptions deleteOptions)
}

/// <inheritdoc/>
public DeleteAsyncResult<Input, Output, Context> CreateCompletedResult(Status status, Output output, RecordMetadata recordMetadata) => new DeleteAsyncResult<Input, Output, Context>(status);
public readonly DeleteAsyncResult<Input, Output, Context> CreateCompletedResult(Status status, Output output, RecordMetadata recordMetadata) => new DeleteAsyncResult<Input, Output, Context>(status);

/// <inheritdoc/>
public Status DoFastOperation(FasterKV<Key, Value> fasterKV, ref PendingContext<Input, Output, Context> pendingContext, IFasterSession<Key, Value, Input, Output, Context> fasterSession,
public readonly Status DoFastOperation(FasterKV<Key, Value> fasterKV, ref PendingContext<Input, Output, Context> pendingContext, IFasterSession<Key, Value, Input, Output, Context> fasterSession,
out Output output)
{
OperationStatus internalStatus;
Expand All @@ -39,12 39,12 @@ public Status DoFastOperation(FasterKV<Key, Value> fasterKV, ref PendingContext<
}

/// <inheritdoc/>
public ValueTask<DeleteAsyncResult<Input, Output, Context>> DoSlowOperation(FasterKV<Key, Value> fasterKV, IFasterSession<Key, Value, Input, Output, Context> fasterSession,
public readonly ValueTask<DeleteAsyncResult<Input, Output, Context>> DoSlowOperation(FasterKV<Key, Value> fasterKV, IFasterSession<Key, Value, Input, Output, Context> fasterSession,
PendingContext<Input, Output, Context> pendingContext, CancellationToken token)
=> SlowDeleteAsync(fasterKV, fasterSession, pendingContext, deleteOptions, token);

/// <inheritdoc/>
public bool HasPendingIO => false;
public readonly bool HasPendingIO => false;
}

/// <summary>
Expand Down Expand Up @@ -73,14 73,14 @@ internal DeleteAsyncResult(FasterKV<Key, Value> fasterKV, IFasterSession<Key, Va

/// <summary>Complete the Delete operation, issuing additional allocation asynchronously if needed. It is usually preferable to use Complete() instead of this.</summary>
/// <returns>ValueTask for Delete result. User needs to await again if result status is Status.PENDING.</returns>
public ValueTask<DeleteAsyncResult<Input, Output, Context>> CompleteAsync(CancellationToken token = default)
public readonly ValueTask<DeleteAsyncResult<Input, Output, Context>> CompleteAsync(CancellationToken token = default)
=> this.Status.IsPending
? updateAsyncInternal.CompleteAsync(token)
: new ValueTask<DeleteAsyncResult<Input, Output, Context>>(new DeleteAsyncResult<Input, Output, Context>(this.Status));

/// <summary>Complete the Delete operation, issuing additional I/O synchronously if needed.</summary>
/// <returns>Status of Delete operation</returns>
public Status Complete() => this.Status.IsPending ? updateAsyncInternal.CompleteSync().Status : this.Status;
public readonly Status Complete() => this.Status.IsPending ? updateAsyncInternal.CompleteSync().Status : this.Status;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
12 changes: 6 additions & 6 deletions cs/src/core/Async/RMWAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 23,7 @@ internal RmwAsyncOperation(AsyncIOContext<Key, Value> diskRequest, ref RMWOption
}

/// <inheritdoc/>
public RmwAsyncResult<Input, Output, Context> CreateCompletedResult(Status status, Output output, RecordMetadata recordMetadata) => new(status, output, recordMetadata);
public readonly RmwAsyncResult<Input, Output, Context> CreateCompletedResult(Status status, Output output, RecordMetadata recordMetadata) => new(status, output, recordMetadata);

/// <inheritdoc/>
public Status DoFastOperation(FasterKV<Key, Value> fasterKV, ref PendingContext<Input, Output, Context> pendingContext, IFasterSession<Key, Value, Input, Output, Context> fasterSession,
Expand All @@ -39,12 39,12 @@ public Status DoFastOperation(FasterKV<Key, Value> fasterKV, ref PendingContext<
}

/// <inheritdoc/>
public ValueTask<RmwAsyncResult<Input, Output, Context>> DoSlowOperation(FasterKV<Key, Value> fasterKV, IFasterSession<Key, Value, Input, Output, Context> fasterSession,
public readonly ValueTask<RmwAsyncResult<Input, Output, Context>> DoSlowOperation(FasterKV<Key, Value> fasterKV, IFasterSession<Key, Value, Input, Output, Context> fasterSession,
PendingContext<Input, Output, Context> pendingContext, CancellationToken token)
=> SlowRmwAsync(fasterKV, fasterSession, pendingContext, rmwOptions, diskRequest, token);

/// <inheritdoc/>
public bool HasPendingIO => !this.diskRequest.IsDefault();
public readonly bool HasPendingIO => !this.diskRequest.IsDefault();
}

/// <summary>
Expand Down Expand Up @@ -84,19 84,19 @@ internal RmwAsyncResult(FasterKV<Key, Value> fasterKV, IFasterSession<Key, Value

/// <summary>Complete the RMW operation, issuing additional (rare) I/O asynchronously if needed. It is usually preferable to use Complete() instead of this.</summary>
/// <returns>ValueTask for RMW result. User needs to await again if result status is pending.</returns>
public ValueTask<RmwAsyncResult<Input, TOutput, Context>> CompleteAsync(CancellationToken token = default)
public readonly ValueTask<RmwAsyncResult<Input, TOutput, Context>> CompleteAsync(CancellationToken token = default)
=> this.Status.IsPending
? updateAsyncInternal.CompleteAsync(token)
: new ValueTask<RmwAsyncResult<Input, TOutput, Context>>(new RmwAsyncResult<Input, TOutput, Context>(this.Status, this.Output, this.RecordMetadata));

/// <summary>Complete the RMW operation, issuing additional (rare) I/O synchronously if needed.</summary>
/// <returns>Status of RMW operation</returns>
public (Status status, TOutput output) Complete()
public readonly (Status status, TOutput output) Complete()
=> Complete(out _);

/// <summary>Complete the RMW operation, issuing additional (rare) I/O synchronously if needed.</summary>
/// <returns>Status of RMW operation</returns>
public (Status status, TOutput output) Complete(out RecordMetadata recordMetadata)
public readonly (Status status, TOutput output) Complete(out RecordMetadata recordMetadata)
{
if (!this.Status.IsPending)
{
Expand Down
10 changes: 5 additions & 5 deletions cs/src/core/Async/ReadAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 23,7 @@ internal ReadAsyncOperation(AsyncIOContext<Key, Value> diskRequest, ref ReadOpti
}

/// <inheritdoc/>
public ReadAsyncResult<Input, Output, Context> CreateCompletedResult(Status status, Output output, RecordMetadata recordMetadata) => new(status, output, recordMetadata);
public readonly ReadAsyncResult<Input, Output, Context> CreateCompletedResult(Status status, Output output, RecordMetadata recordMetadata) => new(status, output, recordMetadata);

/// <inheritdoc/>
public Status DoFastOperation(FasterKV<Key, Value> fasterKV, ref PendingContext<Input, Output, Context> pendingContext,
Expand All @@ -39,12 39,12 @@ public Status DoFastOperation(FasterKV<Key, Value> fasterKV, ref PendingContext<
}

/// <inheritdoc/>
public ValueTask<ReadAsyncResult<Input, Output, Context>> DoSlowOperation(FasterKV<Key, Value> fasterKV, IFasterSession<Key, Value, Input, Output, Context> fasterSession,
public readonly ValueTask<ReadAsyncResult<Input, Output, Context>> DoSlowOperation(FasterKV<Key, Value> fasterKV, IFasterSession<Key, Value, Input, Output, Context> fasterSession,
PendingContext<Input, Output, Context> pendingContext, CancellationToken token)
=> SlowReadAsync(fasterKV, fasterSession, pendingContext, this.readOptions, this.diskRequest, token);

/// <inheritdoc/>
public bool HasPendingIO => !this.diskRequest.IsDefault();
public readonly bool HasPendingIO => !this.diskRequest.IsDefault();
}

/// <summary>
Expand Down Expand Up @@ -83,12 83,12 @@ internal ReadAsyncResult(FasterKV<Key, Value> fasterKV, IFasterSession<Key, Valu

/// <summary>Complete the RMW operation, issuing additional (rare) I/O synchronously if needed.</summary>
/// <returns>Status of RMW operation</returns>
public (Status status, TOutput output) Complete()
public readonly (Status status, TOutput output) Complete()
=> Complete(out _);

/// <summary>Complete the RMW operation, issuing additional (rare) I/O synchronously if needed.</summary>
/// <returns>Status of RMW operation</returns>
public (Status status, TOutput output) Complete(out RecordMetadata recordMetadata)
public readonly (Status status, TOutput output) Complete(out RecordMetadata recordMetadata)
{
if (!this.Status.IsPending)
{
Expand Down
Loading