|
8 | 8 | package org.elasticsearch.xpack.transform.transforms;
|
9 | 9 |
|
10 | 10 | import org.apache.lucene.search.TotalHits;
|
| 11 | +import org.elasticsearch.ElasticsearchException; |
11 | 12 | import org.elasticsearch.ElasticsearchParseException;
|
12 | 13 | import org.elasticsearch.ElasticsearchTimeoutException;
|
13 | 14 | import org.elasticsearch.action.ActionListener;
|
|
20 | 21 | import org.elasticsearch.action.search.SearchResponse;
|
21 | 22 | import org.elasticsearch.action.search.ShardSearchFailure;
|
22 | 23 | import org.elasticsearch.client.Client;
|
| 24 | +import org.elasticsearch.cluster.block.ClusterBlockException; |
| 25 | +import org.elasticsearch.cluster.metadata.MetadataIndexStateService; |
23 | 26 | import org.elasticsearch.common.breaker.CircuitBreaker.Durability;
|
24 | 27 | import org.elasticsearch.common.breaker.CircuitBreakingException;
|
25 | 28 | import org.elasticsearch.core.TimeValue;
|
26 | 29 | import org.elasticsearch.index.reindex.BulkByScrollResponse;
|
27 | 30 | import org.elasticsearch.index.reindex.DeleteByQueryRequest;
|
| 31 | +import org.elasticsearch.rest.RestStatus; |
28 | 32 | import org.elasticsearch.script.ScriptException;
|
29 | 33 | import org.elasticsearch.search.SearchHit;
|
30 | 34 | import org.elasticsearch.search.SearchHits;
|
@@ -520,6 +524,130 @@ public void testScriptError() throws Exception {
|
520 | 524 | );
|
521 | 525 | }
|
522 | 526 |
|
| 527 | + public void testDontFailForClusterBlockException() throws Exception { |
| 528 | + Integer pageSize = randomBoolean() ? null : randomIntBetween(500, 10_000); |
| 529 | + String transformId = randomAlphaOfLength(10); |
| 530 | + TransformConfig config = new TransformConfig( |
| 531 | + transformId, |
| 532 | + randomSourceConfig(), |
| 533 | + randomDestConfig(), |
| 534 | + null, |
| 535 | + null, |
| 536 | + null, |
| 537 | + randomPivotConfig(), |
| 538 | + null, |
| 539 | + randomBoolean() ? null : randomAlphaOfLengthBetween(1, 1000), |
| 540 | + new SettingsConfig(pageSize, null, (Boolean) null, null, null), |
| 541 | + null, |
| 542 | + null, |
| 543 | + null, |
| 544 | + null |
| 545 | + ); |
| 546 | + AtomicReference<IndexerState> state = new AtomicReference<>(IndexerState.STOPPED); |
| 547 | + Function<SearchRequest, SearchResponse> searchFunction = searchRequest -> { |
| 548 | + throw new ClusterBlockException( |
| 549 | + Collections.singletonMap("test-index", Collections.singleton(MetadataIndexStateService.INDEX_CLOSED_BLOCK)) |
| 550 | + ); |
| 551 | + }; |
| 552 | + |
| 553 | + Function<BulkRequest, BulkResponse> bulkFunction = bulkRequest -> new BulkResponse(new BulkItemResponse[0], 100); |
| 554 | + |
| 555 | + TransformAuditor auditor = MockTransformAuditor.createMockAuditor(); |
| 556 | + TransformContext context = new TransformContext(TransformTaskState.STARTED, "", 0, mock(TransformContext.Listener.class)); |
| 557 | + |
| 558 | + MockedTransformIndexer indexer = createMockIndexer( |
| 559 | + config, |
| 560 | + state, |
| 561 | + searchFunction, |
| 562 | + bulkFunction, |
| 563 | + null, |
| 564 | + null, |
| 565 | + threadPool, |
| 566 | + ThreadPool.Names.GENERIC, |
| 567 | + auditor, |
| 568 | + context |
| 569 | + ); |
| 570 | + final CountDownLatch latch = indexer.newLatch(1); |
| 571 | + indexer.start(); |
| 572 | + assertThat(indexer.getState(), equalTo(IndexerState.STARTED)); |
| 573 | + assertTrue(indexer.maybeTriggerAsyncJob(System.currentTimeMillis())); |
| 574 | + assertThat(indexer.getState(), equalTo(IndexerState.INDEXING)); |
| 575 | + |
| 576 | + latch.countDown(); |
| 577 | + assertBusy(() -> assertThat(indexer.getState(), equalTo(IndexerState.STARTED)), 10, TimeUnit.MINUTES); |
| 578 | + assertThat(context.getFailureCount(), equalTo(1)); |
| 579 | + } |
| 580 | + |
| 581 | + public void testFailForNonRetryableElasticSearchException() throws Exception { |
| 582 | + Integer pageSize = randomBoolean() ? null : randomIntBetween(500, 10_000); |
| 583 | + String transformId = randomAlphaOfLength(10); |
| 584 | + TransformConfig config = new TransformConfig( |
| 585 | + transformId, |
| 586 | + randomSourceConfig(), |
| 587 | + randomDestConfig(), |
| 588 | + null, |
| 589 | + null, |
| 590 | + null, |
| 591 | + randomPivotConfig(), |
| 592 | + null, |
| 593 | + randomBoolean() ? null : randomAlphaOfLengthBetween(1, 1000), |
| 594 | + new SettingsConfig(pageSize, null, (Boolean) null, null, null), |
| 595 | + null, |
| 596 | + null, |
| 597 | + null, |
| 598 | + null |
| 599 | + ); |
| 600 | + AtomicReference<IndexerState> state = new AtomicReference<>(IndexerState.STOPPED); |
| 601 | + Function<SearchRequest, SearchResponse> searchFunction = searchRequest -> { |
| 602 | + throw new ElasticsearchException("internal error") { |
| 603 | + @Override |
| 604 | + public RestStatus status() { |
| 605 | + return RestStatus.BAD_REQUEST; |
| 606 | + } |
| 607 | + }; |
| 608 | + }; |
| 609 | + |
| 610 | + Function<BulkRequest, BulkResponse> bulkFunction = bulkRequest -> new BulkResponse(new BulkItemResponse[0], 100); |
| 611 | + |
| 612 | + final AtomicBoolean failIndexerCalled = new AtomicBoolean(false); |
| 613 | + final AtomicReference<String> failureMessage = new AtomicReference<>(); |
| 614 | + Consumer<String> failureConsumer = message -> { |
| 615 | + failIndexerCalled.compareAndSet(false, true); |
| 616 | + failureMessage.compareAndSet(null, message); |
| 617 | + }; |
| 618 | + |
| 619 | + MockTransformAuditor auditor = MockTransformAuditor.createMockAuditor(); |
| 620 | + TransformContext.Listener contextListener = mock(TransformContext.Listener.class); |
| 621 | + TransformContext context = new TransformContext(TransformTaskState.STARTED, "", 0, contextListener); |
| 622 | + |
| 623 | + MockedTransformIndexer indexer = createMockIndexer( |
| 624 | + config, |
| 625 | + state, |
| 626 | + searchFunction, |
| 627 | + bulkFunction, |
| 628 | + null, |
| 629 | + failureConsumer, |
| 630 | + threadPool, |
| 631 | + ThreadPool.Names.GENERIC, |
| 632 | + auditor, |
| 633 | + context |
| 634 | + ); |
| 635 | + |
| 636 | + final CountDownLatch latch = indexer.newLatch(1); |
| 637 | + |
| 638 | + indexer.start(); |
| 639 | + assertThat(indexer.getState(), equalTo(IndexerState.STARTED)); |
| 640 | + assertTrue(indexer.maybeTriggerAsyncJob(System.currentTimeMillis())); |
| 641 | + assertThat(indexer.getState(), equalTo(IndexerState.INDEXING)); |
| 642 | + |
| 643 | + latch.countDown(); |
| 644 | + assertBusy(() -> assertThat(indexer.getState(), equalTo(IndexerState.STARTED)), 10, TimeUnit.SECONDS); |
| 645 | + assertTrue(failIndexerCalled.get()); |
| 646 | + verify(contextListener, times(1)).fail(matches("task encountered irrecoverable failure: .*: internal error"), any()); |
| 647 | + |
| 648 | + assertThat(failureMessage.get(), matchesRegex("task encountered irrecoverable failure: .*: internal error")); |
| 649 | + } |
| 650 | + |
523 | 651 | public void testRetentionPolicyDeleteByQueryThrowsIrrecoverable() throws Exception {
|
524 | 652 | String transformId = randomAlphaOfLength(10);
|
525 | 653 | TransformConfig config = new TransformConfig(
|
|
0 commit comments