|
26 | 26 | import static org.apache.hadoop.hbase.zookeeper.ZKMetadata.removeMetaData; |
27 | 27 |
|
28 | 28 | import java.io.IOException; |
| 29 | +import java.util.List; |
29 | 30 | import java.util.concurrent.CompletableFuture; |
| 31 | +import java.util.stream.Collectors; |
30 | 32 | import org.apache.commons.lang3.mutable.MutableInt; |
31 | 33 | import org.apache.hadoop.conf.Configuration; |
32 | 34 | import org.apache.hadoop.hbase.ClusterId; |
@@ -134,12 +136,13 @@ private Pair<RegionState.State, ServerName> getStateAndServerName( |
134 | 136 | ServerName.valueOf(snProto.getHostName(), snProto.getPort(), snProto.getStartCode())); |
135 | 137 | } |
136 | 138 |
|
137 | | - @Override |
138 | | - public CompletableFuture<RegionLocations> getMetaRegionLocation() { |
139 | | - CompletableFuture<RegionLocations> future = new CompletableFuture<>(); |
140 | | - HRegionLocation[] locs = new HRegionLocation[znodePaths.metaReplicaZNodes.size()]; |
| 139 | + private void getMetaRegionLocation(CompletableFuture<RegionLocations> future, |
| 140 | + List<String> metaReplicaZNodes) { |
| 141 | + HRegionLocation[] locs = new HRegionLocation[metaReplicaZNodes.size()]; |
141 | 142 | MutableInt remaining = new MutableInt(locs.length); |
142 | | - znodePaths.metaReplicaZNodes.forEach((replicaId, path) -> { |
| 143 | + for (String metaReplicaZNode : metaReplicaZNodes) { |
| 144 | + int replicaId = znodePaths.getMetaReplicaIdFromZnode(metaReplicaZNode); |
| 145 | + String path = ZNodePaths.joinZNode(znodePaths.baseZNode, metaReplicaZNode); |
143 | 146 | if (replicaId == DEFAULT_REPLICA_ID) { |
144 | 147 | addListener(getAndConvert(path, ZKAsyncRegistry::getMetaProto), (proto, error) -> { |
145 | 148 | if (error != null) { |
@@ -186,7 +189,23 @@ public CompletableFuture<RegionLocations> getMetaRegionLocation() { |
186 | 189 | tryComplete(remaining, locs, future); |
187 | 190 | }); |
188 | 191 | } |
189 | | - }); |
| 192 | + } |
| 193 | + } |
| 194 | + |
| 195 | + @Override |
| 196 | + public CompletableFuture<RegionLocations> getMetaRegionLocation() { |
| 197 | + CompletableFuture<RegionLocations> future = new CompletableFuture<>(); |
| 198 | + addListener( |
| 199 | + zk.list(znodePaths.baseZNode) |
| 200 | + .thenApply(children -> children.stream() |
| 201 | + .filter(c -> c.startsWith(znodePaths.metaZNodePrefix)).collect(Collectors.toList())), |
| 202 | + (metaReplicaZNodes, error) -> { |
| 203 | + if (error != null) { |
| 204 | + future.completeExceptionally(error); |
| 205 | + return; |
| 206 | + } |
| 207 | + getMetaRegionLocation(future, metaReplicaZNodes); |
| 208 | + }); |
190 | 209 | return future; |
191 | 210 | } |
192 | 211 |
|
|
0 commit comments