sijie commented on a change in pull request #641: Issue-596 Issue-583: Auto 
replication should honor ensemble placement policy
URL: https://github.com/apache/bookkeeper/pull/641#discussion_r146480883
 
 

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
 ##########
 @@ -810,47 +780,71 @@ public void openComplete(int newrc, final LedgerHandle 
newlh, Object newctx) {
                  */
                 for (final Long startEntryId : ledgerFragmentsToRecover) {
                     Long endEntryId = ledgerFragmentsRange.get(startEntryId);
-                    BookieSocketAddress newBookie = null;
+                    ArrayList<BookieSocketAddress> ensemble = 
lh.getLedgerMetadata().getEnsembles().get(startEntryId);
+                    // Get bookies to replace
+                    Map<Integer, BookieSocketAddress> targetBookieAddresses;
                     try {
-                        newBookie = 
getNewBookie(lh.getLedgerMetadata().getEnsembles().get(startEntryId),
-                                                 availableBookies);
-                    } catch (BKException.BKNotEnoughBookiesException bke) {
-                        
ledgerFragmentsMcb.processResult(BKException.Code.NotEnoughBookiesException,
-                                                         null, null);
+                        targetBookieAddresses = getReplacedBookies(lh, 
ensemble, bookiesSrc);
+                    } catch (BKException.BKNotEnoughBookiesException e) {
+                        if (!dryrun) {
+                            
ledgerFragmentsMcb.processResult(BKException.Code.NotEnoughBookiesException, 
null, null);
+                        } else {
+                            System.out.println("  Fragment [" + startEntryId + 
" - " + endEntryId + " ] : "
+                                               + 
BKException.getMessage(BKException.Code.NotEnoughBookiesException));
+                        }
+                        continue;
+                    }
+
+                    if (dryrun) {
+                        ArrayList<BookieSocketAddress> newEnsemble =
+                                replaceBookiesInEnsemble(ensemble, 
targetBookieAddresses);
+                        System.out.println("  Fragment [" + startEntryId + " - 
" + endEntryId + " ] : ");
+                        System.out.println("    old ensemble : " + 
formatEnsemble(ensemble, bookiesSrc, '*'));
+                        System.out.println("    new ensemble : " + 
formatEnsemble(newEnsemble, bookiesSrc, '*'));
                         continue;
                     }
 
                     if (LOG.isDebugEnabled()) {
                         LOG.debug("Replicating fragment from [" + startEntryId
                                   + "," + endEntryId + "] of ledger " + 
lh.getId()
-                                  + " to " + newBookie);
+                                  + " to " + targetBookieAddresses);
                     }
                     try {
                         LedgerFragmentReplicator.SingleFragmentCallback cb = 
new LedgerFragmentReplicator.SingleFragmentCallback(
-                                                                               
ledgerFragmentsMcb, lh, startEntryId, bookieSrc, newBookie);
-                        ArrayList<BookieSocketAddress> currentEnsemble = 
lh.getLedgerMetadata().getEnsemble(
-                                startEntryId);
-                        int bookieIndex = -1;
-                        if (null != currentEnsemble) {
-                            for (int i = 0; i < currentEnsemble.size(); i++) {
-                                if (currentEnsemble.get(i).equals(bookieSrc)) {
-                                    bookieIndex = i;
-                                    break;
-                                }
-                            }
-                        }
+                                ledgerFragmentsMcb, lh, startEntryId, 
getReplacedBookiesMap(ensemble, targetBookieAddresses));
                         LedgerFragment ledgerFragment = new LedgerFragment(lh,
-                                startEntryId, endEntryId, bookieIndex);
-                        asyncRecoverLedgerFragment(lh, ledgerFragment, cb, 
newBookie);
+                                startEntryId, endEntryId, 
targetBookieAddresses.keySet());
+                        asyncRecoverLedgerFragment(lh, ledgerFragment, cb, 
Sets.newHashSet(targetBookieAddresses.values()));
 
 Review comment:
   sure, will move the else contents into a method.

----------------------------------------------------------------
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

Reply via email to