/** Store block recovery work. */
 void addBlockToBeRecovered(BlockInfoUnderConstruction block) {
   if (recoverBlocks.contains(block)) {
     // this prevents adding the same block twice to the recovery queue
     BlockManager.LOG.info(block + " is already in the recovery queue");
     return;
   }
   recoverBlocks.offer(block);
 }
 @Override
 public void onDisable() {
   log.info("Shutting down blockqueue and undothread, please wait.");
   bq.shouldrun = false;
   while (bq.isAlive()) {
     // wait
   }
   ut.shouldRun = false;
   while (ut.isAlive()) {
     // wait
   }
   log.info("WorldThreadit Disabled.");
 }
示例#3
0
  @Test
  public void remove() {
    Thread t1 =
        new Thread(
            new Runnable() {

              @Override
              public void run() {
                try {
                  Thread.sleep(2000);
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }

                int i = 5;
                while (i > 0) {
                  bq.add(new Object());
                  i--;
                }
              }
            });
    t1.start();

    bq.remove();

    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
 @Override
 public String dumpDatanode() {
   StringBuilder sb = new StringBuilder(super.dumpDatanode());
   int repl = replicateBlocks.size();
   if (repl > 0) {
     sb.append(" ").append(repl).append(" blocks to be replicated;");
   }
   int inval = invalidateBlocks.size();
   if (inval > 0) {
     sb.append(" ").append(inval).append(" blocks to be invalidated;");
   }
   int recover = recoverBlocks.size();
   if (recover > 0) {
     sb.append(" ").append(recover).append(" blocks to be recovered;");
   }
   return sb.toString();
 }
 @Override
 public void onEnable() {
   WorldThreadit.plugin = this;
   log = getLogger();
   getServer().getPluginManager().registerEvents(new WorldThreadit(), this);
   bq = new BlockQueue(this);
   bq.start();
   ut = new UndoThread(this);
   ut.start();
   log.info("WorldThreadit enabled!");
   getCommand("wt").setExecutor(new BaseCommandExecutor(this));
 }
 public BlockInfoUnderConstruction[] getLeaseRecoveryCommand(int maxTransfers) {
   List<BlockInfoUnderConstruction> blocks = recoverBlocks.poll(maxTransfers);
   if (blocks == null) return null;
   return blocks.toArray(new BlockInfoUnderConstruction[blocks.size()]);
 }
 public List<BlockTargetPair> getReplicationCommand(int maxTransfers) {
   return replicateBlocks.poll(maxTransfers);
 }
 /** The number of work items that are pending to be replicated */
 int getNumberOfBlocksToBeReplicated() {
   return PendingReplicationWithoutTargets + replicateBlocks.size();
 }
 /** Store block replication work. */
 void addBlockToBeReplicated(Block block, DatanodeStorageInfo[] targets) {
   assert (block != null && targets != null && targets.length > 0);
   replicateBlocks.offer(new BlockTargetPair(block, targets));
 }