Skip to content

Commit

Permalink
Merge pull request #124 from koculu/123-enhancement-expose-the-copy-o…
Browse files Browse the repository at this point in the history
…f-the-internal-options

Expose the copy of the options.
  • Loading branch information
koculu authored Jan 18, 2025
2 parents d11268d + a2867aa commit 89e7d6e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
62 changes: 62 additions & 0 deletions src/ZoneTree/Core/ZoneTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,66 @@ public IMaintainer CreateMaintainer()
{
return new ZoneTreeMaintainer<TKey, TValue>(this);
}

public ZoneTreeOptions<TKey, TValue> CloneOptions()
{
var options = Options;
var wal = Options.WriteAheadLogOptions;
var dsk = Options.DiskSegmentOptions;

var clonedWal = new WriteAheadLogOptions()
{
AsyncCompressedModeOptions = new()
{
EmptyQueuePollInterval = wal.AsyncCompressedModeOptions.EmptyQueuePollInterval,
},
CompressionBlockSize = wal.CompressionBlockSize,
CompressionLevel = wal.CompressionLevel,
CompressionMethod = wal.CompressionMethod,
CustomOptions = wal.CustomOptions,
EnableIncrementalBackup = wal.EnableIncrementalBackup,
SyncCompressedModeOptions = new()
{
EnableTailWriterJob = wal.SyncCompressedModeOptions.EnableTailWriterJob,
TailWriterJobInterval = wal.SyncCompressedModeOptions.TailWriterJobInterval
},
WriteAheadLogMode = wal.WriteAheadLogMode,
};

var clonesDiskSegmentOptions = new DiskSegmentOptions()
{
CompressionBlockSize = dsk.CompressionBlockSize,
CompressionLevel = dsk.CompressionLevel,
CompressionMethod = dsk.CompressionMethod,
DefaultSparseArrayStepSize = dsk.DefaultSparseArrayStepSize,
DiskSegmentMode = dsk.DiskSegmentMode,
KeyCacheRecordLifeTimeInMillisecond = dsk.KeyCacheRecordLifeTimeInMillisecond,
KeyCacheSize = dsk.KeyCacheSize,
MaximumRecordCount = dsk.MaximumRecordCount,
MinimumRecordCount = dsk.MinimumRecordCount,
ValueCacheRecordLifeTimeInMillisecond = dsk.ValueCacheRecordLifeTimeInMillisecond,
ValueCacheSize = dsk.ValueCacheSize,
};

var clone = new ZoneTreeOptions<TKey, TValue>()
{
BTreeLeafSize = options.BTreeLeafSize,
BTreeLockMode = options.BTreeLockMode,
BTreeNodeSize = options.BTreeNodeSize,
Comparer = options.Comparer,
DiskSegmentMaxItemCount = options.DiskSegmentMaxItemCount,
DiskSegmentOptions = dsk,
EnableSingleSegmentGarbageCollection = options.EnableSingleSegmentGarbageCollection,
IsDeleted = options.IsDeleted,
KeySerializer = options.KeySerializer,
Logger = options.Logger,
MarkValueDeleted = options.MarkValueDeleted,
MutableSegmentMaxItemCount = options.MutableSegmentMaxItemCount,
RandomAccessDeviceManager = options.RandomAccessDeviceManager,
ValueSerializer = options.ValueSerializer,
WriteAheadLogOptions = clonedWal,
WriteAheadLogProvider = options.WriteAheadLogProvider,
};
return clone;
}
}
12 changes: 11 additions & 1 deletion src/ZoneTree/IZoneTreeMaintenance.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Tenray.ZoneTree.Segments;
using Tenray.ZoneTree.Options;
using Tenray.ZoneTree.Segments;
using Tenray.ZoneTree.Segments.Disk;

namespace Tenray.ZoneTree;
Expand Down Expand Up @@ -207,6 +208,15 @@ public interface IZoneTreeMaintenance<TKey, TValue>
/// Event is fired when the ZoneTree is disposing.
/// </summary>
event ZoneTreeIsDisposing<TKey, TValue> OnZoneTreeIsDisposing;

/// <summary>
/// Clones the options used by ZoneTree instance.
/// </summary>
/// <remarks>
/// Modifying the cloned option values does not change the ZoneTree instance's behavior.
/// </remarks>
/// <returns>Cloned ZoneTree options.</returns>
public ZoneTreeOptions<TKey, TValue> CloneOptions();
}

/// <summary>
Expand Down

0 comments on commit 89e7d6e

Please sign in to comment.