Skip to content

Commit d82a775

Browse files
committed
executing shard recovery in project context
1 parent 74fd66c commit d82a775

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import org.elasticsearch.core.AbstractRefCounted;
7676
import org.elasticsearch.core.CheckedConsumer;
7777
import org.elasticsearch.core.CheckedFunction;
78+
import org.elasticsearch.core.CheckedRunnable;
7879
import org.elasticsearch.core.IOUtils;
7980
import org.elasticsearch.core.Nullable;
8081
import org.elasticsearch.core.Releasable;
@@ -950,6 +951,7 @@ public synchronized void verifyIndexMetadata(IndexMetadata metadata, IndexMetada
950951

951952
@Override
952953
public void createShard(
954+
final ProjectId projectId,
953955
final ShardRouting shardRouting,
954956
final PeerRecoveryTargetService recoveryTargetService,
955957
final PeerRecoveryTargetService.RecoveryListener recoveryListener,
@@ -968,7 +970,7 @@ public void createShard(
968970
RecoveryState recoveryState = indexService.createRecoveryState(shardRouting, targetNode, sourceNode);
969971
IndexShard indexShard = indexService.createShard(shardRouting, globalCheckpointSyncer, retentionLeaseSyncer);
970972
indexShard.addShardFailureCallback(onShardFailure);
971-
indexShard.startRecovery(
973+
final CheckedRunnable<RuntimeException> recoveryRunnable = () -> indexShard.startRecovery(
972974
recoveryState,
973975
recoveryTargetService,
974976
postRecoveryMerger.maybeMergeAfterRecovery(indexService.getMetadata(), shardRouting, recoveryListener),
@@ -989,6 +991,7 @@ public void createShard(
989991
this,
990992
clusterStateVersion
991993
);
994+
projectResolver.executeOnProject(projectId, recoveryRunnable);
992995
}
993996

994997
@Override

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.elasticsearch.cluster.ClusterStateApplier;
2727
import org.elasticsearch.cluster.action.shard.ShardStateAction;
2828
import org.elasticsearch.cluster.metadata.IndexMetadata;
29+
import org.elasticsearch.cluster.metadata.ProjectId;
2930
import org.elasticsearch.cluster.metadata.ProjectMetadata;
3031
import org.elasticsearch.cluster.node.DiscoveryNode;
3132
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -781,6 +782,7 @@ private void createShardWhenLockAvailable(
781782
try {
782783
logger.debug("{} creating shard with primary term [{}], iteration [{}]", shardRouting.shardId(), primaryTerm, iteration);
783784
indicesService.createShard(
785+
originalState.metadata().projectFor(shardRouting.index()).id(),
784786
shardRouting,
785787
recoveryTargetService,
786788
new RecoveryListener(shardRouting, primaryTerm),
@@ -1330,6 +1332,7 @@ void removeIndex(
13301332
/**
13311333
* Creates a shard for the specified shard routing and starts recovery.
13321334
*
1335+
* @param projectId the project for the shard
13331336
* @param shardRouting the shard routing
13341337
* @param recoveryTargetService recovery service for the target
13351338
* @param recoveryListener a callback when recovery changes state (finishes or fails)
@@ -1343,6 +1346,7 @@ void removeIndex(
13431346
* @throws IOException if an I/O exception occurs when creating the shard
13441347
*/
13451348
void createShard(
1349+
ProjectId projectId,
13461350
ShardRouting shardRouting,
13471351
PeerRecoveryTargetService recoveryTargetService,
13481352
PeerRecoveryTargetService.RecoveryListener recoveryListener,

test/framework/src/main/java/org/elasticsearch/indices/cluster/AbstractIndicesClusterStateServiceTestCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.action.ActionListener;
1313
import org.elasticsearch.cluster.ClusterState;
1414
import org.elasticsearch.cluster.metadata.IndexMetadata;
15+
import org.elasticsearch.cluster.metadata.ProjectId;
1516
import org.elasticsearch.cluster.metadata.ProjectMetadata;
1617
import org.elasticsearch.cluster.node.DiscoveryNode;
1718
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
@@ -242,6 +243,7 @@ public MockIndexService indexService(Index index) {
242243

243244
@Override
244245
public void createShard(
246+
final ProjectId projectId,
245247
final ShardRouting shardRouting,
246248
final PeerRecoveryTargetService recoveryTargetService,
247249
final PeerRecoveryTargetService.RecoveryListener recoveryListener,

0 commit comments

Comments
 (0)