Examples of BlockCommand


Examples of org.apache.hadoop.hdfs.server.protocol.BlockCommand

     * @throws IOException
     */
  private boolean processCommand(DatanodeCommand cmd) throws IOException {
    if (cmd == null)
      return true;
    final BlockCommand bcmd = cmd instanceof BlockCommand? (BlockCommand)cmd: null;

    switch(cmd.getAction()) {
    case DatanodeProtocol.DNA_TRANSFER:
      // Send a copy of a block to another datanode
      transferBlocks(bcmd.getBlocks(), bcmd.getTargets());
      myMetrics.blocksReplicated.inc(bcmd.getBlocks().length);
      break;
    case DatanodeProtocol.DNA_INVALIDATE:
      //
      // Some local block(s) are obsolete and can be
      // safely garbage-collected.
      //
      Block toDelete[] = bcmd.getBlocks();
      try {
        if (blockScanner != null) {
          blockScanner.deleteBlocks(toDelete);
        }
        data.invalidate(toDelete);
      } catch(IOException e) {
        checkDiskError();
        throw e;
      }
      myMetrics.blocksRemoved.inc(toDelete.length);
      break;
    case DatanodeProtocol.DNA_SHUTDOWN:
      // shut down the data node
      this.shutdown();
      return false;
    case DatanodeProtocol.DNA_REGISTER:
      // namenode requested a registration - at start or if NN lost contact
      LOG.info("DatanodeCommand action: DNA_REGISTER");
      register();
      break;
    case DatanodeProtocol.DNA_FINALIZE:
      storage.finalizeUpgrade();
      break;
    case UpgradeCommand.UC_ACTION_START_UPGRADE:
      // start distributed upgrade here
      processDistributedUpgradeCommand((UpgradeCommand)cmd);
      break;
    case DatanodeProtocol.DNA_RECOVERBLOCK:
      recoverBlocks(bcmd.getBlocks(), bcmd.getTargets());
      break;
    default:
      LOG.warn("Unknown DatanodeCommand action: " + cmd.getAction());
    }
    return true;
View Full Code Here

Examples of org.apache.hadoop.hdfs.server.protocol.BlockCommand

    }

    if (currentAvatar == Avatar.STANDBY) {
      Collection<Block> failed = super.blockReportWithRetries(nodeReg, rep);

      BlockCommand bCmd = new BlockCommand(DatanodeProtocols.DNA_RETRY,
          failed.toArray(new Block[failed.size()]));
      return bCmd;
    } else {
      return super.blockReport(nodeReg, rep);
    }
View Full Code Here

Examples of org.apache.hadoop.hdfs.server.protocol.BlockCommand

   * @throws IOException
   */
  private boolean processCommand(DatanodeCommand cmd) throws IOException, InterruptedException {
    if (cmd == null)
      return true;
    final BlockCommand bcmd = cmd instanceof BlockCommand? (BlockCommand)cmd: null;

    boolean retValue = true;
    long startTime = System.currentTimeMillis();

    switch(cmd.getAction()) {
    case DatanodeProtocol.DNA_TRANSFER:
      // Send a copy of a block to another datanode
      anode.transferBlocks(servicePair.namespaceId, bcmd.getBlocks(), bcmd.getTargets());
      myMetrics.blocksReplicated.inc(bcmd.getBlocks().length);
      break;
    case DatanodeProtocol.DNA_INVALIDATE:
      //
      // Some local block(s) are obsolete and can be
      // safely garbage-collected.
      //
      Block toDelete[] = bcmd.getBlocks();
      try {
        if (anode.blockScanner != null) {
          //TODO temporary
          anode.blockScanner.deleteBlocks(servicePair.namespaceId, toDelete);
        }
        servicePair.removeReceivedBlocks(toDelete);
        data.invalidate(servicePair.namespaceId, toDelete);
      } catch(IOException e) {
        anode.checkDiskError();
        throw e;
      }
      myMetrics.blocksRemoved.inc(toDelete.length);
      break;
    case DatanodeProtocol.DNA_SHUTDOWN:
      // shut down the data node
      servicePair.shutdown();
      retValue = false;
      break;
    case DatanodeProtocol.DNA_REGISTER:
      // namenode requested a registration - at start or if NN lost contact
      LOG.info("AvatarDatanodeCommand action: DNA_REGISTER");
      if (shouldRun()) {
        servicePair.register(namenode, namenodeAddress);
        firstBlockReportSent = false;
        scheduleBlockReport(0);
      }
      break;
    case DatanodeProtocol.DNA_FINALIZE:
      anode.getStorage().finalizedUpgrade(servicePair.namespaceId);
      break;
    case UpgradeCommand.UC_ACTION_START_UPGRADE:
      // start distributed upgrade here
      servicePair.processUpgradeCommand((UpgradeCommand)cmd);
      break;
    case DatanodeProtocol.DNA_RECOVERBLOCK:
      anode.recoverBlocks(servicePair.namespaceId, bcmd.getBlocks(), bcmd.getTargets());
      break;
    case DatanodeProtocols.DNA_BACKOFF:
      // We can get a BACKOFF request as a response to a full block report.
      setBackoff(true);
      break;
    case DatanodeProtocols.DNA_CLEARPRIMARY:
      LOG.info("CLEAR PRIMARY requested by : " + this.avatarnodeAddress);
      retValue = clearPrimary();
      break;
    case DatanodeProtocols.DNA_RETRY:
      // We will get a RETRY request as a response to only a full block report.
      LOG.info(this.avatarnodeAddress + " has requested the retry of : "
          + bcmd.getBlocks().length + " blocks in response to a full block"
          + " report");
      // Retry the blocks that failed on the Standby.
      processFailedBlocks(bcmd.getBlocks(), bcmd.getBlocks().length);
      break;
    default:
      LOG.warn("Unknown DatanodeCommand action: " + cmd.getAction());
    }

View Full Code Here

Examples of org.apache.hadoop.hdfs.server.protocol.BlockCommand

  }
 
  BlockCommand getReplicationCommand(int maxTransfers) {
    List<BlockTargetPair> blocktargetlist = replicateBlocks.poll(maxTransfers);
    return blocktargetlist == null? null:
        new BlockCommand(DatanodeProtocol.DNA_TRANSFER, blocktargetlist);
  }
View Full Code Here

Examples of org.apache.hadoop.hdfs.server.protocol.BlockCommand

  }

  BlockCommand getLeaseRecoveryCommand(int maxTransfers) {
    List<BlockTargetPair> blocktargetlist = recoverBlocks.poll(maxTransfers);
    return blocktargetlist == null? null:
        new BlockCommand(DatanodeProtocol.DNA_RECOVERBLOCK, blocktargetlist);
  }
View Full Code Here

Examples of org.apache.hadoop.hdfs.server.protocol.BlockCommand

    synchronized (invalidateBlocks) {
      deleteList = invalidateBlocks.pollToArray(new Block[Math.min(
          invalidateBlocks.size(), maxblocks)]);
    }
    return (deleteList == null || deleteList.length == 0) ?
        null: new BlockCommand(DatanodeProtocol.DNA_INVALIDATE, deleteList);
  }
View Full Code Here

Examples of org.apache.hadoop.hdfs.server.protocol.BlockCommand

          rep, 0L, 0L, 0, 0, 0).getCommands();
      if (cmds != null) {
        for (DatanodeCommand cmd : cmds) {
          if (cmd.getAction() == DatanodeProtocol.DNA_TRANSFER) {
            // Send a copy of a block to another datanode
            BlockCommand bcmd = (BlockCommand)cmd;
            return transferBlocks(bcmd.getBlocks(), bcmd.getTargets(),
                                  bcmd.getTargetStorageIDs());
          }
        }
      }
      return 0;
    }
View Full Code Here

Examples of org.apache.hadoop.hdfs.server.protocol.BlockCommand

      action = DatanodeProtocol.DNA_SHUTDOWN;
      break;
    default:
      throw new AssertionError("Unknown action type: " + blkCmd.getAction());
    }
    return new BlockCommand(action, blkCmd.getBlockPoolId(), blocks, targets,
        targetStorageIDs);
  }
View Full Code Here

Examples of org.apache.hadoop.hdfs.server.protocol.BlockCommand

        final List<DatanodeCommand> cmds = new ArrayList<DatanodeCommand>();
        //check pending replication
        List<BlockTargetPair> pendingList = nodeinfo.getReplicationCommand(
              maxTransfers);
        if (pendingList != null) {
          cmds.add(new BlockCommand(DatanodeProtocol.DNA_TRANSFER, blockPoolId,
              pendingList));
        }
        //check block invalidation
        Block[] blks = nodeinfo.getInvalidateBlocks(blockInvalidateLimit);
        if (blks != null) {
          cmds.add(new BlockCommand(DatanodeProtocol.DNA_INVALIDATE,
              blockPoolId, blks));
        }
       
        blockManager.addKeyUpdateCommand(cmds, nodeinfo);
View Full Code Here

Examples of org.apache.hadoop.hdfs.server.protocol.BlockCommand

  public void testIgnoreDeletionsFromNonActive() throws Exception {
    BPOfferService bpos = setupBPOSForNNs(mockNN1, mockNN2);

    // Ask to invalidate FAKE_BLOCK when block report hits the
    // standby
    Mockito.doReturn(new BlockCommand(DatanodeProtocol.DNA_INVALIDATE,
        FAKE_BPID, new Block[] { FAKE_BLOCK.getLocalBlock() }))
        .when(mockNN2).blockReport(
            Mockito.<DatanodeRegistration>anyObject()
            Mockito.eq(FAKE_BPID),
            Mockito.<StorageBlockReport[]>anyObject());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.