Skip to content

Commit

Permalink
[C#] Modified bit in FASTER (#743)
Browse files Browse the repository at this point in the history
* Add KeyHash to XxxInfo

* Add SessioonID to DeleteInfo

* Modified Bit and API

* Minor changes

Co-authored-by: Sajjad Rahnama <sajjad.rahnama7@gmail.com>
  • Loading branch information
badrishc and sajjadrahnama authored Sep 10, 2022
1 parent bc07dfb commit 02a8c1d
Show file tree
Hide file tree
Showing 10 changed files with 755 additions and 60 deletions.
10 changes: 10 additions & 0 deletions cs/src/core/ClientSession/BasicContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ public ValueTask<FasterKV<Key, Value>.DeleteAsyncResult<Input, Output, Context>>
public ValueTask<FasterKV<Key, Value>.DeleteAsyncResult<Input, Output, Context>> DeleteAsync(Key key, Context userContext = default, long serialNo = 0, CancellationToken token = default)
=> clientSession.DeleteAsync(key, userContext, serialNo, token);

/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ResetModified(ref Key key)
=> clientSession.ResetModified(ref key);

/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal bool IsModified(Key key)
=> clientSession.IsModified(ref key);

/// <inheritdoc/>
public void Refresh()
=> clientSession.Refresh();
Expand Down
75 changes: 64 additions & 11 deletions cs/src/core/ClientSession/ClientSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,47 @@ public async ValueTask ReadyToCompletePendingAsync(CancellationToken token = def

#region Other Operations

/// <inheritdoc/>
public unsafe void ResetModified(ref Key key)
{
UnsafeResumeThread();
try
{
OperationStatus status;
do
status = fht.InternalModifiedBitOperation(ref key, out _);
while (fht.HandleImmediateNonPendingRetryStatus(status, ctx, FasterSession));
}
finally
{
UnsafeSuspendThread();
}
}
/// <inheritdoc/>
public unsafe void ResetModified(Key key) => ResetModified(ref key);

/// <inheritdoc/>
internal unsafe bool IsModified(ref Key key)
{
RecordInfo modifiedInfo;
UnsafeResumeThread();
try
{
OperationStatus status;
do
status = fht.InternalModifiedBitOperation(ref key, out modifiedInfo, false);
while (fht.HandleImmediateNonPendingRetryStatus(status, ctx, FasterSession));
}
finally
{
UnsafeSuspendThread();
}
return modifiedInfo.Modified;
}

/// <inheritdoc/>
internal unsafe bool IsModified(Key key) => IsModified(ref key);

/// <summary>
/// Wait for commit of all operations completed until the current point in session.
/// Does not itself issue checkpoint/commits.
Expand Down Expand Up @@ -963,8 +1004,11 @@ public bool SingleWriter(ref Key key, ref Input input, ref Value src, ref Value
=> _clientSession.functions.SingleWriter(ref key, ref input, ref src, ref dst, ref output, ref upsertInfo, reason);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
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)
=> _clientSession.functions.PostSingleWriter(ref key, ref input, ref src, ref dst, ref output, ref upsertInfo, reason);
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)
{
recordInfo.SetDirtyAndModified();
_clientSession.functions.PostSingleWriter(ref key, ref input, ref src, ref dst, ref output, ref upsertInfo, reason);
}

[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, out bool lockFailed)
Expand All @@ -978,7 +1022,7 @@ public bool ConcurrentWriter(ref Key key, ref Input input, ref Value src, ref Va
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool ConcurrentWriterNoLock(ref Key key, ref Input input, ref Value src, ref Value dst, ref Output output, ref RecordInfo recordInfo, ref UpsertInfo upsertInfo)
{
recordInfo.SetDirty();
recordInfo.SetDirtyAndModified();
// Note: KeyIndexes do not need notification of in-place updates because the key does not change.
return _clientSession.functions.ConcurrentWriter(ref key, ref input, ref src, ref dst, ref output, ref upsertInfo);
}
Expand Down Expand Up @@ -1014,8 +1058,11 @@ public bool InitialUpdater(ref Key key, ref Input input, ref Value value, ref Ou
=> _clientSession.functions.InitialUpdater(ref key, ref input, ref value, ref output, ref rmwInfo);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PostInitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo)
=> _clientSession.functions.PostInitialUpdater(ref key, ref input, ref value, ref output, ref rmwInfo);
public void PostInitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo)
{
recordInfo.SetDirtyAndModified();
_clientSession.functions.PostInitialUpdater(ref key, ref input, ref value, ref output, ref rmwInfo);
}
#endregion InitialUpdater

#region CopyUpdater
Expand All @@ -1028,8 +1075,11 @@ public bool CopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Va
=> _clientSession.functions.CopyUpdater(ref key, ref input, ref oldValue, ref newValue, ref output, ref rmwInfo);

[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)
=> _clientSession.functions.PostCopyUpdater(ref key, ref input, ref oldValue, ref newValue, ref output, ref rmwInfo);
public void PostCopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Value newValue, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo)
{
recordInfo.SetDirtyAndModified();
_clientSession.functions.PostCopyUpdater(ref key, ref input, ref oldValue, ref newValue, ref output, ref rmwInfo);
}
#endregion CopyUpdater

#region InPlaceUpdater
Expand All @@ -1043,8 +1093,11 @@ public bool InPlaceUpdater(ref Key key, ref Input input, ref Value value, ref Ou
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool InPlaceUpdaterNoLock(ref Key key, ref Input input, ref Output output, ref Value value, ref RecordInfo recordInfo, ref RMWInfo rmwInfo, out OperationStatus status)
=> _clientSession.InPlaceUpdater(ref key, ref input, ref output, ref value, ref recordInfo, ref rmwInfo, out status);
private bool InPlaceUpdaterNoLock(ref Key key, ref Input input, ref Output output, ref Value value, ref RecordInfo recordInfo, ref RMWInfo rmwInfo, out OperationStatus status)
{
recordInfo.SetDirtyAndModified();
return _clientSession.InPlaceUpdater(ref key, ref input, ref output, ref value, ref recordInfo, ref rmwInfo, out status);
}

private bool InPlaceUpdaterLock(ref Key key, ref Input input, ref Output output, ref Value value, ref RecordInfo recordInfo, ref RMWInfo rmwInfo, out bool lockFailed, out OperationStatus status)
{
Expand Down Expand Up @@ -1084,7 +1137,7 @@ public bool SingleDeleter(ref Key key, ref Value value, ref RecordInfo recordInf
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PostSingleDeleter(ref Key key, ref RecordInfo recordInfo, ref DeleteInfo deleteInfo)
{
recordInfo.SetDirty();
recordInfo.SetDirtyAndModified();
_clientSession.functions.PostSingleDeleter(ref key, ref deleteInfo);
}

Expand All @@ -1100,7 +1153,7 @@ public bool ConcurrentDeleter(ref Key key, ref Value value, ref RecordInfo recor
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool ConcurrentDeleterNoLock(ref Key key, ref Value value, ref RecordInfo recordInfo, ref DeleteInfo deleteInfo)
{
recordInfo.SetDirty();
recordInfo.SetDirtyAndModified();
recordInfo.SetTombstone();
return _clientSession.functions.ConcurrentDeleter(ref key, ref value, ref deleteInfo);
}
Expand Down
7 changes: 7 additions & 0 deletions cs/src/core/ClientSession/IFasterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,13 @@ ValueTask<FasterKV<Key, Value>.ReadAsyncResult<Input, Output, Context>> ReadAtAd
/// to complete the Upsert operation. Failure to complete the operation will result in leaked allocations.</remarks>
ValueTask<FasterKV<Key, Value>.DeleteAsyncResult<Input, Output, Context>> DeleteAsync(Key key, Context userContext = default, long serialNo = 0, CancellationToken token = default);


/// <summary>
/// Reset the modified bit of a record (for in memory records)
/// </summary>
/// <param name="key"></param>
void ResetModified(ref Key key);

/// <summary>
/// Refresh session epoch and handle checkpointing phases. Used only
/// in case of thread-affinitized sessions (async support is disabled).
Expand Down
32 changes: 26 additions & 6 deletions cs/src/core/ClientSession/LockableContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,16 @@ public ValueTask<FasterKV<Key, Value>.DeleteAsyncResult<Input, Output, Context>>
public ValueTask<FasterKV<Key, Value>.DeleteAsyncResult<Input, Output, Context>> DeleteAsync(Key key, Context userContext = default, long serialNo = 0, CancellationToken token = default)
=> DeleteAsync(ref key, userContext, serialNo, token);

/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ResetModified(ref Key key)
=> clientSession.ResetModified(ref key);

/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal bool IsModified(Key key)
=> clientSession.IsModified(ref key);

/// <inheritdoc/>
public void Refresh()
{
Expand Down Expand Up @@ -591,14 +601,17 @@ public bool SingleWriter(ref Key key, ref Input input, ref Value src, ref Value

[MethodImpl(MethodImplOptions.AggressiveInlining)]
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)
=> _clientSession.functions.PostSingleWriter(ref key, ref input, ref src, ref dst, ref output, ref upsertInfo, reason);
{
recordInfo.SetDirtyAndModified();
_clientSession.functions.PostSingleWriter(ref key, ref input, ref src, ref dst, ref output, ref upsertInfo, reason);
}

[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, out bool lockFailed)
{
// Note: KeyIndexes do not need notification of in-place updates because the key does not change.
lockFailed = false;
recordInfo.SetDirty();
recordInfo.SetDirtyAndModified();
return _clientSession.functions.ConcurrentWriter(ref key, ref input, ref src, ref dst, ref output, ref upsertInfo);
}
#endregion IFunctions - Upserts
Expand All @@ -615,7 +628,10 @@ public bool InitialUpdater(ref Key key, ref Input input, ref Value value, ref Ou

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PostInitialUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo)
=> _clientSession.functions.PostInitialUpdater(ref key, ref input, ref value, ref output, ref rmwInfo);
{
recordInfo.SetDirtyAndModified();
_clientSession.functions.PostInitialUpdater(ref key, ref input, ref value, ref output, ref rmwInfo);
}
#endregion InitialUpdater

#region CopyUpdater
Expand All @@ -629,13 +645,17 @@ public bool CopyUpdater(ref Key key, ref Input input, ref Value oldValue, ref Va

[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)
=> _clientSession.functions.PostCopyUpdater(ref key, ref input, ref oldValue, ref newValue, ref output, ref rmwInfo);
{
recordInfo.SetDirtyAndModified();
_clientSession.functions.PostCopyUpdater(ref key, ref input, ref oldValue, ref newValue, ref output, ref rmwInfo);
}
#endregion CopyUpdater

#region InPlaceUpdater
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool InPlaceUpdater(ref Key key, ref Input input, ref Value value, ref Output output, ref RecordInfo recordInfo, ref RMWInfo rmwInfo, out bool lockFailed, out OperationStatus status)
{
recordInfo.SetDirtyAndModified();
lockFailed = false;
return _clientSession.InPlaceUpdater(ref key, ref input, ref output, ref value, ref recordInfo, ref rmwInfo, out status);
}
Expand All @@ -654,15 +674,15 @@ public bool SingleDeleter(ref Key key, ref Value value, ref RecordInfo recordInf
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PostSingleDeleter(ref Key key, ref RecordInfo recordInfo, ref DeleteInfo deleteInfo)
{
recordInfo.SetDirty();
recordInfo.SetDirtyAndModified();
_clientSession.functions.PostSingleDeleter(ref key, ref deleteInfo);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ConcurrentDeleter(ref Key key, ref Value value, ref RecordInfo recordInfo, ref DeleteInfo deleteInfo, out bool lockFailed)
{
lockFailed = false;
recordInfo.SetDirty();
recordInfo.SetDirtyAndModified();
recordInfo.Tombstone = true;
return _clientSession.functions.ConcurrentDeleter(ref key, ref value, ref deleteInfo);
}
Expand Down
Loading

0 comments on commit 02a8c1d

Please sign in to comment.