Skip to content

Commit

Permalink
Rough sketch of session without touching currrent thread-local framew…
Browse files Browse the repository at this point in the history
…ork: session-based acccess just updates existing thread-local variables to set the session for the current thread.
  • Loading branch information
badrishc committed Jul 11, 2019
1 parent 3d17a2d commit 2b7e24f
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cs/src/core/Epochs/LightEpoch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ public void Release()
(*(tableAligned + entry)).threadId = 0;
}

internal FastThreadLocal<int> ThreadEntry => threadEntryIndex;

/// <summary>
/// Increment global current epoch
/// </summary>
Expand Down
30 changes: 30 additions & 0 deletions cs/src/core/Index/FASTER/FASTER.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,36 @@ public void Recover(Guid indexCheckpointToken, Guid hybridLogCheckpointToken)
InternalRecover(indexCheckpointToken, hybridLogCheckpointToken);
}


/// <summary>
/// Start shared (not thread-specific) session with FASTER
/// </summary>
/// <returns></returns>
public Session<Key, Value, Input, Output, Context, Functions> StartSharedSession()
{
StartSession();
return new Session<Key, Value, Input, Output, Context, Functions>
(this, prevThreadCtx.Value, threadCtx.Value, epoch.ThreadEntry.Value);
}

/// <summary>
/// Continue shared (not thread-specific) session with FASTER
/// </summary>
/// <returns></returns>
public Session<Key, Value, Input, Output, Context, Functions> ContinueSharedSession(Guid guid)
{
ContinueSession(guid);
return new Session<Key, Value, Input, Output, Context, Functions>
(this, prevThreadCtx.Value, threadCtx.Value, epoch.ThreadEntry.Value);
}

internal void SetContext(FasterExecutionContext prevThreadCtx, FasterExecutionContext threadCtx, int epochEntry)
{
this.prevThreadCtx.Value = prevThreadCtx;
this.threadCtx.Value = threadCtx;
epoch.ThreadEntry.Value = epochEntry;
}

/// <summary>
/// Start session with FASTER - call once per thread before using FASTER
/// </summary>
Expand Down
67 changes: 67 additions & 0 deletions cs/src/core/Index/FASTER/Session.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

#pragma warning disable 0162

using System;

namespace FASTER.core
{
/// <summary>
/// Thread-independent session interface to FASTER
/// </summary>
/// <typeparam name="Key"></typeparam>
/// <typeparam name="Value"></typeparam>
/// <typeparam name="Input"></typeparam>
/// <typeparam name="Output"></typeparam>
/// <typeparam name="Context"></typeparam>
/// <typeparam name="Functions"></typeparam>
public class Session<Key, Value, Input, Output, Context, Functions> : IDisposable
where Key : new()
where Value : new()
where Functions : IFunctions<Key, Value, Input, Output, Context>
{
FasterKV<Key, Value, Input, Output, Context, Functions> fht;
private FasterKV<Key, Value, Input, Output, Context, Functions>.FasterExecutionContext prevThreadCtx;
private FasterKV<Key, Value, Input, Output, Context, Functions>.FasterExecutionContext threadCtx;
private int epochEntry;

internal Session(
FasterKV<Key, Value, Input, Output, Context, Functions> fht,
FasterKV<Key, Value, Input, Output, Context, Functions>.FasterExecutionContext prevThreadCtx,
FasterKV<Key, Value, Input, Output, Context, Functions>.FasterExecutionContext threadCtx,
int epochEntry)
{
this.fht = fht;
this.prevThreadCtx = prevThreadCtx;
this.threadCtx = threadCtx;
this.epochEntry = epochEntry;
}

/// <summary>
/// Get session Guid
/// </summary>
public Guid ID { get { return threadCtx.guid; } }

/// <summary>
/// Dispose session
/// </summary>
public void Dispose()
{
Resume();

fht.StopSession();
prevThreadCtx = threadCtx = null;
epochEntry = 0;
fht = null;
}

/// <summary>
/// Resume session on current thread
/// </summary>
public void Resume()
{
fht.SetContext(prevThreadCtx, threadCtx, epochEntry);
}
}
}

0 comments on commit 2b7e24f

Please sign in to comment.