Skip to content

Commit

Permalink
config(reindex): create reindex timeout configuration (#11456)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-leifker committed Sep 23, 2024
1 parent a481ea4 commit 090c514
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
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

0 comments on commit 090c514

Please sign in to comment.