-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Fix Watcher deadlock that can cause in-abilty to index documents. #41418
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4900c89
Fix Watcher deadlock that can cause in-abilty to index documents.
jakelandis 5222e61
Merge branch 'master' into watcher_deadlock
jakelandis fa3364c
added test that fails or deadlocks in prior code
jakelandis 99694a4
add missing header
jakelandis b24ebdf
you win checkstyle
jakelandis ba1137b
Merge branch 'master' into watcher_deadlock
jakelandis 420d4d6
fix compilation error from merge collision
jakelandis b65517f
remove unecessary lock
jakelandis ce7f7e0
fix imports
jakelandis 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
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
81 changes: 81 additions & 0 deletions
81
...rc/test/java/org/elasticsearch/xpack/watcher/test/integration/RejectedExecutionTests.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,81 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.watcher.test.integration; | ||
|
||
import org.elasticsearch.action.search.SearchResponse; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.license.LicenseService; | ||
import org.elasticsearch.xpack.core.XPackSettings; | ||
import org.elasticsearch.xpack.core.watcher.client.WatcherClient; | ||
import org.elasticsearch.xpack.watcher.condition.CompareCondition; | ||
import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateRequest; | ||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; | ||
import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.elasticsearch.index.query.QueryBuilders.termQuery; | ||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; | ||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction; | ||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder; | ||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput; | ||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.templateRequest; | ||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule; | ||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.greaterThanOrEqualTo; | ||
|
||
public class RejectedExecutionTests extends AbstractWatcherIntegrationTestCase { | ||
|
||
@Override | ||
protected boolean timeWarped() { | ||
//need to use the real scheduler | ||
return false; | ||
} | ||
|
||
public void testHistoryAndTriggeredOnRejection() throws Exception { | ||
WatcherClient watcherClient = watcherClient(); | ||
createIndex("idx"); | ||
client().prepareIndex("idx", "_doc").setSource("field", "a").get(); | ||
refresh(); | ||
WatcherSearchTemplateRequest request = templateRequest(searchSource().query(termQuery("field", "a")), "idx"); | ||
watcherClient.preparePutWatch(randomAlphaOfLength(5)) | ||
.setSource(watchBuilder() | ||
.trigger(schedule(interval(1, IntervalSchedule.Interval.Unit.SECONDS))) | ||
.input(searchInput(request)) | ||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L)) | ||
.addAction("_logger", loggingAction("_logging") | ||
.setCategory("_category"))) | ||
.get(); | ||
|
||
assertBusy(() -> { | ||
flushAndRefresh(".watcher-history-*"); | ||
SearchResponse searchResponse = client().prepareSearch(".watcher-history-*").get(); | ||
assertThat(searchResponse.getHits().getTotalHits().value, greaterThanOrEqualTo(2L)); | ||
}, 10, TimeUnit.SECONDS); | ||
|
||
flushAndRefresh(".triggered_watches"); | ||
SearchResponse searchResponse = client().prepareSearch(".triggered_watches").get(); | ||
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); | ||
} | ||
|
||
@Override | ||
protected Settings nodeSettings(int nodeOrdinal) { | ||
|
||
return Settings.builder() | ||
.put(super.nodeSettings(nodeOrdinal)) | ||
.put(XPackSettings.MONITORING_ENABLED.getKey(), false) | ||
.put(XPackSettings.SECURITY_ENABLED.getKey(), false) | ||
.put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), "trial") | ||
.put("thread_pool.write.size", 1) | ||
.put("thread_pool.write.queue_size", 1) | ||
.put("xpack.watcher.thread_pool.size", 1) | ||
.put("xpack.watcher.thread_pool.queue_size", 0) | ||
.build(); | ||
} | ||
|
||
|
||
} |
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.
this method was pulled from git history, this is the implementation prior to the bulk processor.