Skip to content

Commit

Permalink
Merge branch 'list-commands' of https://github.com/hishamco/garnet in…
Browse files Browse the repository at this point in the history
…to pr/382
  • Loading branch information
TalZaccai committed May 28, 2024
2 parents 3ffd1aa + 723d74a commit df6cea8
Show file tree
Hide file tree
Showing 118 changed files with 4,622 additions and 2,549 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="7.5.1" />
<PackageVersion Include="Microsoft.IdentityModel.Validators" Version="7.5.1" />
<PackageVersion Include="StackExchange.Redis" Version="2.6.80" />
<PackageVersion Include="StackExchange.Redis" Version="2.7.33" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
<PackageVersion Include="System.Interactive.Async" Version="6.0.1" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion Garnet.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31808.319
Expand Down
56 changes: 56 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,59 @@ the Author.
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.

## mmcloughlin/geohash

**Source**: https://github.com/mmcloughlin/geohash

The MIT License (MIT)

Copyright (c) 2015 Michael McLoughlin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

## georust/geohash

**Source**: https://github.com/georust/geohash

Copyright (c) 2016 Ning Sun

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
27 changes: 27 additions & 0 deletions benchmark/BDN.benchmark/GeoHashBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BenchmarkDotNet.Attributes;

using Garnet.server;

namespace BDN.benchmark
{
[MemoryDiagnoser]
public class GeoHashBenchmarks
{
private const double Latitude = 47.642219912251285;
private const double Longitude = -122.14205560231471;

private const long GeoHashInteger = 1557413161902764;

[Benchmark]
public long GeoToLongValue() => GeoHash.GeoToLongValue(Latitude, Longitude);

[Benchmark]
public (double, double) GetCoordinatesFromLong() => GeoHash.GetCoordinatesFromLong(GeoHashInteger);

[Benchmark]
public string GetGeoHashCode() => GeoHash.GetGeoHashCode(GeoHashInteger);
}
}
33 changes: 24 additions & 9 deletions benchmark/BDN.benchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Running;

var config = DefaultConfig.Instance
.AddJob(Job.Default
.WithRuntime(CoreRuntime.Core60)
.WithId(".NET 6"))
.AddJob(Job.Default
.WithRuntime(CoreRuntime.Core80)
.WithEnvironmentVariables(new EnvironmentVariable("DOTNET_TieredPGO", "0"))
.WithId(".NET 8"));
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, new BaseConfig());

BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config);
public class BaseConfig : ManualConfig
{
public Job Net6BaseJob { get; }
public Job Net8BaseJob { get; }

public BaseConfig()
{
AddLogger(ConsoleLogger.Default);
AddExporter(DefaultExporters.Markdown);
AddColumnProvider(DefaultColumnProviders.Instance);

var baseJob = Job.Default.WithGcServer(true);

Net6BaseJob = baseJob.WithRuntime(CoreRuntime.Core60);
Net8BaseJob = baseJob.WithRuntime(CoreRuntime.Core80)
.WithEnvironmentVariables(new EnvironmentVariable("DOTNET_TieredPGO", "0"));

AddJob(Net6BaseJob.WithId(".NET 6"), Net8BaseJob.WithId(".NET 8"));
}
}
20 changes: 8 additions & 12 deletions benchmark/BDN.benchmark/RecoveryBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,23 @@

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using Embedded.perftest;
using Garnet.server;

namespace BDN.benchmark
{
public class CustomConfig : ManualConfig
[Config(typeof(Config))]
public class RecoveryBenchmark
{
public CustomConfig()
private class Config : BaseConfig
{
AddColumn(StatisticColumn.Mean);
AddColumn(StatisticColumn.StdDev);
AddColumn(StatisticColumn.Median);
AddColumn(StatisticColumn.P90);
AddColumn(StatisticColumn.P95);
public Config()
{
AddColumn(StatisticColumn.P90);
AddColumn(StatisticColumn.P95);
}
}
}

[Config(typeof(CustomConfig))]
public class RecoveryBenchmark
{
[ParamsSource(nameof(CommandLineArgsProvider))]
public string LogDir { get; set; }

Expand Down
1 change: 0 additions & 1 deletion libs/cluster/CmdStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ static class CmdStrings
public static ReadOnlySpan<byte> send_ckpt_metadata => "SEND_CKPT_METADATA"u8;
public static ReadOnlySpan<byte> send_ckpt_file_segment => "SEND_CKPT_FILE_SEGMENT"u8;
public static ReadOnlySpan<byte> begin_replica_recover => "BEGIN_REPLICA_RECOVER"u8;
public static ReadOnlySpan<byte> failauthreq => "FAILAUTHREQ"u8;
public static ReadOnlySpan<byte> failstopwrites => "FAILSTOPWRITES"u8;
public static ReadOnlySpan<byte> failreplicationoffset => "FAILREPLICATIONOFFSET"u8;

Expand Down
1 change: 0 additions & 1 deletion libs/cluster/Parsing/ClusterSubCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ internal enum ClusterSubcommand : byte

// Failover management commands
FAILOVER,
FAILAUTHREQ,
FAILSTOPWRITES,
FAILREPLICATIONOFFSET,

Expand Down
1 change: 0 additions & 1 deletion libs/cluster/Parsing/ClusterSubCommandParsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ _ when param.SequenceEqual(CmdStrings.send_ckpt_metadata) => ClusterSubcommand.S
_ when param.SequenceEqual(CmdStrings.aofsync) => ClusterSubcommand.AOFSYNC,
_ when param.SequenceEqual(CmdStrings.begin_replica_recover) => ClusterSubcommand.BEGIN_REPLICA_RECOVER,
_ when param.SequenceEqual(CmdStrings.initiate_replica_sync) => ClusterSubcommand.INITIATE_REPLICA_SYNC,
_ when param.SequenceEqual(CmdStrings.failauthreq) => ClusterSubcommand.FAILAUTHREQ,
_ when param.SequenceEqual(CmdStrings.failstopwrites) => ClusterSubcommand.FAILSTOPWRITES,
_ when param.SequenceEqual(CmdStrings.failreplicationoffset) => ClusterSubcommand.FAILREPLICATIONOFFSET,
_ => ConvertToClusterSubcommandIgnoreCase(ref param)
Expand Down
63 changes: 0 additions & 63 deletions libs/cluster/Server/ClusterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public ClusterConfig()
workers[0].Port = 0;
workers[0].Nodeid = null;
workers[0].ConfigEpoch = 0;
workers[0].LastVotedConfigEpoch = 0;
workers[0].Role = NodeRole.UNASSIGNED;
workers[0].ReplicaOfNodeId = null;
workers[0].ReplicationOffset = 0;
Expand Down Expand Up @@ -90,8 +89,6 @@ public ClusterConfig Copy()
/// <param name="address">Local worker IP address.</param>
/// <param name="port">Local worker port.</param>
/// <param name="configEpoch">Local worker config epoch.</param>
/// <param name="currentConfigEpoch">Local worker current config epoch.</param>
/// <param name="lastVotedConfigEpoch">Local worker last voted epoch.</param>
/// <param name="role">Local worker role.</param>
/// <param name="replicaOfNodeId">Local worker primary id.</param>
/// <param name="hostname">Local worker hostname.</param>
Expand All @@ -101,8 +98,6 @@ public ClusterConfig InitializeLocalWorker(
string address,
int port,
long configEpoch,
long currentConfigEpoch,
long lastVotedConfigEpoch,
NodeRole role,
string replicaOfNodeId,
string hostname)
Expand All @@ -113,8 +108,6 @@ public ClusterConfig InitializeLocalWorker(
newWorkers[1].Port = port;
newWorkers[1].Nodeid = nodeId;
newWorkers[1].ConfigEpoch = configEpoch;
newWorkers[1].LastVotedConfigEpoch = currentConfigEpoch;
newWorkers[1].LastVotedConfigEpoch = lastVotedConfigEpoch;
newWorkers[1].Role = role;
newWorkers[1].ReplicaOfNodeId = replicaOfNodeId;
newWorkers[1].ReplicationOffset = 0;
Expand Down Expand Up @@ -216,18 +209,6 @@ public bool IsKnown(string nodeid)
/// <returns>Config epoch of local node.</returns>
public long LocalNodeConfigEpoch => workers[1].ConfigEpoch;

/// <summary>
/// Next valid config epoch which can be used as requestedEpoch for voting.
/// </summary>
/// <returns>Current config epoch of local node.</returns>
public long LocalNodeCurrentConfigEpoch => workers[1].CurrentConfigEpoch;

/// <summary>
/// Get last epoch this node has voted for
/// </summary>
/// <returns>Last voted config epoch of local node.</returns>
public long LocalNodeLastVotedEpoch => workers[1].LastVotedConfigEpoch;

/// <summary>
/// Return endpoint of primary if this node is a replica.
/// </summary>
Expand Down Expand Up @@ -475,18 +456,6 @@ public byte[] GetClaimedSlotsFromNodeId(string nodeId)
var workerId = GetWorkerIdFromNodeId(nodeid);
return (workers[workerId].Address, workers[workerId].Port);
}

/// <summary>
/// Get config epoch from slot.
/// </summary>
/// <param name="slot">Slot number.</param>
/// <returns>Long value representing config epoch.</returns>
public long GetConfigEpochFromSlot(int slot)
{
if (slotMap[slot].workerId < 0)
return 0;
return workers[slotMap[slot].workerId].ConfigEpoch;
}
#endregion

/// <summary>
Expand Down Expand Up @@ -898,8 +867,6 @@ public ClusterConfig Merge(ClusterConfig other, ConcurrentDictionary<string, lon
other.workers[i].Address,
other.workers[i].Port,
other.workers[i].ConfigEpoch,
other.workers[i].CurrentConfigEpoch,
other.workers[i].LastVotedConfigEpoch,
other.workers[i].Role,
other.workers[i].ReplicaOfNodeId,
other.workers[i].hostname,
Expand All @@ -913,8 +880,6 @@ private ClusterConfig InPlaceUpdateWorker(
string address,
int port,
long configEpoch,
long currentConfigEpoch,
long lastVotedConfigEpoch,
NodeRole role,
string replicaOfNodeId,
string hostname,
Expand Down Expand Up @@ -945,8 +910,6 @@ private ClusterConfig InPlaceUpdateWorker(
newWorkers[workerId].Port = port;
newWorkers[workerId].Nodeid = nodeid;
newWorkers[workerId].ConfigEpoch = configEpoch;
newWorkers[workerId].CurrentConfigEpoch = currentConfigEpoch;
newWorkers[workerId].LastVotedConfigEpoch = lastVotedConfigEpoch;
newWorkers[workerId].Role = role;
newWorkers[workerId].ReplicaOfNodeId = replicaOfNodeId;
newWorkers[workerId].hostname = hostname;
Expand Down Expand Up @@ -1192,19 +1155,6 @@ public ClusterConfig BumpLocalNodeConfigEpoch()
return new ClusterConfig(slotMap, newWorkers);
}

/// <summary>
/// Bump current config epoch for voting
/// </summary>
/// <returns>ClusterConfig object with updates.</returns>
public ClusterConfig BumpLocalNodeCurrentConfigEpoch()
{
long nextValidConfigEpoch = LocalNodeCurrentConfigEpoch;
var newWorkers = new Worker[workers.Length];
Array.Copy(workers, newWorkers, workers.Length);
newWorkers[1].CurrentConfigEpoch = nextValidConfigEpoch == 0 ? GetMaxConfigEpoch() : nextValidConfigEpoch + 1;
return new ClusterConfig(slotMap, newWorkers);
}

/// <summary>
/// Check if sender has same local worker epoch as the receiver node and resolve collision.
/// </summary>
Expand All @@ -1227,18 +1177,5 @@ public ClusterConfig HandleConfigEpochCollision(ClusterConfig other)
newWorkers[1].ConfigEpoch++;
return new ClusterConfig(slotMap, newWorkers);
}

/// <summary>
/// Updated last voted epoch to requested epoch.
/// </summary>
/// <param name="requestedEpoch">Requested epoch value.</param>
/// <returns>ClusterConfig object with updates.</returns>
public ClusterConfig SetLocalNodeLastVotedConfigEpoch(long requestedEpoch)
{
var newWorkers = new Worker[workers.Length];
Array.Copy(workers, newWorkers, workers.Length);
newWorkers[1].LastVotedConfigEpoch = requestedEpoch;
return new ClusterConfig(slotMap, newWorkers);
}
}
}
4 changes: 0 additions & 4 deletions libs/cluster/Server/ClusterConfigSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public byte[] ToByteArray()
//29 bytes
writer.Write(worker.Port);
writer.Write(worker.ConfigEpoch);
writer.Write(worker.CurrentConfigEpoch);
writer.Write(worker.LastVotedConfigEpoch);
writer.Write((byte)worker.Role);

//1 byte
Expand Down Expand Up @@ -120,8 +118,6 @@ public static ClusterConfig FromByteArray(byte[] other)
newWorkers[i].Address = reader.ReadString();
newWorkers[i].Port = reader.ReadInt32();
newWorkers[i].ConfigEpoch = reader.ReadInt64();
newWorkers[i].CurrentConfigEpoch = reader.ReadInt64();
newWorkers[i].LastVotedConfigEpoch = reader.ReadInt64();
newWorkers[i].Role = (NodeRole)reader.ReadByte();

byte isNull = reader.ReadByte();
Expand Down
Loading

0 comments on commit df6cea8

Please sign in to comment.