-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from koculu/65-bug-count-method-fails-when-dis…
…k-segment-is-dropped Attack to the disk segment during count to delay the drops.
- Loading branch information
Showing
5 changed files
with
165 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
using Tenray.ZoneTree.Comparers; | ||
using Tenray.ZoneTree.Options; | ||
using Tenray.ZoneTree.Serializers; | ||
|
||
namespace Tenray.ZoneTree.UnitTests; | ||
|
||
public sealed class CountTests | ||
{ | ||
[TestCase(DiskSegmentMode.MultiPartDiskSegment, 33, 77, false)] | ||
[TestCase(DiskSegmentMode.MultiPartDiskSegment, 33, 77, true)] | ||
public void CountRecordsDuringAMerge( | ||
DiskSegmentMode diskSegmentMode, | ||
int minimumRecordCount, | ||
int maximumRecordCount, | ||
bool useFullScan) | ||
{ | ||
var dataPath = "data/CountRecordsDuringAMerge" + diskSegmentMode + minimumRecordCount + maximumRecordCount + useFullScan; | ||
if (Directory.Exists(dataPath)) | ||
Directory.Delete(dataPath, true); | ||
|
||
using var zoneTree = new ZoneTreeFactory<string, int>() | ||
.SetIsValueDeletedDelegate((in int x) => x == -1) | ||
.SetMarkValueDeletedDelegate((ref int x) => x = -1) | ||
.SetMutableSegmentMaxItemCount(100) | ||
.SetDataDirectory(dataPath) | ||
.SetWriteAheadLogDirectory(dataPath) | ||
.SetComparer(new StringCurrentCultureComparerAscending()) | ||
.SetKeySerializer(new Utf8StringSerializer()) | ||
.SetValueSerializer(new Int32Serializer()) | ||
.ConfigureDiskSegmentOptions(x => | ||
{ | ||
x.DiskSegmentMode = diskSegmentMode; | ||
if (minimumRecordCount > 0) | ||
x.MinimumRecordCount = minimumRecordCount; | ||
if (maximumRecordCount > 0) | ||
x.MaximumRecordCount = maximumRecordCount; | ||
}) | ||
.OpenOrCreate(); | ||
var recordCount = 300; | ||
PrepareData1(zoneTree, recordCount, "a"); | ||
zoneTree.Maintenance.MoveMutableSegmentForward(); | ||
zoneTree.Maintenance.StartMergeOperation()?.Join(); | ||
var stepSize = 37; | ||
PrepareData1(zoneTree, recordCount); | ||
var deletedCount = DeleteData1(zoneTree, recordCount, stepSize); | ||
|
||
var expectedCount = recordCount * 8 - deletedCount; | ||
var failedCount = 0; | ||
|
||
var mergeThread = zoneTree.Maintenance.StartMergeOperation(); | ||
|
||
var isMergeFinished = false; | ||
var task = Task.Factory.StartNew(() => | ||
{ | ||
while (!isMergeFinished) | ||
{ | ||
var actualCount = useFullScan ? zoneTree.CountFullScan() : zoneTree.Count(); | ||
if (actualCount != expectedCount) | ||
++failedCount; | ||
} | ||
}); | ||
mergeThread?.Join(); | ||
isMergeFinished = true; | ||
task.Wait(); | ||
zoneTree.Maintenance.DestroyTree(); | ||
|
||
Assert.That(failedCount, Is.EqualTo(0)); | ||
} | ||
|
||
static void PrepareData1(IZoneTree<string, int> zoneTree, int n, string postfix = "") | ||
{ | ||
for (var i = 0; i < n; ++i) | ||
{ | ||
var key = $"myprefix1|string{i}{postfix}"; | ||
zoneTree.Upsert(key, i); | ||
} | ||
for (var i = 0; i < n; ++i) | ||
{ | ||
var key = $"myprefix2|string{i}{postfix}"; | ||
zoneTree.Upsert(key, i); | ||
} | ||
for (var i = 0; i < n; ++i) | ||
{ | ||
var key = $"myprefix3|string{i}{postfix}"; | ||
zoneTree.Upsert(key, i); | ||
} | ||
for (var i = 0; i < n; ++i) | ||
{ | ||
var key = $"myprefix4|string{i}{postfix}"; | ||
zoneTree.Upsert(key, i); | ||
} | ||
} | ||
|
||
static int DeleteData1(IZoneTree<string, int> zoneTree, int n, int step) | ||
{ | ||
var deletedCount = 0; | ||
for (var i = step; i < n; i += step) | ||
{ | ||
var key = $"myprefix1|string{i}"; | ||
zoneTree.ForceDelete(key); | ||
++deletedCount; | ||
|
||
} | ||
for (var i = step; i < n; i += step) | ||
{ | ||
var key = $"myprefix2|string{i}"; | ||
zoneTree.ForceDelete(key); | ||
++deletedCount; | ||
} | ||
for (var i = step; i < n; i += step) | ||
{ | ||
var key = $"myprefix3|string{i}"; | ||
zoneTree.ForceDelete(key); | ||
++deletedCount; | ||
} | ||
for (var i = step; i < n; i += step) | ||
{ | ||
var key = $"myprefix4|string{i}"; | ||
zoneTree.ForceDelete(key); | ||
++deletedCount; | ||
} | ||
return deletedCount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters