sijie commented on a change in pull request #275: BOOKKEEPER-1102: Fix
BookKeeeperDiskSpaceWeightedLedgerPlacementTest
URL: https://github.com/apache/bookkeeper/pull/275#discussion_r128890595
##########
File path:
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookieInfoReader.java
##########
@@ -80,121 +78,278 @@ public String toString() {
}
}
+
+ /**
+ * Tracks the most recently reported set of bookies from BookieWatcher as
well
+ * as current BookieInfo for bookies we've successfully queried.
+ */
+ private static class BookieInfoMap {
+ /**
+ * Contains the most recently obtained information on the contained
bookies.
+ * When an error happens querying a bookie, the entry is removed.
+ */
+ private final Map<BookieSocketAddress, BookieInfo> infoMap = new
HashMap<>();
+
+ /**
+ * Contains the most recently reported set of bookies from
BookieWatcher
+ * A partial query consists of every member of
mostRecentlyReportedBookies
+ * minus the entries in bookieInfoMap.
+ */
+ private Collection<BookieSocketAddress> mostRecentlyReportedBookies =
new ArrayList<>();
+
+ public void updateBookies(Collection<BookieSocketAddress>
updatedBookieSet) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(
+ "updateBookies: current: {}, new: {}",
+ mostRecentlyReportedBookies, updatedBookieSet);
+ }
+ infoMap.keySet().retainAll(updatedBookieSet);
+ mostRecentlyReportedBookies = updatedBookieSet;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Collection<BookieSocketAddress> getPartialScanTargets() {
+ return CollectionUtils.subtract(mostRecentlyReportedBookies,
infoMap.keySet());
+ }
+
+ public Collection<BookieSocketAddress> getFullScanTargets() {
+ return mostRecentlyReportedBookies;
+ }
+
+ /**
+ * Returns info for bookie, null if not known
+ *
+ * @param bookie bookie for which to get info
+ * @return Info for bookie, null otherwise
+ */
+ public BookieInfo getInfo(BookieSocketAddress bookie) {
+ return infoMap.get(bookie);
+ }
+
+ /**
+ * Removes bookie from bookieInfoMap
+ *
+ * @param bookie bookie on which we observed an error
+ */
+ public void clearInfo(BookieSocketAddress bookie) {
+ infoMap.remove(bookie);
+ }
+
+ /**
+ * Report new info on bookie
+ *
+ * @param bookie bookie for which we obtained new info
+ * @param info the new info
+ */
+ public void gotInfo(BookieSocketAddress bookie, BookieInfo info) {
+ infoMap.put(bookie, info);
+ }
+
+ /**
+ * Get bookie info map
+ */
+ public Map<BookieSocketAddress, BookieInfo> getBookieMap() {
+ return infoMap;
+ }
+ }
+ private final BookieInfoMap bookieInfoMap = new BookieInfoMap();
+
+ /**
+ * Tracks whether there is an execution in progress as well as whether
+ * another is pending.
+ */
+ static final int UNQUEUED = 0;
Review comment:
is there any reason not using an Enum?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services