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

Psf functions in session #1

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f10e9be
Simple PSF insert/query work
TedHartMS May 11, 2020
751eefc
Implement PSF updates via RCU
TedHartMS Jun 4, 2020
7137737
Clear out a bunch of TODOs:
TedHartMS Jun 6, 2020
5e9ae40
Remove the IPSFProviderDataCreator interface
TedHartMS Jun 6, 2020
e731d46
Rename ChainPost->PSFValueAccessor and ChainHeight->PSFCount
TedHartMS Jun 6, 2020
a432bd1
Move Upsert/RMW/Delete calls to PSF to be outside the UnsafeResume/Su…
TedHartMS Jun 7, 2020
381e83e
- RETRY_LATER if ReadAddress has to go to the disk during Phase.PREPARE
TedHartMS Jun 8, 2020
0084058
- Fix multiple PSFs in a single group
TedHartMS Jun 14, 2020
b970991
Change to KeyPointer
TedHartMS Jun 17, 2020
1cdb8ab
Merge upstream master
TedHartMS Jun 23, 2020
267716c
Faster:
TedHartMS Jul 7, 2020
aae1854
- Change external API to from PSF<TPSFKey, provider-specific-TRecordI…
TedHartMS Jul 7, 2020
7375d45
PSF Updates:
TedHartMS Jul 15, 2020
ca9e43c
Add QueryPSFAsync and flushing PSF logs
TedHartMS Aug 12, 2020
fdee602
Merge upstream (functions-in-session etc.)
TedHartMS Aug 14, 2020
9163f1f
Prep for functions-in-session:
TedHartMS Aug 24, 2020
7750141
Move PSFResultFlags into KeyPointer; add OffsetToStartOfKeys to make …
TedHartMS Aug 25, 2020
2dcf7c6
First part of moving PSFs to functions-in-session
TedHartMS Aug 26, 2020
f265b3c
Make PSF methods public; first cut at README
TedHartMS Sep 4, 2020
42e96ba
Merge master (from upstream)
TedHartMS Sep 4, 2020
ffbad7b
Changes to PSFs to match most recent upstream (removal of new() const…
TedHartMS Sep 4, 2020
97c9f73
Fix release build
TedHartMS Sep 4, 2020
bf42cd8
merge upstream (v1.5)
TedHartMS Sep 8, 2020
47d7078
Merge remote-tracking branch 'origin/master' into PSF-functionsInSession
TedHartMS Sep 9, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,4 @@ packages/
*.lib
nativebin/
/cs/benchmark/Properties/launchSettings.json
/cs/playground/FasterPSFSample/Properties/launchSettings.json
11 changes: 11 additions & 0 deletions cs/FASTER.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClassRecoveryDurablity", "p
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FasterKVDiskReadBenchmark", "playground\FasterKVDiskReadBenchmark\FasterKVDiskReadBenchmark.csproj", "{642DCE86-1BAA-4FFF-98BF-0FB9BB11CD49}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FasterPSFSample", "playground\FasterPSFSample\FasterPSFSample.csproj", "{BBC2B5E3-4D3E-49FE-BE23-99F859E0D386}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -196,6 +198,14 @@ Global
{642DCE86-1BAA-4FFF-98BF-0FB9BB11CD49}.Release|Any CPU.Build.0 = Release|x64
{642DCE86-1BAA-4FFF-98BF-0FB9BB11CD49}.Release|x64.ActiveCfg = Release|x64
{642DCE86-1BAA-4FFF-98BF-0FB9BB11CD49}.Release|x64.Build.0 = Release|x64
{BBC2B5E3-4D3E-49FE-BE23-99F859E0D386}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BBC2B5E3-4D3E-49FE-BE23-99F859E0D386}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BBC2B5E3-4D3E-49FE-BE23-99F859E0D386}.Debug|x64.ActiveCfg = Debug|Any CPU
{BBC2B5E3-4D3E-49FE-BE23-99F859E0D386}.Debug|x64.Build.0 = Debug|Any CPU
{BBC2B5E3-4D3E-49FE-BE23-99F859E0D386}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BBC2B5E3-4D3E-49FE-BE23-99F859E0D386}.Release|Any CPU.Build.0 = Release|Any CPU
{BBC2B5E3-4D3E-49FE-BE23-99F859E0D386}.Release|x64.ActiveCfg = Release|Any CPU
{BBC2B5E3-4D3E-49FE-BE23-99F859E0D386}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -220,6 +230,7 @@ Global
{859F76F4-93D8-4D60-BF9A-363E217FA247} = {E6026D6A-01C5-4582-B2C1-64751490DABE}
{95AC8766-84F9-4E95-B2E9-2169B6375FB2} = {E6026D6A-01C5-4582-B2C1-64751490DABE}
{642DCE86-1BAA-4FFF-98BF-0FB9BB11CD49} = {E6026D6A-01C5-4582-B2C1-64751490DABE}
{BBC2B5E3-4D3E-49FE-BE23-99F859E0D386} = {E6026D6A-01C5-4582-B2C1-64751490DABE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A0750637-2CCB-4139-B25E-F2CE740DCFAC}
Expand Down
2 changes: 2 additions & 0 deletions cs/playground/FasterKVDiskReadBenchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.Threading.Tasks;
using FASTER.core;

#pragma warning disable CS0162 // Unreachable code detected

namespace FasterKVDiskReadBenchmark
{
public class Program
Expand Down
73 changes: 73 additions & 0 deletions cs/playground/FasterPSFSample/BlittableOrders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using FASTER.core;
using System;

namespace FasterPSFSample
{
public struct BlittableOrders : IOrders
{
public int Id { get; set; }

// Colors, strings, and enums are not blittable so we use int
public int SizeInt { get; set; }

public int ColorArgb { get; set; }

public int Count { get; set; }

public override string ToString() => $"{(Constants.Size)this.SizeInt}, {Constants.ColorDict[this.ColorArgb].Name}, {Count}";

public class Functions : IFunctions<Key, BlittableOrders, Input<BlittableOrders>, Output<BlittableOrders>, Context<BlittableOrders>>
{
#region Read
public void ConcurrentReader(ref Key key, ref Input<BlittableOrders> input, ref BlittableOrders value, ref Output<BlittableOrders> dst)
=> dst.Value = value;

public void SingleReader(ref Key key, ref Input<BlittableOrders> input, ref BlittableOrders value, ref Output<BlittableOrders> dst)
=> dst.Value = value;

public void ReadCompletionCallback(ref Key key, ref Input<BlittableOrders> input, ref Output<BlittableOrders> output, Context<BlittableOrders> context, Status status)
{ /* Output is not set by pending operations */ }
#endregion Read

#region Upsert
public bool ConcurrentWriter(ref Key key, ref BlittableOrders src, ref BlittableOrders dst)
{
dst = src;
return true;
}

public void SingleWriter(ref Key key, ref BlittableOrders src, ref BlittableOrders dst)
=> dst = src;

public void UpsertCompletionCallback(ref Key key, ref BlittableOrders value, Context<BlittableOrders> context)
{ }
#endregion Upsert

#region RMW
public void CopyUpdater(ref Key key, ref Input<BlittableOrders> input, ref BlittableOrders oldValue, ref BlittableOrders newValue)
=> throw new NotImplementedException();

public void InitialUpdater(ref Key key, ref Input<BlittableOrders> input, ref BlittableOrders value)
=> value = input.InitialUpdateValue;

public bool InPlaceUpdater(ref Key key, ref Input<BlittableOrders> input, ref BlittableOrders value)
{
value.ColorArgb = input.IPUColorInt;
return true;
}

public void RMWCompletionCallback(ref Key key, ref Input<BlittableOrders> input, Context<BlittableOrders> context, Status status)
{ }
#endregion RMW

public void CheckpointCompletionCallback(string sessionId, CommitPoint commitPoint)
{ }

public void DeleteCompletionCallback(ref Key key, Context<BlittableOrders> context)
{ }
}
}
}
22 changes: 22 additions & 0 deletions cs/playground/FasterPSFSample/ColorKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using FASTER.core;
using System.Drawing;

namespace FasterPSFSample
{
public struct ColorKey : IFasterEqualityComparer<ColorKey>
{
// Colors, strings, and enums are not blittable so we use int
public int ColorArgb;

public ColorKey(Color color) => this.ColorArgb = color.ToArgb();

public override string ToString() => Constants.ColorDict[this.ColorArgb].Name;

public long GetHashCode64(ref ColorKey key) => Utility.GetHashCode(key.ColorArgb);

public bool Equals(ref ColorKey k1, ref ColorKey k2) => k1.ColorArgb == k2.ColorArgb;
}
}
51 changes: 51 additions & 0 deletions cs/playground/FasterPSFSample/CombinedKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using FASTER.core;
using System.Drawing;

namespace FasterPSFSample
{
public struct CombinedKey : IFasterEqualityComparer<CombinedKey>
{
public int ValueType;
public int ValueInt;

public CombinedKey(Constants.Size size)
{
this.ValueType = (int)Constants.ValueType.Size;
this.ValueInt = (int)size;
}

public CombinedKey(Color color)
{
this.ValueType = (int)Constants.ValueType.Color;
this.ValueInt = color.ToArgb();
}

public CombinedKey(int countBin)
{
this.ValueType = (int)Constants.ValueType.Count;
this.ValueInt = countBin;
}

public override string ToString()
{
var valueType = (Constants.ValueType)this.ValueType;
var valueTypeString = $"{valueType}";
return valueType switch
{
Constants.ValueType.Size => $"{valueTypeString}: {(Constants.Size)this.ValueInt}",
Constants.ValueType.Color => $"{valueTypeString}: {Constants.ColorDict[this.ValueInt]}",
Constants.ValueType.Count => $"{valueTypeString}: {this.ValueInt}",
_ => throw new System.NotImplementedException("Unknown ValueType")
};
}

public long GetHashCode64(ref CombinedKey key)
=> (long)key.ValueType << 32 | (uint)key.ValueInt.GetHashCode();

public bool Equals(ref CombinedKey k1, ref CombinedKey k2)
=> k1.ValueType == k2.ValueType && k1.ValueInt == k2.ValueInt;
}
}
41 changes: 41 additions & 0 deletions cs/playground/FasterPSFSample/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.Drawing;

namespace FasterPSFSample
{
public static class Constants
{
// Colors, strings, and enums are not blittable so we store int
public enum Size
{
Small,
Medium,
Large,
XLarge,
XXLarge,
NumSizes
}

static internal Dictionary<int, Color> ColorDict = new Dictionary<int, Color>
{
[Color.Black.ToArgb()] = Color.Black,
[Color.Red.ToArgb()] = Color.Red,
[Color.Green.ToArgb()] = Color.Green,
[Color.Blue.ToArgb()] = Color.Blue,
[Color.Purple.ToArgb()] = Color.Purple
};

static internal Color[] Colors = { Color.Black, Color.Red, Color.Green, Color.Blue, Color.Purple };

public enum ValueType
{
Size,
Color,
Count
}
}
}
12 changes: 12 additions & 0 deletions cs/playground/FasterPSFSample/Context.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System.Collections.Generic;

namespace FasterPSFSample
{
public class Context<TValue>
{
public List<TValue> Value { get; set; } = new List<TValue>();
}
}
31 changes: 31 additions & 0 deletions cs/playground/FasterPSFSample/CountBinKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using FASTER.core;

namespace FasterPSFSample
{
public struct CountBinKey : IFasterEqualityComparer<CountBinKey>
{
internal const int BinSize = 100;
internal const int MaxOrders = BinSize * 10;
internal const int LastBin = 9; // 0-based
internal static bool WantLastBin;

public int Bin;

public CountBinKey(int bin) => this.Bin = bin;

internal static bool GetBin(int numOrders, out int bin)
{
// Skip the last bin during initial inserts to illustrate not matching the PSF (returning null)
bin = numOrders / BinSize;
return WantLastBin || bin < LastBin;
}

// Make the hashcode for this distinct from size enum values
public long GetHashCode64(ref CountBinKey key) => Utility.GetHashCode(key.Bin + 1000);

public bool Equals(ref CountBinKey k1, ref CountBinKey k2) => k1.Bin == k2.Bin;
}
}
99 changes: 99 additions & 0 deletions cs/playground/FasterPSFSample/FPSF.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using FASTER.core;
using System;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

namespace FasterPSFSample
{
class FPSF<TValue, TInput, TOutput, TFunctions, TSerializer>
where TValue : IOrders, new()
where TOutput : new()
where TFunctions : IFunctions<Key, TValue, TInput, TOutput, Context<TValue>>, new()
where TSerializer : BinaryObjectSerializer<TValue>, new()
{
internal IFasterKV<Key, TValue> FasterKV { get; set; }

private LogFiles logFiles;

// MultiGroup PSFs -- different key types, one per group.
internal IPSF SizePsf, ColorPsf, CountBinPsf;
internal IPSF CombinedSizePsf, CombinedColorPsf, CombinedCountBinPsf;

internal FPSF(bool useObjectValues, bool useMultiGroup, bool useReadCache)
{
this.logFiles = new LogFiles(useObjectValues, useReadCache, useMultiGroup ? 3 : 1);

this.FasterKV = new FasterKV<Key, TValue>(
1L << 20, this.logFiles.LogSettings,
null, // TODO: add checkpoints
useObjectValues ? new SerializerSettings<Key, TValue> { valueSerializer = () => new TSerializer() } : null);

if (useMultiGroup)
{
var groupOrdinal = 0;
this.SizePsf = FasterKV.RegisterPSF(CreatePSFRegistrationSettings<SizeKey>(groupOrdinal++), nameof(this.SizePsf),
(k, v) => new SizeKey((Constants.Size)v.SizeInt));
this.ColorPsf = FasterKV.RegisterPSF(CreatePSFRegistrationSettings<ColorKey>(groupOrdinal++), nameof(this.ColorPsf),
(k, v) => new ColorKey(Constants.ColorDict[v.ColorArgb]));
this.CountBinPsf = FasterKV.RegisterPSF(CreatePSFRegistrationSettings<CountBinKey>(groupOrdinal++), nameof(this.CountBinPsf),
(k, v) => CountBinKey.GetBin(v.Count, out int bin) ? new CountBinKey(bin) : (CountBinKey?)null);
}
else
{
var psfs = FasterKV.RegisterPSF(CreatePSFRegistrationSettings<CombinedKey>(0),
new (string, Func<Key, TValue, CombinedKey?>)[]
{
(nameof(this.SizePsf), (k, v) => new CombinedKey((Constants.Size)v.SizeInt)),
(nameof(this.ColorPsf), (k, v) => new CombinedKey(Constants.ColorDict[v.ColorArgb])),
(nameof(this.CountBinPsf), (k, v) => CountBinKey.GetBin(v.Count, out int bin)
? new CombinedKey(bin) : (CombinedKey?)null)
});
this.CombinedSizePsf = psfs[0];
this.CombinedColorPsf = psfs[1];
this.CombinedCountBinPsf = psfs[2];
}
}

PSFRegistrationSettings<TKey> CreatePSFRegistrationSettings<TKey>(int groupOrdinal)
{
var regSettings = new PSFRegistrationSettings<TKey>
{
HashTableSize = 1L << 20,
LogSettings = this.logFiles.PSFLogSettings[groupOrdinal],
CheckpointSettings = new CheckpointSettings(), // TODO checkpoints
IPU1CacheSize = 0, // TODO IPUCache
IPU2CacheSize = 0
};

// Override some things.
var regLogSettings = regSettings.LogSettings;
regLogSettings.PageSizeBits = 20;
regLogSettings.SegmentSizeBits = 25;
regLogSettings.MemorySizeBits = 29;
regLogSettings.CopyReadsToTail = false; // TODO--test this in both primary and secondary FKV
if (!(regLogSettings.ReadCacheSettings is null))
{
regLogSettings.ReadCacheSettings.PageSizeBits = regLogSettings.PageSizeBits;
regLogSettings.ReadCacheSettings.MemorySizeBits = regLogSettings.MemorySizeBits;
}
return regSettings;
}

internal void Close()
{
if (!(this.FasterKV is null))
{
this.FasterKV.Dispose();
this.FasterKV = null;
}
if (!(this.logFiles is null))
{
this.logFiles.Close();
this.logFiles = null;
}
}
}
}
Loading