-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Watcher: Ensure that execution triggers properly on initial setup (#3…
…3360) This commit reverts most of #33157 as it introduces another race condition and breaks a common case of watcher, when the first watch is added to the system and the index does not exist yet. This means, that the index will be created, which triggers a reload, but during this time the put watch operation that triggered this is not yet indexed, so that both processes finish roughly add the same time and should not overwrite each other but act complementary. This commit reverts the logic of cleaning out the ticker engine watches on start up, as this is done already when the execution is paused - which also gets paused on the cluster state listener again, as we can be sure here, that the watches index has not yet been created. This also adds a new test, that starts a one node cluster and emulates the case of a non existing watches index and a watch being added, which should result in proper execution. Closes #33320
- Loading branch information
Showing
7 changed files
with
147 additions
and
104 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
66 changes: 66 additions & 0 deletions
66
...tcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SingleNodeTests.java
This file contains 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,66 @@ | ||
/* | ||
* 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.admin.cluster.state.ClusterStateResponse; | ||
import org.elasticsearch.action.search.SearchResponse; | ||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; | ||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope; | ||
import org.elasticsearch.xpack.core.watcher.watch.Watch; | ||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; | ||
import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule; | ||
import org.elasticsearch.xpack.watcher.watch.WatchStoreUtils; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE; | ||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
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.simpleInput; | ||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule; | ||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval; | ||
import static org.hamcrest.Matchers.greaterThanOrEqualTo; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@ClusterScope(scope = SUITE, numClientNodes = 0, transportClientRatio = 0, maxNumDataNodes = 1, supportsDedicatedMasters = false) | ||
public class SingleNodeTests extends AbstractWatcherIntegrationTestCase { | ||
|
||
@Override | ||
protected boolean timeWarped() { | ||
return false; | ||
} | ||
|
||
// this is the standard setup when starting watcher in a regular cluster | ||
// the index does not exist, a watch gets added | ||
// the watch should be executed properly, despite the index being created and the cluster state listener being reloaded | ||
public void testThatLoadingWithNonExistingIndexWorks() throws Exception { | ||
stopWatcher(); | ||
ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().get(); | ||
IndexMetaData metaData = WatchStoreUtils.getConcreteIndex(Watch.INDEX, clusterStateResponse.getState().metaData()); | ||
String watchIndexName = metaData.getIndex().getName(); | ||
assertAcked(client().admin().indices().prepareDelete(watchIndexName)); | ||
startWatcher(); | ||
|
||
String watchId = randomAlphaOfLength(20); | ||
// now we start with an empty set up, store a watch and expected it to be executed | ||
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch(watchId) | ||
.setSource(watchBuilder() | ||
.trigger(schedule(interval(1, IntervalSchedule.Interval.Unit.SECONDS))) | ||
.input(simpleInput()) | ||
.addAction("_logger", loggingAction("logging of watch _name"))) | ||
.get(); | ||
assertThat(putWatchResponse.isCreated(), is(true)); | ||
|
||
assertBusy(() -> { | ||
client().admin().indices().prepareRefresh(".watcher-history*"); | ||
SearchResponse searchResponse = client().prepareSearch(".watcher-history*").setSize(0).get(); | ||
assertThat(searchResponse.getHits().getTotalHits(), is(greaterThanOrEqualTo(1L))); | ||
}, 5, TimeUnit.SECONDS); | ||
} | ||
|
||
} |
Oops, something went wrong.