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

config(reindex): create reindex timeout configuration #11456

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public class ESIndexBuilder {

@Getter private final GitVersion gitVersion;

@Getter private final int maxReindexHours;

private static final RequestOptions REQUEST_OPTIONS =
RequestOptions.DEFAULT.toBuilder()
.setRequestConfig(RequestConfig.custom().setSocketTimeout(180 * 1000).build())
Expand All @@ -106,6 +108,34 @@ public ESIndexBuilder(
boolean enableStructuredPropertiesReindex,
ElasticSearchConfiguration elasticSearchConfiguration,
GitVersion gitVersion) {
this(
searchClient,
numShards,
numReplicas,
numRetries,
refreshIntervalSeconds,
indexSettingOverrides,
enableIndexSettingsReindex,
enableIndexMappingsReindex,
enableStructuredPropertiesReindex,
elasticSearchConfiguration,
gitVersion,
0);
}

public ESIndexBuilder(
RestHighLevelClient searchClient,
int numShards,
int numReplicas,
int numRetries,
int refreshIntervalSeconds,
Map<String, Map<String, String>> indexSettingOverrides,
boolean enableIndexSettingsReindex,
boolean enableIndexMappingsReindex,
boolean enableStructuredPropertiesReindex,
ElasticSearchConfiguration elasticSearchConfiguration,
GitVersion gitVersion,
int maxReindexHours) {
this._searchClient = searchClient;
this.numShards = numShards;
this.numReplicas = numReplicas;
Expand All @@ -117,6 +147,7 @@ public ESIndexBuilder(
this.elasticSearchConfiguration = elasticSearchConfiguration;
this.enableStructuredPropertiesReindex = enableStructuredPropertiesReindex;
this.gitVersion = gitVersion;
this.maxReindexHours = maxReindexHours;

RetryConfig config =
RetryConfig.custom()
Expand Down Expand Up @@ -348,10 +379,10 @@ private static String getNextIndexName(String base, long startTime) {
private void reindex(ReindexConfig indexState) throws Throwable {
final long startTime = System.currentTimeMillis();

final int maxReindexHours = 8;
final long initialCheckIntervalMilli = 1000;
final long finalCheckIntervalMilli = 60000;
final long timeoutAt = startTime + (1000 * 60 * 60 * maxReindexHours);
final long timeoutAt =
maxReindexHours > 0 ? startTime + (1000L * 60 * 60 * maxReindexHours) : Long.MAX_VALUE;

String tempIndexName = getNextIndexName(indexState.name(), startTime);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ elasticsearch:
mainTokenizer: ${ELASTICSEARCH_MAIN_TOKENIZER:#{null}}
enableMappingsReindex: ${ELASTICSEARCH_INDEX_BUILDER_MAPPINGS_REINDEX:false}
enableSettingsReindex: ${ELASTICSEARCH_INDEX_BUILDER_SETTINGS_REINDEX:false}
maxReindexHours: ${ELASTICSEARCH_INDEX_BUILDER_MAX_REINDEX_HOURS:0} # <= 0 - no timeout
settingsOverrides: ${ELASTICSEARCH_INDEX_BUILDER_SETTINGS_OVERRIDES:#{null}}
entitySettingsOverrides: ${ELASTICSEARCH_INDEX_BUILDER_ENTITY_SETTINGS_OVERRIDES:#{null}}
docIds:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public class ElasticSearchIndexBuilderFactory {
@Value("#{new Boolean('${structuredProperties.systemUpdateEnabled}')}")
private boolean enableStructuredPropertiesReindex;

@Value("${elasticsearch.index.maxReindexHours}")
private Integer maxReindexHours;

@Bean(name = "elasticSearchIndexSettingsOverrides")
@Nonnull
protected Map<String, Map<String, String>> getIndexSettingsOverrides(
Expand Down Expand Up @@ -90,7 +93,8 @@ protected ESIndexBuilder getInstance(
enableMappingsReindex,
enableStructuredPropertiesReindex,
configurationProvider.getElasticSearch(),
gitVersion);
gitVersion,
maxReindexHours);
}

@Nonnull
Expand Down
Loading