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 2017/12/25 13:16:25 UTC

[GitHub] jiazhai closed pull request #896: ISSUE #895: print entrylog metadata

jiazhai closed pull request #896: ISSUE #895: print entrylog metadata
URL: https://github.com/apache/bookkeeper/pull/896
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
index aacd7a21f..d0a15f3c9 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java
@@ -51,6 +51,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
@@ -135,6 +136,7 @@
     static final String CMD_SIMPLETEST = "simpletest";
     static final String CMD_BOOKIESANITYTEST = "bookiesanity";
     static final String CMD_READLOG = "readlog";
+    static final String CMD_READLOGMETADATA = "readlogmetadata";
     static final String CMD_READJOURNAL = "readjournal";
     static final String CMD_LASTMARK = "lastmark";
     static final String CMD_AUTORECOVERY = "autorecovery";
@@ -1104,6 +1106,63 @@ Options getOptions() {
         }
     }
 
+    /**
+     * Command to print metadata of entrylog.
+     */
+    class ReadLogMetadataCmd extends MyCommand {
+        Options rlOpts = new Options();
+
+        ReadLogMetadataCmd() {
+            super(CMD_READLOGMETADATA);
+        }
+
+        @Override
+        public int runCmd(CommandLine cmdLine) throws Exception {
+            String[] leftArgs = cmdLine.getArgs();
+            if (leftArgs.length <= 0) {
+                LOG.error("ERROR: missing entry log id or entry log file name");
+                printUsage();
+                return -1;
+            }
+
+            long logId;
+            try {
+                logId = Long.parseLong(leftArgs[0]);
+            } catch (NumberFormatException nfe) {
+                // not a entry log id
+                File f = new File(leftArgs[0]);
+                String name = f.getName();
+                if (!name.endsWith(".log")) {
+                    // not a log file
+                    LOG.error("ERROR: invalid entry log file name " + leftArgs[0]);
+                    printUsage();
+                    return -1;
+                }
+                String idString = name.split("\\.")[0];
+                logId = Long.parseLong(idString, 16);
+            }
+
+            printEntryLogMetadata(logId);
+
+            return 0;
+        }
+
+        @Override
+        String getDescription() {
+            return "Prints entrylog's metadata";
+        }
+
+        @Override
+        String getUsage() {
+            return "readlogmetadata <entry_log_id | entry_log_file_name>";
+        }
+
+        @Override
+        Options getOptions() {
+            return rlOpts;
+        }
+    }
+
     /**
      * Command to read journal files.
      */
@@ -2364,6 +2423,7 @@ int runCmd(CommandLine cmdLine) throws Exception {
         commands.put(CMD_SIMPLETEST, new SimpleTestCmd());
         commands.put(CMD_BOOKIESANITYTEST, new BookieSanityTestCmd());
         commands.put(CMD_READLOG, new ReadLogCmd());
+        commands.put(CMD_READLOGMETADATA, new ReadLogMetadataCmd());
         commands.put(CMD_READJOURNAL, new ReadJournalCmd());
         commands.put(CMD_LASTMARK, new LastMarkCmd());
         commands.put(CMD_AUTORECOVERY, new AutoRecoveryCmd());
@@ -2682,6 +2742,16 @@ protected void readLedgerIndexEntries(long ledgerId) throws IOException {
         }
     }
 
+    protected void printEntryLogMetadata(long logId) throws IOException {
+        LOG.info("Print entryLogMetadata of entrylog {} ({}.log)", logId, Long.toHexString(logId));
+        initEntryLogger();
+        EntryLogMetadata entryLogMetadata = entryLogger.getEntryLogMetadata(logId);
+        entryLogMetadata.getLedgersMap().forEach((ledgerId, size) -> {
+            LOG.info("--------- Lid={}, TotalSizeOfEntriesOfLedger={}  ---------",
+                    ledgerIdFormatter.formatLedgerId(ledgerId), size);
+        });
+    }
+
     /**
      * Get an iterable over pages of entries and locations for a ledger.
      *


 

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