Skip to content

Commit

Permalink
Merge branch 'v5.4' of github.com:ravendb/ravendb into v6.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Voron/ValueReader.cs
#	test/RachisTests/BasicTests.cs
  • Loading branch information
arekpalinski committed May 9, 2024
2 parents edafc43 + 8ce3fa9 commit 2402a3f
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ protected override AbstractClusterDashboardNotification CreateNotification()
DirtyMemory = dirtyMemoryState.TotalDirty.GetValue(SizeUnit.Bytes),
AvailableMemory = memoryInfo.AvailableMemory.GetValue(SizeUnit.Bytes),
AvailableMemoryForProcessing = memoryInfo.AvailableMemoryForProcessing.GetValue(SizeUnit.Bytes),
TotalSwapUsage = memoryInfo.TotalSwapUsage.GetValue(SizeUnit.Bytes)
TotalSwapUsage = memoryInfo.TotalSwapUsage.GetValue(SizeUnit.Bytes),
LuceneUnmanagedAllocations = NativeMemory.TotalLuceneUnmanagedAllocationsForSorting
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public sealed class MemoryUsagePayload : AbstractClusterDashboardNotification
public long AvailableMemory { get; set; }
public long AvailableMemoryForProcessing { get; set; }
public long TotalSwapUsage { get; set; }
public long LuceneUnmanagedAllocations { get; set; }

public override ClusterDashboardNotificationType Type => ClusterDashboardNotificationType.MemoryUsage;

Expand All @@ -47,6 +48,7 @@ public override DynamicJsonValue ToJson()
json[nameof(AvailableMemory)] = AvailableMemory;
json[nameof(AvailableMemoryForProcessing)] = AvailableMemoryForProcessing;
json[nameof(TotalSwapUsage)] = TotalSwapUsage;
json[nameof(LuceneUnmanagedAllocations)] = LuceneUnmanagedAllocations;

return json;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Raven.Server/Documents/ReplayTxCommandHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal static async IAsyncEnumerable<ReplayProgress> ReplayAsync(DocumentDatab
await using (var readersItr = readers.GetAsyncEnumerator())
{
await ReadStartRecordingDetailsAsync(readersItr, context, peepingTomStream);
while (await readersItr.MoveNextAsync())
while (await readersItr.MoveNextAsync().ConfigureAwait(true))
{
using (readersItr.Current)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class memoryUsage extends historyAwareNodeStats<Raven.Server.Dashboard.Cluster.N
systemCommitLimit = this.dataExtractor(x => x.SystemCommitLimit);
totalSwapUsage = this.dataExtractor(x => x.TotalSwapUsage);
totalSwap = this.dataExtractor(x => x.PhysicalMemory != null && x.SystemCommitLimit != null ? x.SystemCommitLimit - x.PhysicalMemory : undefined);

luceneUnmanagedAllocations = this.dataExtractor(x => x.LuceneUnmanagedAllocations);

workingSetFormatted: KnockoutComputed<[string, string]>;
machineMemoryUsage: KnockoutComputed<string>;
machineMemoryUsagePercentage: KnockoutComputed<string>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ <h4>RavenDB Memory usage</h4>
<div class="details-item-name">Unmanaged Allocations</div>
<div class="details-item-value" data-bind="text: sizeFormatter(unmanagedAllocations())"></div>
</div>
<div class="details-item">
<div class="details-item-name">Lucene Unmanaged Allocations</div>
<div class="details-item-value" data-bind="text: sizeFormatter(luceneUnmanagedAllocations())"></div>
</div>
<div class="details-item" data-bind="visible: showEncryptionBuffers">
<div class="details-item-name">Encryption Buffers in Use</div>
<div class="details-item-value" data-bind="text: sizeFormatter(encryptionBuffersInUse())"></div>
Expand Down
16 changes: 10 additions & 6 deletions src/Voron/Impl/LowLevelTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,7 @@ public void Dispose()
if (_txState.HasFlag(TxState.Disposed))
return;

if (Flags == TransactionFlags.ReadWrite && NativeMemory.CurrentThreadStats != CurrentTransactionHolder)
ThrowDisposeOfTxMustBeCalledOnTheSameThreadThatCreatedIt();
EnsureDisposeOfWriteTxIsOnTheSameThreadThatCreatedIt();

try
{
Expand Down Expand Up @@ -1358,11 +1357,16 @@ private static void ThrowAlreadyCommitted()
throw new InvalidOperationException("Cannot commit already committed transaction.");
}

private void ThrowDisposeOfTxMustBeCalledOnTheSameThreadThatCreatedIt()
[Conditional("DEBUG")]
private void EnsureDisposeOfWriteTxIsOnTheSameThreadThatCreatedIt()
{
throw new InvalidOperationException($"Dispose of the transaction must be called from the same thread that created it. " +
$"Transaction {Id} (Flags: {Flags}) was created by {CurrentTransactionHolder.Name}, thread Id: {CurrentTransactionHolder.ManagedThreadId}. " +
$"The dispose was called from {NativeMemory.CurrentThreadStats.Name}, thread Id: {NativeMemory.CurrentThreadStats.ManagedThreadId}");
if (Flags == TransactionFlags.ReadWrite && NativeMemory.CurrentThreadStats != CurrentTransactionHolder)
{
throw new InvalidOperationException($"Dispose of the write transaction must be called from the same thread that created it. " +
$"Transaction {Id} (Flags: {Flags}) was created by {CurrentTransactionHolder.Name}, thread Id: {CurrentTransactionHolder.ManagedThreadId}. " +
$"The dispose was called from {NativeMemory.CurrentThreadStats.Name}, thread Id: {NativeMemory.CurrentThreadStats.ManagedThreadId}. " +
$"Do you have any await call in the scope of the write transaction?");
}
}

public void Rollback()
Expand Down
2 changes: 2 additions & 0 deletions src/Voron/ValueReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public long ReadBigEndianInt64()

var val = *(long*) (Base + _pos);

_pos += sizeof(long);

return Bits.SwapBytes(val);
}

Expand Down
11 changes: 6 additions & 5 deletions test/RachisTests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading;
using System.Threading.Tasks;
using Raven.Client.ServerWide;
using Raven.Client.Util;
using Raven.Server.Rachis;
using Raven.Server.ServerWide.Context;
using Sparrow.Json;
Expand Down Expand Up @@ -59,12 +60,12 @@ await ActionWithLeader(async l =>
}

[Fact]
public async Task RavenDB_13659()
public void RavenDB_13659()
{
EnableCaptureWriteTransactionStackTrace = true;

var leader = await CreateNetworkAndGetLeader(1);
var mre = new AsyncManualResetEvent();
var leader = AsyncHelpers.RunSync(() => CreateNetworkAndGetLeader(1));
var mre = new ManualResetEventSlim();
var tcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
var currentThread = NativeMemory.CurrentThreadStats.ManagedThreadId;

Expand Down Expand Up @@ -92,12 +93,12 @@ public async Task RavenDB_13659()
using (leader.ContextPool.AllocateOperationContext(out ClusterOperationContext context))
using (context.OpenWriteTransaction())
{
await mre.WaitAsync();
mre.Wait();
leader.SetNewStateInTx(context, RachisState.Follower, null, leader.CurrentTerm, "deadlock");
context.Transaction.Commit();
}

await tcs.Task;
AsyncHelpers.RunSync(() => tcs.Task);
}
}
}
9 changes: 6 additions & 3 deletions test/SlowTests/Voron/Issues/RavenDB_22257.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ protected override void Configure(StorageEnvironmentOptions options)

options.ManualFlushing = true;
}

#if DEBUG
[RavenFact(RavenTestCategory.Voron)]
#else
[RavenFact(RavenTestCategory.Voron, Skip = "This test relies on Debug only check - LowLevelTransaction.EnsureDisposeOfWriteTxIsOnTheSameThreadThatCreatedIt()")]
#endif
public void MustNotAllowToHaveTwoWriteTransactionsConcurrently()
{
RequireFileBasedPager();
Expand All @@ -48,7 +51,7 @@ public void MustNotAllowToHaveTwoWriteTransactionsConcurrently()
{
ex = Assert.Throws<InvalidOperationException>(() =>
{
txw1.Dispose(); // this is supposed to throw because we're attempting to dispose write tx from a different thread
txw1.Dispose(); // this is supposed to throw in Debug because we're attempting to dispose write tx from a different thread

txw2 = Env.NewLowLevelTransaction(new TransactionPersistentContext(), TransactionFlags.ReadWrite);

Expand All @@ -60,7 +63,7 @@ public void MustNotAllowToHaveTwoWriteTransactionsConcurrently()

newTransactionThread.Join();

Assert.StartsWith("Dispose of the transaction must be called from the same thread that created it. Transaction 2 (Flags: ReadWrite) was created by", ex.Message);
Assert.StartsWith("Dispose of the write transaction must be called from the same thread that created it. Transaction 2 (Flags: ReadWrite) was created by", ex.Message);
});

/*
Expand Down

0 comments on commit 2402a3f

Please sign in to comment.