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

Expose timestamp field type on coordinator node #65873

Conversation

DaveCTurner
Copy link
Contributor

Today a coordinating node does not have (easy) access to the mappings
for the indices for the searches it wishes to coordinate. This means it
can't properly interpret a timestamp range filter in a query and must
involve a copy of every shard in at least the can_match phase. It
therefore cannot cope with cases when shards are temporarily not started
even if those shards are irrelevant to the search.

This commit captures the mapping of the @timestamp field for indices
which expose a timestamp range in their index metadata.

Today a coordinating node does not have (easy) access to the mappings
for the indices for the searches it wishes to coordinate. This means it
can't properly interpret a timestamp range filter in a query and must
involve a copy of every shard in at least the `can_match` phase. It
therefore cannot cope with cases when shards are temporarily not started
even if those shards are irrelevant to the search.

This commit captures the mapping of the `@timestamp` field for indices
which expose a timestamp range in their index metadata.
@DaveCTurner DaveCTurner requested a review from fcofdez December 4, 2020 10:26
@elasticmachine elasticmachine added the Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. label Dec 4, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

@Nullable
public DateFieldMapper.DateFieldType getTimestampFieldType(Index index) {
final PlainActionFuture<DateFieldMapper.DateFieldType> future = fieldTypesByIndex.get(index);
if (future == null || future.isDone() == false) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There remains a question of whether we should block here or not (and if so, for how long).

On reflection I think we shouldn't block. Returning null sooner will allow the search coordination to proceed normally, ignoring any timestamp filter and deferring any skipping to the individual shards. This means we'll see shard failures if the coordinating node falls behind on extracting these mappings AND some of the shards are unassigned, which is hopefully rare.

As a follow-up we could in theory add another more patient getter to support a workflow that goes:

  1. we call getTimestampFieldType which returns null
  2. some shards are unavailable for the can_match phase
  3. we call getTimestampFieldTypePatiently to see for whether those shard failures can be ignored or not

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it makes sense to return null and proceed regularly if the mapping isn't available yet. This should be rare enough to cause too much trouble.
I guess the most problematic scenario is when a node joins and has to parse a lot of mappings, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, although in that case there's no particular reason to expect shards to be unavailable.

Copy link
Contributor

@fcofdez fcofdez left a comment

Choose a reason for hiding this comment

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

LGTM, just some minor comments in the test 👍

timestampFieldTypeFuture.onResponse(timestampFieldType);
});
assertTrue(timestampFieldTypeFuture.isDone());
assertThat(timestampFieldTypeFuture.get().dateTimeFormatter().locale().toString(), equalTo(locale));
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can add a an assertion that checks that DateFieldMapper.DateFieldType#parse works with the original timestamp string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok let me try and remember the month names in French to give this assertion some teeth 🇫🇷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 79ef7b0. Remembering the names wasn't the hard bit, it was working out that in French we write month names lower-case, with a trailing ., and sometimes use more than 3 letters.

@Nullable
public DateFieldMapper.DateFieldType getTimestampFieldType(Index index) {
final PlainActionFuture<DateFieldMapper.DateFieldType> future = fieldTypesByIndex.get(index);
if (future == null || future.isDone() == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it makes sense to return null and proceed regularly if the mapping isn't available yet. This should be rare enough to cause too much trouble.
I guess the most problematic scenario is when a node joins and has to parse a lot of mappings, right?

@DaveCTurner
Copy link
Contributor Author

@elasticmachine please run elasticsearch-ci/bwc

@DaveCTurner
Copy link
Contributor Author

@elasticmachine please run elasticsearch-ci/2

@DaveCTurner DaveCTurner merged commit e1e1974 into elastic:master Dec 4, 2020
@DaveCTurner DaveCTurner deleted the 2020-12-03-extract-timestamp-field-type branch December 4, 2020 16:11
DaveCTurner added a commit that referenced this pull request Dec 4, 2020
Today a coordinating node does not have (easy) access to the mappings
for the indices for the searches it wishes to coordinate. This means it
can't properly interpret a timestamp range filter in a query and must
involve a copy of every shard in at least the `can_match` phase. It
therefore cannot cope with cases when shards are temporarily not started
even if those shards are irrelevant to the search.

This commit captures the mapping of the `@timestamp` field for indices
which expose a timestamp range in their index metadata.
@DaveCTurner
Copy link
Contributor Author

The backport failed in CI: https://gradle-enterprise.elastic.co/s/s3kleye5lwxds/console-log?task=:x-pack:plugin:frozen-indices:internalClusterTest

No idea why yet but I've reverted it from 7.x for now.

DaveCTurner added a commit that referenced this pull request Dec 4, 2020
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Dec 7, 2020
Today a coordinating node does not have (easy) access to the mappings
for the indices for the searches it wishes to coordinate. This means it
can't properly interpret a timestamp range filter in a query and must
involve a copy of every shard in at least the `can_match` phase. It
therefore cannot cope with cases when shards are temporarily not started
even if those shards are irrelevant to the search.

This commit captures the mapping of the `@timestamp` field for indices
which expose a timestamp range in their index metadata.
DaveCTurner added a commit that referenced this pull request Dec 7, 2020
Today a coordinating node does not have (easy) access to the mappings
for the indices for the searches it wishes to coordinate. This means it
can't properly interpret a timestamp range filter in a query and must
involve a copy of every shard in at least the `can_match` phase. It
therefore cannot cope with cases when shards are temporarily not started
even if those shards are irrelevant to the search.

This commit captures the mapping of the `@timestamp` field for indices
which expose a timestamp range in their index metadata.

Backport of #65873 to 7.x
@DaveCTurner
Copy link
Contributor Author

I reinstated the backport with a few JDK8-specific tweaks in #65925.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >enhancement Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v7.11.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants