Skip to content

Add rollover API support for max_primary_shard_size #5353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ public interface IRolloverConditions
/// </remarks>
[DataMember(Name ="max_size")]
string MaxSize { get; set; }

/// <summary>
/// The maximum size of the primary shards in the index e.g. "2gb"
/// </summary>
/// <remarks>
/// Valid in Elasticsearch 7.12.0+
/// </remarks>
[DataMember(Name = "max_primary_shard_size")]
string MaxPrimaryShardSize { get; set; }
}

/// <inheritdoc />
Expand All @@ -48,6 +57,9 @@ public class RolloverConditions : IRolloverConditions

/// <inheritdoc />
public string MaxSize { get; set; }

/// <inheritdoc />
public string MaxPrimaryShardSize { get; set; }
}

/// <inheritdoc cref="IRolloverConditions" />
Expand All @@ -57,6 +69,7 @@ public class RolloverConditionsDescriptor
Time IRolloverConditions.MaxAge { get; set; }
long? IRolloverConditions.MaxDocs { get; set; }
string IRolloverConditions.MaxSize { get; set; }
string IRolloverConditions.MaxPrimaryShardSize { get; set; }

/// <inheritdoc cref="IRolloverConditions.MaxAge" />
public RolloverConditionsDescriptor MaxAge(Time maxAge) => Assign(maxAge, (a, v) => a.MaxAge = v);
Expand All @@ -66,5 +79,8 @@ public class RolloverConditionsDescriptor

/// <inheritdoc cref="IRolloverConditions.MaxSize" />
public RolloverConditionsDescriptor MaxSize(string maxSize) => Assign(maxSize, (a, v) => a.MaxSize = v);

/// <inheritdoc cref="IRolloverConditions.MaxPrimaryShardSize" />
public RolloverConditionsDescriptor MaxPrimaryShardSize(string maxPrimaryShardSize) => Assign(maxPrimaryShardSize, (a, v) => a.MaxPrimaryShardSize = v);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
Expand Down Expand Up @@ -166,4 +167,165 @@ protected override void ExpectResponse(RolloverIndexResponse response)
response.Conditions["[max_docs: 1000]"].Should().BeTrue();
}
}

[SkipVersion("<7.12.0", "Tests all parameters available in 7.12.0 and higher")]
public class RolloverIndexApiWithAllParametersTests
: ApiIntegrationTestBase<WritableCluster, RolloverIndexResponse, IRolloverIndexRequest, RolloverIndexDescriptor, RolloverIndexRequest>
{
public RolloverIndexApiWithAllParametersTests(WritableCluster cluster, EndpointUsage usage)
: base(cluster, usage) { }

protected override bool ExpectIsValid => true;
protected override int ExpectStatusCode => 200;
protected override HttpMethod HttpMethod => HttpMethod.POST;
protected override bool SupportsDeserialization => false;
protected override string UrlPath => $"/{CallIsolatedValue}-alias/_rollover/{CallIsolatedValue}-new";

protected override object ExpectJson => new
{
conditions = new
{
max_age = "7d",
max_docs = 1000,
max_size = "5gb",
max_primary_shard_size = "2gb"
},
settings = new Dictionary<string, object>
{
{ "index.number_of_shards", 1 },
{ "index.number_of_replicas", 1 }
},
mappings = new
{
properties = new
{
branches = new
{
type = "text",
fields = new
{
keyword = new
{
type = "keyword",
ignore_above = 256
}
}
}
}
},
aliases = new Dictionary<string, object>
{
{ CallIsolatedValue + "-new_projects", new { } }
}
};

protected override Func<RolloverIndexDescriptor, IRolloverIndexRequest> Fluent => f => f
.NewIndex(CallIsolatedValue + "-new")
.Conditions(c => c
.MaxAge("7d")
.MaxDocs(1000)
.MaxSize("5gb")
.MaxPrimaryShardSize("2gb")
)
.Settings(s => s
.NumberOfShards(1)
.NumberOfReplicas(1)
)
.Map<Project>(p => p
.Properties(pp => pp
.Text(t => t
.Name(n => n.Branches)
.Fields(pf => pf
.Keyword(k => k
.Name("keyword")
.IgnoreAbove(256)
)
)
)
)
)
.Aliases(a => a
.Alias(CallIsolatedValue + "-new_projects")
);

protected override RolloverIndexRequest Initializer => new RolloverIndexRequest(CallIsolatedValue + "-alias", CallIsolatedValue + "-new")
{
Conditions = new RolloverConditions
{
MaxAge = "7d",
MaxDocs = 1000,
MaxSize = "5gb",
MaxPrimaryShardSize = "2gb"
},
Settings = new Nest.IndexSettings
{
NumberOfShards = 1,
NumberOfReplicas = 1
},
Mappings = new TypeMapping
{
Properties = new Properties<Project>
{
{
p => p.Branches, new TextProperty
{
Fields = new Properties
{
{
"keyword", new KeywordProperty
{
IgnoreAbove = 256
}
}
}
}
}
}
},
Aliases = new Aliases
{
{ CallIsolatedValue + "-new_projects", new Alias() }
}
};

protected override void OnBeforeCall(IElasticClient client)
{
var create = client.Indices.Create(CallIsolatedValue, c => c
.Aliases(a => a
.Alias(CallIsolatedValue + "-alias")
)
);
create.ShouldBeValid();
var someDocs = client.Bulk(b => b
.Index(CallIsolatedValue)
.Refresh(Refresh.True)
.IndexMany(Project.Generator.Generate(1200))
);
someDocs.ShouldBeValid();

}

protected override LazyResponses ClientUsage() => Calls(
(client, f) => client.Indices.Rollover(CallIsolatedValue + "-alias", f),
(client, f) => client.Indices.RolloverAsync(CallIsolatedValue + "-alias", f),
(client, r) => client.Indices.Rollover(r),
(client, r) => client.Indices.RolloverAsync(r)
);

protected override RolloverIndexDescriptor NewDescriptor() => new RolloverIndexDescriptor(CallIsolatedValue + "-alias");

protected override void ExpectResponse(RolloverIndexResponse response)
{
response.ShouldBeValid();
response.OldIndex.Should().NotBeNullOrEmpty();
response.NewIndex.Should().NotBeNullOrEmpty();
response.RolledOver.Should().BeTrue();
response.ShardsAcknowledged.Should().BeTrue();
response.Conditions.Should().NotBeNull().And.HaveCount(4);
response.Conditions["[max_age: 7d]"].Should().BeFalse();
response.Conditions["[max_docs: 1000]"].Should().BeTrue();
response.Conditions["[max_size: 5gb]"].Should().BeFalse();
response.Conditions["[max_primary_shard_size: 2gb]"].Should().BeFalse();
}
}
}