|
14 | 14 | import org.elasticsearch.client.Client;
|
15 | 15 | import org.elasticsearch.cluster.ClusterState;
|
16 | 16 | import org.elasticsearch.cluster.metadata.IndexMetadata;
|
| 17 | +import org.elasticsearch.cluster.metadata.RepositoriesMetadata; |
| 18 | +import org.elasticsearch.cluster.metadata.RepositoryMetadata; |
17 | 19 | import org.elasticsearch.cluster.node.DiscoveryNode;
|
18 | 20 | import org.elasticsearch.cluster.node.DiscoveryNodes;
|
19 | 21 | import org.elasticsearch.cluster.routing.RecoverySource;
|
|
31 | 33 | import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider;
|
32 | 34 | import org.elasticsearch.common.Nullable;
|
33 | 35 | import org.elasticsearch.common.Priority;
|
| 36 | +import org.elasticsearch.common.Strings; |
34 | 37 | import org.elasticsearch.common.collect.Tuple;
|
35 | 38 | import org.elasticsearch.common.settings.Settings;
|
36 | 39 | import org.elasticsearch.common.unit.ByteSizeValue;
|
|
59 | 62 | import java.util.stream.Collectors;
|
60 | 63 | import java.util.stream.StreamSupport;
|
61 | 64 |
|
| 65 | +import static java.util.Collections.emptyList; |
62 | 66 | import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.SNAPSHOT_INDEX_ID_SETTING;
|
63 | 67 | import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.SNAPSHOT_INDEX_NAME_SETTING;
|
64 |
| -import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants.SNAPSHOT_PARTIAL_SETTING; |
65 | 68 | import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.SNAPSHOT_REPOSITORY_NAME_SETTING;
|
| 69 | +import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.SNAPSHOT_REPOSITORY_UUID_SETTING; |
66 | 70 | import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.SNAPSHOT_SNAPSHOT_ID_SETTING;
|
67 | 71 | import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.SNAPSHOT_SNAPSHOT_NAME_SETTING;
|
| 72 | +import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants.SNAPSHOT_PARTIAL_SETTING; |
68 | 73 |
|
69 | 74 | public class SearchableSnapshotAllocator implements ExistingShardsAllocator {
|
70 | 75 |
|
@@ -144,8 +149,28 @@ public void allocateUnassigned(
|
144 | 149 | SNAPSHOT_SNAPSHOT_NAME_SETTING.get(indexSettings),
|
145 | 150 | SNAPSHOT_SNAPSHOT_ID_SETTING.get(indexSettings)
|
146 | 151 | );
|
147 |
| - final String repository = SNAPSHOT_REPOSITORY_NAME_SETTING.get(indexSettings); |
148 |
| - final Snapshot snapshot = new Snapshot(repository, snapshotId); |
| 152 | + |
| 153 | + final String repositoryUuid = SNAPSHOT_REPOSITORY_UUID_SETTING.get(indexSettings); |
| 154 | + final String repositoryName; |
| 155 | + if (Strings.hasLength(repositoryUuid) == false) { |
| 156 | + repositoryName = SNAPSHOT_REPOSITORY_NAME_SETTING.get(indexSettings); |
| 157 | + } else { |
| 158 | + final RepositoriesMetadata repoMetadata = allocation.metadata().custom(RepositoriesMetadata.TYPE); |
| 159 | + final List<RepositoryMetadata> repositories = repoMetadata == null ? emptyList() : repoMetadata.repositories(); |
| 160 | + repositoryName = repositories.stream() |
| 161 | + .filter(r -> repositoryUuid.equals(r.uuid())) |
| 162 | + .map(RepositoryMetadata::name) |
| 163 | + .findFirst() |
| 164 | + .orElse(null); |
| 165 | + } |
| 166 | + |
| 167 | + if (repositoryName == null) { |
| 168 | + // TODO if the repository we seek appears later, we will need to get its UUID (usually automatic) and then reroute |
| 169 | + unassignedAllocationHandler.removeAndIgnore(UnassignedInfo.AllocationStatus.DECIDERS_NO, allocation.changes()); |
| 170 | + return; |
| 171 | + } |
| 172 | + |
| 173 | + final Snapshot snapshot = new Snapshot(repositoryName, snapshotId); |
149 | 174 |
|
150 | 175 | shardRouting = unassignedAllocationHandler.updateUnassigned(
|
151 | 176 | shardRouting.unassignedInfo(),
|
|
0 commit comments