Skip to content

Conversation

masseyke
Copy link
Member

@masseyke masseyke commented Mar 30, 2022

We are seeing this error in 8.0.1 if a node is restarted after the .watcher-history-16 data stream is pointing to more than one index.

[instance-0000000000] error validating to start watcher
java.lang.IllegalStateException: Alias [.watcher-history-16] points to more than one index
	at org.elasticsearch.xpack.watcher.watch.WatchStoreUtils.getConcreteIndex(WatchStoreUtils.java:32) ~[x-pack-watcher-8.1.0.jar:8.1.0]
	at org.elasticsearch.xpack.watcher.history.HistoryStore.validate(HistoryStore.java:79) ~[x-pack-watcher-8.1.0.jar:8.1.0]
	at org.elasticsearch.xpack.watcher.WatcherService.validate(WatcherService.java:158) [x-pack-watcher-8.1.0.jar:8.1.0]
	at org.elasticsearch.xpack.watcher.WatcherLifeCycleService.clusterChanged(WatcherLifeCycleService.java:162) [x-pack-watcher-8.1.0.jar:8.1.0]
	at org.elasticsearch.cluster.service.ClusterApplierService.callClusterStateListener(ClusterApplierService.java:564) [elasticsearch-8.1.0.jar:8.1.0]
	at org.elasticsearch.cluster.service.ClusterApplierService.callClusterStateListeners(ClusterApplierService.java:550) [elasticsearch-8.1.0.jar:8.1.0]
	at org.elasticsearch.cluster.service.ClusterApplierService.applyChanges(ClusterApplierService.java:510) [elasticsearch-8.1.0.jar:8.1.0]
	at org.elasticsearch.cluster.service.ClusterApplierService.runTask(ClusterApplierService.java:428) [elasticsearch-8.1.0.jar:8.1.0]
	at org.elasticsearch.cluster.service.ClusterApplierService$UpdateTask.run(ClusterApplierService.java:154) [elasticsearch-8.1.0.jar:8.1.0]
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:717) [elasticsearch-8.1.0.jar:8.1.0]
	at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:260) [elasticsearch-8.1.0.jar:8.1.0]
	at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:223) [elasticsearch-8.1.0.jar:8.1.0]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
	at java.lang.Thread.run(Thread.java:833) [?:?]

This change makes it ok to use an alias with a write index or a data stream (which always has a write index).
Closes #85508

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

@masseyke masseyke added the >bug label Mar 30, 2022
@elasticsearchmachine
Copy link
Collaborator

Hi @masseyke, I've created a changelog YAML for you.

@masseyke masseyke requested a review from martijnvg March 30, 2022 20:42
Copy link
Member

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I left a question and a comments about the tests.

}

if (indexAbstraction.getType() != IndexAbstraction.Type.CONCRETE_INDEX && indexAbstraction.getIndices().size() > 1) {
if ((indexAbstraction.getType() != IndexAbstraction.Type.CONCRETE_INDEX
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if statement does look a bit complicated.
Can we instead have two simpler if statements for the valid cases?
One if statement for when indexAbstraction is a data stream and one when indexAbstraction is an alias.
In all other cases we would fail.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also support if it's just a concrete index, right? I was not sure if there were other types I didn't know about so I left it mostly as it was. If there are definitely just those 3 though (alias, data stream, concrete index) I can definitely simplify it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also support if it's just a concrete index, right?

I thought it was either an alias or data stream. But I might be wrong here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In at least one place we pass .watches to this method, which I believe is a concrete index (although I could definitely be wrong about that).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to explicitly look for aliases here, which does simplify things a little.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it does.

…github.com:masseyke/elasticsearch into fix/watcher-validation-fails-with-multiple-indices
@masseyke masseyke requested a review from martijnvg March 31, 2022 19:35
@masseyke
Copy link
Member Author

@elasticmachine update branch

Copy link
Member

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM (pending successful build)

Failure occurred due to error message change:

java.lang.AssertionError: |  
-- | --
  | Expected: is "Alias [.triggered_watches] points to more than one index" |  
  | but: was "Alias [.triggered_watches] points to 2 indices, and does not have a designated write index" |  
  | at __randomizedtesting.SeedInfo.seed([8F6C099FB918BA97:988C8EAA4DCC424]:0) |  
  | at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18) |  
  | at org.junit.Assert.assertThat(Assert.java:956) |  
  | at org.junit.Assert.assertThat(Assert.java:923) |  
  | at org.elasticsearch.xpack.watcher.execution.TriggeredWatchStoreTests.testLoadingFailsWithTwoAliases(TriggeredWatchStoreTests.java:391)

(and I think bwc failures should be fixed by merging in master)

masseyke added 2 commits April 1, 2022 09:46
…github.com:masseyke/elasticsearch into fix/watcher-validation-fails-with-multiple-indices
@masseyke
Copy link
Member Author

masseyke commented Apr 1, 2022

@elasticmachine update branch

@masseyke masseyke merged commit 40fc3a5 into elastic:master Apr 1, 2022
@masseyke masseyke deleted the fix/watcher-validation-fails-with-multiple-indices branch April 1, 2022 15:48
masseyke added a commit to masseyke/elasticsearch that referenced this pull request Apr 1, 2022
…than one index (elastic#85507)

This commit fixes a validation bug that prevented watcher from starting if the .watcher-history-16 data stream is
pointing to more than one index. Before 8.0, .watcher-history-16 data had been an alias and had never pointed
to more than one index, so this had not been a problem.
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.2

elasticsearchmachine pushed a commit that referenced this pull request Apr 1, 2022
…than one index (#85507) (#85631)

This commit fixes a validation bug that prevented watcher from starting if the .watcher-history-16 data stream is
pointing to more than one index. Before 8.0, .watcher-history-16 data had been an alias and had never pointed
to more than one index, so this had not been a problem.
masseyke added a commit to masseyke/elasticsearch that referenced this pull request Apr 7, 2022
…than one index (elastic#85507)

This commit fixes a validation bug that prevented watcher from starting if the .watcher-history-16 data stream is
pointing to more than one index. Before 8.0, .watcher-history-16 data had been an alias and had never pointed
to more than one index, so this had not been a problem.
elasticsearchmachine pushed a commit that referenced this pull request Apr 7, 2022
…than one index (#85507) (#85755)

* Avoiding watcher validation errors when a data stream points to more than one index (#85507)

This commit fixes a validation bug that prevented watcher from starting if the .watcher-history-16 data stream is
pointing to more than one index. Before 8.0, .watcher-history-16 data had been an alias and had never pointed
to more than one index, so this had not been a problem.

* Fixing test for backport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Watcher can fail to restart in early version of 8.x
5 participants