You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2018/08/24 23:45:11 UTC

[GitHub] athanatos commented on a change in pull request #1621: Recovery uses immutable metadata

athanatos commented on a change in pull request #1621: Recovery uses immutable metadata
URL: https://github.com/apache/bookkeeper/pull/1621#discussion_r212777799
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ReadOnlyLedgerHandle.java
 ##########
 @@ -207,4 +206,197 @@ public void readLastConfirmedComplete(int rc, long lastConfirmed, Object ctx) {
             }
         }, ctx);
     }
+
+    List<BookieSocketAddress> replaceBookiesInEnsemble(LedgerMetadata metadata,
+                                                       List<BookieSocketAddress> oldEnsemble,
+                                                       Map<Integer, BookieSocketAddress> failedBookies)
+            throws BKException.BKNotEnoughBookiesException {
+        List<BookieSocketAddress> newEnsemble = new ArrayList<>(oldEnsemble);
+
+        int ensembleSize = metadata.getEnsembleSize();
+        int writeQ = metadata.getWriteQuorumSize();
+        int ackQ = metadata.getAckQuorumSize();
+        Map<String, byte[]> customMetadata = metadata.getCustomMetadata();
+
+        Set<BookieSocketAddress> exclude = new HashSet<>(failedBookies.values());
+
+        int replaced = 0;
+        for (Map.Entry<Integer, BookieSocketAddress> entry : failedBookies.entrySet()) {
+            int idx = entry.getKey();
+            BookieSocketAddress addr = entry.getValue();
+            LOG.debug("[EnsembleChange-L{}] replacing bookie: {} index: {}", getId(), addr, idx);
+
+            if (!newEnsemble.get(idx).equals(addr)) {
+                LOG.debug("[EnsembleChange-L{}] Not changing failed bookie {} at index {}, already changed to {}",
+                          getId(), addr, idx, newEnsemble.get(idx));
+                continue;
+            }
+            try {
+                BookieSocketAddress newBookie = clientCtx.getBookieWatcher().replaceBookie(
+                        ensembleSize, writeQ, ackQ, customMetadata, newEnsemble, idx, exclude);
+                newEnsemble.set(idx, newBookie);
+
+                replaced++;
+            } catch (BKException.BKNotEnoughBookiesException e) {
+                // if there is no bookie replaced, we throw not enough bookie exception
+                if (replaced <= 0) {
+                    throw e;
+                } else {
+                    break;
+                }
+            }
+        }
+        return newEnsemble;
+    }
+
+    private static Set<Integer> diffEnsemble(List<BookieSocketAddress> e1,
+                                             List<BookieSocketAddress> e2) {
+        checkArgument(e1.size() == e2.size(), "Ensembles must be of same size");
+        Set<Integer> diff = new HashSet<>();
+        for (int i = 0; i < e1.size(); i++) {
+            if (!e1.get(i).equals(e2.get(i))) {
+                diff.add(i);
+            }
+        }
+        return diff;
+    }
+
+    /**
+     * For a read only ledger handle, this method will only ever be called during recovery,
+     * when we are reading forward from LAC and writing back those entries. As such,
+     * unlike with LedgerHandle, we do not want to persist changes to the metadata as they occur,
+     * but rather, we want to defer the persistence until recovery has completed, and do it all
+     * on the close.
+     */
+    @Override
+    void handleBookieFailure(final Map<Integer, BookieSocketAddress> failedBookies) {
+        blockAddCompletions.incrementAndGet();
 
 Review comment:
   Do we need to do this on a ReadOnlyLedgerHandle?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services