@Override
 public synchronized long getAndIncrementEpoch() throws Exception {
   Path epochNodePath = getNodePath(rootDirPath, EPOCH_NODE);
   long currentEpoch = 0;
   FileStatus status = getFileStatusWithRetries(epochNodePath);
   if (status != null) {
     // load current epoch
     byte[] data = readFileWithRetries(epochNodePath, status.getLen());
     Epoch epoch = new EpochPBImpl(EpochProto.parseFrom(data));
     currentEpoch = epoch.getEpoch();
     // increment epoch and store it
     byte[] storeData = Epoch.newInstance(currentEpoch + 1).getProto().toByteArray();
     updateFile(epochNodePath, storeData, false);
   } else {
     // initialize epoch file with 1 for the next time.
     byte[] storeData = Epoch.newInstance(currentEpoch + 1).getProto().toByteArray();
     writeFileWithRetries(epochNodePath, storeData, false);
   }
   return currentEpoch;
 }