Skip to content

Commit 045714e

Browse files
authored
Targeted test logging API, BDN cluster improvements, and client/libs cleanup (#1707)
* add BDN changes * libs/client cherry-pick * implemented targetted logging API for testing * bulk ops cherry-pick * libs configure await missing * addressing comments * fix formatting
1 parent b86f828 commit 045714e

62 files changed

Lines changed: 359 additions & 222 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<SignAssembly>true</SignAssembly>
7-
<AssemblyOriginatorKeyFile>../../Garnet.snk</AssemblyOriginatorKeyFile>
8-
<DelaySign>false</DelaySign>
9-
</PropertyGroup>
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<SignAssembly>true</SignAssembly>
7+
<AssemblyOriginatorKeyFile>../../Garnet.snk</AssemblyOriginatorKeyFile>
8+
<DelaySign>false</DelaySign>
9+
</PropertyGroup>
1010

11-
<ItemGroup>
12-
<PackageReference Include="BenchmarkDotNet" />
11+
<ItemGroup>
12+
<PackageReference Include="BenchmarkDotNet" />
1313
<PackageReference Include="KeraLua" />
1414
</ItemGroup>
1515

16-
<ItemGroup>
17-
<ProjectReference Include="..\..\libs\cluster\Garnet.cluster.csproj" />
18-
<ProjectReference Include="..\..\libs\host\Garnet.host.csproj" />
19-
<ProjectReference Include="..\..\libs\common\Garnet.common.csproj" />
20-
<ProjectReference Include="..\..\libs\server\Garnet.server.csproj" />
21-
<ProjectReference Include="..\..\modules\GarnetJSON\GarnetJSON.csproj" />
22-
<ProjectReference Include="..\..\modules\NoOpModule\NoOpModule.csproj" />
23-
</ItemGroup>
16+
<ItemGroup>
17+
<ProjectReference Include="..\..\libs\cluster\Garnet.cluster.csproj" />
18+
<ProjectReference Include="..\..\libs\host\Garnet.host.csproj" />
19+
<ProjectReference Include="..\..\libs\common\Garnet.common.csproj" />
20+
<ProjectReference Include="..\..\libs\server\Garnet.server.csproj" />
21+
<ProjectReference Include="..\..\modules\GarnetJSON\GarnetJSON.csproj" />
22+
<ProjectReference Include="..\..\modules\NoOpModule\NoOpModule.csproj" />
23+
</ItemGroup>
2424

25-
<ItemGroup>
26-
<Compile Include="..\..\main\GarnetServer\Extensions\MyDictObject.cs" Link="Custom\MyDictObject.cs" />
27-
<Compile Include="..\..\main\GarnetServer\Extensions\MyDictSet.cs" Link="Custom\MyDictSet.cs" />
28-
<Compile Include="..\..\main\GarnetServer\Extensions\MyDictGet.cs" Link="Custom\MyDictGet.cs" />
29-
<Compile Include="..\..\main\GarnetServer\Extensions\SetIfPM.cs" Link="Custom\SetIfPM.cs" />
30-
</ItemGroup>
25+
<ItemGroup>
26+
<Compile Include="..\..\main\GarnetServer\Extensions\MyDictObject.cs" Link="Custom\MyDictObject.cs" />
27+
<Compile Include="..\..\main\GarnetServer\Extensions\MyDictSet.cs" Link="Custom\MyDictSet.cs" />
28+
<Compile Include="..\..\main\GarnetServer\Extensions\MyDictGet.cs" Link="Custom\MyDictGet.cs" />
29+
<Compile Include="..\..\main\GarnetServer\Extensions\SetIfPM.cs" Link="Custom\SetIfPM.cs" />
30+
</ItemGroup>
3131

32-
</Project>
32+
</Project>

benchmark/BDN.benchmark/Cluster/ClusterContext.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,28 @@ public void Dispose()
2929
server.Dispose();
3030
}
3131

32-
public void SetupSingleInstance(bool disableSlotVerification = false)
32+
public void SetupSingleInstance(ClusterParams clusterParams)
3333
{
3434
var opt = new GarnetServerOptions
3535
{
3636
QuietMode = true,
37-
EnableCluster = !disableSlotVerification,
37+
EnableCluster = !clusterParams.disableSlotVerification,
3838
EndPoints = [new IPEndPoint(IPAddress.Loopback, port)],
3939
CleanClusterConfig = true,
40-
ClusterAnnounceEndpoint = new IPEndPoint(IPAddress.Loopback, port)
40+
ClusterAnnounceEndpoint = new IPEndPoint(IPAddress.Loopback, port),
41+
EnableAOF = clusterParams.enableAof,
4142
};
43+
44+
if (clusterParams.enableAof)
45+
{
46+
opt.EnableAOF = true;
47+
opt.UseAofNullDevice = true;
48+
opt.FastAofTruncate = true;
49+
opt.CommitFrequencyMs = -1;
50+
opt.AofPageSize = "128m";
51+
opt.AofMemorySize = "256m";
52+
}
53+
4254
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
4355
opt.CheckpointDir = "/tmp";
4456
server = new EmbeddedRespServer(opt);
@@ -168,5 +180,4 @@ public void CreateCTXNSET(int keySize = 8, int batchSize = 100)
168180
public void Consume(byte* ptr, int length)
169181
=> session.TryConsumeMessages(ptr, length);
170182
}
171-
172183
}

benchmark/BDN.benchmark/Cluster/ClusterMigrate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public unsafe class ClusterMigrate
2525
/// </summary>
2626
public IEnumerable<ClusterParams> ClusterParamsProvider()
2727
{
28-
yield return new(false);
28+
yield return new(false, false);
2929
}
3030

3131
ClusterContext cc;
@@ -34,7 +34,7 @@ public IEnumerable<ClusterParams> ClusterParamsProvider()
3434
public void GlobalSetup()
3535
{
3636
cc = new ClusterContext();
37-
cc.SetupSingleInstance();
37+
cc.SetupSingleInstance(Params);
3838
cc.AddSlotRange([(0, 16383)]);
3939
cc.CreateGetSet();
4040
cc.CreateMGetMSet();

benchmark/BDN.benchmark/Cluster/ClusterOperations.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ public unsafe class ClusterOperations
2222
/// </summary>
2323
public IEnumerable<ClusterParams> ClusterParamsProvider()
2424
{
25-
yield return new(false);
26-
yield return new(true);
25+
yield return new(false, false);
26+
yield return new(true, false);
27+
yield return new(false, true);
2728
}
2829

2930
ClusterContext cc;
@@ -32,7 +33,7 @@ public IEnumerable<ClusterParams> ClusterParamsProvider()
3233
public virtual void GlobalSetup()
3334
{
3435
cc = new ClusterContext();
35-
cc.SetupSingleInstance(Params.disableSlotVerification);
36+
cc.SetupSingleInstance(Params);
3637
cc.AddSlotRange([(0, 16383)]);
3738
cc.CreateGetSet();
3839
cc.CreateMGetMSet();

benchmark/BDN.benchmark/Cluster/ClusterParams.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,35 @@ public struct ClusterParams
1313
/// </summary>
1414
public bool disableSlotVerification;
1515

16+
/// <summary>
17+
/// Whether to enable AOF
18+
/// </summary>
19+
public bool enableAof;
20+
1621
/// <summary>
1722
/// Constructor
1823
/// </summary>
19-
public ClusterParams(bool disableSlotVerification)
24+
public ClusterParams(bool disableSlotVerification, bool enableAof)
2025
{
2126
this.disableSlotVerification = disableSlotVerification;
27+
this.enableAof = enableAof;
2228
}
2329

2430
/// <summary>
2531
/// String representation
2632
/// </summary>
2733
public override string ToString()
2834
{
29-
if (!disableSlotVerification)
35+
if (!disableSlotVerification && !enableAof)
3036
return "None";
3137

3238
var ret = "";
3339
if (disableSlotVerification)
3440
ret += "DSV";
41+
42+
if (enableAof)
43+
ret += ret.Length == 0 ? "AOF" : "+AOF";
44+
3545
return ret;
3646
}
3747
}

libs/client/ClientSession/GarnetClientSession.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ private async Task<Socket> ConnectSendSocketAsync(int millisecondsTimeout = 0, C
216216
NoDelay = true
217217
};
218218

219-
if (await TryConnectSocketAsync(socket, endpoint, millisecondsTimeout, cancellationToken))
219+
if (await TryConnectSocketAsync(socket, endpoint, millisecondsTimeout, cancellationToken).ConfigureAwait(false))
220220
return socket;
221221
}
222222
}
@@ -226,7 +226,7 @@ private async Task<Socket> ConnectSendSocketAsync(int millisecondsTimeout = 0, C
226226
if (EndPoint is not UnixDomainSocketEndPoint)
227227
socket.NoDelay = true;
228228

229-
if (await TryConnectSocketAsync(socket, EndPoint, millisecondsTimeout, cancellationToken))
229+
if (await TryConnectSocketAsync(socket, EndPoint, millisecondsTimeout, cancellationToken).ConfigureAwait(false))
230230
return socket;
231231
}
232232

@@ -251,12 +251,12 @@ private async Task<bool> TryConnectSocketAsync(Socket socket, EndPoint endpoint,
251251
using var timeoutCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
252252

253253
var connectTask = socket.ConnectAsync(endpoint, timeoutCts.Token).AsTask();
254-
if (await Task.WhenAny(connectTask, Task.Delay(millisecondsTimeout, timeoutCts.Token)) == connectTask)
254+
if (await Task.WhenAny(connectTask, Task.Delay(millisecondsTimeout, timeoutCts.Token)).ConfigureAwait(false) == connectTask)
255255
{
256256
// Task completed within timeout.
257257
// Consider that the task may have faulted or been canceled.
258258
// We re-await the task so that any exceptions/cancellation is rethrown.
259-
await connectTask;
259+
await connectTask.ConfigureAwait(false);
260260
}
261261
else
262262
{

libs/client/ClientSession/GarnetClientSessionReplicationExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public sealed unsafe partial class GarnetClientSession : IServerHook, IMessageCo
3131
/// <param name="aofBeginAddress"></param>
3232
/// <param name="aofTailAddress"></param>
3333
/// <returns></returns>
34-
/// <seealso cref="T:Garnet.cluster.ClusterSession.NetworkClusterInitiateReplicaSync"/>
34+
/// <seealso cref="M:Garnet.cluster.ClusterSession.NetworkClusterInitiateReplicaSync"/>
3535
public Task<string> ExecuteReplicaSync(string nodeId, string primary_replid, byte[] checkpointEntryData, long aofBeginAddress, long aofTailAddress)
3636
{
3737
var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
@@ -113,7 +113,7 @@ public Task<string> ExecuteReplicaSync(string nodeId, string primary_replid, byt
113113
/// <param name="fileTokenBytes"></param>
114114
/// <param name="fileType"></param>
115115
/// <param name="data"></param>
116-
/// <seealso cref="T:Garnet.cluster.ClusterSession.NetworkClusterSendCheckpointMetadata"/>
116+
/// <seealso cref="M:Garnet.cluster.ClusterSession.NetworkClusterSendCheckpointMetadata"/>
117117
public Task<string> ExecuteSendCkptMetadata(Memory<byte> fileTokenBytes, int fileType, Memory<byte> data)
118118
{
119119
var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
@@ -180,7 +180,7 @@ public Task<string> ExecuteSendCkptMetadata(Memory<byte> fileTokenBytes, int fil
180180
/// <param name="startAddress"></param>
181181
/// <param name="data"></param>
182182
/// <param name="segmentId"></param>
183-
/// <seealso cref="T:Garnet.cluster.ClusterSession.NetworkClusterSendCheckpointFileSegment"/>
183+
/// <seealso cref="M:Garnet.cluster.ClusterSession.NetworkClusterSendCheckpointFileSegment"/>
184184
public Task<string> ExecuteSendFileSegments(Memory<byte> fileTokenBytes, int fileType, long startAddress, Span<byte> data, int segmentId = -1)
185185
{
186186
var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
@@ -266,7 +266,7 @@ public Task<string> ExecuteSendFileSegments(Memory<byte> fileTokenBytes, int fil
266266
/// <param name="beginAddress"></param>
267267
/// <param name="tailAddress"></param>
268268
/// <returns></returns>
269-
/// <seealso cref="T:Garnet.cluster.ClusterSession.NetworkClusterBeginReplicaRecover"/>
269+
/// <seealso cref="M:Garnet.cluster.ClusterSession.NetworkClusterBeginReplicaRecover"/>
270270
public Task<string> ExecuteBeginReplicaRecover(bool sendStoreCheckpoint, bool replayAOF, string primary_replid, byte[] checkpointEntryData, long beginAddress, long tailAddress)
271271
{
272272
var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
@@ -355,7 +355,7 @@ public Task<string> ExecuteBeginReplicaRecover(bool sendStoreCheckpoint, bool re
355355
/// </summary>
356356
/// <param name="syncMetadata"></param>
357357
/// <returns></returns>
358-
/// <seealso cref="T:Garnet.cluster.ClusterSession.NetworkClusterAttachSync"/>
358+
/// <seealso cref="M:Garnet.cluster.ClusterSession.NetworkClusterAttachSync"/>
359359
public Task<string> ExecuteAttachSync(byte[] syncMetadata)
360360
{
361361
var tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
@@ -403,7 +403,7 @@ public Task<string> ExecuteAttachSync(byte[] syncMetadata)
403403
/// Set CLUSTER SYNC header info
404404
/// </summary>
405405
/// <param name="sourceNodeId"></param>
406-
/// <seealso cref="T:Garnet.cluster.ClusterSession.NetworkClusterSync"/>
406+
/// <seealso cref="M:Garnet.cluster.ClusterSession.NetworkClusterSync"/>
407407
public void SetClusterSyncHeader(string sourceNodeId)
408408
{
409409
// Unlike Migration, where we don't know at the time of header initialization if we have a record or not, in Replication

0 commit comments

Comments
 (0)