-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Auto-allocate searchable snapshots #52527
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
Auto-allocate searchable snapshots #52527
Conversation
This commit allows plugins to supply their own allocator for existing shards, generalizing the default `GatewayAllocator`. It uses this to implement a very simple auto-allocation process for searchable snapshots which respects the allocation deciders but which can otherwise be assigned to any node.
Pinging @elastic/es-distributed (:Distributed/Snapshot/Restore) |
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.
I'm opening this for initial comments before I get too deep into adding/modifying tests to match the changes here; it should pass the existing test suite at least.
server/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java
Outdated
Show resolved
Hide resolved
@elasticmachine please run elasticsearch-ci/2 |
I forgot to mention that of course we expect to have a more sophisticated mechanism in future with async fetching of information from the individual nodes before making a decision. This PR is only focussed on the plumbing needed to expose this kind of allocation to plugins. |
@elasticmachine please run elasticsearch-ci/2 |
…-allocator-for-existing-shards
…-allocator-for-existing-shards
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.
Thanks Dave, I read through it mainly out of interest. I added a few comments anyway, feel free to dismiss me quickly if it makes no sense 😃
server/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java
Outdated
Show resolved
Hide resolved
...s/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotAllocator.java
Outdated
Show resolved
Hide resolved
...s/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotAllocator.java
Outdated
Show resolved
Hide resolved
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.
I've left some thoughts similar to what Henning said
server/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java
Outdated
Show resolved
Hide resolved
Move the iteration through the shards from the individual allocators up to the AllocationService, allowing us to allocate them in proper priority order and also allowing us to assign a unique allocator to each shard according to an index setting.
I've taken this in the direction suggested by both @ywelsch and @henningandersen, added some tests, and removed the WIP label. This is ready for a proper review now. |
…-allocator-for-existing-shards
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.
I've left some smaller comments, overall looking good. Should we also have some basic tests for SearchableSnapshotAllocator
or do you want to leave that to a follow-up?
server/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java
Outdated
Show resolved
Hide resolved
private ExistingShardsAllocator getAllocatorForShard(ShardRouting shardRouting, RoutingAllocation routingAllocation) { | ||
assert assertInitialized(); | ||
final String allocatorName = ExistingShardsAllocator.EXISTING_SHARDS_ALLOCATOR_SETTING.get( | ||
routingAllocation.metaData().getIndexSafe(shardRouting.index()).getSettings()); |
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.
as these lookups can be expensive in case there are many unassigned shards, I wonder if we should pass the retrieved IndexMetaData to the ExistingShardsAllocator.
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.
It involves passing the IndexMetaData
around to a lot of places. I mean we could do that if you're sure this is sufficiently expensive, but it seems surprising to me that this would be a concern.
server/src/main/java/org/elasticsearch/cluster/ClusterModule.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/plugins/ClusterPlugin.java
Outdated
Show resolved
Hide resolved
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.
I left a number of smaller comments and a question on how the balancer and searchable snapshot allocation will interact.
server/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/routing/allocation/ExistingShardsAllocator.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/routing/allocation/ExistingShardsAllocator.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java
Outdated
Show resolved
Hide resolved
...s/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotAllocator.java
Show resolved
Hide resolved
…-allocator-for-existing-shards
Hey folks, any more comments on this PR? |
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.
LGTM
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.
LGTM.
: clusterPlugin.getExistingShardsAllocators().entrySet()) { | ||
final String allocatorName = existingShardsAllocatorEntry.getKey(); | ||
if (existingShardsAllocators.put(allocatorName, existingShardsAllocatorEntry.getValue()) != null) { | ||
throw new IllegalArgumentException("ExistingShardsAllocator [" + allocatorName + "] already defined"); |
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.
Can we include clusterPlugin.getClass().getName()
into the message?
* Called before starting a round of allocation, allowing the allocator to invalidate some caches if appropriate. | ||
*/ | ||
void beforeAllocation(RoutingAllocation allocation); | ||
|
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.
nit: remove extra empty line.
while (unassignedIterator.hasNext()) { | ||
final ShardRouting shard = unassignedIterator.next(); | ||
final AllocateUnassignedDecision allocateUnassignedDecision = makeAllocationDecision(shard, allocation, logger); | ||
public void allocateUnassigned(RoutingAllocation allocation, ShardRouting shardRouting, |
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.
nit: swap argument order to make it the same as in ExistingShardsAllocator
:
public void allocateUnassigned(RoutingAllocation allocation, ShardRouting shardRouting, | |
public void allocateUnassigned(ShardRouting shardRouting, RoutingAllocation allocation, |
…-allocator-for-existing-shards
…-allocator-for-existing-shards
…-allocator-for-existing-shards
In elastic#50239 we introduced a temporary workaround in Store#tryOpenIndex to allow searchable snapshots shards to be allocated anywhere. elastic#52527 reverts this workaround but did not revert the associated test changes. This commit reverts the associated test changes.
This commit allows plugins to supply their own allocator for existing shards,
generalizing the default
GatewayAllocator
. It uses this to implement a verysimple auto-allocation process for searchable snapshots which respects the
allocation deciders but which can otherwise be assigned to any node.
Relates #50999