Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor disk segments #33

Merged
merged 6 commits into from
May 28, 2023
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
5 changes: 3 additions & 2 deletions src/Playground/RecoverFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Tenray.ZoneTree.Logger;
using Tenray.ZoneTree.Options;
using Tenray.ZoneTree.Segments.Disk;
using Tenray.ZoneTree.Segments.RandomAccess;
using Tenray.ZoneTree.Serializers;
using Tenray.ZoneTree.WAL;

Expand Down Expand Up @@ -38,7 +39,7 @@ public static void Recover1()
= WriteAheadLogMode.AsyncCompressed;

var stopWatch = new Stopwatch();
var disk = new DiskSegment<string, string>(54, options);
var disk = DiskSegmentFactory.CreateDiskSegment(54, options);
disk.InitSparseArray(100);

Console.WriteLine("Elapsed: " + stopWatch.ElapsedMilliseconds);
Expand All @@ -57,7 +58,7 @@ public static void Recover2()
WriteAheadLogProvider = new WriteAheadLogProvider(
new ConsoleLogger(), fileStreamProvider, path),
WriteAheadLogOptions = meta.WriteAheadLogOptions,
RandomAccessDeviceManager = deviceManager,
RandomAccessDeviceManager = deviceManager,
DiskSegmentOptions = new()
{
CompressionBlockSize = meta.DiskSegmentOptions.CompressionBlockSize,
Expand Down
2 changes: 2 additions & 0 deletions src/ZoneTree/Core/ZoneTree.BottomSegments.Merge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using Tenray.ZoneTree.Collections;
using Tenray.ZoneTree.Exceptions;
using Tenray.ZoneTree.Options;
using Tenray.ZoneTree.Segments;
using Tenray.ZoneTree.Segments.Disk;
using Tenray.ZoneTree.Segments.MultiPart;

namespace Tenray.ZoneTree.Core;

Expand Down
3 changes: 2 additions & 1 deletion src/ZoneTree/Core/ZoneTree.Iterators.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Tenray.ZoneTree.Collections;
using Tenray.ZoneTree.Segments.Disk;
using Tenray.ZoneTree.Segments;
using Tenray.ZoneTree.Segments.NullDisk;

namespace Tenray.ZoneTree.Core;

Expand Down
3 changes: 3 additions & 0 deletions src/ZoneTree/Core/ZoneTree.Merge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
using Tenray.ZoneTree.Options;
using Tenray.ZoneTree.Segments;
using Tenray.ZoneTree.Segments.Disk;
using Tenray.ZoneTree.Segments.InMemory;
using Tenray.ZoneTree.Segments.MultiPart;
using Tenray.ZoneTree.Segments.NullDisk;

namespace Tenray.ZoneTree.Core;

Expand Down
3 changes: 2 additions & 1 deletion src/ZoneTree/Core/ZoneTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
using Tenray.ZoneTree.Logger;
using Tenray.ZoneTree.Options;
using Tenray.ZoneTree.Segments;
using Tenray.ZoneTree.Segments.Disk;
using Tenray.ZoneTree.Segments.InMemory;
using Tenray.ZoneTree.Segments.NullDisk;

namespace Tenray.ZoneTree.Core;

Expand Down
2 changes: 1 addition & 1 deletion src/ZoneTree/Core/ZoneTreeIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Tenray.ZoneTree.Comparers;
using Tenray.ZoneTree.Exceptions;
using Tenray.ZoneTree.Options;
using Tenray.ZoneTree.Segments.Disk;
using Tenray.ZoneTree.Segments;

namespace Tenray.ZoneTree.Core;

Expand Down
7 changes: 5 additions & 2 deletions src/ZoneTree/Core/ZoneTreeLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
using Tenray.ZoneTree.Options;
using Tenray.ZoneTree.Segments;
using Tenray.ZoneTree.Segments.Disk;
using Tenray.ZoneTree.Segments.InMemory;
using Tenray.ZoneTree.Segments.MultiPart;
using Tenray.ZoneTree.Segments.NullDisk;

namespace Tenray.ZoneTree.Core;

Expand Down Expand Up @@ -183,7 +186,7 @@ void LoadDiskSegment()
DiskSegment = new MultiPartDiskSegment<TKey, TValue>(segmentId, Options);
return;
}
DiskSegment = new DiskSegment<TKey, TValue>(segmentId, Options);
DiskSegment = DiskSegmentFactory.CreateDiskSegment(segmentId, Options);
}

void LoadBottomSegments()
Expand All @@ -202,7 +205,7 @@ void LoadBottomSegments()
}
else
{
var ds = new DiskSegment<TKey, TValue>(segmentId, Options);
var ds = DiskSegmentFactory.CreateDiskSegment(segmentId, Options);
map.AddOrUpdate(segmentId, ds, (_, _) => ds);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/ZoneTree/Core/ZoneTreeMaintainer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Concurrent;
using Tenray.ZoneTree.Logger;
using Tenray.ZoneTree.Segments.Disk;
using Tenray.ZoneTree.Segments;

namespace Tenray.ZoneTree.Core;

Expand Down
2 changes: 1 addition & 1 deletion src/ZoneTree/Core/ZoneTreeMetaWAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text.Json;
using Tenray.ZoneTree.Exceptions;
using Tenray.ZoneTree.Options;
using Tenray.ZoneTree.Segments.Disk;
using Tenray.ZoneTree.Segments.RandomAccess;
using Tenray.ZoneTree.Serializers;

namespace Tenray.ZoneTree.Core;
Expand Down
16 changes: 16 additions & 0 deletions src/ZoneTree/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@
Scope = "namespaceanddescendants",
Target = "Tenray.ZoneTree.Comparers")]

[assembly: SuppressMessage(
"\tUsage",
"CA2213: Disposable fields should be disposed",
Justification = "False warning: Device is disposed on ReleaseResources method.",
Scope = "namespaceanddescendants",
Target = "Tenray.ZoneTree.Segments.DiskSegmentVariations")]

[assembly: SuppressMessage(
"\tUsage",
"CA2213: Disposable fields should be disposed",
Justification = "False warning: Device is disposed on ReleaseResources method.",
Scope = "member",
Target = "Tenray.ZoneTree.Segments.Disk.DiskSegment.DataDevice")]

#pragma warning disable CA2213 // False warning: Device is disposed on ReleaseResources.

[assembly: SuppressMessage(
"Naming",
"CA1711: Identifiers should not have incorrect suffix",
Expand Down
2 changes: 1 addition & 1 deletion src/ZoneTree/Options/ZoneTreeOptions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Tenray.ZoneTree.Exceptions;
using Tenray.ZoneTree.Segments.Disk;
using Tenray.ZoneTree.WAL;
using Tenray.ZoneTree.Collections.BTree.Lock;
using Tenray.ZoneTree.Logger;
using Tenray.ZoneTree.Serializers;
using Tenray.ZoneTree.Comparers;
using Tenray.ZoneTree.Segments.RandomAccess;

namespace Tenray.ZoneTree.Options;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Concurrent;
using Tenray.ZoneTree.Logger;

namespace Tenray.ZoneTree.Segments.Disk;
namespace Tenray.ZoneTree.Segments.Block;

public sealed class CircularBlockCache
{
Expand Down Expand Up @@ -123,7 +123,7 @@ public bool TryGetBlock(int blockIndex, out DecompressedBlock block)

public void Clear()
{
Array.Fill(Table, null);
Array.Fill(Table, null);
LastReplacementTicks.Clear();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Tenray.ZoneTree.Compression;
using Tenray.ZoneTree.Options;

namespace Tenray.ZoneTree.Segments.Disk;
namespace Tenray.ZoneTree.Segments.Block;

public sealed class DecompressedBlock
{
Expand All @@ -20,13 +20,14 @@ public int Length
}

volatile byte[] Bytes;

public bool IsFull => Length == Bytes.Length;

long _lastAccessTicks;

public long LastAccessTicks {
get => Volatile.Read(ref _lastAccessTicks);
public long LastAccessTicks
{
get => Volatile.Read(ref _lastAccessTicks);
set => Volatile.Write(ref _lastAccessTicks, value);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Tenray.ZoneTree.Segments.Disk;
#if DEBUG

namespace Tenray.ZoneTree.Segments.Block;

/// <summary>
/// Thread-safe LRU Block Cache.
Expand All @@ -14,7 +16,7 @@ public sealed class LRUBlockCache
LinkedListNode<DecompressedBlock>> Cache;

readonly LinkedList<DecompressedBlock> List;

volatile int _count;
public int Count { get => _count; private set => _count = value; }

Expand Down Expand Up @@ -99,4 +101,6 @@ public DecompressedBlock[] ToArray()
return List.ToArray();
}
}
}
}

#endif
Loading