Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions NOTICE.html
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,6 @@ <h1>Third-party software list</h1>
</div>
</td><td>&copy; Microsoft Corporation. All rights reserved.</td>
</tr>
<tr>
<td><a href="https://go.microsoft.com/fwlink/?linkid=869051">Mono.Posix.NETStandard</a></td><td>1.0.0</td><td>
<div>
<a href="https://github.com/mono/mono/blob/main/LICENSE">MIT</a>
</div>
</td><td></td>
</tr>
<tr>
<td><a href="https://dot.net/">NETStandard.Library</a></td><td>2.0.3</td><td>
<div>
Expand Down
7 changes: 0 additions & 7 deletions qodana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ dependencyOverrides:
- key: "MIT"
url: "https://www.nuget.org/packages/Microsoft.Diagnostics.Runtime/2.2.332302"

# the referenced license file is not trivial but appears to imply that this library is MIT
- name: "Mono.Posix.NETStandard"
version: "1.0.0"
licenses:
- key: "MIT"
url: "https://github.com/mono/mono/blob/main/LICENSE"

# not automatically detectable by Qodana
- name: "OpenTelemetry"
version: "1.16.0"
Expand Down
1 change: 0 additions & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<PackageVersion Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.19.2" />
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.7.0" />
<PackageVersion Include="Mono.Posix.NETStandard" Version="1.0.0" />
<PackageVersion Include="NetEscapades.Configuration.Yaml" Version="3.1.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
<PackageVersion Include="NuGet.Protocol" Version="7.6.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,15 @@ public void the_hash_is_invalid()
var exc = Assert.Throws<CorruptIndexException>(() => PTable.FromFile(_copiedfilename, Constants.PTableInitialReaderCount, Constants.PTableMaxReaderCountDefault, 16, false));
Assert.IsInstanceOf<HashValidationException>(exc.InnerException);
}

[Test]
public void failed_open_releases_the_file_handle()
{
Assert.Throws<CorruptIndexException>(() => PTable.FromFile(_copiedfilename, 1, 1, 16, false));

Assert.DoesNotThrow(() =>
{
using var stream = new FileStream(_copiedfilename, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Threading.Tasks;
using EventStore.Core.Index;
using NUnit.Framework;

namespace EventStore.Core.Tests.Index.IndexV1;

[TestFixture(PTableVersions.IndexV2)]
[TestFixture(PTableVersions.IndexV3)]
[TestFixture(PTableVersions.IndexV4)]
public class when_opening_a_ptable_with_one_reader : SpecificationWithFile
{
private readonly byte _version;
private PTable _ptable;

public when_opening_a_ptable_with_one_reader(byte version)
{
_version = version;
}

[SetUp]
public override async Task SetUp()
{
await base.SetUp();

var memTable = new HashListMemTable(_version, maxSize: 1);
memTable.Add(0x010100000000, 1, 42);
_ptable = PTable.FromMemtable(
memTable,
Filename,
initialReaders: 1,
maxReaders: 1,
cacheDepth: 16,
skipIndexVerify: false,
useBloomFilter: false,
lruCacheSize: 0);
}

[TearDown]
public override void TearDown()
{
_ptable.MarkForDestruction();
_ptable.WaitForDisposal(1_000);
base.TearDown();
}

[Test]
public void reader_is_reusable_after_initialization()
{
Assert.That(_ptable.TryGetOneValue(0x010100000000, 1, out var position), Is.True);
Assert.That(position, Is.EqualTo(42));
}
}
39 changes: 39 additions & 0 deletions src/EventStore.Core.Tests/Index/MemTableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,45 @@ public HashListMemTableTests()
: base(() => new HashListMemTable(PTableVersions.IndexV2, maxSize: 20))
{
}

[Test]
public void ordered_iteration_does_not_allocate_a_key_view_for_each_stream()
{
const int streamCount = 1_024;
var warmupTable = CreateTable(streamCount: 2);
_ = MeasureOrderedIterationAllocations(warmupTable);

var table = CreateTable(streamCount);
var firstIteration = MeasureOrderedIterationAllocations(table);
var repeatedIteration = MeasureOrderedIterationAllocations(table);

Assert.That(firstIteration - repeatedIteration, Is.LessThanOrEqualTo(streamCount * IntPtr.Size));
}

private static HashListMemTable CreateTable(int streamCount)
{
var table = new HashListMemTable(PTableVersions.IndexV2, maxSize: streamCount);
for (var stream = 0; stream < streamCount; stream++)
{
table.Add((ulong)stream, version: 0, position: stream);
}

return table;
}

private static long MeasureOrderedIterationAllocations(HashListMemTable table)
{
var allocatedBefore = GC.GetAllocatedBytesForCurrentThread();
var count = 0;
foreach (var _ in table.IterateAllInOrder())
{
count++;
}
var allocated = GC.GetAllocatedBytesForCurrentThread() - allocatedBefore;

GC.KeepAlive(count);
return allocated;
}
}

[TestFixture]
Expand Down
20 changes: 20 additions & 0 deletions src/EventStore.Core.Tests/Index/ReverseComparerTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using EventStore.Core.Index;
using NUnit.Framework;

Expand All @@ -23,4 +24,23 @@ public void same_values_are_equal()
{
Assert.AreEqual(0, new ReverseComparer<int>().Compare(5, 5));
}

[Test]
public void comparing_value_types_does_not_allocate_per_comparison()
{
const int maximumOneTimeAllocation = 24;
var comparer = new ReverseComparer<ulong>();
_ = comparer.Compare(2, 1);

var allocatedBefore = GC.GetAllocatedBytesForCurrentThread();
var result = 0;
for (ulong i = 0; i < 1_000; i++)
{
result += comparer.Compare(i + 1, i);
}
var allocated = GC.GetAllocatedBytesForCurrentThread() - allocatedBefore;

GC.KeepAlive(result);
Assert.That(allocated, Is.LessThanOrEqualTo(maximumOneTimeAllocation));
}
}
Loading
Loading