Java Code Examples for org.apache.hadoop.hdfs.server.protocol.NamenodeProtocol#ACT_SHUTDOWN

The following examples show how to use org.apache.hadoop.hdfs.server.protocol.NamenodeProtocol#ACT_SHUTDOWN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FSImage.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Start checkpoint.
 * <p>
 * If backup storage contains image that is newer than or incompatible with 
 * what the active name-node has, then the backup node should shutdown.<br>
 * If the backup image is older than the active one then it should 
 * be discarded and downloaded from the active node.<br>
 * If the images are the same then the backup image will be used as current.
 * 
 * @param bnReg the backup node registration.
 * @param nnReg this (active) name-node registration.
 * @return {@link NamenodeCommand} if backup node should shutdown or
 * {@link CheckpointCommand} prescribing what backup node should 
 *         do with its image.
 * @throws IOException
 */
NamenodeCommand startCheckpoint(NamenodeRegistration bnReg, // backup node
                                NamenodeRegistration nnReg) // active name-node
throws IOException {
  LOG.info("Start checkpoint at txid " + getEditLog().getLastWrittenTxId());
  String msg = null;
  // Verify that checkpoint is allowed
  if(bnReg.getNamespaceID() != storage.getNamespaceID())
    msg = "Name node " + bnReg.getAddress()
          + " has incompatible namespace id: " + bnReg.getNamespaceID()
          + " expected: " + storage.getNamespaceID();
  else if(bnReg.isRole(NamenodeRole.NAMENODE))
    msg = "Name node " + bnReg.getAddress()
          + " role " + bnReg.getRole() + ": checkpoint is not allowed.";
  else if(bnReg.getLayoutVersion() < storage.getLayoutVersion()
      || (bnReg.getLayoutVersion() == storage.getLayoutVersion()
          && bnReg.getCTime() > storage.getCTime()))
    // remote node has newer image age
    msg = "Name node " + bnReg.getAddress()
          + " has newer image layout version: LV = " +bnReg.getLayoutVersion()
          + " cTime = " + bnReg.getCTime()
          + ". Current version: LV = " + storage.getLayoutVersion()
          + " cTime = " + storage.getCTime();
  if(msg != null) {
    LOG.error(msg);
    return new NamenodeCommand(NamenodeProtocol.ACT_SHUTDOWN);
  }
  boolean needToReturnImg = true;
  if(storage.getNumStorageDirs(NameNodeDirType.IMAGE) == 0)
    // do not return image if there are no image directories
    needToReturnImg = false;
  CheckpointSignature sig = rollEditLog();
  return new CheckpointCommand(sig, needToReturnImg);
}
 
Example 2
Source File: FSImage.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Start checkpoint.
 * <p>
 * If backup storage contains image that is newer than or incompatible with 
 * what the active name-node has, then the backup node should shutdown.<br>
 * If the backup image is older than the active one then it should 
 * be discarded and downloaded from the active node.<br>
 * If the images are the same then the backup image will be used as current.
 * 
 * @param bnReg the backup node registration.
 * @param nnReg this (active) name-node registration.
 * @return {@link NamenodeCommand} if backup node should shutdown or
 * {@link CheckpointCommand} prescribing what backup node should 
 *         do with its image.
 * @throws IOException
 */
NamenodeCommand startCheckpoint(NamenodeRegistration bnReg, // backup node
                                NamenodeRegistration nnReg) // active name-node
throws IOException {
  LOG.info("Start checkpoint at txid " + getEditLog().getLastWrittenTxId());
  String msg = null;
  // Verify that checkpoint is allowed
  if(bnReg.getNamespaceID() != storage.getNamespaceID())
    msg = "Name node " + bnReg.getAddress()
          + " has incompatible namespace id: " + bnReg.getNamespaceID()
          + " expected: " + storage.getNamespaceID();
  else if(bnReg.isRole(NamenodeRole.NAMENODE))
    msg = "Name node " + bnReg.getAddress()
          + " role " + bnReg.getRole() + ": checkpoint is not allowed.";
  else if(bnReg.getLayoutVersion() < storage.getLayoutVersion()
      || (bnReg.getLayoutVersion() == storage.getLayoutVersion()
          && bnReg.getCTime() > storage.getCTime()))
    // remote node has newer image age
    msg = "Name node " + bnReg.getAddress()
          + " has newer image layout version: LV = " +bnReg.getLayoutVersion()
          + " cTime = " + bnReg.getCTime()
          + ". Current version: LV = " + storage.getLayoutVersion()
          + " cTime = " + storage.getCTime();
  if(msg != null) {
    LOG.error(msg);
    return new NamenodeCommand(NamenodeProtocol.ACT_SHUTDOWN);
  }
  boolean needToReturnImg = true;
  if(storage.getNumStorageDirs(NameNodeDirType.IMAGE) == 0)
    // do not return image if there are no image directories
    needToReturnImg = false;
  CheckpointSignature sig = rollEditLog();
  return new CheckpointCommand(sig, needToReturnImg);
}