Skip to content

Commit a7e91d9

Browse files
committed
Release 5.22.0
1 parent ce9d83a commit a7e91d9

File tree

6 files changed

+26
-20
lines changed

6 files changed

+26
-20
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ stages:
145145
artifact: config
146146
- task: AzureCLI@2
147147
inputs:
148-
azureSubscription: '.NEXT Code Signing'
148+
azureSubscription: .NEXT Code Signing
149149
scriptType: pscore
150150
scriptLocation: inlineScript
151151
inlineScript:

src/DotNext.Tests/Net/Cluster/Consensus/Raft/StateMachine/WriteAheadLogTests.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,17 +298,13 @@ public static async Task IncrementalState()
298298

299299
Memory<byte> buffer = new byte[sizeof(long)];
300300
const long count = 1000L;
301-
using var cts = new CancellationTokenSource();
302301
for (var i = 0L; i < count; i++)
303302
{
304303
BinaryPrimitives.WriteInt64LittleEndian(buffer.Span, i);
305-
306-
cts.CancelAfter(DefaultTimeout);
307-
var index = await wal.AppendAsync(buffer, token: cts.Token);
308-
await wal.CommitAsync(index, cts.Token);
309-
await wal.WaitForApplyAsync(index, cts.Token);
310304

311-
True(cts.TryReset());
305+
var index = await wal.AppendAsync(buffer);
306+
await wal.CommitAsync(index);
307+
await wal.WaitForApplyAsync(index);
312308
}
313309

314310
Equal(count * (0L + count - 1L) / 2L, stateMachine.Value);

src/DotNext.Threading/Threading/Leases/LeaseConsumer.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,14 @@ public async Task<TResult> ExecuteAsync<TResult>(Func<CancellationToken, Task<TR
184184
ArgumentNullException.ThrowIfNull(worker);
185185

186186
var exception = default(Exception?);
187-
var leaseToken = Token;
188-
var operationToken = token;
189-
var cts = operationToken.LinkTo(leaseToken);
190-
191-
var task = Fork(worker, operationToken);
187+
var task = Fork(worker, out var cts, out var leaseToken, token);
188+
var timerToken = task.AsCancellationToken();
192189
try
193190
{
194-
Task completedTask;
195191
do
196192
{
197-
completedTask = await Task.WhenAny(Task.Delay(Expiration.Value / 2, operationToken), task).ConfigureAwait(false);
198-
} while (!ReferenceEquals(completedTask, task) && await TryRenewAsync(token).ConfigureAwait(false));
193+
await Task.Delay(Expiration.Value / 2, timerToken).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing);
194+
} while (!task.IsCompleted && await TryRenewAsync(token).ConfigureAwait(false));
199195
}
200196
catch (Exception e)
201197
{
@@ -222,6 +218,14 @@ public async Task<TResult> ExecuteAsync<TResult>(Func<CancellationToken, Task<TR
222218
{
223219
cts?.Dispose();
224220
}
221+
}
222+
223+
private Task<TResult> Fork<TResult>(Func<CancellationToken, Task<TResult>> worker, out LinkedCancellationTokenSource? cts,
224+
out CancellationToken leaseToken,
225+
CancellationToken token)
226+
{
227+
cts = token.LinkTo(leaseToken = Token);
228+
return Fork(worker, token);
225229

226230
static Task<TResult> Fork(Func<CancellationToken, Task<TResult>> function, CancellationToken token)
227231
=> Task.Run(() => function(token), token);

src/cluster/DotNext.Net.Cluster/Net/Cluster/Consensus/Raft/StateMachine/WriteAheadLog.Applier.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private async Task ApplyAsync(CancellationToken token)
3131
await lockManager.AcquireReadLockAsync(token).ConfigureAwait(false);
3232
try
3333
{
34-
await ApplyAsync(appliedIndex + 1L, newIndex, token).ConfigureAwait(false);
34+
await ApplyAsync(LastAppliedIndex + 1L, newIndex, token).ConfigureAwait(false);
3535
}
3636
catch (Exception e) when (e is not OperationCanceledException canceledEx || canceledEx.CancellationToken != token)
3737
{
@@ -54,9 +54,12 @@ private async Task ApplyAsync(CancellationToken token)
5454
public long LastAppliedIndex
5555
{
5656
get => Volatile.Read(in appliedIndex);
57+
5758
private set
5859
{
59-
Volatile.Write(ref appliedIndex, value);
60+
// Full memory barrier to ensure that the index cannot be changed later, somewhere
61+
// within Signal due to inlining
62+
Interlocked.Exchange(ref appliedIndex, value);
6063
appliedEvent.Signal(resumeAll: true);
6164
}
6265
}

src/cluster/DotNext.Net.Cluster/Net/Cluster/Consensus/Raft/StateMachine/WriteAheadLog.Flusher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private long Commit(long index)
169169
return index - oldCommitIndex;
170170
}
171171

172-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
172+
[MethodImpl(MethodImplOptions.NoInlining)]
173173
private void OnCommitted(long count)
174174
{
175175
if (flushOnCommit)

src/cluster/DotNext.Net.Cluster/Net/Cluster/Consensus/Raft/StateMachine/WriteAheadLog.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public WriteAheadLog(Options configuration, IStateMachine stateMachine)
4141
ArgumentNullException.ThrowIfNull(configuration);
4242
ArgumentNullException.ThrowIfNull(stateMachine);
4343

44+
if (nuint.Size < sizeof(ulong))
45+
throw new PlatformNotSupportedException();
46+
4447
lifetimeTokenSource = new();
4548
var rootPath = new DirectoryInfo(configuration.Location);
4649
CreateIfNeeded(rootPath);
@@ -252,7 +255,7 @@ public async ValueTask AppendAsync<TEntry>(TEntry entry, long startIndex, Cancel
252255
if (startIndex <= LastCommittedEntryIndex)
253256
throw new InvalidOperationException(ExceptionMessages.InvalidAppendIndex);
254257

255-
appliedIndex = await stateMachine.ApplyAsync(new LogEntry(entry, startIndex), token).ConfigureAwait(false);
258+
LastAppliedIndex = await stateMachine.ApplyAsync(new LogEntry(entry, startIndex), token).ConfigureAwait(false);
256259
var snapshotIndex = stateMachine.Snapshot?.Index ?? startIndex;
257260
LastEntryIndex = long.Max(tailIndex, LastCommittedEntryIndex = snapshotIndex);
258261
}

0 commit comments

Comments
 (0)