Skip to content

Commit

Permalink
Merge branch 'main' into new/novalue-option-for-hscan
Browse files Browse the repository at this point in the history
  • Loading branch information
Vijay-Nirmal authored Oct 9, 2024
2 parents 5b7ecee + 0da61f5 commit b7e715d
Show file tree
Hide file tree
Showing 62 changed files with 10,780 additions and 2,537 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageVersion Include="StackExchange.Redis" Version="2.8.16" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.0.1" />
<PackageVersion Include="System.Interactive.Async" Version="6.0.1" />
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.0" />
</ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion Garnet.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<dependency id="Microsoft.IdentityModel.Validators" version="8.0.1" />
<dependency id="Azure.Storage.Blobs" version="12.21.2" />
<dependency id="NLua" version="1.7.3" />
<dependency id="System.Text.Json" version="8.0.4" />
<dependency id="System.Text.Json" version="8.0.5" />
</dependencies>
<readme>README.md</readme>
</metadata>
Expand All @@ -37,6 +37,9 @@
<file src="libs\server\bin\Release\net8.0\Garnet.server.dll" target="lib\net8.0" />
<file src="libs\server\bin\Release\net8.0\Garnet.server.pdb" target="lib\net8.0" />
<file src="libs\server\bin\Release\net8.0\Garnet.server.xml" target="lib\net8.0" />
<file src="libs\resources\bin\Release\net8.0\Garnet.resources.dll" target="lib\net8.0" />
<file src="libs\resources\bin\Release\net8.0\Garnet.resources.pdb" target="lib\net8.0" />
<file src="libs\resources\bin\Release\net8.0\Garnet.resources.xml" target="lib\net8.0" />
<file src="libs\common\bin\Release\net8.0\Garnet.common.dll" target="lib\net8.0" />
<file src="libs\common\bin\Release\net8.0\Garnet.common.pdb" target="lib\net8.0" />
<file src="libs\common\bin\Release\net8.0\Garnet.common.xml" target="lib\net8.0" />
Expand Down
12 changes: 12 additions & 0 deletions Garnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleModule", "playground\SampleModule\SampleModule.csproj", "{A8CA619E-8F13-4EF8-943F-2D5E3FEBFB3F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GarnetJSON", "playground\GarnetJSON\GarnetJSON.csproj", "{2C8F1F5D-31E5-4D00-A46E-F3B1D9BC098F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MigrateBench", "playground\MigrateBench\MigrateBench.csproj", "{6B66B394-E410-4B61-9A5A-1595FF6F5E08}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "hosting", "hosting", "{01823EA4-4446-4D66-B268-DFEE55951964}"
Expand All @@ -105,6 +106,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Windows", "Windows", "{6977
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Garnet.worker", "hosting\Windows\Garnet.worker\Garnet.worker.csproj", "{DF2DD03E-87EE-482A-9FBA-6C8FBC23BDC5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Garnet.resources", "libs\resources\Garnet.resources.csproj", "{A48412B4-FD60-467E-A5D9-F155CAB4F907}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -313,6 +316,14 @@ Global
{DF2DD03E-87EE-482A-9FBA-6C8FBC23BDC5}.Release|Any CPU.Build.0 = Release|Any CPU
{DF2DD03E-87EE-482A-9FBA-6C8FBC23BDC5}.Release|x64.ActiveCfg = Release|Any CPU
{DF2DD03E-87EE-482A-9FBA-6C8FBC23BDC5}.Release|x64.Build.0 = Release|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Debug|x64.ActiveCfg = Debug|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Debug|x64.Build.0 = Debug|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Release|Any CPU.Build.0 = Release|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Release|x64.ActiveCfg = Release|Any CPU
{A48412B4-FD60-467E-A5D9-F155CAB4F907}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -346,6 +357,7 @@ Global
{6B66B394-E410-4B61-9A5A-1595FF6F5E08} = {69A71E2C-00E3-42F3-854E-BE157A24834E}
{697766CD-2046-46D9-958A-0FD3B46C98D4} = {01823EA4-4446-4D66-B268-DFEE55951964}
{DF2DD03E-87EE-482A-9FBA-6C8FBC23BDC5} = {697766CD-2046-46D9-958A-0FD3B46C98D4}
{A48412B4-FD60-467E-A5D9-F155CAB4F907} = {147FCE31-EC09-4C90-8E4D-37CA87ED18C3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2C02C405-4798-41CA-AF98-61EDFEF6772E}
Expand Down
33 changes: 33 additions & 0 deletions benchmark/BDN.benchmark/Resp/RespParseStress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public unsafe class RespParseStress
byte[] setexRequestBuffer;
byte* setexRequestBufferPointer;

static ReadOnlySpan<byte> SETNX => "*4\r\n$3\r\nSET\r\n$1\r\na\r\n$1\r\na\r\n$2\r\nNX\r\n"u8;
byte[] setnxRequestBuffer;
byte* setnxRequestBufferPointer;

static ReadOnlySpan<byte> SETXX => "*4\r\n$3\r\nSET\r\n$1\r\na\r\n$1\r\na\r\n$2\r\nXX\r\n"u8;
byte[] setxxRequestBuffer;
byte* setxxRequestBufferPointer;

static ReadOnlySpan<byte> GET => "*2\r\n$3\r\nGET\r\n$1\r\nb\r\n"u8;
byte[] getRequestBuffer;
byte* getRequestBufferPointer;
Expand Down Expand Up @@ -91,6 +99,16 @@ public void GlobalSetup()
for (int i = 0; i < batchSize; i++)
SETEX.CopyTo(new Span<byte>(setexRequestBuffer).Slice(i * SETEX.Length));

setnxRequestBuffer = GC.AllocateArray<byte>(SETNX.Length * batchSize, pinned: true);
setnxRequestBufferPointer = (byte*)Unsafe.AsPointer(ref setnxRequestBuffer[0]);
for (int i = 0; i < batchSize; i++)
SETNX.CopyTo(new Span<byte>(setnxRequestBuffer).Slice(i * SETNX.Length));

setxxRequestBuffer = GC.AllocateArray<byte>(SETXX.Length * batchSize, pinned: true);
setxxRequestBufferPointer = (byte*)Unsafe.AsPointer(ref setxxRequestBuffer[0]);
for (int i = 0; i < batchSize; i++)
SETXX.CopyTo(new Span<byte>(setxxRequestBuffer).Slice(i * SETXX.Length));

getRequestBuffer = GC.AllocateArray<byte>(GET.Length * batchSize, pinned: true);
getRequestBufferPointer = (byte*)Unsafe.AsPointer(ref getRequestBuffer[0]);
for (int i = 0; i < batchSize; i++)
Expand Down Expand Up @@ -121,6 +139,9 @@ public void GlobalSetup()
for (int i = 0; i < batchSize; i++)
HSETDEL.CopyTo(new Span<byte>(hSetDelRequestBuffer).Slice(i * HSETDEL.Length));

// Pre-populate raw string set with a single element
SlowConsumeMessage("*3\r\n$3\r\nSET\r\n$1\r\na\r\n$1\r\na\r\n"u8);

// Pre-populate sorted set with a single element to avoid repeatedly emptying it during the benchmark
SlowConsumeMessage("*4\r\n$4\r\nZADD\r\n$1\r\nc\r\n$1\r\n1\r\n$1\r\nd\r\n"u8);

Expand Down Expand Up @@ -167,6 +188,18 @@ public void SetEx()
_ = session.TryConsumeMessages(setexRequestBufferPointer, setexRequestBuffer.Length);
}

[Benchmark]
public void SetNx()
{
_ = session.TryConsumeMessages(setnxRequestBufferPointer, setnxRequestBuffer.Length);
}

[Benchmark]
public void SetXx()
{
_ = session.TryConsumeMessages(setxxRequestBufferPointer, setxxRequestBuffer.Length);
}

[Benchmark]
public void Get()
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -65,33 +65,6 @@ private void WriteClusterSlotVerificationMessage(ClusterConfig config, ClusterSl
SendAndReset(ref dcurr, ref dend);
}

/// <summary>
/// Check if read or read/write is permitted on a single key and generate the appropriate response
/// LOCAL | ~LOCAL | MIGRATING EXISTS | MIGRATING ~EXISTS | IMPORTING ASKING | IMPORTING ~ASKING
/// R OK | -MOVED | OK | -ASK | OK | -MOVED
/// R/W OK | -MOVED | -MIGRATING | -ASK | OK | -MOVED
/// </summary>
/// <returns>True if redirect, False if can serve</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool NetworkSingleKeySlotVerify(ReadOnlySpan<byte> key, bool readOnly, byte SessionAsking, ref byte* dcurr, ref byte* dend)
{
fixed (byte* keyPtr = key)
{
var keySlice = new ArgSlice(keyPtr, key.Length);
// If cluster is not enabled or a transaction is running skip slot check
if (!clusterProvider.serverOptions.EnableCluster || txnManager.state == TxnState.Running) return false;

var config = clusterProvider.clusterManager.CurrentConfig;
var vres = SingleKeySlotVerify(ref config, ref keySlice, readOnly, SessionAsking);

if (vres.state == SlotVerifiedState.OK)
return false;
else
WriteClusterSlotVerificationMessage(config, vres, ref dcurr, ref dend);
return true;
}
}

/// <summary>
/// Check if read/write is permitted on an array of keys and generate appropriate resp response.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions libs/common/EnumUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public static bool TryParseEnumFromDescription<T>(string strVal, out T val) wher

private static void AddTypeToCache<T>()
{
var valToDesc = new Dictionary<string, string>();
var descToVals = new Dictionary<string, List<string>>();
var valToDesc = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
var descToVals = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);

foreach (var flagFieldInfo in typeof(T).GetFields())
{
Expand Down
7 changes: 5 additions & 2 deletions libs/common/StreamProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,22 @@ public class StreamProviderFactory
/// </summary>
/// <param name="locationType">Type of location of files the stream provider reads from / writes to</param>
/// <param name="connectionString">Connection string to Azure Storage, if applicable</param>
/// <param name="resourceAssembly">Assembly from which to load the embedded resource, if applicable</param>
/// <param name="resourceAssembly">Assembly from which to load the embedded resource, if applicable.</param>
/// <returns>StreamProvider instance</returns>
public static IStreamProvider GetStreamProvider(FileLocationType locationType, string connectionString = null, Assembly resourceAssembly = null)
{
switch (locationType)
{
case FileLocationType.AzureStorage:
if (string.IsNullOrEmpty(connectionString))
throw new ArgumentException("Azure Storage connection string is required to read/write settings to Azure Storage", nameof(connectionString));
throw new ArgumentException("Azure Storage connection string is required to read/write to Azure Storage", nameof(connectionString));
return new AzureStreamProvider(connectionString);
case FileLocationType.Local:
return new LocalFileStreamProvider();
case FileLocationType.EmbeddedResource:
if (resourceAssembly == null)
throw new ArgumentException(
"Assembly is required to read from embedded resource", nameof(resourceAssembly));
return new EmbeddedResourceStreamProvider(resourceAssembly);
default:
throw new NotImplementedException();
Expand Down
19 changes: 19 additions & 0 deletions libs/resources/Garnet.resources.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<None Remove="RespCommandsDocs.json" />
<None Remove="RespCommandsInfo.json" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="RespCommandsDocs.json" />
<EmbeddedResource Include="RespCommandsInfo.json" />
</ItemGroup>

</Project>
Loading

0 comments on commit b7e715d

Please sign in to comment.