@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;
 }
Exemplo n.º 2
0
 @Override
 public synchronized long getAndIncrementEpoch() throws Exception {
   long currentEpoch = 0;
   byte[] dbKeyBytes = bytes(EPOCH_NODE);
   try {
     byte[] data = db.get(dbKeyBytes);
     if (data != null) {
       currentEpoch = EpochProto.parseFrom(data).getEpoch();
     }
     EpochProto proto = Epoch.newInstance(currentEpoch + 1).getProto();
     db.put(dbKeyBytes, proto.toByteArray());
   } catch (DBException e) {
     throw new IOException(e);
   }
   return currentEpoch;
 }