Skip to content

Commit

Permalink
Rename multi-part disk segment to match the disk segment modes to avo…
Browse files Browse the repository at this point in the history
…id confusion.
  • Loading branch information
koculu committed Aug 23, 2022
1 parent 682648e commit 72b19da
Show file tree
Hide file tree
Showing 18 changed files with 268 additions and 268 deletions.
6 changes: 3 additions & 3 deletions src/ZoneTree/Collections/BTree/BTreeSeekableIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class BTreeSeekableIterator<TKey, TValue>

public bool HasCurrent => CurrentNode != null && CurrentNode.HasCurrent;

public bool IsBeginningOfASector => false;
public bool IsBeginningOfAPart => false;

public bool IsEndOfASector => false;
public bool IsEndOfAPart => false;

public bool IsFullyFrozen => BTree.IsReadOnly;

Expand Down Expand Up @@ -90,5 +90,5 @@ public void Skip(int offset)
throw new NotSupportedException();
}

public int GetSectorIndex() => -1;
public int GetPartIndex() => -1;
}
6 changes: 3 additions & 3 deletions src/ZoneTree/Collections/BTree/FrozenBTreeSeekableIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class FrozenBTreeSeekableIterator<TKey, TValue>

public bool HasCurrent => CurrentNode != null && CurrentNode.HasCurrent;

public bool IsBeginningOfASector => false;
public bool IsBeginningOfAPart => false;

public bool IsEndOfASector => false;
public bool IsEndOfAPart => false;

public bool IsFullyFrozen => BTree.IsReadOnly;

Expand Down Expand Up @@ -90,5 +90,5 @@ public void Skip(int offset)
throw new NotSupportedException();
}

public int GetSectorIndex() => -1;
public int GetPartIndex() => -1;
}
6 changes: 3 additions & 3 deletions src/ZoneTree/Collections/IIndexedReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public interface IIndexedReader<TKey, TValue>

int GetFirstGreaterOrEqualPosition(in TKey key);

bool IsBeginningOfASector(int index);
bool IsBeginningOfAPart(int index);

bool IsEndOfASector(int index);
bool IsEndOfAPart(int index);

int GetSectorIndex(int index);
int GetPartIndex(int index);
}


6 changes: 3 additions & 3 deletions src/ZoneTree/Collections/ISeekableIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public interface ISeekableIterator<TKey, TValue>

void Skip(int offset);

bool IsBeginningOfASector { get; }
bool IsBeginningOfAPart { get; }

bool IsEndOfASector { get; }
bool IsEndOfAPart { get; }

int GetSectorIndex();
int GetPartIndex();

bool IsFullyFrozen { get; }
}
6 changes: 3 additions & 3 deletions src/ZoneTree/Collections/SeekableIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class SeekableIterator<TKey, TValue> : ISeekableIterator<TKey, TValue>

public bool HasCurrent => position >= 0 && position < Length;

public bool IsBeginningOfASector => IndexedReader.IsBeginningOfASector(position);
public bool IsBeginningOfAPart => IndexedReader.IsBeginningOfAPart(position);

public bool IsEndOfASector => IndexedReader.IsEndOfASector(position);
public bool IsEndOfAPart => IndexedReader.IsEndOfAPart(position);

/// <summary>
/// All Indexed Readers are always fully frozen.
Expand Down Expand Up @@ -83,6 +83,6 @@ public void Skip(int offset)
position += offset;

}
public int GetSectorIndex() => IndexedReader.GetSectorIndex(position);
public int GetPartIndex() => IndexedReader.GetPartIndex(position);
}

6 changes: 3 additions & 3 deletions src/ZoneTree/Core/IteratorPosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public enum IteratorPosition
{
None,
BeginningOfASector,
MiddleOfASector,
EndOfASector
BeginningOfAPart,
MiddleOfAPart,
EndOfAPart
}
52 changes: 26 additions & 26 deletions src/ZoneTree/Core/ZoneTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,15 +541,15 @@ MergeResult MergeReadOnlySegmentsInternal()
if (IsCancelMergeRequested)
return MergeResult.CANCELLED_BY_USER;

var enableMultiSectorDiskSegment =
var enableMultiPartDiskSegment =
Options.DiskSegmentMode == DiskSegmentMode.MultiPartDiskSegment;

var len = mergingSegments.Count;
var diskSegmentIndex = len - 1;

using IDiskSegmentCreator<TKey, TValue> diskSegmentCreator =
enableMultiSectorDiskSegment ?
new MultiSectorDiskSegmentCreator<TKey, TValue>(Options, IncrementalIdProvider) :
enableMultiPartDiskSegment ?
new MultiPartDiskSegmentCreator<TKey, TValue>(Options, IncrementalIdProvider) :
new DiskSegmentCreator<TKey, TValue>(Options, IncrementalIdProvider);

var heap = new FixedSizeMinHeap<HeapEntry<TKey, TValue>>(len + 1, MinHeapEntryComparer);
Expand Down Expand Up @@ -589,9 +589,9 @@ MergeResult MergeReadOnlySegmentsInternal()
var hasPrev = false;
TKey prevKey = default;

var firstKeysOfEverySector = oldDiskSegment.GetFirstKeysOfEverySector();
var lastKeysOfEverySector = oldDiskSegment.GetLastKeysOfEverySector();
var lastValuesOfEverySector = oldDiskSegment.GetLastValuesOfEverySector();
var firstKeysOfEveryPart = oldDiskSegment.GetFirstKeysOfEveryPart();
var lastKeysOfEveryPart = oldDiskSegment.GetLastKeysOfEveryPart();
var lastValuesOfEveryPart = oldDiskSegment.GetLastValuesOfEveryPart();
var diskSegmentMinimumRecordCount = Options.DiskSegmentMinimumRecordCount;

var dropCount = 0;
Expand Down Expand Up @@ -634,30 +634,30 @@ MergeResult MergeReadOnlySegmentsInternal()
hasPrev = true;
var isDiskSegmentKey = minSegmentIndex == diskSegmentIndex;
var iteratorPosition = IteratorPosition.None;
var currentSectorIndex = -1;
var currentPartIndex = -1;
if (isDiskSegmentKey)
{
var diskIterator = mergingSegments[minSegmentIndex];
iteratorPosition =
diskIterator.IsBeginningOfASector ?
IteratorPosition.BeginningOfASector :
diskIterator.IsEndOfASector ?
IteratorPosition.EndOfASector :
IteratorPosition.MiddleOfASector;
currentSectorIndex = diskIterator.GetSectorIndex();
diskIterator.IsBeginningOfAPart ?
IteratorPosition.BeginningOfAPart :
diskIterator.IsEndOfAPart ?
IteratorPosition.EndOfAPart :
IteratorPosition.MiddleOfAPart;
currentPartIndex = diskIterator.GetPartIndex();
}

// skip a sector without merge if possible
if (enableMultiSectorDiskSegment &&
// skip a part without merge if possible
if (enableMultiPartDiskSegment &&
isDiskSegmentKey &&
iteratorPosition == IteratorPosition.BeginningOfASector)
iteratorPosition == IteratorPosition.BeginningOfAPart)
{
var sector = oldDiskSegment
.GetSector(currentSectorIndex);
if (sector.Length > diskSegmentMinimumRecordCount &&
diskSegmentCreator.CanSkipCurrentSector)
var part = oldDiskSegment
.GetPart(currentPartIndex);
if (part.Length > diskSegmentMinimumRecordCount &&
diskSegmentCreator.CanSkipCurrentPart)
{
var lastKey = lastKeysOfEverySector[currentSectorIndex];
var lastKey = lastKeysOfEveryPart[currentPartIndex];
var islastKeySmallerThanAllOtherKeys = true;
var heapKeys = heap.GetKeys();
var heapKeysLen = heapKeys.Length;
Expand All @@ -676,12 +676,12 @@ MergeResult MergeReadOnlySegmentsInternal()
if (islastKeySmallerThanAllOtherKeys)
{
diskSegmentCreator.Append(
sector,
part,
minEntry.Key,
lastKey,
minEntry.Value,
lastValuesOfEverySector[currentSectorIndex]);
mergingSegments[diskSegmentIndex].Skip(sector.Length - 2);
lastValuesOfEveryPart[currentPartIndex]);
mergingSegments[diskSegmentIndex].Skip(part.Length - 2);
prevKey = lastKey;
skipElement();
++skipCount;
Expand All @@ -690,7 +690,7 @@ MergeResult MergeReadOnlySegmentsInternal()
}
++dropCount;
Logger.LogTrace(
$"drop: {sector.SegmentId} ({dropCount} / {skipCount + dropCount})");
$"drop: {part.SegmentId} ({dropCount} / {skipCount + dropCount})");

}

Expand All @@ -707,7 +707,7 @@ MergeResult MergeReadOnlySegmentsInternal()
MetaWal.NewDiskSegment(newDiskSegment.SegmentId);
try
{
oldDiskSegment.Drop(diskSegmentCreator.AppendedSectorSegmentIds);
oldDiskSegment.Drop(diskSegmentCreator.AppendedPartSegmentIds);
}
catch (Exception e)
{
Expand Down
6 changes: 3 additions & 3 deletions src/ZoneTree/Core/ZoneTreeLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ void LoadDiskSegment()
return;
}
if (Options.RandomAccessDeviceManager
.DeviceExists(segmentId, DiskSegmentConstants.MultiSectorDiskSegmentCategory))
.DeviceExists(segmentId, DiskSegmentConstants.MultiPartDiskSegmentCategory))
{
DiskSegment = new MultiSectorDiskSegment<TKey, TValue>(ZoneTreeMeta.DiskSegment, Options);
DiskSegment = new MultiPartDiskSegment<TKey, TValue>(ZoneTreeMeta.DiskSegment, Options);
return;
}
DiskSegment = new DiskSegment<TKey, TValue>(ZoneTreeMeta.DiskSegment, Options);
Expand All @@ -177,7 +177,7 @@ void SetMaximumId()
{
SetMaximumSegmentId(ZoneTreeMeta.SegmentZero);
SetMaximumSegmentId(ZoneTreeMeta.DiskSegment);
SetMaximumSegmentId(MultiSectorDiskSegment<TKey, TValue>
SetMaximumSegmentId(MultiPartDiskSegment<TKey, TValue>
.ReadMaximumSegmentId(ZoneTreeMeta.DiskSegment, Options.RandomAccessDeviceManager));
var ros = ZoneTreeMeta.ReadOnlySegments;
var maximumId = ros.Count > 0 ? ros[0] : 0;
Expand Down
18 changes: 9 additions & 9 deletions src/ZoneTree/Segments/Disk/DiskSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,22 +410,22 @@ int BinarySearch(in TKey key, int lower, int upper)
return -1;
}

public TKey[] GetFirstKeysOfEverySector()
public TKey[] GetFirstKeysOfEveryPart()
{
return Array.Empty<TKey>();
}

public TKey[] GetLastKeysOfEverySector()
public TKey[] GetLastKeysOfEveryPart()
{
return Array.Empty<TKey>();
}

public TValue[] GetLastValuesOfEverySector()
public TValue[] GetLastValuesOfEveryPart()
{
return Array.Empty<TValue>();
}

public IDiskSegment<TKey, TValue> GetSector(int sectorIndex)
public IDiskSegment<TKey, TValue> GetPart(int partIndex)
{
return null;
}
Expand Down Expand Up @@ -568,16 +568,16 @@ public int ReleaseReadBuffers(long ticks)
return a + b;
}

public void Drop(HashSet<long> excludedSectorIds)
public void Drop(HashSet<long> excludedPartIds)
{
if (excludedSectorIds.Contains(SegmentId))
if (excludedPartIds.Contains(SegmentId))
return;
Drop();
}

public bool IsBeginningOfASector(int index) => false;
public bool IsBeginningOfAPart(int index) => false;

public bool IsEndOfASector(int index) => false;
public bool IsEndOfAPart(int index) => false;

public int GetSectorIndex(int index) => -1;
public int GetPartIndex(int index) => -1;
}
2 changes: 1 addition & 1 deletion src/ZoneTree/Segments/Disk/DiskSegmentConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ public static class DiskSegmentConstants
{
public const string DataHeaderCategory = ".head";
public const string DataCategory = ".data";
public const string MultiSectorDiskSegmentCategory = ".multi";
public const string MultiPartDiskSegmentCategory = ".multi";
}
6 changes: 3 additions & 3 deletions src/ZoneTree/Segments/Disk/DiskSegmentCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public sealed class DiskSegmentCreator<TKey, TValue> : IDiskSegmentCreator<TKey,

public int Length { get; private set; }

public bool CanSkipCurrentSector => false;
public bool CanSkipCurrentPart => false;

public HashSet<long> AppendedSectorSegmentIds { get; } = new();
public HashSet<long> AppendedPartSegmentIds { get; } = new();

public DiskSegmentCreator(
ZoneTreeOptions<TKey, TValue> options,
Expand Down Expand Up @@ -152,7 +152,7 @@ public void Dispose()
DataDevice?.Dispose();
}

public void Append(IDiskSegment<TKey, TValue> sector, TKey key1, TKey key2, TValue value1, TValue value2)
public void Append(IDiskSegment<TKey, TValue> part, TKey key1, TKey key2, TValue value1, TValue value2)
{
throw new NotSupportedException("This method should be called on MultiDiskSegmentCreator.");
}
Expand Down
22 changes: 11 additions & 11 deletions src/ZoneTree/Segments/Disk/IDiskSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ public interface IDiskSegment<TKey, TValue> : IReadOnlySegment<TKey, TValue>, II
int ReleaseReadBuffers(long ticks);

/// <summary>
/// Returns the first keys of every sector.
/// Returns the first keys of every part.
/// </summary>
/// <returns>Keys</returns>
TKey[] GetFirstKeysOfEverySector();
TKey[] GetFirstKeysOfEveryPart();

/// <summary>
/// Returns the last keys of every sector.
/// Returns the last keys of every part.
/// </summary>
/// <returns>Keys</returns>
TKey[] GetLastKeysOfEverySector();
TKey[] GetLastKeysOfEveryPart();

/// <summary>
/// Returns the last values of every sector.
/// Returns the last values of every part.
/// </summary>
/// <returns>Values</returns>
TValue[] GetLastValuesOfEverySector();
TValue[] GetLastValuesOfEveryPart();

/// <summary>
/// Exceptions occurs in delayed drops (eg: iterators delays segment drops)
Expand All @@ -71,15 +71,15 @@ public interface IDiskSegment<TKey, TValue> : IReadOnlySegment<TKey, TValue>, II
internal Action<IDiskSegment<TKey, TValue>, Exception> DropFailureReporter { get; set; }

/// <summary>
/// Gets sector.
/// Gets part.
/// </summary>
/// <param name="sectorIndex"></param>
/// <param name="partIndex"></param>
/// <returns></returns>
IDiskSegment<TKey, TValue> GetSector(int sectorIndex);
IDiskSegment<TKey, TValue> GetPart(int partIndex);

/// <summary>
/// Drops all sectos excluding given exclusion list.
/// </summary>
/// <param name="excludedSectorIds"></param>
void Drop(HashSet<long> excludedSectorIds);
/// <param name="excludedPartIds"></param>
void Drop(HashSet<long> excludedPartIds);
}
6 changes: 3 additions & 3 deletions src/ZoneTree/Segments/Disk/IDiskSegmentCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ namespace Tenray.ZoneTree.Segments.Disk;

public interface IDiskSegmentCreator<TKey, TValue> : IDisposable
{
bool CanSkipCurrentSector { get; }
bool CanSkipCurrentPart { get; }

HashSet<long> AppendedSectorSegmentIds { get; }
HashSet<long> AppendedPartSegmentIds { get; }

void Append(TKey key, TValue value, IteratorPosition iteratorPosition);

void Append(
IDiskSegment<TKey, TValue> sector,
IDiskSegment<TKey, TValue> part,
TKey key1,
TKey key2,
TValue value1,
Expand Down
Loading

0 comments on commit 72b19da

Please sign in to comment.