You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2019/09/17 14:11:11 UTC

[GitHub] [hbase] ZhaoBQ commented on a change in pull request #633: HBASE-22890 Verify the file integrity in persistent IOEngine

ZhaoBQ commented on a change in pull request #633: HBASE-22890 Verify the file integrity in persistent IOEngine
URL: https://github.com/apache/hbase/pull/633#discussion_r325190250
 
 

 ##########
 File path: hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java
 ##########
 @@ -1021,41 +1033,52 @@ void doDrain(final List<RAMQueueEntry> entries) throws InterruptedException {
 
   private void persistToFile() throws IOException {
     assert !cacheEnabled;
-    FileOutputStream fos = null;
-    ObjectOutputStream oos = null;
-    try {
+    try (ObjectOutputStream oos = new ObjectOutputStream(
+      new FileOutputStream(persistencePath, false))){
       if (!ioEngine.isPersistent()) {
         throw new IOException("Attempt to persist non-persistent cache mappings!");
       }
-      fos = new FileOutputStream(persistencePath, false);
-      oos = new ObjectOutputStream(fos);
+      oos.write(ProtobufUtil.PB_MAGIC);
+      byte[] checksum = ((PersistentIOEngine) ioEngine).calculateChecksum();
+      oos.writeInt(checksum.length);
+      oos.write(checksum);
       oos.writeLong(cacheCapacity);
       oos.writeUTF(ioEngine.getClass().getName());
       oos.writeUTF(backingMap.getClass().getName());
       oos.writeObject(deserialiserMap);
       oos.writeObject(backingMap);
-    } finally {
-      if (oos != null) oos.close();
-      if (fos != null) fos.close();
+    } catch (NoSuchAlgorithmException e) {
+      LOG.error("No such algorithm : " + algorithm + "! Failed to persist data on exit",e);
     }
   }
 
   @SuppressWarnings("unchecked")
-  private void retrieveFromFile(int[] bucketSizes) throws IOException, BucketAllocatorException,
+  private void retrieveFromFile(int[] bucketSizes) throws IOException,
       ClassNotFoundException {
     File persistenceFile = new File(persistencePath);
     if (!persistenceFile.exists()) {
       return;
     }
     assert !cacheEnabled;
-    FileInputStream fis = null;
     ObjectInputStream ois = null;
     try {
       if (!ioEngine.isPersistent())
         throw new IOException(
             "Attempt to restore non-persistent cache mappings!");
-      fis = new FileInputStream(persistencePath);
-      ois = new ObjectInputStream(fis);
+      ois = new ObjectInputStream(new FileInputStream(persistencePath));
+      // there are two situations that can cause verification to fail
+      if (!((FileIOEngine) ioEngine).verifyFileIntegrity(persistencePath, ois)) {
 
 Review comment:
   My fault, it's should be PersistentIOEngine.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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