-
Notifications
You must be signed in to change notification settings - Fork 25.6k
TSDB: add index timestamp range check #78291
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
Changes from 21 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
2bad389
add settings
weizijun 8809757
add check code
weizijun 6c42357
add some comment
weizijun c3f1e66
add yaml tests
weizijun 79e96e0
add the time_series mode check
weizijun b4a68c3
improve
weizijun 63e552c
Revert "improve"
weizijun 0e67726
Revert "Revert "improve""
weizijun e3b7256
Merge branch 'upstream/master' into tsdb-deal-timestreamp
weizijun 78c132d
spotless
weizijun fe8f654
Merge branch 'upstream/master' into tsdb-deal-timestreamp
weizijun 120cdaf
improve
weizijun 563ca87
fix ccr tests
weizijun daccfb7
Merge branch 'master' into tsdb-deal-timestreamp
weizijun 14a2378
spotless
weizijun 2c45c57
improve
weizijun d2a00ec
Merge branch 'master' into tsdb-deal-timestreamp
elasticmachine d631649
Merge branch 'master' into tsdb-deal-timestreamp
elasticmachine 1dcebb0
fix bwc
weizijun 79db882
improve
weizijun 69df14d
Maybe like this?
nik9000 6c77b18
fix failed tests
weizijun 40f2e82
fix failed tests
weizijun 582588f
fix failed tests
weizijun bfe25c5
improve
weizijun 6350ee1
checkStyle
weizijun a5a116f
spotless
weizijun 7236ee1
fixex tsdb settings tests
weizijun 20c21a8
Merge branch 'master' into tsdb-deal-timestreamp
nik9000 9e92d09
Fixup after merge
nik9000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,10 +26,12 @@ | |
| import org.elasticsearch.ingest.IngestService; | ||
| import org.elasticsearch.node.Node; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.Collections; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.Consumer; | ||
| import java.util.function.Function; | ||
|
|
@@ -474,6 +476,55 @@ public static boolean isTimeSeriesModeEnabled() { | |
| return Build.CURRENT.isSnapshot() || (TIME_SERIES_MODE_FEATURE_FLAG_REGISTERED != null && TIME_SERIES_MODE_FEATURE_FLAG_REGISTERED); | ||
| } | ||
|
|
||
| /** | ||
| * in time series mode, the start time of the index, timestamp must larger than start_time | ||
| */ | ||
| public static final Setting<Optional<Instant>> TIME_SERIES_START_TIME = Setting.dateSetting( | ||
| "index.time_series.start_time", | ||
| Optional.empty(), | ||
| v -> {}, | ||
| Property.IndexScope, | ||
| Property.Final | ||
| ); | ||
|
|
||
| /** | ||
| * in time series mode, the end time of the index, timestamp must smaller than start_time | ||
| */ | ||
| public static final Setting<Optional<Instant>> TIME_SERIES_END_TIME = Setting.dateSetting( | ||
| "index.time_series.end_time", | ||
| Optional.empty(), | ||
| new Setting.Validator<>() { | ||
| @Override | ||
| public void validate(Optional<Instant> value) {} | ||
|
|
||
| @Override | ||
| public void validate(Optional<Instant> value, Map<Setting<?>, Object> settings) { | ||
| @SuppressWarnings("unchecked") | ||
| Optional<Instant> startTime = (Optional<Instant>) settings.get(TIME_SERIES_START_TIME); | ||
| if (value.isEmpty()) { | ||
| if (startTime.isPresent()) { | ||
| throw new IllegalArgumentException("index.time_series.start_time must be set with index.time_series.end_time"); | ||
| } | ||
| return; | ||
| } | ||
| if (startTime.isEmpty()) { | ||
| throw new IllegalArgumentException("index.time_series.start_time must be set with index.time_series.end_time"); | ||
| } | ||
| if (startTime.get().compareTo(value.get()) < 0) { | ||
| throw new IllegalArgumentException("index.time_series.start_time must be larger than index.time_series.end_time"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Iterator<Setting<?>> settings() { | ||
| List<Setting<?>> settings = List.of(TIME_SERIES_START_TIME); | ||
| return settings.iterator(); | ||
| } | ||
| }, | ||
| Property.IndexScope, | ||
| Property.Dynamic | ||
| ); | ||
|
|
||
| /** | ||
| * The {@link IndexMode "mode"} of the index. | ||
| */ | ||
|
|
@@ -509,6 +560,14 @@ public Iterator<Setting<?>> settings() { | |
| * The {@link IndexMode "mode"} of the index. | ||
| */ | ||
| private final IndexMode mode; | ||
| /** | ||
| * Start time of the time_series index. | ||
| */ | ||
| private final Instant timeSeriesStartTime; | ||
| /** | ||
| * End time of the time_series index. | ||
| */ | ||
| private volatile Instant timeSeriesEndTime; | ||
|
||
|
|
||
| // volatile fields are updated via #updateIndexMetadata(IndexMetadata) under lock | ||
| private volatile Settings settings; | ||
|
|
@@ -651,6 +710,8 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti | |
| this.indexMetadata = indexMetadata; | ||
| numberOfShards = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_SHARDS, null); | ||
| mode = isTimeSeriesModeEnabled() ? scopedSettings.get(MODE) : IndexMode.STANDARD; | ||
| timeSeriesStartTime = TIME_SERIES_START_TIME.get(settings).orElse(null); | ||
| timeSeriesEndTime = TIME_SERIES_END_TIME.get(settings).orElse(null); | ||
|
|
||
| this.searchThrottled = INDEX_SEARCH_THROTTLED.get(settings); | ||
| this.queryStringLenient = QUERY_STRING_LENIENT_SETTING.get(settings); | ||
|
|
@@ -765,6 +826,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti | |
| scopedSettings.addSettingsUpdateConsumer(INDEX_MAPPING_DEPTH_LIMIT_SETTING, this::setMappingDepthLimit); | ||
| scopedSettings.addSettingsUpdateConsumer(INDEX_MAPPING_FIELD_NAME_LENGTH_LIMIT_SETTING, this::setMappingFieldNameLengthLimit); | ||
| scopedSettings.addSettingsUpdateConsumer(INDEX_MAPPING_DIMENSION_FIELDS_LIMIT_SETTING, this::setMappingDimensionFieldsLimit); | ||
| scopedSettings.addSettingsUpdateConsumer(TIME_SERIES_END_TIME, this::updateTimeSeriesEndTime); | ||
| } | ||
|
|
||
| private void setSearchIdleAfter(TimeValue searchIdleAfter) { | ||
|
|
@@ -1278,4 +1340,26 @@ public long getMappingDimensionFieldsLimit() { | |
| private void setMappingDimensionFieldsLimit(long value) { | ||
| this.mappingDimensionFieldsLimit = value; | ||
| } | ||
|
|
||
| public Instant getTimeSeriesStartTime() { | ||
| return timeSeriesStartTime; | ||
| } | ||
|
|
||
| public Instant getTimeSeriesEndTime() { | ||
| return timeSeriesEndTime; | ||
| } | ||
|
|
||
| public void updateTimeSeriesEndTime(Optional<Instant> endTime) { | ||
| if (endTime.isEmpty()) { | ||
| this.timeSeriesEndTime = null; | ||
| return; | ||
| } | ||
| Instant endInstant = endTime.get(); | ||
| if (this.timeSeriesEndTime.isAfter(endInstant)) { | ||
| throw new IllegalArgumentException( | ||
| "index.time_series.end_time must be larger than current value [" + this.timeSeriesEndTime + "]" | ||
| ); | ||
| } | ||
| this.timeSeriesEndTime = endInstant; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.