Skip to content

Commit

Permalink
Refactor SpanByteFunctions<Input, Output, Context> for user-specified…
Browse files Browse the repository at this point in the history
… Input (#214)

* Create SpanByteFunctions<Input, Output, Context> for user-specified Input.

* Update version
  • Loading branch information
badrishc authored Apr 1, 2024
1 parent 96f5cc6 commit c106792
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .azure/pipelines/azure-pipelines-external-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# 1) update the name: string below (line 6) -- this is the version for the nuget package (e.g. 1.0.0)
# 2) update \libs\host\GarnetServer.cs readonly string version (~line 45) -- NOTE - these two values need to be the same
######################################
name: 1.0.2
name: 1.0.3
trigger: none
resources:
repositories:
Expand Down
2 changes: 1 addition & 1 deletion libs/host/GarnetServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class GarnetServer : IDisposable
protected StoreWrapper storeWrapper;

// IMPORTANT: Keep the version in sync with .azure\pipelines\azure-pipelines-external-release.yml line ~6.
readonly string version = "1.0.2";
readonly string version = "1.0.3";

/// <summary>
/// Resp protocol version
Expand Down
2 changes: 1 addition & 1 deletion libs/server/Storage/SizeTracker/CacheSizeTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public long CalculateRecordSize(RecordInfo recordInfo, byte[] key, IGarnetObject
}

/// <summary>Class to track and update cache size</summary>
/// <param name="store">FASTER store instance</param>
/// <param name="store">Tsavorite store instance</param>
/// <param name="logSettings">Hybrid log settings</param>
/// <param name="targetSize">Total memory size target</param>
/// <param name="loggerFactory"></param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;

namespace FASTER.core
namespace Tsavorite.core
{
/// <summary>
/// Represents a synchronization event that, when signaled, resets automatically after releasing a single waiter.
Expand Down
60 changes: 33 additions & 27 deletions libs/storage/Tsavorite/cs/src/core/VarLen/SpanByteFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ public override bool ConcurrentReader(ref SpanByte key, ref SpanByte input, ref
}

/// <summary>
/// Callback functions for SpanByte key, value, input; specified Output and Context
/// Callback functions for SpanByte key, value; specified Input, Output, and Context
/// </summary>
public class SpanByteFunctions<Output, Context> : FunctionsBase<SpanByte, SpanByte, SpanByte, Output, Context>
public class SpanByteFunctions<Input, Output, Context> : FunctionsBase<SpanByte, SpanByte, Input, Output, Context>
{
/// <inheritdoc />
public override bool SingleWriter(ref SpanByte key, ref SpanByte input, ref SpanByte src, ref SpanByte dst, ref Output output, ref UpsertInfo upsertInfo, WriteReason reason, ref RecordInfo recordInfo)
public override bool SingleWriter(ref SpanByte key, ref Input input, ref SpanByte src, ref SpanByte dst, ref Output output, ref UpsertInfo upsertInfo, WriteReason reason, ref RecordInfo recordInfo)
=> DoSafeCopy(ref src, ref dst, ref upsertInfo, ref recordInfo);

/// <inheritdoc />
public override bool ConcurrentWriter(ref SpanByte key, ref SpanByte input, ref SpanByte src, ref SpanByte dst, ref Output output, ref UpsertInfo upsertInfo, ref RecordInfo recordInfo)
public override bool ConcurrentWriter(ref SpanByte key, ref Input input, ref SpanByte src, ref SpanByte dst, ref Output output, ref UpsertInfo upsertInfo, ref RecordInfo recordInfo)
=> DoSafeCopy(ref src, ref dst, ref upsertInfo, ref recordInfo);

/// <summary>
Expand All @@ -72,29 +72,6 @@ public static bool DoSafeCopy(ref SpanByte src, ref SpanByte dst, ref UpsertInfo
return result;
}

/// <inheritdoc/>
public override bool InitialUpdater(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref Output output, ref RMWInfo rmwInfo, ref RecordInfo recordInfo)
=> DoSafeCopy(ref input, ref value, ref rmwInfo, ref recordInfo);

/// <inheritdoc/>
public override bool CopyUpdater(ref SpanByte key, ref SpanByte input, ref SpanByte oldValue, ref SpanByte newValue, ref Output output, ref RMWInfo rmwInfo, ref RecordInfo recordInfo)
=> DoSafeCopy(ref oldValue, ref newValue, ref rmwInfo, ref recordInfo);

/// <inheritdoc/>
// The default implementation of IPU simply writes input to destination, if there is space
public override bool InPlaceUpdater(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref Output output, ref RMWInfo rmwInfo, ref RecordInfo recordInfo)
=> DoSafeCopy(ref input, ref value, ref rmwInfo, ref recordInfo);

/// <summary>
/// Length of resulting object when doing RMW with given value and input. Here we set the length
/// to the max of input and old value lengths. You can provide a custom implementation for other cases.
/// </summary>
public override int GetRMWModifiedValueLength(ref SpanByte t, ref SpanByte input)
=> sizeof(int) + (t.Length > input.Length ? t.Length : input.Length);

/// <inheritdoc/>
public override int GetRMWInitialValueLength(ref SpanByte input) => input.TotalSize;

/// <summary>
/// Utility function for SpanByte copying, RMW version.
/// </summary>
Expand Down Expand Up @@ -146,4 +123,33 @@ public override unsafe void DisposeForRevivification(ref SpanByte key, ref SpanB
key.Length = newKeySize - sizeof(int);
}
}

/// <summary>
/// Callback functions for SpanByte key, value, input; specified Output and Context
/// </summary>
public class SpanByteFunctions<Output, Context> : SpanByteFunctions<SpanByte, Output, Context>
{
/// <inheritdoc/>
public override bool InitialUpdater(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref Output output, ref RMWInfo rmwInfo, ref RecordInfo recordInfo)
=> DoSafeCopy(ref input, ref value, ref rmwInfo, ref recordInfo);

/// <inheritdoc/>
public override bool CopyUpdater(ref SpanByte key, ref SpanByte input, ref SpanByte oldValue, ref SpanByte newValue, ref Output output, ref RMWInfo rmwInfo, ref RecordInfo recordInfo)
=> DoSafeCopy(ref oldValue, ref newValue, ref rmwInfo, ref recordInfo);

/// <inheritdoc/>
// The default implementation of IPU simply writes input to destination, if there is space
public override bool InPlaceUpdater(ref SpanByte key, ref SpanByte input, ref SpanByte value, ref Output output, ref RMWInfo rmwInfo, ref RecordInfo recordInfo)
=> DoSafeCopy(ref input, ref value, ref rmwInfo, ref recordInfo);

/// <summary>
/// Length of resulting object when doing RMW with given value and input. Here we set the length
/// to the max of input and old value lengths. You can provide a custom implementation for other cases.
/// </summary>
public override int GetRMWModifiedValueLength(ref SpanByte t, ref SpanByte input)
=> sizeof(int) + (t.Length > input.Length ? t.Length : input.Length);

/// <inheritdoc/>
public override int GetRMWInitialValueLength(ref SpanByte input) => input.TotalSize;
}
}

0 comments on commit c106792

Please sign in to comment.