-
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
Replica allocation consider no-op #42518
Closed
henningandersen
wants to merge
9
commits into
elastic:master
from
henningandersen:enhance_replica_allocator_no_syncid
+1,090
−117
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
06f4d3c
Replica allocation consider no-op
henningandersen 57cac72
Merge remote-tracking branch 'origin/master' into enhance_replica_all…
henningandersen ba09f21
Merge remote-tracking branch 'origin/master' into enhance_replica_all…
henningandersen 94a3c8d
Fixed rolling-upgrade test
henningandersen b01c3fc
Increase delayed allocation time
henningandersen 0c9da5b
Lock during cleanup files
henningandersen 647f21d
Check style fixes
henningandersen 4afe2c9
Merge remote-tracking branch 'origin/master' into enhance_replica_all…
henningandersen a7dd7ee
Fixed a few outdated comments.
henningandersen 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.action.support.nodes.BaseNodeResponse; | ||
import org.elasticsearch.action.support.nodes.BaseNodesResponse; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.cluster.node.DiscoveryNodes; | ||
import org.elasticsearch.cluster.routing.RoutingNodes; | ||
import org.elasticsearch.cluster.routing.RoutingService; | ||
import org.elasticsearch.cluster.routing.ShardRouting; | ||
|
@@ -35,7 +37,11 @@ | |
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.indices.store.TransportNodesListShardStoreMetaData; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
public class GatewayAllocator { | ||
|
@@ -52,6 +58,9 @@ public class GatewayAllocator { | |
private final ConcurrentMap<ShardId, AsyncShardFetch<TransportNodesListShardStoreMetaData.NodeStoreFilesMetaData>> | ||
asyncFetchStore = ConcurrentCollections.newConcurrentMap(); | ||
|
||
// contains ephemeralIds | ||
private volatile Set<String> lastDataNodes = Collections.emptySet(); | ||
|
||
@Inject | ||
public GatewayAllocator(RoutingService routingService, | ||
TransportNodesListGatewayStartedShards startedAction, | ||
|
@@ -101,6 +110,7 @@ public void applyFailedShards(final RoutingAllocation allocation, final List<Fai | |
} | ||
|
||
public void allocateUnassigned(final RoutingAllocation allocation) { | ||
ensureAsyncFetchStorePrimaryRecency(allocation); | ||
innerAllocatedUnassigned(allocation, primaryShardAllocator, replicaShardAllocator); | ||
} | ||
|
||
|
@@ -128,6 +138,43 @@ public AllocateUnassignedDecision decideUnassignedShardAllocation(ShardRouting u | |
} | ||
} | ||
|
||
/** | ||
* Whenever we see a new data node, we clear the information we have on primary to ensure it is at least as recent as the start | ||
* of the new node. This reduces risk of making a decision on stale information from primary. | ||
*/ | ||
private void ensureAsyncFetchStorePrimaryRecency(RoutingAllocation allocation) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make a separate PR for this enhancement? |
||
DiscoveryNodes nodes = allocation.nodes(); | ||
if (hasNewNodes(nodes, lastDataNodes)) { | ||
asyncFetchStore.values().forEach(fetch -> clearCacheForPrimary(fetch, allocation)); | ||
// recalc to also (lazily) clear out old nodes. | ||
Set<String> newDataNodes = new HashSet<>(nodes.getDataNodes().size()); | ||
for (Iterator<DiscoveryNode> iterator = nodes.getDataNodes().valuesIt(); iterator.hasNext(); ) { | ||
newDataNodes.add(iterator.next().getEphemeralId()); | ||
} | ||
this.lastDataNodes = newDataNodes; | ||
} | ||
} | ||
|
||
private void clearCacheForPrimary(AsyncShardFetch<TransportNodesListShardStoreMetaData.NodeStoreFilesMetaData> fetch, | ||
RoutingAllocation allocation) { | ||
ShardRouting primary = allocation.routingNodes().activePrimary(fetch.shardId); | ||
if (primary != null) { | ||
fetch.clearCacheForNode(primary.currentNodeId()); | ||
} | ||
} | ||
|
||
private boolean hasNewNodes(DiscoveryNodes nodes, Set<String> lastDataNodes) { | ||
for (Iterator<DiscoveryNode> iterator = nodes.getDataNodes().valuesIt(); iterator.hasNext(); ) { | ||
DiscoveryNode node = iterator.next(); | ||
if (lastDataNodes.contains(node.getEphemeralId()) == false) { | ||
logger.trace("new node {} found, clearing primary async-fetch-store cache", node); | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
class InternalAsyncFetch<T extends BaseNodeResponse> extends AsyncShardFetch<T> { | ||
|
||
InternalAsyncFetch(Logger logger, String type, ShardId shardId, Lister<? extends BaseNodesResponse<T>, T> action) { | ||
|
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 |
---|---|---|
|
@@ -49,7 +49,6 @@ | |
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING; | ||
|
||
|
@@ -101,17 +100,16 @@ public void processExistingRecoveries(RoutingAllocation allocation) { | |
DiscoveryNode currentNode = allocation.nodes().get(shard.currentNodeId()); | ||
DiscoveryNode nodeWithHighestMatch = matchingNodes.getNodeWithHighestMatch(); | ||
// current node will not be in matchingNodes as it is filtered away by SameShardAllocationDecider | ||
final String currentSyncId; | ||
final TransportNodesListShardStoreMetaData.StoreFilesMetaData currentStore; | ||
if (shardStores.getData().containsKey(currentNode)) { | ||
currentSyncId = shardStores.getData().get(currentNode).storeFilesMetaData().syncId(); | ||
currentStore = shardStores.getData().get(currentNode).storeFilesMetaData(); | ||
} else { | ||
currentSyncId = null; | ||
currentStore = null; | ||
} | ||
if (currentNode.equals(nodeWithHighestMatch) == false | ||
&& Objects.equals(currentSyncId, primaryStore.syncId()) == false | ||
&& matchingNodes.isNodeMatchBySyncID(nodeWithHighestMatch)) { | ||
// we found a better match that has a full sync id match, the existing allocation is not fully synced | ||
// so we found a better one, cancel this one | ||
&& isNoopRecovery(primaryStore, currentStore) == false | ||
&& matchingNodes.isNoopRecovery(nodeWithHighestMatch)) { | ||
// we found a better match that can do a fast recovery, cancel current recovery | ||
logger.debug("cancelling allocation of replica on [{}], sync id match found on node [{}]", | ||
currentNode, nodeWithHighestMatch); | ||
UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.REALLOCATED_REPLICA, | ||
|
@@ -363,10 +361,7 @@ private MatchingNodes findMatchingNodes(ShardRouting shard, RoutingAllocation al | |
|
||
private static long computeMatchingBytes(TransportNodesListShardStoreMetaData.StoreFilesMetaData primaryStore, | ||
TransportNodesListShardStoreMetaData.StoreFilesMetaData storeFilesMetaData) { | ||
String primarySyncId = primaryStore.syncId(); | ||
String replicaSyncId = storeFilesMetaData.syncId(); | ||
// see if we have a sync id we can make use of | ||
if (replicaSyncId != null && replicaSyncId.equals(primarySyncId)) { | ||
if (isNoopRecovery(primaryStore, storeFilesMetaData)) { | ||
return Long.MAX_VALUE; | ||
} else { | ||
long sizeMatched = 0; | ||
|
@@ -380,6 +375,34 @@ private static long computeMatchingBytes(TransportNodesListShardStoreMetaData.St | |
} | ||
} | ||
|
||
/** | ||
* Is a "noop recovery", which means expecting no operations to recover (though with sync-id, we could in principle still | ||
* have a few). | ||
*/ | ||
private static boolean isNoopRecovery(TransportNodesListShardStoreMetaData.StoreFilesMetaData primaryStore, | ||
TransportNodesListShardStoreMetaData.StoreFilesMetaData candidateStore) { | ||
// keeping syncIdMatch for 7.x to remain backwards compatible with pre-7.3 versions, but will remove for 8.0. | ||
return syncIdMatch(primaryStore, candidateStore) | ||
|| noopMatch(primaryStore, candidateStore); | ||
} | ||
|
||
private static boolean syncIdMatch(TransportNodesListShardStoreMetaData.StoreFilesMetaData primaryStore, | ||
TransportNodesListShardStoreMetaData.StoreFilesMetaData candidateStore) { | ||
String primarySyncId = primaryStore.syncId(); | ||
String replicaSyncId = candidateStore.syncId(); | ||
return (replicaSyncId != null && replicaSyncId.equals(primarySyncId)); | ||
} | ||
|
||
private static boolean noopMatch(TransportNodesListShardStoreMetaData.StoreFilesMetaData primaryStore, | ||
TransportNodesListShardStoreMetaData.StoreFilesMetaData candidateStore) { | ||
// We need the maxSeqNo conditions until we support non-noop recovery for closed indices (and preferably also have | ||
// retention leases in place to ensure ops based recovery will actually be performed). | ||
return primaryStore.hasSeqNoInfo() | ||
&& primaryStore.maxSeqNo() == candidateStore.maxSeqNo() | ||
&& primaryStore.provideRecoverySeqNo() <= candidateStore.requireRecoverySeqNo() | ||
&& candidateStore.requireRecoverySeqNo() == primaryStore.maxSeqNo() + 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if we need the last condition? |
||
} | ||
|
||
protected abstract AsyncShardFetch.FetchResult<NodeStoreFilesMetaData> fetchData(ShardRouting shard, RoutingAllocation allocation); | ||
|
||
/** | ||
|
@@ -418,7 +441,10 @@ public DiscoveryNode getNodeWithHighestMatch() { | |
return this.nodeWithHighestMatch; | ||
} | ||
|
||
public boolean isNodeMatchBySyncID(DiscoveryNode node) { | ||
/** | ||
* Is supplied node a no-operations recovery, either sync-id match or sequence number match. | ||
*/ | ||
public boolean isNoopRecovery(DiscoveryNode node) { | ||
return nodesToSize.get(node) == Long.MAX_VALUE; | ||
} | ||
|
||
|
Oops, something went wrong.
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.
I think this test passed with the current behaviour. Can we make a small PR for this test only?