Explorar el Código

ZOOKEEPER-200. the magic number for snapshot and log must be different

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@706686 13f79535-47bb-0310-9956-ffa450edef68
Patrick D. Hunt hace 16 años
padre
commit
4a1154ac08

+ 3 - 0
CHANGES.txt

@@ -35,6 +35,9 @@ Backward compatibile changes:
 
 
   BUGFIXES: 
   BUGFIXES: 
 
 
+  ZOOKEEPER-200. the magic number for snapshot and log must be different
+  (currently same) (phunt)
+
   ZOOKEEPER-199. fix log messages in persistence code (mahadev via phunt)
   ZOOKEEPER-199. fix log messages in persistence code (mahadev via phunt)
 
 
   ZOOKEEPER-197. create checksums for snapshots (mahadev via phunt)
   ZOOKEEPER-197. create checksums for snapshots (mahadev via phunt)

+ 9 - 8
src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java

@@ -51,11 +51,12 @@ public class FileSnap implements SnapShot {
     private static final int VERSION=2;
     private static final int VERSION=2;
     private static final long dbId=-1;
     private static final long dbId=-1;
     private static final Logger LOG = Logger.getLogger(FileSnap.class);
     private static final Logger LOG = Logger.getLogger(FileSnap.class);
-    public final static int MAGIC = ByteBuffer.wrap("AK47".getBytes()).getInt();
+    public final static int SNAP_MAGIC
+        = ByteBuffer.wrap("ZKSN".getBytes()).getInt();
     public FileSnap(File snapDir) {
     public FileSnap(File snapDir) {
         this.snapDir = snapDir;
         this.snapDir = snapDir;
     }
     }
-    
+
     /**
     /**
      * deserialize a data tree from the most recent snapshot
      * deserialize a data tree from the most recent snapshot
      * @return the zxid of the snapshot
      * @return the zxid of the snapshot
@@ -81,7 +82,7 @@ public class FileSnap implements SnapShot {
         dt.lastProcessedZxid = Util.getZxidFromName(snap.getName(), "snapshot");
         dt.lastProcessedZxid = Util.getZxidFromName(snap.getName(), "snapshot");
         return dt.lastProcessedZxid;
         return dt.lastProcessedZxid;
     }
     }
-    
+
     /**
     /**
      * deserialize the datatree from an inputarchive
      * deserialize the datatree from an inputarchive
      * @param dt the datatree to be serialized into
      * @param dt the datatree to be serialized into
@@ -95,7 +96,7 @@ public class FileSnap implements SnapShot {
         header.deserialize(ia, "fileheader");
         header.deserialize(ia, "fileheader");
         SerializeUtils.deserializeSnapshot(dt,ia,sessions);
         SerializeUtils.deserializeSnapshot(dt,ia,sessions);
     }
     }
-    
+
     /**
     /**
      * find the most recent snapshot in the database.
      * find the most recent snapshot in the database.
      * @return the file containing the most recent snapshot
      * @return the file containing the most recent snapshot
@@ -119,7 +120,7 @@ public class FileSnap implements SnapShot {
      */
      */
     protected void serialize(DataTree dt,Map<Long, Integer> sessions,
     protected void serialize(DataTree dt,Map<Long, Integer> sessions,
             OutputArchive oa, FileHeader header) throws IOException {
             OutputArchive oa, FileHeader header) throws IOException {
-        // this is really a programmatic error and not something that can 
+        // this is really a programmatic error and not something that can
         // happen at runtime
         // happen at runtime
         if(header==null)
         if(header==null)
             throw new IllegalStateException(
             throw new IllegalStateException(
@@ -127,7 +128,7 @@ public class FileSnap implements SnapShot {
         header.serialize(oa, "fileheader");
         header.serialize(oa, "fileheader");
         SerializeUtils.serializeSnapshot(dt,oa,sessions);
         SerializeUtils.serializeSnapshot(dt,oa,sessions);
     }
     }
-    
+
     /**
     /**
      * serialize the datatree and session into the file snapshot
      * serialize the datatree and session into the file snapshot
      * @param dt the datatree to be serialized
      * @param dt the datatree to be serialized
@@ -140,7 +141,7 @@ public class FileSnap implements SnapShot {
         CheckedOutputStream crcOut = new CheckedOutputStream(sessOS, new Adler32());
         CheckedOutputStream crcOut = new CheckedOutputStream(sessOS, new Adler32());
         //CheckedOutputStream cout = new CheckedOutputStream()
         //CheckedOutputStream cout = new CheckedOutputStream()
         OutputArchive oa = BinaryOutputArchive.getArchive(crcOut);
         OutputArchive oa = BinaryOutputArchive.getArchive(crcOut);
-        FileHeader header = new FileHeader(MAGIC, VERSION, dbId);
+        FileHeader header = new FileHeader(SNAP_MAGIC, VERSION, dbId);
         serialize(dt,sessions,oa, header);
         serialize(dt,sessions,oa, header);
         long val = crcOut.getChecksum().getValue();
         long val = crcOut.getChecksum().getValue();
         oa.writeLong(val, "val");
         oa.writeLong(val, "val");
@@ -149,5 +150,5 @@ public class FileSnap implements SnapShot {
         crcOut.close();
         crcOut.close();
         sessOS.close();
         sessOS.close();
     }
     }
-   
+
  }
  }

+ 3 - 2
src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java

@@ -53,7 +53,8 @@ public class FileTxnLog implements TxnLog {
     volatile OutputArchive oa;
     volatile OutputArchive oa;
     
     
     File logDir;
     File logDir;
-    public final static int MAGIC = ByteBuffer.wrap("AK47".getBytes()).getInt();
+    public final static int TXNLOG_MAGIC =
+        ByteBuffer.wrap("ZKLG".getBytes()).getInt();
     public final static int VERSION = 2;
     public final static int VERSION = 2;
     private boolean forceSync = true;
     private boolean forceSync = true;
     long dbId;
     long dbId;
@@ -127,7 +128,7 @@ public class FileTxnLog implements TxnLog {
                        Long.toHexString(hdr.getZxid())));
                        Long.toHexString(hdr.getZxid())));
                logStream=new FileOutputStream(logFileWrite);
                logStream=new FileOutputStream(logFileWrite);
                oa = BinaryOutputArchive.getArchive(logStream);
                oa = BinaryOutputArchive.getArchive(logStream);
-               FileHeader fhdr = new FileHeader(MAGIC,VERSION, dbId);
+               FileHeader fhdr = new FileHeader(TXNLOG_MAGIC,VERSION, dbId);
                fhdr.serialize(oa, "fileheader");
                fhdr.serialize(oa, "fileheader");
                currentSize = logStream.getChannel().position();
                currentSize = logStream.getChannel().position();
                streamsToFlush.add(logStream);
                streamsToFlush.add(logStream);