[#23] Client: Refactoring to optimize memory usage
All checks were successful
DCO / DCO (pull_request) Successful in 53s
All checks were successful
DCO / DCO (pull_request) Successful in 53s
Signed-off-by: Pavel Gross <p.gross@yando.com>
This commit is contained in:
parent
6562aa27a5
commit
704ce41173
5 changed files with 35 additions and 35 deletions
|
@ -62,7 +62,7 @@ var param = new PrmObjectPut
|
||||||
|
|
||||||
FrostFsObjectId objectId = await client.PutObjectAsync(param);
|
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] }))
|
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(containerId) { Filters = [filter] }))
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,11 +10,11 @@ public static class ObjectFilterMapper
|
||||||
{
|
{
|
||||||
var objMatchTypeName = filter.MatchType switch
|
var objMatchTypeName = filter.MatchType switch
|
||||||
{
|
{
|
||||||
FrostFsObjectMatchType.Unspecified => MatchType.Unspecified,
|
FrostFsMatchType.Unspecified => MatchType.Unspecified,
|
||||||
FrostFsObjectMatchType.Equals => MatchType.StringEqual,
|
FrostFsMatchType.Equals => MatchType.StringEqual,
|
||||||
FrostFsObjectMatchType.NotEquals => MatchType.StringNotEqual,
|
FrostFsMatchType.NotEquals => MatchType.StringNotEqual,
|
||||||
FrostFsObjectMatchType.KeyAbsent => MatchType.NotPresent,
|
FrostFsMatchType.KeyAbsent => MatchType.NotPresent,
|
||||||
FrostFsObjectMatchType.StartsWith => MatchType.CommonPrefix,
|
FrostFsMatchType.StartsWith => MatchType.CommonPrefix,
|
||||||
|
|
||||||
_ => throw new ArgumentException($"Unknown MatchType. Value: '{filter.MatchType}'.")
|
_ => throw new ArgumentException($"Unknown MatchType. Value: '{filter.MatchType}'.")
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
namespace FrostFS.SDK;
|
namespace FrostFS.SDK;
|
||||||
|
|
||||||
public enum FrostFsObjectMatchType
|
public enum FrostFsMatchType
|
||||||
{
|
{
|
||||||
Unspecified = 0,
|
Unspecified = 0,
|
||||||
Equals = 1,
|
Equals = 1,
|
|
@ -2,15 +2,15 @@ namespace FrostFS.SDK;
|
||||||
|
|
||||||
public interface IObjectFilter
|
public interface IObjectFilter
|
||||||
{
|
{
|
||||||
public FrostFsObjectMatchType MatchType { get; set; }
|
public FrostFsMatchType MatchType { get; set; }
|
||||||
public string Key { get; set; }
|
public string Key { get; set; }
|
||||||
|
|
||||||
string? GetSerializedValue();
|
string? GetSerializedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class FrostFsObjectFilter<T>(FrostFsObjectMatchType matchType, string key, T value) : IObjectFilter
|
public abstract class FrostFsObjectFilter<T>(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 string Key { get; set; } = key;
|
||||||
|
|
||||||
public T Value { get; set; } = value;
|
public T Value { get; set; } = value;
|
||||||
|
@ -27,85 +27,85 @@ public abstract class FrostFsObjectFilter<T>(FrostFsObjectMatchType matchType, s
|
||||||
/// <param name="matchType">Match type</param>
|
/// <param name="matchType">Match type</param>
|
||||||
/// <param name="key">Attribute key</param>
|
/// <param name="key">Attribute key</param>
|
||||||
/// <param name="value">Attribute value</param>
|
/// <param name="value">Attribute value</param>
|
||||||
public class FilterByAttribute(FrostFsObjectMatchType matchType, string key, string value) : FrostFsObjectFilter<string>(matchType, key, value) { }
|
public class FilterByAttribute(FrostFsMatchType matchType, string key, string value) : FrostFsObjectFilter<string>(matchType, key, value) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates filter to search by ObjectId
|
/// Creates filter to search by ObjectId
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchType">Match type</param>
|
/// <param name="matchType">Match type</param>
|
||||||
/// <param name="objectId">ObjectId</param>
|
/// <param name="objectId">ObjectId</param>
|
||||||
public class FilterByObjectId(FrostFsObjectMatchType matchType, FrostFsObjectId objectId) : FrostFsObjectFilter<FrostFsObjectId>(matchType, Constants.FilterHeaderObjectID, objectId) { }
|
public class FilterByObjectId(FrostFsMatchType matchType, FrostFsObjectId objectId) : FrostFsObjectFilter<FrostFsObjectId>(matchType, Constants.FilterHeaderObjectID, objectId) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates filter to search by OwnerId
|
/// Creates filter to search by OwnerId
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchType">Match type</param>
|
/// <param name="matchType">Match type</param>
|
||||||
/// <param name="ownerId">ObjectId</param>
|
/// <param name="ownerId">ObjectId</param>
|
||||||
public class FilterByOwnerId(FrostFsObjectMatchType matchType, FrostFsOwner ownerId) : FrostFsObjectFilter<FrostFsOwner>(matchType, Constants.FilterHeaderOwnerID, ownerId) { }
|
public class FilterByOwnerId(FrostFsMatchType matchType, FrostFsOwner ownerId) : FrostFsObjectFilter<FrostFsOwner>(matchType, Constants.FilterHeaderOwnerID, ownerId) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates filter to search by Version
|
/// Creates filter to search by Version
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchType">Match type</param>
|
/// <param name="matchType">Match type</param>
|
||||||
/// <param name="version">Version</param>
|
/// <param name="version">Version</param>
|
||||||
public class FilterByVersion(FrostFsObjectMatchType matchType, FrostFsVersion version) : FrostFsObjectFilter<FrostFsVersion>(matchType, Constants.FilterHeaderVersion, version) { }
|
public class FilterByVersion(FrostFsMatchType matchType, FrostFsVersion version) : FrostFsObjectFilter<FrostFsVersion>(matchType, Constants.FilterHeaderVersion, version) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates filter to search by ContainerId
|
/// Creates filter to search by ContainerId
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchType">Match type</param>
|
/// <param name="matchType">Match type</param>
|
||||||
/// <param name="containerId">ContainerId</param>
|
/// <param name="containerId">ContainerId</param>
|
||||||
public class FilterByContainerId(FrostFsObjectMatchType matchType, FrostFsContainerId containerId) : FrostFsObjectFilter<FrostFsContainerId>(matchType, Constants.FilterHeaderContainerID, containerId) { }
|
public class FilterByContainerId(FrostFsMatchType matchType, FrostFsContainerId containerId) : FrostFsObjectFilter<FrostFsContainerId>(matchType, Constants.FilterHeaderContainerID, containerId) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates filter to search by creation Epoch
|
/// Creates filter to search by creation Epoch
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchType">Match type</param>
|
/// <param name="matchType">Match type</param>
|
||||||
/// <param name="epoch">Creation Epoch</param>
|
/// <param name="epoch">Creation Epoch</param>
|
||||||
public class FilterByEpoch(FrostFsObjectMatchType matchType, ulong epoch) : FrostFsObjectFilter<ulong>(matchType, Constants.FilterHeaderCreationEpoch, epoch) { }
|
public class FilterByEpoch(FrostFsMatchType matchType, ulong epoch) : FrostFsObjectFilter<ulong>(matchType, Constants.FilterHeaderCreationEpoch, epoch) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates filter to search by Payload Length
|
/// Creates filter to search by Payload Length
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchType">Match type</param>
|
/// <param name="matchType">Match type</param>
|
||||||
/// <param name="payloadLength">Payload Length</param>
|
/// <param name="payloadLength">Payload Length</param>
|
||||||
public class FilterByPayloadLength(FrostFsObjectMatchType matchType, ulong payloadLength) : FrostFsObjectFilter<ulong>(matchType, Constants.FilterHeaderPayloadLength, payloadLength) { }
|
public class FilterByPayloadLength(FrostFsMatchType matchType, ulong payloadLength) : FrostFsObjectFilter<ulong>(matchType, Constants.FilterHeaderPayloadLength, payloadLength) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates filter to search by Payload Hash
|
/// Creates filter to search by Payload Hash
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchType">Match type</param>
|
/// <param name="matchType">Match type</param>
|
||||||
/// <param name="payloadHash">Payload Hash</param>
|
/// <param name="payloadHash">Payload Hash</param>
|
||||||
public class FilterByPayloadHash(FrostFsObjectMatchType matchType, CheckSum payloadHash) : FrostFsObjectFilter<CheckSum>(matchType, Constants.FilterHeaderPayloadHash, payloadHash) { }
|
public class FilterByPayloadHash(FrostFsMatchType matchType, CheckSum payloadHash) : FrostFsObjectFilter<CheckSum>(matchType, Constants.FilterHeaderPayloadHash, payloadHash) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates filter to search by Parent
|
/// Creates filter to search by Parent
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchType">Match type</param>
|
/// <param name="matchType">Match type</param>
|
||||||
/// <param name="parentId">Parent</param>
|
/// <param name="parentId">Parent</param>
|
||||||
public class FilterByParent(FrostFsObjectMatchType matchType, FrostFsObjectId parentId) : FrostFsObjectFilter<FrostFsObjectId>(matchType, Constants.FilterHeaderParent, parentId) { }
|
public class FilterByParent(FrostFsMatchType matchType, FrostFsObjectId parentId) : FrostFsObjectFilter<FrostFsObjectId>(matchType, Constants.FilterHeaderParent, parentId) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates filter to search by SplitId
|
/// Creates filter to search by SplitId
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchType">Match type</param>
|
/// <param name="matchType">Match type</param>
|
||||||
/// <param name="splitId">SplitId</param>
|
/// <param name="splitId">SplitId</param>
|
||||||
public class FilterBySplitId(FrostFsObjectMatchType matchType, SplitId splitId) : FrostFsObjectFilter<SplitId>(matchType, Constants.FilterHeaderSplitID, splitId) { }
|
public class FilterBySplitId(FrostFsMatchType matchType, SplitId splitId) : FrostFsObjectFilter<SplitId>(matchType, Constants.FilterHeaderSplitID, splitId) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates filter to search by Payload Hash
|
/// Creates filter to search by Payload Hash
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchType">Match type</param>
|
/// <param name="matchType">Match type</param>
|
||||||
/// <param name="ecParentId">Payload Hash</param>
|
/// <param name="ecParentId">Payload Hash</param>
|
||||||
public class FilterByECParent(FrostFsObjectMatchType matchType, FrostFsObjectId ecParentId) : FrostFsObjectFilter<FrostFsObjectId>(matchType, Constants.FilterHeaderECParent, ecParentId) { }
|
public class FilterByECParent(FrostFsMatchType matchType, FrostFsObjectId ecParentId) : FrostFsObjectFilter<FrostFsObjectId>(matchType, Constants.FilterHeaderECParent, ecParentId) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates filter to search Root objects
|
/// Creates filter to search Root objects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class FilterByRootObject() : FrostFsObjectFilter<string>(FrostFsObjectMatchType.Unspecified, Constants.FilterHeaderRoot, string.Empty) { }
|
public class FilterByRootObject() : FrostFsObjectFilter<string>(FrostFsMatchType.Unspecified, Constants.FilterHeaderRoot, string.Empty) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates filter to search objects that are physically stored on the server
|
/// Creates filter to search objects that are physically stored on the server
|
||||||
/// </summary
|
/// </summary
|
||||||
public class FilterByPhysicallyStored() : FrostFsObjectFilter<string>(FrostFsObjectMatchType.Unspecified, Constants.FilterHeaderPhy, string.Empty) { }
|
public class FilterByPhysicallyStored() : FrostFsObjectFilter<string>(FrostFsMatchType.Unspecified, Constants.FilterHeaderPhy, string.Empty) { }
|
||||||
|
|
||||||
|
|
|
@ -183,25 +183,25 @@ public class SmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
var networkInfo = await client.GetNetmapSnapshotAsync();
|
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);
|
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());
|
await CheckFilter(client, containerId, new FilterByPhysicallyStored());
|
||||||
}
|
}
|
||||||
|
@ -272,7 +272,7 @@ public class SmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
var objectId = await client.PutObjectAsync(param);
|
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;
|
bool hasObject = false;
|
||||||
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(createdContainer) { Filters = [filter] }))
|
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 objectId = await client.PutObjectAsync(param);
|
||||||
|
|
||||||
var filter = new FilterByAttribute(FrostFsObjectMatchType.Equals, "fileName", "test");
|
var filter = new FilterByAttribute(FrostFsMatchType.Equals, "fileName", "test");
|
||||||
|
|
||||||
bool hasObject = false;
|
bool hasObject = false;
|
||||||
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(container) { Filters = [filter], SessionToken = token }))
|
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 objectId = await client.PutObjectAsync(param);
|
||||||
|
|
||||||
var filter = new FilterByAttribute(FrostFsObjectMatchType.Equals, "fileName", "test");
|
var filter = new FilterByAttribute(FrostFsMatchType.Equals, "fileName", "test");
|
||||||
|
|
||||||
bool hasObject = false;
|
bool hasObject = false;
|
||||||
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(containerId, filter)))
|
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(containerId, filter)))
|
||||||
|
|
Loading…
Reference in a new issue