Ejemplo n.º 1
0
 /// <exception cref="System.Exception"/>
 public override long GetAndIncrementEpoch()
 {
     lock (this)
     {
         Path       epochNodePath = GetNodePath(rootDirPath, EpochNode);
         long       currentEpoch  = 0;
         FileStatus status        = GetFileStatusWithRetries(epochNodePath);
         if (status != null)
         {
             // load current epoch
             byte[] data  = ReadFileWithRetries(epochNodePath, status.GetLen());
             Epoch  epoch = new EpochPBImpl(YarnServerResourceManagerRecoveryProtos.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);
     }
 }
Ejemplo n.º 2
0
 /// <exception cref="System.Exception"/>
 public override long GetAndIncrementEpoch()
 {
     lock (this)
     {
         long   currentEpoch = 0;
         byte[] dbKeyBytes   = JniDBFactory.Bytes(EpochNode);
         try
         {
             byte[] data = db.Get(dbKeyBytes);
             if (data != null)
             {
                 currentEpoch = YarnServerResourceManagerRecoveryProtos.EpochProto.ParseFrom(data)
                                .GetEpoch();
             }
             YarnServerResourceManagerRecoveryProtos.EpochProto proto = Epoch.NewInstance(currentEpoch
                                                                                          + 1).GetProto();
             db.Put(dbKeyBytes, proto.ToByteArray());
         }
         catch (DBException e)
         {
             throw new IOException(e);
         }
         return(currentEpoch);
     }
 }