1919import org .elasticsearch .cluster .block .ClusterBlockException ;
2020import org .elasticsearch .cluster .block .ClusterBlocks ;
2121import org .elasticsearch .cluster .metadata .IndexMetadata ;
22- import org .elasticsearch .cluster .metadata .Metadata ;
22+ import org .elasticsearch .cluster .metadata .ProjectId ;
23+ import org .elasticsearch .cluster .metadata .ProjectMetadata ;
2324import org .elasticsearch .cluster .node .DiscoveryNode ;
2425import org .elasticsearch .cluster .node .DiscoveryNodeUtils ;
2526import org .elasticsearch .cluster .routing .IndexShardRoutingTable ;
3233import org .elasticsearch .core .TimeValue ;
3334import org .elasticsearch .index .Index ;
3435import org .elasticsearch .index .IndexService ;
36+ import org .elasticsearch .index .IndexVersion ;
3537import org .elasticsearch .index .shard .ShardId ;
3638import org .elasticsearch .indices .IndicesService ;
3739import org .elasticsearch .tasks .Task ;
@@ -161,11 +163,7 @@ protected void unpromotableShardOperation(
161163
162164 var withRefreshBlock = randomBoolean ();
163165 if (withRefreshBlock ) {
164- setState (
165- clusterService ,
166- ClusterState .builder (clusterService .state ())
167- .blocks (ClusterBlocks .builder ().addIndexBlock (shardId .getIndexName (), IndexMetadata .INDEX_REFRESH_BLOCK ))
168- );
166+ setState (clusterService , clusterStateWithRefreshBlock (clusterService .state (), shardId , ProjectId .DEFAULT ));
169167 }
170168
171169 final var future = new PlainActionFuture <ActionResponse .Empty >();
@@ -196,7 +194,8 @@ protected void unpromotableShardOperation(
196194 ClusterState .builder (clusterService .state ())
197195 .blocks (
198196 ClusterBlocks .builder ()
199- .removeIndexBlock (Metadata .DEFAULT_PROJECT_ID , shardId .getIndexName (), IndexMetadata .INDEX_REFRESH_BLOCK )
197+ .blocks (clusterService .state ().blocks ())
198+ .removeIndexBlock (ProjectId .DEFAULT , shardId .getIndexName (), IndexMetadata .INDEX_REFRESH_BLOCK )
200199 )
201200 );
202201 }
@@ -231,11 +230,7 @@ protected void unpromotableShardOperation(
231230 }
232231 };
233232
234- setState (
235- clusterService ,
236- ClusterState .builder (clusterService .state ())
237- .blocks (ClusterBlocks .builder ().addIndexBlock (shardId .getIndexName (), IndexMetadata .INDEX_REFRESH_BLOCK ))
238- );
233+ setState (clusterService , clusterStateWithRefreshBlock (clusterService .state (), shardId , ProjectId .DEFAULT ));
239234
240235 final var countDownLatch = new CountDownLatch (1 );
241236 final var request = new UnpromotableShardRefreshRequest (
@@ -262,6 +257,18 @@ protected void unpromotableShardOperation(
262257 safeAwait (countDownLatch );
263258 }
264259
260+ private ClusterState clusterStateWithRefreshBlock (ClusterState base , ShardId shardId , ProjectId projectId ) {
261+ IndexMetadata indexMetadata = IndexMetadata .builder (shardId .getIndexName ())
262+ .settings (indexSettings (IndexVersion .current (), shardId .getIndex ().getUUID (), 1 , 0 ).build ())
263+ .build ();
264+ return ClusterState .builder (base )
265+ .putProjectMetadata (ProjectMetadata .builder (projectId ).put (indexMetadata , false ))
266+ .blocks (
267+ ClusterBlocks .builder (base .blocks ()).addIndexBlock (projectId , shardId .getIndexName (), IndexMetadata .INDEX_REFRESH_BLOCK )
268+ )
269+ .build ();
270+ }
271+
265272 private IndexShardRoutingTable createShardRoutingTableWithPrimaryAndSearchShards (ShardId shardId , boolean withSearchShards ) {
266273 final var shardRouting = TestShardRouting .newShardRouting (
267274 shardId ,
0 commit comments