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 13:17:43 UTC

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

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

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/LedgerMetadataSerDe.java
 ##########
 @@ -66,59 +76,70 @@
     private final int maxLedgerMetadataFormatVersion;
 
     public LedgerMetadataSerDe(int maxLedgerMetadataFormatVersion) {
+        log.info("SerDe initialized with max version {}", maxLedgerMetadataFormatVersion, new Exception());
         this.maxLedgerMetadataFormatVersion = maxLedgerMetadataFormatVersion;
     }
 
-    public byte[] serialize(LedgerMetadata metadata) {
-        if (metadata.getMetadataFormatVersion() == 1) {
-            return serializeVersion1(metadata);
-        }
-
-        StringBuilder s = new StringBuilder();
-        s.append(VERSION_KEY).append(FIELD_SPLITTER)
-            .append(CURRENT_METADATA_FORMAT_VERSION).append(LINE_SPLITTER);
-        s.append(TextFormat.printToString(buildProtoFormat(metadata)));
-        if (log.isDebugEnabled()) {
-            log.debug("Serialized config: {}", s);
-        }
-        return s.toString().getBytes(UTF_8);
+    private static void writeHeader(OutputStream os, int version) throws IOException {
+        os.write(VERSION_KEY_BYTES);
+        os.write(String.valueOf(version).getBytes(UTF_8));
+        os.write(LINE_SPLITTER_BYTES);
     }
 
-    private byte[] serializeVersion1(LedgerMetadata metadata) {
-        StringBuilder s = new StringBuilder();
-        s.append(VERSION_KEY).append(FIELD_SPLITTER)
-            .append(metadata.getMetadataFormatVersion()).append(LINE_SPLITTER);
-        s.append(metadata.getWriteQuorumSize()).append(LINE_SPLITTER)
-            .append(metadata.getEnsembleSize()).append(LINE_SPLITTER).append(metadata.getLength());
+    private static int readHeader(InputStream is) throws IOException {
+        checkState(LINE_SPLITTER_BYTES.length == 1, "LINE_SPLITTER must be single byte");
 
 Review comment:
   This should be in a static{}  block. 

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