private static EventQueueBackingStore upgrade(
     File checkpointFile,
     int capacity,
     String name,
     File backupCheckpointDir,
     boolean shouldBackup,
     boolean compressBackup)
     throws Exception {
   LOG.info("Attempting upgrade of " + checkpointFile + " for " + name);
   EventQueueBackingStoreFileV2 backingStoreV2 =
       new EventQueueBackingStoreFileV2(checkpointFile, capacity, name);
   String backupName = checkpointFile.getName() + "-backup-" + System.currentTimeMillis();
   Files.copy(checkpointFile, new File(checkpointFile.getParentFile(), backupName));
   File metaDataFile = Serialization.getMetaDataFile(checkpointFile);
   EventQueueBackingStoreFileV3.upgrade(backingStoreV2, checkpointFile, metaDataFile);
   return new EventQueueBackingStoreFileV3(
       checkpointFile, capacity, name, backupCheckpointDir, shouldBackup, compressBackup);
 }
 static EventQueueBackingStore get(
     File checkpointFile,
     File backupCheckpointDir,
     int capacity,
     String name,
     boolean upgrade,
     boolean shouldBackup,
     boolean compressBackup)
     throws Exception {
   File metaDataFile = Serialization.getMetaDataFile(checkpointFile);
   RandomAccessFile checkpointFileHandle = null;
   try {
     boolean checkpointExists = checkpointFile.exists();
     boolean metaDataExists = metaDataFile.exists();
     if (metaDataExists) {
       // if we have a metadata file but no checkpoint file, we have a problem
       // delete everything in the checkpoint directory and force
       // a full replay.
       if (!checkpointExists || checkpointFile.length() == 0) {
         LOG.warn(
             "MetaData file for checkpoint "
                 + " exists but checkpoint does not. Checkpoint = "
                 + checkpointFile
                 + ", metaDataFile = "
                 + metaDataFile);
         throw new BadCheckpointException(
             "The last checkpoint was not completed correctly, "
                 + "since Checkpoint file does not exist while metadata "
                 + "file does.");
       }
     }
     // brand new, use v3
     if (!checkpointExists) {
       if (!checkpointFile.createNewFile()) {
         throw new IOException("Cannot create " + checkpointFile);
       }
       return new EventQueueBackingStoreFileV3(
           checkpointFile, capacity, name, backupCheckpointDir, shouldBackup, compressBackup);
     }
     // v3 due to meta file, version will be checked by backing store
     if (metaDataExists) {
       return new EventQueueBackingStoreFileV3(
           checkpointFile, capacity, name, backupCheckpointDir, shouldBackup, compressBackup);
     }
     checkpointFileHandle = new RandomAccessFile(checkpointFile, "r");
     int version = (int) checkpointFileHandle.readLong();
     if (Serialization.VERSION_2 == version) {
       if (upgrade) {
         return upgrade(
             checkpointFile, capacity, name, backupCheckpointDir, shouldBackup, compressBackup);
       }
       return new EventQueueBackingStoreFileV2(checkpointFile, capacity, name);
     }
     LOG.error("Found version " + Integer.toHexString(version) + " in " + checkpointFile);
     throw new BadCheckpointException(
         "Checkpoint file exists with "
             + Serialization.VERSION_3
             + " but no metadata file found.");
   } finally {
     if (checkpointFileHandle != null) {
       try {
         checkpointFileHandle.close();
       } catch (IOException e) {
         LOG.warn("Unable to close " + checkpointFile, e);
       }
     }
   }
 }