-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Allow shards of closed indices to be replicated as regular shards #38024
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
Changes from all commits
bc92dc0
a5a940a
acd7f49
0801f59
27bb402
5af364d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,7 @@ | |
import static org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason.DELETED; | ||
import static org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason.FAILURE; | ||
import static org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason.NO_LONGER_ASSIGNED; | ||
import static org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason.REOPENED; | ||
|
||
public class IndicesClusterStateService extends AbstractLifecycleComponent implements ClusterStateApplier { | ||
private static final Logger logger = LogManager.getLogger(IndicesClusterStateService.class); | ||
|
@@ -240,7 +241,7 @@ public synchronized void applyClusterState(final ClusterChangedEvent event) { | |
|
||
deleteIndices(event); // also deletes shards of deleted indices | ||
|
||
removeUnallocatedIndices(event); // also removes shards of removed indices | ||
removeIndices(event); // also removes shards of removed indices | ||
|
||
failMissingShards(state); | ||
|
||
|
@@ -352,17 +353,18 @@ protected void doRun() throws Exception { | |
} | ||
|
||
/** | ||
* Removes indices that have no shards allocated to this node. This does not delete the shard data as we wait for enough | ||
* shard copies to exist in the cluster before deleting shard data (triggered by {@link org.elasticsearch.indices.store.IndicesStore}). | ||
* Removes indices that have no shards allocated to this node or indices whose state has changed. This does not delete the shard data | ||
* as we wait for enough shard copies to exist in the cluster before deleting shard data (triggered by | ||
* {@link org.elasticsearch.indices.store.IndicesStore}). | ||
* | ||
* @param event the cluster changed event | ||
*/ | ||
private void removeUnallocatedIndices(final ClusterChangedEvent event) { | ||
private void removeIndices(final ClusterChangedEvent event) { | ||
final ClusterState state = event.state(); | ||
final String localNodeId = state.nodes().getLocalNodeId(); | ||
assert localNodeId != null; | ||
|
||
Set<Index> indicesWithShards = new HashSet<>(); | ||
final Set<Index> indicesWithShards = new HashSet<>(); | ||
RoutingNode localRoutingNode = state.getRoutingNodes().node(localNodeId); | ||
if (localRoutingNode != null) { // null e.g. if we are not a data node | ||
for (ShardRouting shardRouting : localRoutingNode) { | ||
|
@@ -371,20 +373,27 @@ private void removeUnallocatedIndices(final ClusterChangedEvent event) { | |
} | ||
|
||
for (AllocatedIndex<? extends Shard> indexService : indicesService) { | ||
Index index = indexService.index(); | ||
if (indicesWithShards.contains(index) == false) { | ||
final Index index = indexService.index(); | ||
final IndexMetaData indexMetaData = state.metaData().index(index); | ||
final IndexMetaData existingMetaData = indexService.getIndexSettings().getIndexMetaData(); | ||
|
||
AllocatedIndices.IndexRemovalReason reason = null; | ||
if (indexMetaData != null && indexMetaData.getState() != existingMetaData.getState()) { | ||
reason = indexMetaData.getState() == IndexMetaData.State.CLOSE ? CLOSED : REOPENED; | ||
} else if (indicesWithShards.contains(index) == false) { | ||
// if the cluster change indicates a brand new cluster, we only want | ||
// to remove the in-memory structures for the index and not delete the | ||
// contents on disk because the index will later be re-imported as a | ||
// dangling index | ||
final IndexMetaData indexMetaData = state.metaData().index(index); | ||
assert indexMetaData != null || event.isNewCluster() : | ||
"index " + index + " does not exist in the cluster state, it should either " + | ||
"have been deleted or the cluster must be new"; | ||
final AllocatedIndices.IndexRemovalReason reason = | ||
indexMetaData != null && indexMetaData.getState() == IndexMetaData.State.CLOSE ? CLOSED : NO_LONGER_ASSIGNED; | ||
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. for BWC reasons, I think we will need to keep this. 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. I guess you're thinking of the search context releasing? 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. Sorry for not being clear here. I was rather thinking about the case where an older-version master has removed the routing table for a closed index (i.e. old-style closed indices). We still need to handle these here. |
||
logger.debug("{} removing index, [{}]", index, reason); | ||
indicesService.removeIndex(index, reason, "removing index (no shards allocated)"); | ||
reason = indexMetaData != null && indexMetaData.getState() == IndexMetaData.State.CLOSE ? CLOSED : NO_LONGER_ASSIGNED; | ||
} | ||
|
||
if (reason != null) { | ||
logger.debug("{} removing index ({})", index, reason); | ||
indicesService.removeIndex(index, reason, "removing index (" + reason + ")"); | ||
} | ||
} | ||
} | ||
|
@@ -595,7 +604,7 @@ private void updateShard(DiscoveryNodes nodes, ShardRouting shardRouting, Shard | |
ClusterState clusterState) { | ||
final ShardRouting currentRoutingEntry = shard.routingEntry(); | ||
assert currentRoutingEntry.isSameAllocation(shardRouting) : | ||
"local shard has a different allocation id but wasn't cleaning by removeShards. " | ||
"local shard has a different allocation id but wasn't cleaned by removeShards. " | ||
+ "cluster state: " + shardRouting + " local: " + currentRoutingEntry; | ||
|
||
final long primaryTerm; | ||
|
@@ -730,7 +739,7 @@ private void failAndRemoveShard(ShardRouting shardRouting, boolean sendShardFail | |
private void sendFailShard(ShardRouting shardRouting, String message, @Nullable Exception failure, ClusterState state) { | ||
try { | ||
logger.warn(() -> new ParameterizedMessage( | ||
"[{}] marking and sending shard failed due to [{}]", shardRouting.shardId(), message), failure); | ||
"{} marking and sending shard failed due to [{}]", shardRouting.shardId(), message), failure); | ||
failedShardsCache.put(shardRouting.shardId(), shardRouting); | ||
shardStateAction.localShardFailed(shardRouting, message, failure, SHARD_STATE_ACTION_LISTENER, state); | ||
} catch (Exception inner) { | ||
|
@@ -931,7 +940,7 @@ enum IndexRemovalReason { | |
DELETED, | ||
|
||
/** | ||
* The index have been closed. The index should be removed and all associated resources released. Persistent parts of the index | ||
* The index has been closed. The index should be removed and all associated resources released. Persistent parts of the index | ||
* like the shards files, state and transaction logs are kept around in the case of a disaster recovery. | ||
*/ | ||
CLOSED, | ||
|
@@ -941,7 +950,13 @@ enum IndexRemovalReason { | |
* Persistent parts of the index like the shards files, state and transaction logs are kept around in the | ||
* case of a disaster recovery. | ||
*/ | ||
FAILURE | ||
FAILURE, | ||
|
||
/** | ||
* The index has been reopened. The index should be removed and all associated resources released. Persistent parts of the index | ||
* like the shards files, state and transaction logs are kept around in the case of a disaster recovery. | ||
*/ | ||
REOPENED, | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.