Skip to content

Collapse IndexMode#getConfiguredTimestampRange(...) into IndexMode#getTimestampBound(...)#88258

Merged
elasticsearchmachine merged 6 commits intoelastic:masterfrom
martijnvg:collapse_getConfiguredTimestampRange_into_getTimestampBound
Jul 6, 2022
Merged

Collapse IndexMode#getConfiguredTimestampRange(...) into IndexMode#getTimestampBound(...)#88258
elasticsearchmachine merged 6 commits intoelastic:masterfrom
martijnvg:collapse_getConfiguredTimestampRange_into_getTimestampBound

Conversation

@martijnvg
Copy link
Copy Markdown
Member

IndexMode#getConfiguredTimestampRange(...) functionally overlaps a lot with IndexMode#getTimestampBound(...).
In order to reuse IndexMode#getTimestampBound(...) for the use case IndexMode#getConfiguredTimestampRange(...)
is reused a change had to be made to TimestampBounds.

During query rewrite and in TimestampFieldMapperService no IndexScopedSettings is available,
so made this an optional parameter. Only the usage in IndexSettings needs this, so that the
instance is updated in the case index.time_series.end_time setting is updated. In the case of
query rewrite and in TimestampFieldMapperService this isn't needed, since the instance is
kept around and reused.

Followup from #85162

@martijnvg martijnvg added the :StorageEngine/TSDB You know, for Metrics label Jul 4, 2022
…tTimestampBound(...)

`IndexMode#getConfiguredTimestampRange(...)` functionally overlaps a lot with `IndexMode#getTimestampBound(...)`.
In order to reuse `IndexMode#getTimestampBound(...)` for the use case `IndexMode#getConfiguredTimestampRange(...)`
is reused a change had to be made to TimestampBounds.

During query rewrite and in `TimestampFieldMapperService` no `IndexScopedSettings` is available,
so made this an optional parameter. Only the usage in `IndexSettings` needs this, so that the
instance is updated in the case `index.time_series.end_time` setting is updated. In the case of
query rewrite and in `TimestampFieldMapperService` this isn't needed,  since the instance is
kept around and reused.

Followup from elastic#85162
@martijnvg martijnvg force-pushed the collapse_getConfiguredTimestampRange_into_getTimestampBound branch from c05577d to d73200c Compare July 4, 2022 16:18
@martijnvg
Copy link
Copy Markdown
Member Author

Not super happy about the fact that IndexScopedSettings is an optional parameter in TimestampBounds's constructor. In the case where it is really need (usage in IndexSettings) it really needs to be provided, otherwise weird bugs can occur.

@martijnvg martijnvg requested a review from nik9000 July 4, 2022 16:20
endTime = indexMetadata.getTimeSeriesEnd().toEpochMilli();
if (scopedSettings != null) {
scopedSettings.addSettingsUpdateConsumer(IndexSettings.TIME_SERIES_END_TIME, this::updateEndTime);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah! I see. What a pain.

I wonder if it's better to have the bounds object be immutable and to move the replacement of the end time to the IndexSettings. Or wrap this in something mutable over there when in tsdb mode. I'd wanted to avoid having a volatile read from IndexSettings for every document write which is why I made this mutable. The way it is now you only do the volatile read when you are in tsdb mode.

The mutability here is annoying. Sorry!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I tried to the following: ba5460c
Which updates the timestampBounds in IndexSettings if end_time setting changes and makes TimestampBounds immutable.

if (bounds != null) {
var indexMode = context.indexSettings().getMode();
if (indexMode == IndexMode.TIME_SERIES) {
TimestampBounds bounds = context.indexSettings().getTimestampBounds();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This avoids doing a volatile read in case of non tsdb indices. Seems like a good idea?
I think this is the only place where getTimestampBounds() getter is being used.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

Could you make this context.indexSettings().getMode().validateTimestamp(bounds, first, context)? Or maybe context.indexSettings().getMode().shouldValidateTimestamp()? We're trying to avoid all of the hard checks against indexMode's types. That way you can look at index mode and see "all the things" that it changes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I pushed this: 8ae391a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@martijnvg martijnvg marked this pull request as ready for review July 6, 2022 14:09
@elasticmachine elasticmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Jul 6, 2022
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-analytics-geo (Team:Analytics)

Copy link
Copy Markdown
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

LGTM.

@nik9000
Copy link
Copy Markdown
Member

nik9000 commented Jul 6, 2022

It's better than what we had, for sure. A nice compromise.

@martijnvg martijnvg added >non-issue auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) labels Jul 6, 2022
@elasticsearchmachine elasticsearchmachine merged commit 8531e36 into elastic:master Jul 6, 2022
@martijnvg martijnvg deleted the collapse_getConfiguredTimestampRange_into_getTimestampBound branch July 6, 2022 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) >non-issue :StorageEngine/TSDB You know, for Metrics Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants