Skip to content

Commit

Permalink
Merge pull request #13168 from ppekrol/v5.3
Browse files Browse the repository at this point in the history
5.2 to 5.3 merge
  • Loading branch information
ppekrol committed Nov 29, 2021
2 parents 6807792 + c4b62e1 commit 5309063
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 49 deletions.
Binary file modified src/Raven.Studio/wwwroot/Content/css/fonts/icomoon.eot
Binary file not shown.
1 change: 1 addition & 0 deletions src/Raven.Studio/wwwroot/Content/css/fonts/icomoon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/Raven.Studio/wwwroot/Content/css/fonts/icomoon.ttf
Binary file not shown.
Binary file modified src/Raven.Studio/wwwroot/Content/css/fonts/icomoon.woff
Binary file not shown.
1 change: 1 addition & 0 deletions src/Raven.Studio/wwwroot/Content/css/icons.less
Expand Up @@ -161,6 +161,7 @@
.make-icon(graph-range, "\ea2b");
.make-icon(timeseries, "\ea29");
.make-icon(timeseries-settings, "\ea29");
.make-icon(thread-stack-trace, "\ea57");
.make-icon(reference-pattern, "\ea28");
.make-icon(output-collection, "\ea27");
.make-icon(expos-refresh, "\ea26");
Expand Down
36 changes: 25 additions & 11 deletions src/Sparrow.Server/Platform/PlatformSpecific.cs
@@ -1,7 +1,9 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using Sparrow.Global;
using Sparrow.Platform;
using Sparrow.Server.LowMemory;
using Sparrow.Server.Platform.Posix;
Expand Down Expand Up @@ -36,21 +38,28 @@ public static class NativeMemory

if (PlatformDetails.RunningOnPosix)
{
byte* ptr;
var rc = Syscall.posix_memalign(&ptr, (IntPtr)4096, (IntPtr)size);
if (rc != 0)
Syscall.ThrowLastError(rc, "Could not allocate memory");
// we pass NULL (IntPtr.Zero) as the first parameter (address / start) so the kernel chooses the(page-aligned) address at which to create the mapping

return ptr;
var pageAlignedMemory = Syscall.mmap64(IntPtr.Zero, (UIntPtr)size, MmapProts.PROT_READ | MmapProts.PROT_WRITE,
MmapFlags.MAP_PRIVATE | MmapFlags.MAP_ANONYMOUS, -1, 0L);

if (pageAlignedMemory.ToInt64() == -1)
{
var err = Marshal.GetLastWin32Error();
Syscall.ThrowLastError(err,
$"Could not allocate memory (allocation size: {size / Constants.Size.Kilobyte:#,#0} kb)");
}

return (byte*)pageAlignedMemory;
}

var allocate4KbAllignedMemory = Win32MemoryProtectMethods.VirtualAlloc(null, (UIntPtr)size, Win32MemoryProtectMethods.AllocationType.COMMIT,
var allocate4KbAlignedMemory = Win32MemoryProtectMethods.VirtualAlloc(null, (UIntPtr)size, Win32MemoryProtectMethods.AllocationType.COMMIT,
Win32MemoryProtectMethods.MemoryProtection.READWRITE);

if (allocate4KbAllignedMemory == null)
if (allocate4KbAlignedMemory == null)
ThrowFailedToAllocate();

return allocate4KbAllignedMemory;
return allocate4KbAlignedMemory;
}

public static void Free4KbAlignedMemory(byte* ptr, long size, Sparrow.Utils.NativeMemory.ThreadStats stats)
Expand All @@ -61,11 +70,16 @@ public static void Free4KbAlignedMemory(byte* ptr, long size, Sparrow.Utils.Nati
Sparrow.Utils.NativeMemory.UpdateMemoryStatsForThread(stats, size);

Interlocked.Add(ref Sparrow.Utils.NativeMemory._totalAllocatedMemory, -size);

var p = new IntPtr(ptr);

if (PlatformDetails.RunningOnPosix)
{
Syscall.free(p);
var result = Syscall.munmap((IntPtr)ptr, (UIntPtr)(uint)size);
if (result == -1)
{
var err = Marshal.GetLastWin32Error();
Syscall.ThrowLastError(err, "Failed to munmap ");
}

return;
}

Expand Down
30 changes: 28 additions & 2 deletions test/SlowTests/Issues/RavenDB-15080.cs
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using System.Threading.Tasks;
using FastTests.Server.Replication;
using Raven.Client.Documents;
using Raven.Client.Documents.Operations;
using Raven.Client.Documents.Smuggler;
using Raven.Server.ServerWide.Context;
Expand Down Expand Up @@ -185,9 +186,10 @@ public async Task CanSplitAndReplicateRandomCounterName()
}
});
await Task.WhenAll(t1, t2);

Assert.True(EnsureReplicating(storeA, storeB, out var errMsg), errMsg);
Assert.True(EnsureReplicating(storeB, storeA, out errMsg), errMsg);

EnsureReplicating(storeA, storeB);
EnsureReplicating(storeB, storeA);
await EnsureNoReplicationLoop(Server, storeA.Database);
await EnsureNoReplicationLoop(Server, storeB.Database);
}
Expand Down Expand Up @@ -631,5 +633,29 @@ private static string RandomString(int size, Random random)
}
return builder.ToString();
}

private bool EnsureReplicating(IDocumentStore src, IDocumentStore dst, out string errorMsg)
{
errorMsg = string.Empty;

var id = "marker/" + Guid.NewGuid();
using (var s = src.OpenSession())
{
s.Store(new { }, id);
s.SaveChanges();
}

if (WaitForDocumentToReplicate<object>(dst, id, 15 * 1000) != null)
return true;

errorMsg = $"Failed to replicate from '{src.Database}' to '{dst.Database}' : ";
var replicationLoader = GetDocumentDatabaseInstanceFor(src).Result.ReplicationLoader;
foreach (var e in replicationLoader.OutgoingFailureInfo)
{
errorMsg += string.Join(", ", e.Value.Errors.Select(x => x.Message));
}

return false;
}
}
}
87 changes: 51 additions & 36 deletions test/SlowTests/Server/Documents/ETL/EtlTimeSeriesTests.cs
Expand Up @@ -1748,50 +1748,65 @@ await using (OpenEtlOffArea(src, etlResult.TaskId, true))

var timeSeriesEntriesToAppend = timeSeriesEntries.ToList();

var (src, dest, _) = CreateSrcDestAndAddEtl(collections, script, collections.Length == 0, srcOptions: _options);

using (var session = src.OpenAsyncSession())
using (var src = GetDocumentStore(_options))
using (var dest = GetDocumentStore())
{
var entity = new User { Name = "Joe Doe" };
await session.StoreAsync(entity, documentId);
await session.SaveChangesAsync();
}

random = new Random(0);
var j = 0;
while (timeSeriesEntriesToAppend.Count > 0)
{
using var session = src.OpenAsyncSession();
using (var session = src.OpenAsyncSession())
{
var entity = new User { Name = "Joe Doe" };
await session.StoreAsync(entity, documentId);
await session.SaveChangesAsync();
}

random = new Random(0);
var j = 0;
while (timeSeriesEntriesToAppend.Count > 0)
{
int index = random.Next(0, timeSeriesEntriesToAppend.Count - 1);
var entry = timeSeriesEntriesToAppend[index];
session.TimeSeriesFor(documentId, timeSeriesName).Append(entry.Timestamp, entry.Values, entry.Tag);
timeSeriesEntriesToAppend.RemoveAt(index);
if (j++ % (toAppendCount / 10) == 0)
break;
using var session = src.OpenAsyncSession();

while (timeSeriesEntriesToAppend.Count > 0)
{
int index = random.Next(0, timeSeriesEntriesToAppend.Count - 1);
var entry = timeSeriesEntriesToAppend[index];
session.TimeSeriesFor(documentId, timeSeriesName).Append(entry.Timestamp, entry.Values, entry.Tag);
timeSeriesEntriesToAppend.RemoveAt(index);
if (j++ % (toAppendCount / 10) == 0)
break;
}

await session.SaveChangesAsync();
}

await session.SaveChangesAsync();
}
var db = await GetDocumentDatabaseInstanceFor(src);
long lastEtag;
using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
using (context.OpenReadTransaction())
{
lastEtag = db.DocumentsStorage.TimeSeriesStorage.GetLastTimeSeriesEtag(context);
}

TimeSeriesEntry[] actual = null;
await AssertWaitForValueAsync(async () =>
{
using IAsyncDocumentSession session = dest.OpenAsyncSession();
var result = await session.TimeSeriesFor(documentId, timeSeriesName).GetAsync(DateTime.MinValue, DateTime.MaxValue);
if (result == null)
return 0;
actual = result.ToArray();
return actual.Count();
}, timeSeriesEntries.Length, interval: 1000);
var etlDone = WaitForEtl(src, (_, statistics) => statistics.LastProcessedEtag >= lastEtag);
AddEtl(src, dest, collections, script, applyToAllDocuments : collections.Length == 0);

Assert.True(etlDone.Wait(TimeSpan.FromSeconds(30)));

for (int i = 0; i < timeSeriesEntries.Length; i++)
{
Assert.Equal(timeSeriesEntries[i].Timestamp, actual[i].Timestamp);
Assert.Equal(timeSeriesEntries[i].Tag, actual[i].Tag);
Assert.Equal(timeSeriesEntries[i].Value, actual[i].Value);
TimeSeriesEntry[] actual = null;
await AssertWaitForValueAsync(async () =>
{
using IAsyncDocumentSession session = dest.OpenAsyncSession();
var result = await session.TimeSeriesFor(documentId, timeSeriesName).GetAsync(DateTime.MinValue, DateTime.MaxValue);
if (result == null)
return 0;
actual = result.ToArray();
return actual.Count();
}, timeSeriesEntries.Length, interval: 1000);

for (int i = 0; i < timeSeriesEntries.Length; i++)
{
Assert.Equal(timeSeriesEntries[i].Timestamp, actual[i].Timestamp);
Assert.Equal(timeSeriesEntries[i].Tag, actual[i].Tag);
Assert.Equal(timeSeriesEntries[i].Value, actual[i].Value);
}
}
}

Expand Down

0 comments on commit 5309063

Please sign in to comment.