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/12/07 21:23:12 UTC

[GitHub] sijie commented on a change in pull request #1866: Binary metadata format

sijie commented on a change in pull request #1866: Binary metadata format
URL: https://github.com/apache/bookkeeper/pull/1866#discussion_r239949818
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/LedgerMetadataSerDe.java
 ##########
 @@ -187,55 +301,61 @@ public LedgerMetadataFormat buildProtoFormat(LedgerMetadata metadata) {
      */
     public LedgerMetadata parseConfig(byte[] bytes,
                                       Optional<Long> metadataStoreCtime) throws IOException {
-        String config = new String(bytes, UTF_8);
-
         if (log.isDebugEnabled()) {
-            log.debug("Parsing Config: {}", config);
-        }
-        BufferedReader reader = new BufferedReader(new StringReader(config));
-        String versionLine = reader.readLine();
-        if (versionLine == null) {
-            throw new IOException("Invalid metadata. Content missing");
-        }
-        final int metadataFormatVersion;
-        if (versionLine.startsWith(VERSION_KEY)) {
-            String parts[] = versionLine.split(FIELD_SPLITTER);
-            metadataFormatVersion = Integer.parseInt(parts[1]);
-        } else {
-            // if no version is set, take it to be version 1
-            // as the parsing is the same as what we had before
-            // we introduce versions
-            metadataFormatVersion = 1;
-            // reset the reader
-            reader.close();
-            reader = new BufferedReader(new StringReader(config));
-        }
-
-        if (metadataFormatVersion < LOWEST_COMPAT_METADATA_FORMAT_VERSION
-            || metadataFormatVersion > CURRENT_METADATA_FORMAT_VERSION) {
-            throw new IOException(
-                    String.format("Metadata version not compatible. Expected between %d and %d, but got %d",
-                                  LOWEST_COMPAT_METADATA_FORMAT_VERSION, CURRENT_METADATA_FORMAT_VERSION,
-                                  metadataFormatVersion));
+            log.debug("Deserializing {}", Base64.getEncoder().encodeToString(bytes));
         }
+        try (ByteArrayInputStream is = new ByteArrayInputStream(bytes)) {
+            int metadataFormatVersion = readHeader(is);
+            if (log.isDebugEnabled()) {
+                log.debug("Format version {} detected", metadataFormatVersion);
+            }
 
-        if (metadataFormatVersion == 1) {
-            return parseVersion1Config(reader);
+            switch (metadataFormatVersion) {
+            case 3:
 
 Review comment:
   constants

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