-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Historical Startup -- Configurable loading strategy #18687
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
Open
GWphua
wants to merge
22
commits into
apache:master
Choose a base branch
from
GWphua:lazy-load-by-period
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+419
−9
Open
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d47c8e6
Add segment load on startup by period
GWphua 34081ee
Change test file
GWphua 88407fc
Unit test for Strategy Factory
GWphua 9978f73
Load eagerly test
GWphua e15b8be
Test unknown strategy
GWphua 5064bcc
Documentation for load eagerly before period
GWphua f0ced70
Checkstyle
GWphua f325cf1
Forbidden API
GWphua ae15550
checkstyle
GWphua 05509cd
Setup test for deprecated method
GWphua dc8c7d7
Update docs/configuration/index.md
GWphua 8351de1
Resolve nitpick
GWphua 019a3bd
Javadocs
GWphua 84efec7
JsonTypeInfo
GWphua 288223d
Use JSON config... TODO: Change Factory class.
GWphua 430e216
Add test to JSON serialize correctly
GWphua a0fd32e
Load strategy test
GWphua 6c641dc
Add String method to all
GWphua 4978b21
Documentation update
GWphua aa11aa0
Javadocs for all classes added
GWphua a29350d
Merge remote-tracking branch 'origin/master' into lazy-load-by-period
GWphua 7e420d8
Set startupLoadPeriod property to null by default
GWphua 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
Some comments aren't visible on the classic Files Changed page.
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
46 changes: 46 additions & 0 deletions
46
...java/org/apache/druid/server/coordination/startup/HistoricalStartupCacheLoadStrategy.java
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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.druid.server.coordination.startup; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
| import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
| import org.apache.druid.timeline.DataSegment; | ||
|
|
||
| /** | ||
| * Strategy for determining whether segments should be loaded lazily or eagerly during | ||
| * Historical process startup. Lazy loading can help to lower Historical startup time at the | ||
| * expense of query latency, by deferring the loading process to the first access of that segment. | ||
| */ | ||
| @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") | ||
| @JsonSubTypes(value = { | ||
| @JsonSubTypes.Type(name = LoadAllEagerlyStrategy.STRATEGY_NAME, value = LoadAllEagerlyStrategy.class), | ||
| @JsonSubTypes.Type(name = LoadAllLazilyStrategy.STRATEGY_NAME, value = LoadAllLazilyStrategy.class), | ||
| @JsonSubTypes.Type(name = LoadEagerlyBeforePeriod.STRATEGY_NAME, value = LoadEagerlyBeforePeriod.class) | ||
| }) | ||
| public interface HistoricalStartupCacheLoadStrategy | ||
| { | ||
| /** | ||
| * Indicates whether the provided segment should be loaded lazily during Historical startup. | ||
| * | ||
| * @param segment the segment being evaluated | ||
| * @return {@code true} if the segment should be loaded lazily, {@code false} if it should be loaded eagerly. | ||
| */ | ||
| boolean shouldLoadLazily(DataSegment segment); | ||
| } |
55 changes: 55 additions & 0 deletions
55
...er/src/main/java/org/apache/druid/server/coordination/startup/LoadAllEagerlyStrategy.java
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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.druid.server.coordination.startup; | ||
|
|
||
| import org.apache.druid.java.util.common.logger.Logger; | ||
| import org.apache.druid.timeline.DataSegment; | ||
|
|
||
| import java.util.Locale; | ||
|
|
||
| /** | ||
| * Eagerly loads column metadata for all segments at Historical startup. | ||
| * <p> | ||
| * Optimizes for predictable first-query latency at the cost of longer startup time and higher I/O during bootstrap. | ||
| * {@link #shouldLoadLazily(DataSegment)} always returns {@code false}. | ||
| */ | ||
| public class LoadAllEagerlyStrategy implements HistoricalStartupCacheLoadStrategy | ||
| { | ||
| private static final Logger log = new Logger(LoadAllEagerlyStrategy.class); | ||
|
|
||
| public static final String STRATEGY_NAME = "loadAllEagerly"; | ||
|
|
||
| public LoadAllEagerlyStrategy() | ||
| { | ||
| log.info("Using [%s] strategy", STRATEGY_NAME); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean shouldLoadLazily(DataSegment segment) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() | ||
| { | ||
| return String.format(Locale.ROOT, "{type=%s}", STRATEGY_NAME); | ||
| } | ||
| } |
55 changes: 55 additions & 0 deletions
55
server/src/main/java/org/apache/druid/server/coordination/startup/LoadAllLazilyStrategy.java
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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.druid.server.coordination.startup; | ||
|
|
||
| import org.apache.druid.java.util.common.logger.Logger; | ||
| import org.apache.druid.timeline.DataSegment; | ||
|
|
||
| import java.util.Locale; | ||
|
|
||
| /** | ||
| * Defers column metadata loading for all segments until first access. | ||
| * <p> | ||
| * Minimizes Historical startup time and I/O during bootstrap at the expense of increased latency on the first | ||
| * query that touches a segment. {@link #shouldLoadLazily(DataSegment)} always returns {@code true}. | ||
| */ | ||
| public class LoadAllLazilyStrategy implements HistoricalStartupCacheLoadStrategy | ||
| { | ||
| private static final Logger log = new Logger(LoadAllLazilyStrategy.class); | ||
|
|
||
| public static final String STRATEGY_NAME = "loadAllLazily"; | ||
|
|
||
| public LoadAllLazilyStrategy() | ||
| { | ||
| log.info("Using [%s] strategy", STRATEGY_NAME); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean shouldLoadLazily(DataSegment segment) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() | ||
| { | ||
| return String.format(Locale.ROOT, "{type=%s}", STRATEGY_NAME); | ||
| } | ||
| } |
76 changes: 76 additions & 0 deletions
76
...r/src/main/java/org/apache/druid/server/coordination/startup/LoadEagerlyBeforePeriod.java
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 |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.druid.server.coordination.startup; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.google.common.annotations.VisibleForTesting; | ||
| import org.apache.druid.java.util.common.DateTimes; | ||
| import org.apache.druid.java.util.common.logger.Logger; | ||
| import org.apache.druid.timeline.DataSegment; | ||
| import org.joda.time.DateTime; | ||
| import org.joda.time.Interval; | ||
| import org.joda.time.Period; | ||
|
|
||
| import java.util.Locale; | ||
|
|
||
| /** | ||
| * Eagerly loads column metadata for segments whose intervals overlap a recent sliding window; all others load lazily. | ||
| * <p> | ||
| * Balances bootstrap time and first-query performance by eagerly loading only "hot" segments. The window is | ||
| * computed as {@code [now - period, now]} at Historical startup. | ||
| */ | ||
| public class LoadEagerlyBeforePeriod implements HistoricalStartupCacheLoadStrategy | ||
GWphua marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| private static final Logger log = new Logger(LoadEagerlyBeforePeriod.class); | ||
| public static final String STRATEGY_NAME = "loadEagerlyBeforePeriod"; | ||
|
|
||
| private final Interval eagerLoadingInterval; | ||
|
|
||
| @VisibleForTesting | ||
| @JsonCreator | ||
| public LoadEagerlyBeforePeriod( | ||
| @JsonProperty("period") Period eagerLoadingPeriod | ||
| ) | ||
| { | ||
| DateTime now = DateTimes.nowUtc(); | ||
| this.eagerLoadingInterval = new Interval(now.minus(eagerLoadingPeriod), now); | ||
|
|
||
| log.info("Using [%s] strategy with Interval[%s]", STRATEGY_NAME, eagerLoadingInterval); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public Interval getEagerLoadingInterval() | ||
| { | ||
| return this.eagerLoadingInterval; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean shouldLoadLazily(DataSegment segment) | ||
| { | ||
| return !segment.getInterval().overlaps(eagerLoadingInterval); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() | ||
| { | ||
| return String.format(Locale.ROOT, "{type=%s,interval=%s}", STRATEGY_NAME, getEagerLoadingInterval()); | ||
| } | ||
| } | ||
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How feasible/extensible is it to accept a map of datasource to load period, to allow configurable periods per datasource? (similar to the
loadByPeriod- load rules config where each datasource can have different load retention rules)I think having that option would allow a lot more flexibility to operators as the query workloads can be vastly different.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is workable --
I can change
startupLoadStrategy.periodtostartupLoadStrategy.datasourceToPeriodMapping, which receives something like a JSONe.g.
{"DS1": "P7D", "DS2": "P2D", ".": "P7D"}Where
.refers to the default configuration (since datasources cannot start with.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My opinion is that let's keep the change in this PR small enough. for datasource level configuration, if there's really need for this feature, we can implement it by defining a datasource level configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel we can leave this for another PR, since it is out of scope of this intended PR. WDYT? @abhishekrb19