Skip to content

Commit 08c15a9

Browse files
committed
Apply review feedback
1 parent 53fe3b1 commit 08c15a9

File tree

3 files changed

+7
-90
lines changed

3 files changed

+7
-90
lines changed

x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/DownsampleIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,11 @@ private void downsampleAndAssert(String dataStreamName, String mapping, Supplier
174174
}
175175

176176
private String generateForceMergeMetadata() {
177-
return switch (randomIntBetween(0, 3)) {
177+
return switch (randomIntBetween(0, 4)) {
178178
case 0 -> "\"_meta\": { \"downsample.forcemerge.enabled\": false},";
179179
case 1 -> "\"_meta\": { \"downsample.forcemerge.enabled\": true},";
180180
case 2 -> "\"_meta\": { \"downsample.forcemerge.enabled\": 4},";
181+
case 3 -> "\"_meta\": { \"downsample.forcemerge.enabled\": null},";
181182
default -> "";
182183
};
183184
}

x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleAction.java

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,7 @@ protected void masterOperation(
301301
final TaskId parentTask = new TaskId(clusterService.localNode().getId(), task.getId());
302302
// Short circuit if target index has been downsampled:
303303
final String downsampleIndexName = request.getTargetIndex();
304-
if (canShortCircuit(
305-
sourceIndexName,
306-
downsampleIndexName,
307-
parentTask,
308-
request.masterNodeTimeout(),
309-
request.getWaitTimeout(),
310-
startTime,
311-
projectMetadata,
312-
listener
313-
)) {
304+
if (canShortCircuit(downsampleIndexName, parentTask, request.getWaitTimeout(), startTime, true, projectMetadata, listener)) {
314305
logger.info("Skipping downsampling, because a previous execution already completed downsampling");
315306
return;
316307
}
@@ -479,73 +470,6 @@ private boolean isForceMergeEnabled(Map<String, Object> sourceIndexMappings) {
479470
return true;
480471
}
481472

482-
/**
483-
* Shortcircuit when another downsample api invocation already completed successfully.
484-
*/
485-
private boolean canShortCircuit(
486-
String sourceIndexName,
487-
String targetIndexName,
488-
TaskId parentTask,
489-
TimeValue masterNodeTimeout,
490-
TimeValue waitTimeout,
491-
long startTime,
492-
ProjectMetadata projectMetadata,
493-
ActionListener<AcknowledgedResponse> listener
494-
) {
495-
IndexMetadata targetIndexMetadata = projectMetadata.index(targetIndexName);
496-
if (targetIndexMetadata == null) {
497-
return false;
498-
}
499-
500-
var downsampleStatus = IndexMetadata.INDEX_DOWNSAMPLE_STATUS.get(targetIndexMetadata.getSettings());
501-
if (downsampleStatus == DownsampleTaskStatus.UNKNOWN) {
502-
// This isn't a downsample index, so fail:
503-
listener.onFailure(new ResourceAlreadyExistsException(targetIndexMetadata.getIndex()));
504-
return true;
505-
} else if (downsampleStatus == DownsampleTaskStatus.SUCCESS) {
506-
listener.onResponse(AcknowledgedResponse.TRUE);
507-
return true;
508-
}
509-
// In case the write block has been set on the target index means that the shard level downsampling itself was successful,
510-
// but the previous invocation failed later performing settings update, refresh or force merge.
511-
// The write block is used a signal to resume from the refresh part of the downsample api invocation.
512-
if (targetIndexMetadata.getSettings().get(IndexMetadata.SETTING_BLOCKS_WRITE) != null) {
513-
// 1. Extract source index mappings
514-
final GetMappingsRequest getMappingsRequest = new GetMappingsRequest(masterNodeTimeout).indices(sourceIndexName);
515-
getMappingsRequest.setParentTask(parentTask);
516-
client.admin().indices().getMappings(getMappingsRequest, listener.delegateFailureAndWrap((delegate, getMappingsResponse) -> {
517-
final Map<String, Object> sourceIndexMappings = getMappingsResponse.mappings()
518-
.entrySet()
519-
.stream()
520-
.filter(entry -> sourceIndexName.equals(entry.getKey()))
521-
.findFirst()
522-
.map(mappingMetadata -> mappingMetadata.getValue().sourceAsMap())
523-
.orElseThrow(
524-
() -> new IllegalArgumentException("No mapping found for downsample source index [" + sourceIndexName + "]")
525-
);
526-
var forceMergeEnabled = isForceMergeEnabled(sourceIndexMappings);
527-
var refreshRequest = new RefreshRequest(targetIndexMetadata.getIndex().getName());
528-
refreshRequest.setParentTask(parentTask);
529-
client.admin()
530-
.indices()
531-
.refresh(
532-
refreshRequest,
533-
new RefreshDownsampleIndexActionListener(
534-
projectMetadata.id(),
535-
delegate,
536-
parentTask,
537-
targetIndexMetadata.getIndex().getName(),
538-
waitTimeout,
539-
startTime,
540-
forceMergeEnabled
541-
)
542-
);
543-
}));
544-
return true;
545-
}
546-
return false;
547-
}
548-
549473
/**
550474
* Shortcircuit when another downsample api invocation already completed successfully.
551475
*/

x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/TransportDownsampleActionTests.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -279,21 +279,12 @@ private void downsample(String mapping) throws IOException {
279279
}
280280

281281
public void testDownsamplingForceMergeWithShortCircuitAfterCreation() {
282-
String mapping = switch (randomIntBetween(0, 2)) {
282+
String mapping = switch (randomIntBetween(0, 3)) {
283283
case 0 -> NO_METADATA_MAPPING;
284284
case 1 -> OTHER_METADATA_MAPPING;
285-
default -> FORCE_MERGE_ENABLED_MAPPING;
285+
case 2 -> FORCE_MERGE_ENABLED_MAPPING;
286+
default -> FORCE_MERGE_DISABLED_MAPPING;
286287
};
287-
downsampleSkipsForceMergeWithShortCircuitAfterCreation(mapping);
288-
verify(indicesAdminClient).forceMerge(any(), any());
289-
}
290-
291-
public void testDownsamplingSkipsForceMergeWithShortCircuitAfterCreation() {
292-
downsampleSkipsForceMergeWithShortCircuitAfterCreation(FORCE_MERGE_DISABLED_MAPPING);
293-
verify(indicesAdminClient, never()).forceMerge(any(), any());
294-
}
295-
296-
public void downsampleSkipsForceMergeWithShortCircuitAfterCreation(String mapping) {
297288
mockGetMapping(mapping);
298289

299290
var projectMetadata = ProjectMetadata.builder(projectId)
@@ -323,6 +314,7 @@ public void downsampleSkipsForceMergeWithShortCircuitAfterCreation(String mappin
323314
);
324315
safeGet(listener);
325316
verify(downsampleMetrics).recordOperation(anyLong(), eq(DownsampleMetrics.ActionStatus.SUCCESS));
317+
verify(indicesAdminClient).forceMerge(any(), any());
326318
}
327319

328320
public void testDownsamplingForceMergeWithShortCircuitDuringCreation() throws IOException {

0 commit comments

Comments
 (0)