From 2c1b05d27edfec83362ac093144bb0ce8fc6675c Mon Sep 17 00:00:00 2001 From: Ahmed Yasin Koculu Date: Sat, 18 Jan 2025 02:30:13 +0100 Subject: [PATCH] Expose default values. --- src/ZoneTree/Directory.Build.props | 4 +-- src/ZoneTree/Options/DefaultValues.cs | 17 ++++++++++++ .../Options/DiskSegmentDefaultValues.cs | 26 +++++++++++++++++++ src/ZoneTree/Options/DiskSegmentOptions.cs | 22 ++++++++-------- .../Options/WriteAheadLogDefaultValues.cs | 18 +++++++++++++ src/ZoneTree/Options/WriteAheadLogMode.cs | 2 +- src/ZoneTree/Options/WriteAheadLogOptions.cs | 8 +++--- src/ZoneTree/Options/ZoneTreeOptions.cs | 10 +++---- .../WAL/Async/AsyncCompressedModeOptions.cs | 6 +++-- .../SyncCompressedModeOptions.cs | 8 +++--- 10 files changed, 93 insertions(+), 28 deletions(-) create mode 100644 src/ZoneTree/Options/DefaultValues.cs create mode 100644 src/ZoneTree/Options/DiskSegmentDefaultValues.cs create mode 100644 src/ZoneTree/Options/WriteAheadLogDefaultValues.cs diff --git a/src/ZoneTree/Directory.Build.props b/src/ZoneTree/Directory.Build.props index 40aac7a..4de4acf 100644 --- a/src/ZoneTree/Directory.Build.props +++ b/src/ZoneTree/Directory.Build.props @@ -5,8 +5,8 @@ Ahmed Yasin Koculu ZoneTree ZoneTree - 1.8.4.0 - 1.8.4.0 + 1.8.5.0 + 1.8.5.0 Ahmed Yasin Koculu ZoneTree ZoneTree is a persistent, high-performance, transactional, ACID-compliant ordered key-value database for NET. It can operate in memory or on local/cloud storage. diff --git a/src/ZoneTree/Options/DefaultValues.cs b/src/ZoneTree/Options/DefaultValues.cs new file mode 100644 index 0000000..3608090 --- /dev/null +++ b/src/ZoneTree/Options/DefaultValues.cs @@ -0,0 +1,17 @@ +using System.Collections.ObjectModel; +using Tenray.ZoneTree.Collections.BTree.Lock; + +namespace Tenray.ZoneTree.Options; + +public static class DefaultValues +{ + public static readonly int MutableSegmentMaxItemCount = 1_000_000; + + public static readonly int DiskSegmentMaxItemCount = 20_000_000; + + public static readonly BTreeLockMode BTreeLockMode = BTreeLockMode.NodeLevelMonitor; + + public static readonly int BTreeNodeSize = 128; + + public static readonly int BTreeLeafSize = 128; +} \ No newline at end of file diff --git a/src/ZoneTree/Options/DiskSegmentDefaultValues.cs b/src/ZoneTree/Options/DiskSegmentDefaultValues.cs new file mode 100644 index 0000000..76ae9c3 --- /dev/null +++ b/src/ZoneTree/Options/DiskSegmentDefaultValues.cs @@ -0,0 +1,26 @@ +namespace Tenray.ZoneTree.Options; + +public static class DiskSegmentDefaultValues +{ + public static readonly DiskSegmentMode DiskSegmentMode = DiskSegmentMode.MultiPartDiskSegment; + + public static readonly int CompressionBlockSize = 4 * 1024 * 1024; + + public static readonly CompressionMethod CompressionMethod = CompressionMethod.LZ4; + + public static readonly int CompressionLevel = CompressionLevels.LZ4Fastest; + + public static readonly int MaximumRecordCount = 3_000_000; + + public static readonly int MinimumRecordCount = 1_500_000; + + public static readonly int KeyCacheSize = 1024; + + public static readonly int ValueCacheSize = 1024; + + public static readonly int KeyCacheRecordLifeTimeInMillisecond = 1024; + + public static readonly int ValueCacheRecordLifeTimeInMillisecond = 10_000; + + public static readonly int DefaultSparseArrayStepSize = 1024; +} diff --git a/src/ZoneTree/Options/DiskSegmentOptions.cs b/src/ZoneTree/Options/DiskSegmentOptions.cs index 815ab4a..4444929 100644 --- a/src/ZoneTree/Options/DiskSegmentOptions.cs +++ b/src/ZoneTree/Options/DiskSegmentOptions.cs @@ -10,32 +10,32 @@ public sealed class DiskSegmentOptions /// Default value is . /// public DiskSegmentMode DiskSegmentMode { get; set; } - = DiskSegmentMode.MultiPartDiskSegment; + = DiskSegmentDefaultValues.DiskSegmentMode; /// /// Gets or sets the block size for disk segment compression, in bytes. /// Default value is 4 MB (4 * 1024 * 1024 bytes). /// - public int CompressionBlockSize { get; set; } = 4 * 1024 * 1024; + public int CompressionBlockSize { get; set; } = DiskSegmentDefaultValues.CompressionBlockSize; /// /// Gets or sets the compression method used if compression is enabled. /// Default value is . /// - public CompressionMethod CompressionMethod { get; set; } = CompressionMethod.LZ4; + public CompressionMethod CompressionMethod { get; set; } = DiskSegmentDefaultValues.CompressionMethod; /// /// Gets or sets the compression level for the selected compression method. /// Default value is . /// - public int CompressionLevel { get; set; } = CompressionLevels.LZ4Fastest; + public int CompressionLevel { get; set; } = DiskSegmentDefaultValues.CompressionLevel; /// /// Gets or sets the maximum number of records allowed in a disk segment when /// is enabled. /// Default value is 3M records. /// - public int MaximumRecordCount { get; set; } = 3_000_000; + public int MaximumRecordCount { get; set; } = DiskSegmentDefaultValues.MaximumRecordCount; /// /// Gets or sets the minimum number of records required in a disk segment when @@ -43,38 +43,38 @@ public sealed class DiskSegmentOptions /// are not enough records. /// Default value is 1.5M records. /// - public int MinimumRecordCount { get; set; } = 1_500_000; + public int MinimumRecordCount { get; set; } = DiskSegmentDefaultValues.MinimumRecordCount; /// /// Gets or sets the size of the circular buffer cache for keys. /// This cache is checked before accessing the block cache during lookups and searches. /// Default value is 1024. /// - public int KeyCacheSize { get; set; } = 1024; + public int KeyCacheSize { get; set; } = DiskSegmentDefaultValues.KeyCacheSize; /// /// Gets or sets the size of the circular buffer cache for values. /// This cache is checked before accessing the block cache during lookups and searches. /// Default value is 1024. /// - public int ValueCacheSize { get; set; } = 1024; + public int ValueCacheSize { get; set; } = DiskSegmentDefaultValues.ValueCacheSize; /// /// Gets or sets the maximum lifetime of a record in the key cache, in milliseconds. /// Default value is 10,000 milliseconds (10 seconds). /// - public int KeyCacheRecordLifeTimeInMillisecond { get; set; } = 10_000; + public int KeyCacheRecordLifeTimeInMillisecond { get; set; } = DiskSegmentDefaultValues.KeyCacheRecordLifeTimeInMillisecond; /// /// Gets or sets the maximum lifetime of a record in the value cache, in milliseconds. /// Default value is 10,000 milliseconds (10 seconds). /// - public int ValueCacheRecordLifeTimeInMillisecond { get; set; } = 10_000; + public int ValueCacheRecordLifeTimeInMillisecond { get; set; } = DiskSegmentDefaultValues.ValueCacheRecordLifeTimeInMillisecond; /// /// Gets or sets the default step size for the default sparse array of disk segments. /// Setting the step size to zero disables loading and creating the default sparse array. /// Default value is 1024. /// - public int DefaultSparseArrayStepSize { get; set; } = 1024; + public int DefaultSparseArrayStepSize { get; set; } = DiskSegmentDefaultValues.DefaultSparseArrayStepSize; } diff --git a/src/ZoneTree/Options/WriteAheadLogDefaultValues.cs b/src/ZoneTree/Options/WriteAheadLogDefaultValues.cs new file mode 100644 index 0000000..1cc479e --- /dev/null +++ b/src/ZoneTree/Options/WriteAheadLogDefaultValues.cs @@ -0,0 +1,18 @@ +namespace Tenray.ZoneTree.Options; + +public static class WriteAheadLogDefaultValues +{ + public static readonly WriteAheadLogMode WriteAheadLogMode = WriteAheadLogMode.AsyncCompressed; + + public static readonly int CompressionBlockSize = 1024 * 32 * 8; + + public static readonly CompressionMethod CompressionMethod = CompressionMethod.LZ4; + + public static readonly int CompressionLevel = CompressionLevels.LZ4Fastest; + + public static readonly bool SyncCompressedModeEnableTailWriterJob = true; + + public static readonly int SyncCompressedModeTailWriterJobInterval = 500; + + public static readonly int AsyncCompressedModeEmptyQueuePollInterval = 100; +} diff --git a/src/ZoneTree/Options/WriteAheadLogMode.cs b/src/ZoneTree/Options/WriteAheadLogMode.cs index b31f803..cfb4608 100644 --- a/src/ZoneTree/Options/WriteAheadLogMode.cs +++ b/src/ZoneTree/Options/WriteAheadLogMode.cs @@ -8,7 +8,7 @@ public enum WriteAheadLogMode : byte /// /// Sync mode write ahead log ensures that the data is flushed to the device /// immediately. - /// It provides maximum durability in case of a crash/power cut, + /// It provides maximum durability in case of a crash, /// but slower write speed. /// Sync = 0, diff --git a/src/ZoneTree/Options/WriteAheadLogOptions.cs b/src/ZoneTree/Options/WriteAheadLogOptions.cs index c1f9447..ff4459e 100644 --- a/src/ZoneTree/Options/WriteAheadLogOptions.cs +++ b/src/ZoneTree/Options/WriteAheadLogOptions.cs @@ -14,7 +14,7 @@ public sealed class WriteAheadLogOptions /// based on this setting. Default value is AsyncCompressed. /// public WriteAheadLogMode WriteAheadLogMode { get; set; } - = WriteAheadLogMode.AsyncCompressed; + = WriteAheadLogDefaultValues.WriteAheadLogMode; /// /// The custom options are reserved to be used @@ -27,19 +27,19 @@ public sealed class WriteAheadLogOptions /// based on this setting. Default value = 256 KB /// public int CompressionBlockSize { get; set; } - = 1024 * 32 * 8; + = WriteAheadLogDefaultValues.CompressionBlockSize; /// /// The compression method for the WALs with compression enabled. /// Default is LZ4. /// - public CompressionMethod CompressionMethod { get; set; } = CompressionMethod.LZ4; + public CompressionMethod CompressionMethod { get; set; } = WriteAheadLogDefaultValues.CompressionMethod; /// /// The compression level of the selected compression method. /// Default is . /// - public int CompressionLevel { get; set; } = CompressionLevels.LZ4Fastest; + public int CompressionLevel { get; set; } = WriteAheadLogDefaultValues.CompressionLevel; /// /// Options for sync-compressed mode. diff --git a/src/ZoneTree/Options/ZoneTreeOptions.cs b/src/ZoneTree/Options/ZoneTreeOptions.cs index 4a23c17..06dda8b 100644 --- a/src/ZoneTree/Options/ZoneTreeOptions.cs +++ b/src/ZoneTree/Options/ZoneTreeOptions.cs @@ -39,14 +39,14 @@ public sealed class ZoneTreeOptions /// MoveMutableSegmentForward is called and current mutable segment is enqueued to /// the ReadOnlySegments layer. /// - public int MutableSegmentMaxItemCount { get; set; } = 1_000_000; + public int MutableSegmentMaxItemCount { get; set; } = DefaultValues.MutableSegmentMaxItemCount; /// /// Disk segment maximumum key-value pair count. /// When the maximum count is reached /// The disk segment is enqueued into to the bottom segments layer. /// - public int DiskSegmentMaxItemCount { get; set; } = 20_000_000; + public int DiskSegmentMaxItemCount { get; set; } = DefaultValues.DiskSegmentMaxItemCount; /// /// The key comparer. @@ -92,17 +92,17 @@ public sealed class ZoneTreeOptions /// Controls lock granularity of in-memory BTree that represents the /// mutable segment. /// - public BTreeLockMode BTreeLockMode { get; set; } = BTreeLockMode.NodeLevelMonitor; + public BTreeLockMode BTreeLockMode { get; set; } = DefaultValues.BTreeLockMode; /// /// The B+Tree node size. /// - public int BTreeNodeSize { get; set; } = 128; + public int BTreeNodeSize { get; set; } = DefaultValues.BTreeNodeSize; /// /// The B+Tree leaf size. /// - public int BTreeLeafSize { get; set; } = 128; + public int BTreeLeafSize { get; set; } = DefaultValues.BTreeLeafSize; /// /// ZoneTree Logger. diff --git a/src/ZoneTree/WAL/Async/AsyncCompressedModeOptions.cs b/src/ZoneTree/WAL/Async/AsyncCompressedModeOptions.cs index 0e097c4..548ac87 100644 --- a/src/ZoneTree/WAL/Async/AsyncCompressedModeOptions.cs +++ b/src/ZoneTree/WAL/Async/AsyncCompressedModeOptions.cs @@ -1,4 +1,6 @@ -namespace Tenray.ZoneTree.WAL; +using Tenray.ZoneTree.Options; + +namespace Tenray.ZoneTree.WAL; public sealed class AsyncCompressedModeOptions { @@ -7,5 +9,5 @@ public sealed class AsyncCompressedModeOptions /// to retrieve the new entries in the queue, /// when the queue is empty. /// - public int EmptyQueuePollInterval { get; set; } = 100; + public int EmptyQueuePollInterval { get; set; } = WriteAheadLogDefaultValues.AsyncCompressedModeEmptyQueuePollInterval; } diff --git a/src/ZoneTree/WAL/SyncCompressed/SyncCompressedModeOptions.cs b/src/ZoneTree/WAL/SyncCompressed/SyncCompressedModeOptions.cs index 206c5e6..7dd8538 100644 --- a/src/ZoneTree/WAL/SyncCompressed/SyncCompressedModeOptions.cs +++ b/src/ZoneTree/WAL/SyncCompressed/SyncCompressedModeOptions.cs @@ -1,4 +1,6 @@ -namespace Tenray.ZoneTree.WAL; +using Tenray.ZoneTree.Options; + +namespace Tenray.ZoneTree.WAL; public sealed class SyncCompressedModeOptions { @@ -9,11 +11,11 @@ public sealed class SyncCompressedModeOptions /// This improves durability in compressed WALs. /// Default value is true. /// - public bool EnableTailWriterJob { get; set; } = true; + public bool EnableTailWriterJob { get; set; } = WriteAheadLogDefaultValues.SyncCompressedModeEnableTailWriterJob; /// /// The delay in milliseconds before the next tail write. /// Default value is 500 ms. /// - public int TailWriterJobInterval { get; set; } = 500; + public int TailWriterJobInterval { get; set; } = WriteAheadLogDefaultValues.SyncCompressedModeTailWriterJobInterval; }