@@ -1510,7 +1510,8 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
1510
1510
1511
1511
private final Set <RepositoryShardId > currentlyCloning = Collections .synchronizedSet (new HashSet <>());
1512
1512
1513
- private void runReadyClone (
1513
+ // Made to package private to be able to test the method in UTs
1514
+ void runReadyClone (
1514
1515
Snapshot target ,
1515
1516
SnapshotId sourceSnapshot ,
1516
1517
ShardSnapshotStatus shardStatusBefore ,
@@ -1534,69 +1535,75 @@ public void onFailure(Exception e) {
1534
1535
@ Override
1535
1536
protected void doRun () {
1536
1537
final String localNodeId = clusterService .localNode ().getId ();
1537
- repository .getRepositoryData (ActionListener .wrap (repositoryData -> {
1538
- try {
1539
- final IndexMetadata indexMetadata = repository .getSnapshotIndexMetaData (
1540
- repositoryData ,
1538
+ if (remoteStoreIndexShallowCopy == false ) {
1539
+ executeClone (localNodeId , false );
1540
+ } else {
1541
+ repository .getRepositoryData (ActionListener .wrap (repositoryData -> {
1542
+ try {
1543
+ final IndexMetadata indexMetadata = repository .getSnapshotIndexMetaData (
1544
+ repositoryData ,
1545
+ sourceSnapshot ,
1546
+ repoShardId .index ()
1547
+ );
1548
+ final boolean cloneRemoteStoreIndexShardSnapshot = indexMetadata .getSettings ()
1549
+ .getAsBoolean (IndexMetadata .SETTING_REMOTE_STORE_ENABLED , false );
1550
+ executeClone (localNodeId , cloneRemoteStoreIndexShardSnapshot );
1551
+ } catch (IOException e ) {
1552
+ logger .warn ("Failed to get index-metadata from repository data for index [{}]" , repoShardId .index ().getName ());
1553
+ failCloneShardAndUpdateClusterState (target , sourceSnapshot , repoShardId );
1554
+ }
1555
+ }, this ::onFailure ));
1556
+ }
1557
+ }
1558
+
1559
+ private void executeClone (String localNodeId , boolean cloneRemoteStoreIndexShardSnapshot ) {
1560
+ if (currentlyCloning .add (repoShardId )) {
1561
+ if (cloneRemoteStoreIndexShardSnapshot ) {
1562
+ repository .cloneRemoteStoreIndexShardSnapshot (
1541
1563
sourceSnapshot ,
1542
- repoShardId .index ()
1564
+ target .getSnapshotId (),
1565
+ repoShardId ,
1566
+ shardStatusBefore .generation (),
1567
+ remoteStoreLockManagerFactory ,
1568
+ getCloneCompletionListener (localNodeId )
1543
1569
);
1544
- final boolean cloneRemoteStoreIndexShardSnapshot = remoteStoreIndexShallowCopy
1545
- && indexMetadata .getSettings ().getAsBoolean (IndexMetadata .SETTING_REMOTE_STORE_ENABLED , false );
1546
- final SnapshotId targetSnapshot = target .getSnapshotId ();
1547
- final ActionListener <String > listener = ActionListener .wrap (
1548
- generation -> innerUpdateSnapshotState (
1549
- new ShardSnapshotUpdate (
1550
- target ,
1551
- repoShardId ,
1552
- new ShardSnapshotStatus (localNodeId , ShardState .SUCCESS , generation )
1553
- ),
1554
- ActionListener .runBefore (
1555
- ActionListener .wrap (
1556
- v -> logger .trace (
1557
- "Marked [{}] as successfully cloned from [{}] to [{}]" ,
1558
- repoShardId ,
1559
- sourceSnapshot ,
1560
- targetSnapshot
1561
- ),
1562
- e -> {
1563
- logger .warn ("Cluster state update after successful shard clone [{}] failed" , repoShardId );
1564
- failAllListenersOnMasterFailOver (e );
1565
- }
1566
- ),
1567
- () -> currentlyCloning .remove (repoShardId )
1568
- )
1569
- ),
1570
- e -> {
1571
- logger .warn ("Exception [{}] while trying to clone shard [{}]" , e , repoShardId );
1572
- failCloneShardAndUpdateClusterState (target , sourceSnapshot , repoShardId );
1573
- }
1570
+ } else {
1571
+ repository .cloneShardSnapshot (
1572
+ sourceSnapshot ,
1573
+ target .getSnapshotId (),
1574
+ repoShardId ,
1575
+ shardStatusBefore .generation (),
1576
+ getCloneCompletionListener (localNodeId )
1574
1577
);
1575
- if (currentlyCloning .add (repoShardId )) {
1576
- if (cloneRemoteStoreIndexShardSnapshot ) {
1577
- repository .cloneRemoteStoreIndexShardSnapshot (
1578
- sourceSnapshot ,
1579
- targetSnapshot ,
1578
+ }
1579
+ }
1580
+ }
1581
+
1582
+ private ActionListener <String > getCloneCompletionListener (String localNodeId ) {
1583
+ return ActionListener .wrap (
1584
+ generation -> innerUpdateSnapshotState (
1585
+ new ShardSnapshotUpdate (target , repoShardId , new ShardSnapshotStatus (localNodeId , ShardState .SUCCESS , generation )),
1586
+ ActionListener .runBefore (
1587
+ ActionListener .wrap (
1588
+ v -> logger .trace (
1589
+ "Marked [{}] as successfully cloned from [{}] to [{}]" ,
1580
1590
repoShardId ,
1581
- shardStatusBefore .generation (),
1582
- remoteStoreLockManagerFactory ,
1583
- listener
1584
- );
1585
- } else {
1586
- repository .cloneShardSnapshot (
1587
1591
sourceSnapshot ,
1588
- targetSnapshot ,
1589
- repoShardId ,
1590
- shardStatusBefore .generation (),
1591
- listener
1592
- );
1593
- }
1594
- }
1595
- } catch (IOException e ) {
1596
- logger .warn ("Failed to get index-metadata from repository data for index [{}]" , repoShardId .index ().getName ());
1592
+ target .getSnapshotId ()
1593
+ ),
1594
+ e -> {
1595
+ logger .warn ("Cluster state update after successful shard clone [{}] failed" , repoShardId );
1596
+ failAllListenersOnMasterFailOver (e );
1597
+ }
1598
+ ),
1599
+ () -> currentlyCloning .remove (repoShardId )
1600
+ )
1601
+ ),
1602
+ e -> {
1603
+ logger .warn ("Exception [{}] while trying to clone shard [{}]" , e , repoShardId );
1597
1604
failCloneShardAndUpdateClusterState (target , sourceSnapshot , repoShardId );
1598
1605
}
1599
- }, this :: onFailure ) );
1606
+ );
1600
1607
}
1601
1608
});
1602
1609
}
0 commit comments