Skip to content
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

Add rollover-creation-date setting to rolled over index #31144

Merged
merged 17 commits into from
Jun 15, 2018

Conversation

talevy
Copy link
Contributor

@talevy talevy commented Jun 6, 2018

This PR introduces a new section to IndexMetaData for storing information about
rollover actions that took place against a specific index.

Information stored

  • which alias was used to rollover
  • when the index was rolled over with that alias
  • which conditions were met

Closes #30887

This PR introduces a new index setting `index.rollover.creation_date`

much like the `index.creation_date`, it captures the approximate time
that the index was rolled over to a new one.
@talevy talevy added >enhancement review :Data Management/Indices APIs APIs to create and manage indices and templates labels Jun 6, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@talevy
Copy link
Contributor Author

talevy commented Jun 6, 2018

Notes for the reviewer:

  1. I was looking for a way to make the alias-swap + setting update to be atomic, but could not find a clean way
  2. I was looking to add unit tests, but it seems like the approach taken in Rollover is not very unit-test friendly and has, instead, chosen the RolloverIT route to verify behavior.
  3. It was not clear whether new settings should be added to IndexMetaData, or IndexSettings.
  4. I was interested in providing a supplier for the current time, but I don't see that index.creation_date cares much for that, so I just use System millis hardcoded. Since the exact time is not necessarily important, and a close approximate is good, I think this should be fine for now.

@talevy talevy requested a review from colings86 June 6, 2018 16:24
Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think that we should use a setting for this. I think that we should have index metadata that captures:

  • the alias that was rolled over
  • the condition that caused the rollover
  • when this occurred

@talevy Can you look into the feasibility of this?

@talevy
Copy link
Contributor Author

talevy commented Jun 7, 2018

yes @jasontedor , I see no reason this shouldn't be doable. I guess I was just following in line with the resize-settings strategy.

you mean to add properties to IndexMetaData class itself to hold this data. Makes sense since it is for internal use when IndexMetaData is available.

This commit introduces a new property to IndexMetaData called
RolloverInfo. This object contains a map containing the aliases
that were used to rollover the related index, which conditions
were met, and at what time the rollover took place.
@@ -64,4 +66,13 @@ public void writeTo(StreamOutput out) throws IOException {
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return builder.field(NAME, value.getStringRep());
}

public static MaxAgeCondition fromXContent(XContentParser parser) throws IOException {
parser.nextToken();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what am I doing wrong in parsing that led to me wind up calling this here?

@talevy
Copy link
Contributor Author

talevy commented Jun 12, 2018

heya @jasontedor, I've updated the PR to introduce the object you recommended.

I plan on doing one more iteration on this, but I believe it is ready for initial review. thanks!

EDIT: iterations made

@@ -679,6 +693,8 @@ public Custom read(StreamInput in, String key) throws IOException {
});
inSyncAllocationIds = DiffableUtils.readImmutableOpenIntMapDiff(in, DiffableUtils.getVIntKeySerializer(),
DiffableUtils.StringSetValueSerializer.getInstance());
rolloverInfos = DiffableUtils.readImmutableOpenMapDiff(in, DiffableUtils.getStringKeySerializer(), RolloverInfo::new,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm. these diffs should be behind version checks, right?

Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks pretty good; I left a few comments. They are minor.

@Override
public ClusterState execute(ClusterState currentState) {
RolloverInfo rolloverInfo = new RolloverInfo(rolloverRequest.getAlias(), metConditions,
System.currentTimeMillis());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this should be threadPool.absoluteTimeMillis().

List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
entries.addAll(NetworkModule.getNamedWriteables());
entries.addAll(indicesModule.getNamedWriteables());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small nit here; we have the ordering searchModule, indicesModule for the local variables; can we do the same on the invocation to getNamedWritables?

@@ -587,6 +595,9 @@ public boolean equals(Object o) {
if (!inSyncAllocationIds.equals(that.inSyncAllocationIds)) {
return false;
}
if (!rolloverInfos.equals(that.rolloverInfos)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

== false (#30697) (I see there are other places in the source that are not like this but they can stay.)

@@ -84,6 +86,9 @@ public void testRollover() throws Exception {
assertFalse(oldIndex.getAliases().containsKey("test_alias"));
final IndexMetaData newIndex = state.metaData().index("test_index-000003");
assertTrue(newIndex.getAliases().containsKey("test_alias"));
assertThat(oldIndex.getRolloverInfos().size(), equalTo(1));
assertThat(oldIndex.getRolloverInfos().get("test_alias").getAlias(), equalTo("test_alias"));
assertThat(oldIndex.getRolloverInfos().get("test_alias").getMetConditions(), is(empty()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make an assertion on the getTime too. I see a way to do this: take the clock before you submit the request, then assert the value of getTime is more than that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, I guess I was trying avoid timing issues since the system time was being finicky. the move to threadPool makes things more consistent in their world view! thanks

final IndexMetaData oldIndex = client().admin().cluster().prepareState().get().getState().metaData().index("test-1");
List<Condition> metConditions = oldIndex.getRolloverInfos().get("test_alias").getMetConditions();
assertThat(metConditions.size(), equalTo(1));
assertThat(metConditions.get(0).toString(), equalTo(new MaxSizeCondition(maxSizeValue).toString()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us make an assertion on the clock too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@talevy
Copy link
Contributor Author

talevy commented Jun 14, 2018

thanks for the round of review, I've addressed your comments and merged-latest-master/removed-unused-imports. thanks @jasontedor!

Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@talevy
Copy link
Contributor Author

talevy commented Jun 15, 2018

thanks! I will probably finalize the back-porting dance early next week in the hopes of not breaking a CI run on a Friday

@talevy talevy merged commit eda4964 into elastic:master Jun 15, 2018
@talevy talevy deleted the rollover-date branch June 15, 2018 15:44
@talevy talevy added v7.0.0 and removed review labels Jun 18, 2018
dnhatn added a commit that referenced this pull request Jun 19, 2018
* master:
  Add get stored script and delete stored script to high level REST API - post backport fix
  Add get stored script and delete stored script to high level REST API (#31355)
  Core: Combine Action and GenericAction (#31405)
  Fix reference to XContentBuilder.string() (#31337)
  Avoid sending duplicate remote failed shard requests (#31313)
  Fix defaults in GeoShapeFieldMapper output (#31302)
  RestAPI: Reject forcemerge requests with a body (#30792)
  Packaging: Remove windows bin files from the tar distribution (#30596)
  Docs: Use the default distribution to test docs (#31251)
  [DOCS] Adds testing for security APIs (#31345)
  Clarify that IP range data can be specified in CIDR notation. (#31374)
  Use system context for cluster state update tasks (#31241)
  Percentile/Ranks should return null instead of NaN when empty (#30460)
  REST high-level client: add validate query API (#31077)
  Move language analyzers from server to analysis-common module. (#31300)
  [Test] Fix :example-plugins:rest-handler on Windows
  Expose lucene's RemoveDuplicatesTokenFilter (#31275)
  Reload secure settings for plugins (#31383)
  Remove some cases in FieldTypeLookupTests that are no longer relevant. (#31381)
  Ensure we don't use a remote profile if cluster name matches (#31331)
  [TEST] Double write alias fault (#30942)
  [DOCS] Fix version in SQL JDBC Maven template
  [DOCS] Improve install and setup section for SQL JDBC
  SQL: Fix rest endpoint names in node stats (#31371)
  Support for remote path in reindex api - post backport fix Closes #22913
  [ML] Put ML filter API response should contain the filter (#31362)
  Support for remote path in reindex api (#31290)
  Add byte array pooling to nio http transport (#31349)
  Remove trial status info from start trial doc (#31365)
  [DOCS] Adds links to release notes and highlights
  add is-write-index flag to aliases (#30942)
  Add rollover-creation-date setting to rolled over index (#31144)
  [ML] Hold ML filter items in sorted set (#31338)
  [Tests] Fix edge case in ScriptedMetricAggregatorTests (#31357)
talevy added a commit to talevy/elasticsearch that referenced this pull request Jun 19, 2018
This commit introduces a new property to IndexMetaData called
RolloverInfo. This object contains a map containing the aliases
that were used to rollover the related index, which conditions
were met, and at what time the rollover took place.

much like the `index.creation_date`, it captures the approximate time
that the index was rolled over to a new one.
talevy added a commit that referenced this pull request Jun 20, 2018
…31144) (#31413)

This commit introduces a new property to IndexMetaData called
RolloverInfo. This object contains a map containing the aliases
that were used to rollover the related index, which conditions
were met, and at what time the rollover took place.

much like the `index.creation_date`, it captures the approximate time
that the index was rolled over to a new one.

set version serialization check to 6.4
dnhatn added a commit that referenced this pull request Jun 20, 2018
* 6.x:
  [DOCS] Omit shard failures assertion for incompatible responses  (#31430)
  [DOCS] Move licensing APIs to docs (#31445)
  backport of: add is-write-index flag to aliases (#30942) (#31412)
  backport of: Add rollover-creation-date setting to rolled over index (#31144) (#31413)
  [Docs] Extend Homebrew installation instructions (#28902)
  [Docs] Mention ip_range datatypes on ip type page (#31416)
  Multiplexing token filter (#31208)
  Fix use of time zone in date_histogram rewrite (#31407)
  Revert "Mute DefaultShardsIT#testDefaultShards test"
  [DOCS] Fixes code snippet testing for machine learning (#31189)
  Security: fix joining cluster with production license (#31341)
  [DOCS] Updated version in Info API example
  [DOCS] Moves the info API to docs (#31121)
  Revert "Increasing skip version for failing test on 6.x"
  Preserve response headers on cluster update task (#31421)
  [DOCS] Add code snippet testing for more ML APIs (#31404)
  Docs: Advice for reindexing many indices (#31279)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/Indices APIs APIs to create and manage indices and templates >enhancement v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants