-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Watcher: Changing .watches index primary/replica configuration may end up with non distributed watch execution #32636
Comments
Pinging @elastic/es-core-infra |
Looks really interesting 👍 I'll work on this one and let you know. |
@spinscale I've added your test case to my fork and tweaked it a tiny bit to be at ease with variable names. The fundamental change I've made is at line: Here I select the generated shard identifier, whereas you picked up the current shard identifier. Could you please tell me why did you picked up the current shard identifier bitset? |
I've referenced the wrong issue in the Git log message in my previous commit, sorry for that noise. |
your variant is fine as well. However with randomization there might be cases where shards will simply not contain any watches and its fine (i.e. 10 shards and 10 documents, there is no guaranteee of even distribution by design) |
Got it, thank you, I wasn't aware of this not-always-even document distribution among shards. I've removed randomization this avoid this corner case in the unit test. I may have missed a point, but my main issue now is that this test doesn't fail, should it? |
This has been open for quite a while, and hasn't had a lot of interest. For now I'm going to close this as something we aren't planning on implementing. We can re-open it later if needed. |
If you configure the
.watches
index to have a certain primary replica configuration, the distributed execution of the watches only happens on one shard copy.Note: This is not the default configuration in requires some steps to actually archive (as the indexing template cannot be easily overwritten for example).
The basic premise is, that the number of shards (primaries) is equal to the number of replicas minus one. For example
Explanation
The explanation for this requires to understand how watcher decides if a watch should be executed on a replica or on the primary shard. This is the logic to decide where a document should be indexed (not watcher specific).
By hashing the id and run a modulo operation through the number of shards we decide which primary shard to index, in this example shard zero.
If we now have the same number of copies plus the primary shard than the number of primary shards, we use the same hashing function to find out where a watch should be executed. This will result in the exact same calculation, which will return the same result for any document (otherwise it would not have ended up in that shard bucket).
We cannot tell which shard (primary or replica) will be used for execution (as we use the allocation ids to find out the order), but it is only going to be one in this particular case.
An easy workaround for now is to not have the same number of shards as replicas + 1.
This is a unit test to reproduce in 6.x/master (added to the
WatcherIndexingListenerTests
)A possible idea of fixing this might be to change the logic of decision and use something more than the id of watch (just adding a prefix or reversing the string might be enough for the hash function to return a different result). In order to remain BWC we could check if all nodes in the clsuter have surpassed a certain version and only then use the new logic.
The text was updated successfully, but these errors were encountered: