Skip to content

Commit d3cd806

Browse files
committed
Make IndexRemovalReason a top-level enum for sharing
1 parent 250df4c commit d3cd806

File tree

20 files changed

+79
-65
lines changed

20 files changed

+79
-65
lines changed

server/src/internalClusterTest/java/org/elasticsearch/plugins/IndexFoldersDeletionListenerIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.elasticsearch.index.IndexSettings;
2323
import org.elasticsearch.index.shard.ShardId;
2424
import org.elasticsearch.indices.IndicesService;
25-
import org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason;
25+
import org.elasticsearch.indices.cluster.IndexRemovalReason;
2626
import org.elasticsearch.test.ESIntegTestCase;
2727
import org.elasticsearch.test.junit.annotations.TestLogging;
2828

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexAliasesService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
import static java.util.Collections.emptyList;
5050
import static java.util.Collections.emptyMap;
51-
import static org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason.NO_LONGER_ASSIGNED;
51+
import static org.elasticsearch.indices.cluster.IndexRemovalReason.NO_LONGER_ASSIGNED;
5252

5353
/**
5454
* Service responsible for submitting add and remove aliases requests

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

8484
import static java.util.Collections.emptyMap;
8585
import static org.elasticsearch.cluster.metadata.MetadataCreateDataStreamService.validateTimestampFieldMapping;
86-
import static org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason.NO_LONGER_ASSIGNED;
86+
import static org.elasticsearch.indices.cluster.IndexRemovalReason.NO_LONGER_ASSIGNED;
8787

8888
/**
8989
* Service responsible for submitting index templates updates

server/src/main/java/org/elasticsearch/index/CompositeIndexEventListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.elasticsearch.index.shard.IndexShard;
2222
import org.elasticsearch.index.shard.IndexShardState;
2323
import org.elasticsearch.index.shard.ShardId;
24-
import org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason;
24+
import org.elasticsearch.indices.cluster.IndexRemovalReason;
2525
import org.elasticsearch.threadpool.ThreadPool;
2626

2727
import java.util.Collection;

server/src/main/java/org/elasticsearch/index/IndexService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@
8383
import org.elasticsearch.index.store.Store;
8484
import org.elasticsearch.index.translog.Translog;
8585
import org.elasticsearch.indices.breaker.CircuitBreakerService;
86+
import org.elasticsearch.indices.cluster.IndexRemovalReason;
8687
import org.elasticsearch.indices.cluster.IndicesClusterStateService;
87-
import org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason;
8888
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
8989
import org.elasticsearch.indices.recovery.RecoveryState;
9090
import org.elasticsearch.plugins.IndexStorePlugin;

server/src/main/java/org/elasticsearch/index/shard/IndexEventListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.elasticsearch.index.Index;
1616
import org.elasticsearch.index.IndexService;
1717
import org.elasticsearch.index.IndexSettings;
18-
import org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason;
18+
import org.elasticsearch.indices.cluster.IndexRemovalReason;
1919

2020
/**
2121
* An index event listener is the primary extension point for plugins and build-in services

server/src/main/java/org/elasticsearch/indices/IndicesService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
import org.elasticsearch.index.shard.ShardId;
133133
import org.elasticsearch.index.translog.TranslogStats;
134134
import org.elasticsearch.indices.breaker.CircuitBreakerService;
135+
import org.elasticsearch.indices.cluster.IndexRemovalReason;
135136
import org.elasticsearch.indices.cluster.IndicesClusterStateService;
136137
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
137138
import org.elasticsearch.indices.recovery.PeerRecoveryTargetService;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.indices.cluster;
11+
12+
/**
13+
* The reasons why an index or shard is being removed from a node.
14+
*/
15+
public enum IndexRemovalReason {
16+
/**
17+
* Shard of this index were previously assigned to this node but all shards have been relocated.
18+
* The index should be removed and all associated resources released. Persistent parts of the index
19+
* like the shards files, state and transaction logs are kept around in the case of a disaster recovery.
20+
*/
21+
NO_LONGER_ASSIGNED,
22+
23+
/**
24+
* The index is deleted. Persistent parts of the index like the shards files, state and transaction logs are removed once
25+
* all resources are released.
26+
*/
27+
DELETED,
28+
29+
/**
30+
* The index has been closed. The index should be removed and all associated resources released. Persistent parts of the index
31+
* like the shards files, state and transaction logs are kept around in the case of a disaster recovery.
32+
*/
33+
CLOSED,
34+
35+
/**
36+
* Something around index management has failed and the index should be removed.
37+
* Persistent parts of the index like the shards files, state and transaction logs are kept around in the
38+
* case of a disaster recovery.
39+
*/
40+
FAILURE,
41+
42+
/**
43+
* The index has been reopened. The index should be removed and all associated resources released. Persistent parts of the index
44+
* like the shards files, state and transaction logs are kept around in the case of a disaster recovery.
45+
*/
46+
REOPENED,
47+
48+
/**
49+
* The index is closed as part of the node shutdown process. The index should be removed and all associated resources released.
50+
* Persistent parts of the index like the shards files, state and transaction logs should be kept around in the case the node
51+
* restarts.
52+
*/
53+
SHUTDOWN,
54+
}

server/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@
9797
import java.util.function.Consumer;
9898

9999
import static org.elasticsearch.core.Strings.format;
100-
import static org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason.CLOSED;
101-
import static org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason.DELETED;
102-
import static org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason.FAILURE;
103-
import static org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason.NO_LONGER_ASSIGNED;
104-
import static org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason.REOPENED;
100+
import static org.elasticsearch.indices.cluster.IndexRemovalReason.CLOSED;
101+
import static org.elasticsearch.indices.cluster.IndexRemovalReason.DELETED;
102+
import static org.elasticsearch.indices.cluster.IndexRemovalReason.FAILURE;
103+
import static org.elasticsearch.indices.cluster.IndexRemovalReason.NO_LONGER_ASSIGNED;
104+
import static org.elasticsearch.indices.cluster.IndexRemovalReason.REOPENED;
105105

106106
public class IndicesClusterStateService extends AbstractLifecycleComponent implements ClusterStateApplier {
107107
private static final Logger logger = LogManager.getLogger(IndicesClusterStateService.class);
@@ -480,7 +480,7 @@ private void removeIndicesAndShards(final ClusterChangedEvent event) {
480480
final IndexMetadata indexMetadata = project.map(proj -> proj.index(index)).orElse(null);
481481
final IndexMetadata existingMetadata = indexService.getIndexSettings().getIndexMetadata();
482482

483-
AllocatedIndices.IndexRemovalReason reason = null;
483+
IndexRemovalReason reason = null;
484484
if (indexMetadata != null && indexMetadata.getState() != existingMetadata.getState()) {
485485
reason = indexMetadata.getState() == IndexMetadata.State.CLOSE ? CLOSED : REOPENED;
486486
} else if (localRoutingNode == null || localRoutingNode.hasIndex(index) == false) {
@@ -1335,47 +1335,6 @@ default T getShardOrNull(ShardId shardId) {
13351335

13361336
void processPendingDeletes(Index index, IndexSettings indexSettings, TimeValue timeValue) throws IOException, InterruptedException,
13371337
ShardLockObtainFailedException;
1338-
1339-
enum IndexRemovalReason {
1340-
/**
1341-
* Shard of this index were previously assigned to this node but all shards have been relocated.
1342-
* The index should be removed and all associated resources released. Persistent parts of the index
1343-
* like the shards files, state and transaction logs are kept around in the case of a disaster recovery.
1344-
*/
1345-
NO_LONGER_ASSIGNED,
1346-
1347-
/**
1348-
* The index is deleted. Persistent parts of the index like the shards files, state and transaction logs are removed once
1349-
* all resources are released.
1350-
*/
1351-
DELETED,
1352-
1353-
/**
1354-
* The index has been closed. The index should be removed and all associated resources released. Persistent parts of the index
1355-
* like the shards files, state and transaction logs are kept around in the case of a disaster recovery.
1356-
*/
1357-
CLOSED,
1358-
1359-
/**
1360-
* Something around index management has failed and the index should be removed.
1361-
* Persistent parts of the index like the shards files, state and transaction logs are kept around in the
1362-
* case of a disaster recovery.
1363-
*/
1364-
FAILURE,
1365-
1366-
/**
1367-
* The index has been reopened. The index should be removed and all associated resources released. Persistent parts of the index
1368-
* like the shards files, state and transaction logs are kept around in the case of a disaster recovery.
1369-
*/
1370-
REOPENED,
1371-
1372-
/**
1373-
* The index is closed as part of the node shutdown process. The index should be removed and all associated resources released.
1374-
* Persistent parts of the index like the shards files, state and transaction logs should be kept around in the case the node
1375-
* restarts.
1376-
*/
1377-
SHUTDOWN,
1378-
}
13791338
}
13801339

13811340
static class ShardCloseExecutor implements Executor {

server/src/main/java/org/elasticsearch/indices/store/CompositeIndexFoldersDeletionListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.elasticsearch.index.Index;
1313
import org.elasticsearch.index.IndexSettings;
1414
import org.elasticsearch.index.shard.ShardId;
15-
import org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason;
15+
import org.elasticsearch.indices.cluster.IndexRemovalReason;
1616
import org.elasticsearch.plugins.IndexStorePlugin;
1717

1818
import java.nio.file.Path;

0 commit comments

Comments
 (0)