From 704ce41173df55f3cd5814ef30e31d1bc343e2b4 Mon Sep 17 00:00:00 2001 From: Pavel Gross Date: Thu, 12 Sep 2024 11:56:26 +0300 Subject: [PATCH] [#23] Client: Refactoring to optimize memory usage Signed-off-by: Pavel Gross --- README.md | 2 +- .../Mappers/Object/ObjectFilterMapper.cs | 10 +++--- ...ObjectMatchType.cs => FrostFsMatchType.cs} | 2 +- .../Models/Object/FrostFsObjectFilter.cs | 32 +++++++++---------- src/FrostFS.SDK.Tests/SmokeTests.cs | 24 +++++++------- 5 files changed, 35 insertions(+), 35 deletions(-) rename src/FrostFS.SDK.ClientV2/Models/Enums/{FrostFsObjectMatchType.cs => FrostFsMatchType.cs} (77%) diff --git a/README.md b/README.md index d2e5fab..eccf0a2 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ var param = new PrmObjectPut FrostFsObjectId objectId = await client.PutObjectAsync(param); -var filter = new FilterByAttribute(FrostFsObjectMatchType.Equals, "fileName", "test"); +var filter = new FilterByAttribute(FrostFsMatchType.Equals, "fileName", "test"); await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(containerId) { Filters = [filter] })) { diff --git a/src/FrostFS.SDK.ClientV2/Mappers/Object/ObjectFilterMapper.cs b/src/FrostFS.SDK.ClientV2/Mappers/Object/ObjectFilterMapper.cs index e59f51b..0303213 100644 --- a/src/FrostFS.SDK.ClientV2/Mappers/Object/ObjectFilterMapper.cs +++ b/src/FrostFS.SDK.ClientV2/Mappers/Object/ObjectFilterMapper.cs @@ -10,11 +10,11 @@ public static class ObjectFilterMapper { var objMatchTypeName = filter.MatchType switch { - FrostFsObjectMatchType.Unspecified => MatchType.Unspecified, - FrostFsObjectMatchType.Equals => MatchType.StringEqual, - FrostFsObjectMatchType.NotEquals => MatchType.StringNotEqual, - FrostFsObjectMatchType.KeyAbsent => MatchType.NotPresent, - FrostFsObjectMatchType.StartsWith => MatchType.CommonPrefix, + FrostFsMatchType.Unspecified => MatchType.Unspecified, + FrostFsMatchType.Equals => MatchType.StringEqual, + FrostFsMatchType.NotEquals => MatchType.StringNotEqual, + FrostFsMatchType.KeyAbsent => MatchType.NotPresent, + FrostFsMatchType.StartsWith => MatchType.CommonPrefix, _ => throw new ArgumentException($"Unknown MatchType. Value: '{filter.MatchType}'.") }; diff --git a/src/FrostFS.SDK.ClientV2/Models/Enums/FrostFsObjectMatchType.cs b/src/FrostFS.SDK.ClientV2/Models/Enums/FrostFsMatchType.cs similarity index 77% rename from src/FrostFS.SDK.ClientV2/Models/Enums/FrostFsObjectMatchType.cs rename to src/FrostFS.SDK.ClientV2/Models/Enums/FrostFsMatchType.cs index 1fdeb60..b9b3659 100644 --- a/src/FrostFS.SDK.ClientV2/Models/Enums/FrostFsObjectMatchType.cs +++ b/src/FrostFS.SDK.ClientV2/Models/Enums/FrostFsMatchType.cs @@ -1,6 +1,6 @@ namespace FrostFS.SDK; -public enum FrostFsObjectMatchType +public enum FrostFsMatchType { Unspecified = 0, Equals = 1, diff --git a/src/FrostFS.SDK.ClientV2/Models/Object/FrostFsObjectFilter.cs b/src/FrostFS.SDK.ClientV2/Models/Object/FrostFsObjectFilter.cs index e9552bf..feae9bd 100644 --- a/src/FrostFS.SDK.ClientV2/Models/Object/FrostFsObjectFilter.cs +++ b/src/FrostFS.SDK.ClientV2/Models/Object/FrostFsObjectFilter.cs @@ -2,15 +2,15 @@ namespace FrostFS.SDK; public interface IObjectFilter { - public FrostFsObjectMatchType MatchType { get; set; } + public FrostFsMatchType MatchType { get; set; } public string Key { get; set; } string? GetSerializedValue(); } -public abstract class FrostFsObjectFilter(FrostFsObjectMatchType matchType, string key, T value) : IObjectFilter +public abstract class FrostFsObjectFilter(FrostFsMatchType matchType, string key, T value) : IObjectFilter { - public FrostFsObjectMatchType MatchType { get; set; } = matchType; + public FrostFsMatchType MatchType { get; set; } = matchType; public string Key { get; set; } = key; public T Value { get; set; } = value; @@ -27,85 +27,85 @@ public abstract class FrostFsObjectFilter(FrostFsObjectMatchType matchType, s /// Match type /// Attribute key /// Attribute value -public class FilterByAttribute(FrostFsObjectMatchType matchType, string key, string value) : FrostFsObjectFilter(matchType, key, value) { } +public class FilterByAttribute(FrostFsMatchType matchType, string key, string value) : FrostFsObjectFilter(matchType, key, value) { } /// /// Creates filter to search by ObjectId /// /// Match type /// ObjectId -public class FilterByObjectId(FrostFsObjectMatchType matchType, FrostFsObjectId objectId) : FrostFsObjectFilter(matchType, Constants.FilterHeaderObjectID, objectId) { } +public class FilterByObjectId(FrostFsMatchType matchType, FrostFsObjectId objectId) : FrostFsObjectFilter(matchType, Constants.FilterHeaderObjectID, objectId) { } /// /// Creates filter to search by OwnerId /// /// Match type /// ObjectId -public class FilterByOwnerId(FrostFsObjectMatchType matchType, FrostFsOwner ownerId) : FrostFsObjectFilter(matchType, Constants.FilterHeaderOwnerID, ownerId) { } +public class FilterByOwnerId(FrostFsMatchType matchType, FrostFsOwner ownerId) : FrostFsObjectFilter(matchType, Constants.FilterHeaderOwnerID, ownerId) { } /// /// Creates filter to search by Version /// /// Match type /// Version -public class FilterByVersion(FrostFsObjectMatchType matchType, FrostFsVersion version) : FrostFsObjectFilter(matchType, Constants.FilterHeaderVersion, version) { } +public class FilterByVersion(FrostFsMatchType matchType, FrostFsVersion version) : FrostFsObjectFilter(matchType, Constants.FilterHeaderVersion, version) { } /// /// Creates filter to search by ContainerId /// /// Match type /// ContainerId -public class FilterByContainerId(FrostFsObjectMatchType matchType, FrostFsContainerId containerId) : FrostFsObjectFilter(matchType, Constants.FilterHeaderContainerID, containerId) { } +public class FilterByContainerId(FrostFsMatchType matchType, FrostFsContainerId containerId) : FrostFsObjectFilter(matchType, Constants.FilterHeaderContainerID, containerId) { } /// /// Creates filter to search by creation Epoch /// /// Match type /// Creation Epoch -public class FilterByEpoch(FrostFsObjectMatchType matchType, ulong epoch) : FrostFsObjectFilter(matchType, Constants.FilterHeaderCreationEpoch, epoch) { } +public class FilterByEpoch(FrostFsMatchType matchType, ulong epoch) : FrostFsObjectFilter(matchType, Constants.FilterHeaderCreationEpoch, epoch) { } /// /// Creates filter to search by Payload Length /// /// Match type /// Payload Length -public class FilterByPayloadLength(FrostFsObjectMatchType matchType, ulong payloadLength) : FrostFsObjectFilter(matchType, Constants.FilterHeaderPayloadLength, payloadLength) { } +public class FilterByPayloadLength(FrostFsMatchType matchType, ulong payloadLength) : FrostFsObjectFilter(matchType, Constants.FilterHeaderPayloadLength, payloadLength) { } /// /// Creates filter to search by Payload Hash /// /// Match type /// Payload Hash -public class FilterByPayloadHash(FrostFsObjectMatchType matchType, CheckSum payloadHash) : FrostFsObjectFilter(matchType, Constants.FilterHeaderPayloadHash, payloadHash) { } +public class FilterByPayloadHash(FrostFsMatchType matchType, CheckSum payloadHash) : FrostFsObjectFilter(matchType, Constants.FilterHeaderPayloadHash, payloadHash) { } /// /// Creates filter to search by Parent /// /// Match type /// Parent -public class FilterByParent(FrostFsObjectMatchType matchType, FrostFsObjectId parentId) : FrostFsObjectFilter(matchType, Constants.FilterHeaderParent, parentId) { } +public class FilterByParent(FrostFsMatchType matchType, FrostFsObjectId parentId) : FrostFsObjectFilter(matchType, Constants.FilterHeaderParent, parentId) { } /// /// Creates filter to search by SplitId /// /// Match type /// SplitId -public class FilterBySplitId(FrostFsObjectMatchType matchType, SplitId splitId) : FrostFsObjectFilter(matchType, Constants.FilterHeaderSplitID, splitId) { } +public class FilterBySplitId(FrostFsMatchType matchType, SplitId splitId) : FrostFsObjectFilter(matchType, Constants.FilterHeaderSplitID, splitId) { } /// /// Creates filter to search by Payload Hash /// /// Match type /// Payload Hash -public class FilterByECParent(FrostFsObjectMatchType matchType, FrostFsObjectId ecParentId) : FrostFsObjectFilter(matchType, Constants.FilterHeaderECParent, ecParentId) { } +public class FilterByECParent(FrostFsMatchType matchType, FrostFsObjectId ecParentId) : FrostFsObjectFilter(matchType, Constants.FilterHeaderECParent, ecParentId) { } /// /// Creates filter to search Root objects /// -public class FilterByRootObject() : FrostFsObjectFilter(FrostFsObjectMatchType.Unspecified, Constants.FilterHeaderRoot, string.Empty) { } +public class FilterByRootObject() : FrostFsObjectFilter(FrostFsMatchType.Unspecified, Constants.FilterHeaderRoot, string.Empty) { } /// /// Creates filter to search objects that are physically stored on the server /// (FrostFsObjectMatchType.Unspecified, Constants.FilterHeaderPhy, string.Empty) { } +public class FilterByPhysicallyStored() : FrostFsObjectFilter(FrostFsMatchType.Unspecified, Constants.FilterHeaderPhy, string.Empty) { } diff --git a/src/FrostFS.SDK.Tests/SmokeTests.cs b/src/FrostFS.SDK.Tests/SmokeTests.cs index f344303..548d757 100644 --- a/src/FrostFS.SDK.Tests/SmokeTests.cs +++ b/src/FrostFS.SDK.Tests/SmokeTests.cs @@ -183,25 +183,25 @@ public class SmokeTests : SmokeTestsBase var networkInfo = await client.GetNetmapSnapshotAsync(); - await CheckFilter(client, containerId, new FilterByContainerId(FrostFsObjectMatchType.Equals, containerId)); + await CheckFilter(client, containerId, new FilterByContainerId(FrostFsMatchType.Equals, containerId)); - await CheckFilter(client, containerId, new FilterByOwnerId(FrostFsObjectMatchType.Equals, FrostFsOwner.FromKey(ecdsaKey))); + await CheckFilter(client, containerId, new FilterByOwnerId(FrostFsMatchType.Equals, FrostFsOwner.FromKey(ecdsaKey))); - await CheckFilter(client, containerId, new FilterBySplitId(FrostFsObjectMatchType.Equals, param.Header.Split.SplitId)); + await CheckFilter(client, containerId, new FilterBySplitId(FrostFsMatchType.Equals, param.Header.Split.SplitId)); - await CheckFilter(client, containerId, new FilterByAttribute(FrostFsObjectMatchType.Equals, "fileName", "test")); + await CheckFilter(client, containerId, new FilterByAttribute(FrostFsMatchType.Equals, "fileName", "test")); - await CheckFilter(client, containerId, new FilterByObjectId(FrostFsObjectMatchType.Equals, objectId)); + await CheckFilter(client, containerId, new FilterByObjectId(FrostFsMatchType.Equals, objectId)); - await CheckFilter(client, containerId, new FilterByVersion(FrostFsObjectMatchType.Equals, networkInfo.NodeInfoCollection[0].Version)); + await CheckFilter(client, containerId, new FilterByVersion(FrostFsMatchType.Equals, networkInfo.NodeInfoCollection[0].Version)); - await CheckFilter(client, containerId, new FilterByEpoch(FrostFsObjectMatchType.Equals, networkInfo.Epoch)); + await CheckFilter(client, containerId, new FilterByEpoch(FrostFsMatchType.Equals, networkInfo.Epoch)); - await CheckFilter(client, containerId, new FilterByPayloadLength(FrostFsObjectMatchType.Equals, 3)); + await CheckFilter(client, containerId, new FilterByPayloadLength(FrostFsMatchType.Equals, 3)); var checkSum = CheckSum.CreateCheckSum(bytes); - await CheckFilter(client, containerId, new FilterByPayloadHash(FrostFsObjectMatchType.Equals, checkSum)); + await CheckFilter(client, containerId, new FilterByPayloadHash(FrostFsMatchType.Equals, checkSum)); await CheckFilter(client, containerId, new FilterByPhysicallyStored()); } @@ -272,7 +272,7 @@ public class SmokeTests : SmokeTestsBase var objectId = await client.PutObjectAsync(param); - var filter = new FilterByAttribute(FrostFsObjectMatchType.Equals, "fileName", "test"); + var filter = new FilterByAttribute(FrostFsMatchType.Equals, "fileName", "test"); bool hasObject = false; await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(createdContainer) { Filters = [filter] })) @@ -357,7 +357,7 @@ public class SmokeTests : SmokeTestsBase var objectId = await client.PutObjectAsync(param); - var filter = new FilterByAttribute(FrostFsObjectMatchType.Equals, "fileName", "test"); + var filter = new FilterByAttribute(FrostFsMatchType.Equals, "fileName", "test"); bool hasObject = false; await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(container) { Filters = [filter], SessionToken = token })) @@ -438,7 +438,7 @@ public class SmokeTests : SmokeTestsBase var objectId = await client.PutObjectAsync(param); - var filter = new FilterByAttribute(FrostFsObjectMatchType.Equals, "fileName", "test"); + var filter = new FilterByAttribute(FrostFsMatchType.Equals, "fileName", "test"); bool hasObject = false; await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(containerId, filter)))