|
19 | 19 |
|
20 | 20 | package org.apache.hadoop.hbase.replication.regionserver; |
21 | 21 |
|
| 22 | +import com.google.common.collect.Sets; |
22 | 23 | import com.google.common.util.concurrent.ThreadFactoryBuilder; |
23 | 24 |
|
24 | 25 | import java.io.IOException; |
25 | 26 | import java.util.ArrayList; |
26 | 27 | import java.util.Collections; |
27 | 28 | import java.util.HashMap; |
28 | | -import java.util.HashSet; |
29 | | -import java.util.Iterator; |
30 | 29 | import java.util.List; |
31 | 30 | import java.util.Map; |
32 | 31 | import java.util.Random; |
@@ -108,7 +107,7 @@ public class ReplicationSourceManager implements ReplicationListener { |
108 | 107 | private final Configuration conf; |
109 | 108 | private final FileSystem fs; |
110 | 109 | // The paths to the latest log of each wal group, for new coming peers |
111 | | - private Set<Path> latestPaths; |
| 110 | + private final Map<String, Path> latestPaths; |
112 | 111 | // Path to the wals directories |
113 | 112 | private final Path logDir; |
114 | 113 | // Path to the wal archive |
@@ -171,7 +170,7 @@ public ReplicationSourceManager(final ReplicationQueues replicationQueues, |
171 | 170 | tfb.setDaemon(true); |
172 | 171 | this.executor.setThreadFactory(tfb.build()); |
173 | 172 | this.rand = new Random(); |
174 | | - this.latestPaths = Collections.synchronizedSet(new HashSet<Path>()); |
| 173 | + this.latestPaths = new HashMap<>(); |
175 | 174 | replicationForBulkLoadDataEnabled = |
176 | 175 | conf.getBoolean(HConstants.REPLICATION_BULKLOAD_ENABLE_KEY, |
177 | 176 | HConstants.REPLICATION_BULKLOAD_ENABLE_DEFAULT); |
@@ -305,23 +304,22 @@ protected ReplicationSourceInterface addSource(String id) throws IOException, |
305 | 304 | this.walsById.put(id, walsByGroup); |
306 | 305 | // Add the latest wal to that source's queue |
307 | 306 | synchronized (latestPaths) { |
308 | | - if (this.latestPaths.size() > 0) { |
309 | | - for (Path logPath : latestPaths) { |
310 | | - String name = logPath.getName(); |
311 | | - String walPrefix = DefaultWALProvider.getWALPrefixFromWALName(name); |
312 | | - SortedSet<String> logs = new TreeSet<String>(); |
313 | | - logs.add(name); |
314 | | - walsByGroup.put(walPrefix, logs); |
| 307 | + if (!latestPaths.isEmpty()) { |
| 308 | + for (Map.Entry<String, Path> walPrefixAndPath : latestPaths.entrySet()) { |
| 309 | + Path walPath = walPrefixAndPath.getValue(); |
| 310 | + SortedSet<String> wals = new TreeSet<>(); |
| 311 | + wals.add(walPath.getName()); |
| 312 | + walsByGroup.put(walPrefixAndPath.getKey(), wals); |
315 | 313 | try { |
316 | | - this.replicationQueues.addLog(id, name); |
| 314 | + this.replicationQueues.addLog(id, walPath.getName()); |
317 | 315 | } catch (ReplicationException e) { |
318 | 316 | String message = |
319 | 317 | "Cannot add log to queue when creating a new source, queueId=" + id |
320 | | - + ", filename=" + name; |
| 318 | + + ", filename=" + walPath.getName(); |
321 | 319 | server.stop(message); |
322 | 320 | throw e; |
323 | 321 | } |
324 | | - src.enqueueLog(logPath); |
| 322 | + src.enqueueLog(walPath); |
325 | 323 | } |
326 | 324 | } |
327 | 325 | } |
@@ -409,15 +407,7 @@ void preLogRoll(Path newLog) throws IOException { |
409 | 407 | String logName = newLog.getName(); |
410 | 408 | String logPrefix = DefaultWALProvider.getWALPrefixFromWALName(logName); |
411 | 409 | synchronized (latestPaths) { |
412 | | - Iterator<Path> iterator = latestPaths.iterator(); |
413 | | - while (iterator.hasNext()) { |
414 | | - Path path = iterator.next(); |
415 | | - if (path.getName().contains(logPrefix)) { |
416 | | - iterator.remove(); |
417 | | - break; |
418 | | - } |
419 | | - } |
420 | | - this.latestPaths.add(newLog); |
| 410 | + latestPaths.put(logPrefix, newLog); |
421 | 411 | } |
422 | 412 | } |
423 | 413 |
|
@@ -693,6 +683,12 @@ public void peerListChanged(List<String> peerIds) { |
693 | 683 | } |
694 | 684 | } |
695 | 685 |
|
| 686 | + Set<Path> getLastestPath() { |
| 687 | + synchronized (latestPaths) { |
| 688 | + return Sets.newHashSet(latestPaths.values()); |
| 689 | + } |
| 690 | + } |
| 691 | + |
696 | 692 | /** |
697 | 693 | * Class responsible to setup new ReplicationSources to take care of the |
698 | 694 | * queues from dead region servers. |
|
0 commit comments