From 479ef9152f09f93ef967e333cdb17411fdb1b165 Mon Sep 17 00:00:00 2001 From: Ogoun Date: Sun, 12 Mar 2023 11:29:05 +0300 Subject: [PATCH] Getting the end date of the task in the sheduler --- PartitionFileStorageTest/Program.cs | 8 ++ .../Services/Collections/BitMapCardTable.cs | 75 +++++++++++++++++++ .../PartitionStorage/Interfaces/IStore.cs | 8 ++ ZeroLevel/Services/PartitionStorage/Store.cs | 15 ++++ .../UniformKeyValueStorage.cs | 7 ++ .../Services/Shedulling/DateTimeSheduller.cs | 11 --- ZeroLevel/Services/Shedulling/ISheduller.cs | 2 + ZeroLevel/Services/Shedulling/Sheduller.cs | 6 +- .../Services/Shedulling/ShedullerImpl.cs | 12 +++ ZeroLevel/ZeroLevel.csproj | 10 +-- 10 files changed, 137 insertions(+), 17 deletions(-) create mode 100644 ZeroLevel/Services/Collections/BitMapCardTable.cs create mode 100644 ZeroLevel/Services/PartitionStorage/UniformKeyValueStorage.cs diff --git a/PartitionFileStorageTest/Program.cs b/PartitionFileStorageTest/Program.cs index ca3a7c8..ecc89d9 100644 --- a/PartitionFileStorageTest/Program.cs +++ b/PartitionFileStorageTest/Program.cs @@ -298,6 +298,14 @@ namespace PartitionFileStorageTest ulong totalData = 0; ulong totalKeys = 0; + + var s = new HashSet(); + store.Bypass(meta, (k, v) => + { + s.Add(k); + }); + Log.Info($"Keys count: {s.Count}"); + using (var readPart = store.CreateAccessor(meta)) { /* diff --git a/ZeroLevel/Services/Collections/BitMapCardTable.cs b/ZeroLevel/Services/Collections/BitMapCardTable.cs new file mode 100644 index 0000000..44b0faf --- /dev/null +++ b/ZeroLevel/Services/Collections/BitMapCardTable.cs @@ -0,0 +1,75 @@ +using System.Collections.Generic; + +namespace ZeroLevel.Services.Collections +{ + public sealed class BitMapCardTable + { + private readonly long[] _bitmap; + public BitMapCardTable(int N) + { + var count = N / 64 + (N % 64 == 0 ? 0 : 1); + _bitmap = new long[count]; + } + + public bool this[int index] + { + get + { + var i = index / 64; + var n = _bitmap[i]; + var bit_index = index % 64; + return (n & (1L << bit_index)) != 0; + } + set + { + var i = index / 64; + var bit_index = index % 64; + if (value) + { + _bitmap[i] = _bitmap[i] | (1L << bit_index); + } + else + { + _bitmap[i] = _bitmap[i] & ~(1L << bit_index); + } + } + } + + public void ResetTo(bool value) + { + if (value) + { + for (int i = 0; i < _bitmap.Length; i++) + { + _bitmap[i] = long.MaxValue; + _bitmap[i] |= 1L << 63; + } + } + else + { + for (int i = 0; i < _bitmap.Length; i++) + { + _bitmap[i] = 0; + } + } + } + + public IEnumerable GetSetIndexes() + { + for (int i = 0; i < _bitmap.Length; i++) + { + if (_bitmap[i] != 0) + { + var start = i * 64; + for (int offset = 0; offset < 64; offset++) + { + if ((_bitmap[i] & (1L << offset)) != 0) + { + yield return start + offset; + } + } + } + } + } + } +} diff --git a/ZeroLevel/Services/PartitionStorage/Interfaces/IStore.cs b/ZeroLevel/Services/PartitionStorage/Interfaces/IStore.cs index d81dbb8..995e25f 100644 --- a/ZeroLevel/Services/PartitionStorage/Interfaces/IStore.cs +++ b/ZeroLevel/Services/PartitionStorage/Interfaces/IStore.cs @@ -31,6 +31,14 @@ namespace ZeroLevel.Services.PartitionStorage /// Task> Search(StoreSearchRequest searchRequest); /// + /// bypass all key value by meta + /// + void Bypass(TMeta meta, Action handler); + /// + /// true - if key exists + /// + bool Exists(TMeta meta, TKey key); + /// /// Deleting a partition /// void RemovePartition(TMeta info); diff --git a/ZeroLevel/Services/PartitionStorage/Store.cs b/ZeroLevel/Services/PartitionStorage/Store.cs index 20e240b..796377a 100644 --- a/ZeroLevel/Services/PartitionStorage/Store.cs +++ b/ZeroLevel/Services/PartitionStorage/Store.cs @@ -95,5 +95,20 @@ namespace ZeroLevel.Services.PartitionStorage { _fileAccessorCachee.Dispose(); } + + public void Bypass(TMeta meta, Action handler) + { + var accessor = CreateAccessor(meta); + foreach (var kv in accessor.Iterate()) + { + handler.Invoke(kv.Key, kv.Value); + } + } + + public bool Exists(TMeta meta, TKey key) + { + var accessor = CreateAccessor(meta); + return accessor.Find(key).Status == SearchResult.Success; + } } } diff --git a/ZeroLevel/Services/PartitionStorage/UniformKeyValueStorage.cs b/ZeroLevel/Services/PartitionStorage/UniformKeyValueStorage.cs new file mode 100644 index 0000000..cfc755b --- /dev/null +++ b/ZeroLevel/Services/PartitionStorage/UniformKeyValueStorage.cs @@ -0,0 +1,7 @@ +namespace ZeroLevel.Services.PartitionStorage +{ + public sealed class UniformKeyValueStorage + { + + } +} diff --git a/ZeroLevel/Services/Shedulling/DateTimeSheduller.cs b/ZeroLevel/Services/Shedulling/DateTimeSheduller.cs index 86f6e17..16c291b 100644 --- a/ZeroLevel/Services/Shedulling/DateTimeSheduller.cs +++ b/ZeroLevel/Services/Shedulling/DateTimeSheduller.cs @@ -1,6 +1,5 @@ using System; using System.Threading; -using System.Threading.Tasks; namespace ZeroLevel.Services.Shedulling { @@ -50,16 +49,6 @@ namespace ZeroLevel.Services.Shedulling { Log.SystemError(ex, $"Fault task '{result.Key}' on expiration date '{result.ExpirationDate.ToString("yyyy-MM-dd HH:mm:ss fff}")}'"); } - /*Task.Run(() => result.Callback(result.Key)).ContinueWith(t => - { - if (t.IsFaulted) - { - Exception ex = t.Exception; - while (ex is AggregateException && ex.InnerException != null) - ex = ex.InnerException; - Log.SystemError(ex, $"Fault task '{result.Key}' on expiration date '{result.ExpirationDate.ToString("yyyy-MM-dd HH:mm:ss fff}")}'"); - } - });*/ } } diff --git a/ZeroLevel/Services/Shedulling/ISheduller.cs b/ZeroLevel/Services/Shedulling/ISheduller.cs index 5ae13c1..b19c385 100644 --- a/ZeroLevel/Services/Shedulling/ISheduller.cs +++ b/ZeroLevel/Services/Shedulling/ISheduller.cs @@ -4,6 +4,8 @@ namespace ZeroLevel.Services.Shedulling { public interface ISheduller : IDisposable { + DateTime this[long index] { get; } + #region One time events long RemindAfter(TimeSpan timespan, Action callback); diff --git a/ZeroLevel/Services/Shedulling/Sheduller.cs b/ZeroLevel/Services/Shedulling/Sheduller.cs index 76dc886..a82b22e 100644 --- a/ZeroLevel/Services/Shedulling/Sheduller.cs +++ b/ZeroLevel/Services/Shedulling/Sheduller.cs @@ -1,5 +1,4 @@ using System; -using System.Threading.Tasks; using ZeroLevel.Services.Shedulling; namespace ZeroLevel @@ -46,6 +45,11 @@ namespace ZeroLevel } } + public static DateTime GetExpirationDate(long index) + { + return DefaultInstance[index]; + } + #endregion Singletones #region Sync default instance api diff --git a/ZeroLevel/Services/Shedulling/ShedullerImpl.cs b/ZeroLevel/Services/Shedulling/ShedullerImpl.cs index c902e9a..b8a30e5 100644 --- a/ZeroLevel/Services/Shedulling/ShedullerImpl.cs +++ b/ZeroLevel/Services/Shedulling/ShedullerImpl.cs @@ -34,6 +34,18 @@ namespace ZeroLevel.Services.Shedulling private readonly ConcurrentDictionary _repitableActions = new ConcurrentDictionary(); + public DateTime this[long index] + { + get + { + if (_repitableActions.TryGetValue(index, out var result)) + { + return result.ExpirationDate; + } + return DateTime.MinValue; + } + } + /// /// Performs an action once a period, while the period is recalculated according to the transferred function at each re-creation of the task. /// diff --git a/ZeroLevel/ZeroLevel.csproj b/ZeroLevel/ZeroLevel.csproj index d257944..8ffc66d 100644 --- a/ZeroLevel/ZeroLevel.csproj +++ b/ZeroLevel/ZeroLevel.csproj @@ -2,20 +2,20 @@ net6.0 - Infrastructure Layer Toolkit. + Multi-tool ogoun ogoun - 3.3.9.5 - Partition storage. Fix. + 3.3.9.8 + Getting the end date of the task in the sheduler https://github.com/ogoun/Zero/wiki Copyright Ogoun 2023 https://github.com/ogoun/Zero git - 3.3.9.5 - 3.3.9.5 + 3.3.9.8 + 3.3.9.8 AnyCPU;x64;x86 zero.png full