Adds block to list of blocks which will be invalidated on
specified datanode and log the move

@param b block
@param n datanode
506305
void addToInvalidates(Block b, DatanodeInfo n, boolean ackRequired) {
    addToInvalidatesNoLog(b, n, ackRequired);
    if (isInitialized && !isInSafeModeInternal()) {
      // do not log in startup phase
      NameNode.stateChangeLog.info("BLOCK* NameSystem.addToInvalidates: "
        + b.getBlockName() + " is added to invalidSet of " + n.getName());
    }
  }
48780
public void addNode(Node n)
  {

    if (!m_mutable)
      throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_NOT_MUTABLE, null)); //"This NodeSet is not mutable!");

    this.addElement(n);
  }
1113279
public BlocksWithLocations getBlocks(DatanodeInfo datanode, long size)
  throws IOException {
    if(size <= 0) {
      throw new IllegalArgumentException(
        "Unexpected not positive size: "+size);
    }

    return namesystem.getBlocks(datanode, size);
  }
727911
public void invalidate(int namespaceId, Block invalidBlks[]) throws IOException {
    boolean error = false;
    for (int i = 0; i < invalidBlks.length; i++) {
      File f = null;
      FSVolume v;
      boolean inlineChecksum;
      DatanodeBlockInfo dinfo = null;
      lock.writeLock().lock();
      try {
        dinfo = volumeMap.get(namespaceId, invalidBlks[i]);
        if (dinfo == null) {
          // It is possible that after block reports, Datanodes receive
          // duplicate invalidate requests from name-node. We just skip
          // the block. In the end of the function, we don't throw an exception,
          // since no need for a disk check.
          //
          DataNode.LOG.info("Unexpected error trying to delete block "
                           + invalidBlks[i] + 
                           ". BlockInfo not found in volumeMap.");
          continue;
        }
        inlineChecksum = dinfo.isInlineChecksum();
        f = dinfo.getDataFileToRead();
        v = dinfo.getBlockDataFile().getVolume();
        if (f == null) {
          DataNode.LOG.warn("Unexpected error trying to delete block "
                            + invalidBlks[i] + 
                            ". Block not found in blockMap." +
                            ((v == null) ? " " : " Block found in volumeMap."));
          error = true;
          continue;
        }
        if (v == null) {
          DataNode.LOG.warn("Unexpected error trying to delete block "
                            + invalidBlks[i] + 
                            ". No volume for this block." +
                            " Block found in blockMap. " + f + ".");
          error = true;
          continue;
        }
        File parent = f.getParentFile();
        if (parent == null) {
          DataNode.LOG.warn("Unexpected error trying to delete block "
                            + invalidBlks[i] + 
                            ". Parent not found for file " + f + ".");
          error = true;
          continue;
        }
        //TODO ???
        v.clearPath(namespaceId, parent);
        volumeMap.remove(namespaceId, invalidBlks[i]);
      } finally {
        lock.writeLock().unlock();
      }
      
      // close the File Channel
      dinfo.getBlockDataFile().closeFileChannel();

      //rename the files to be deleted
      //for safety we add prefix instead of suffix,
      //so the valid block files still start with "blk_"
      File blockFileRenamed = new File(f.getParent()
		  + File.separator + DELETE_FILE_EXT + f.getName());
      
      File metaFile = null;
      File metaFileRenamed = null;

      if (!inlineChecksum) {
        metaFile = BlockWithChecksumFileWriter.getMetaFile( f, invalidBlks[i]);
        metaFileRenamed = new File(metaFile.getParent()
		  + File.separator + DELETE_FILE_EXT + metaFile.getName());
      }

      if((!f.renameTo(blockFileRenamed)) ||
          (!inlineChecksum && !metaFile.renameTo(metaFileRenamed))) {
        DataNode.LOG.warn("Unexpected error trying to delete block "
            + invalidBlks[i] +
            ". Cannot rename files for deletion.");
        error = true;
        continue;
      }

      if(invalidBlks[i].getNumBytes() != BlockFlags.NO_ACK){
        datanode.notifyNamenodeDeletedBlock(namespaceId, invalidBlks[i]);
      }
      // Delete the block asynchronously to make sure we can do it fast enough
      asyncDiskService.deleteAsync(v, blockFileRenamed, metaFileRenamed,
		  invalidBlks[i].toString(), namespaceId);
    }
    if (error) {
      throw new IOException("Error in deleting blocks.");
    }
  }
437271
public void removeNode(N node)
    {
        Pair<HashSet<N>, HashSet<N>> p = nodes.remove(node);
        if(p == null)
            return;
        //Outgoing edges we can ignore removint he node drops them. We need to avoid dangling incoming edges to this node we have removed
        HashSet<N> incomingNodes = p.getIncoming();
        for(N incomingNode : incomingNodes)
            nodes.get(incomingNode).getOutgoing().remove(node);
    }
734414
@Override
  public void write (final int b)
  {
    final int nNewCount = m_nCount + 1;
    if (nNewCount > m_aBuf.length)
      m_aBuf = _enlarge (m_aBuf, Math.max (m_aBuf.length << 1, nNewCount));
    m_aBuf[m_nCount] = (byte) b;
    m_nCount = nNewCount;
  }
1358357
Block addBlock(String path, INode[] inodes, Block block) throws IOException {
    waitForReady();

    writeLock();
    try {
      INodeFile fileNode = (INodeFile) inodes[inodes.length-1];
      INode.enforceRegularStorageINode(fileNode, 
          "addBlock only works for regular file, not " + path);
      
      // check quota limits and updated space consumed
      updateCount(inodes, inodes.length-1, 0,
          fileNode.getPreferredBlockSize()*fileNode.getReplication(), true);

      // associate the new list of blocks with this file
      BlockInfo blockInfo = 
          getFSNamesystem().blocksMap.addINode(block, fileNode,
              fileNode.getReplication());
      fileNode.getStorage().addBlock(blockInfo);

      if (NameNode.stateChangeLog.isDebugEnabled()) {
        NameNode.stateChangeLog.debug("DIR* FSDirectory.addFile: "
                                      + path + " with " + block
                                      + " block is added to the in-memory "
                                      + "file system");
      }
    } finally {
      writeUnlock();
    }
    return block;
  }
1175834
public void blockManagement() {
        Vector dwgObjectsWithoutBlocks = new Vector();
        boolean addingToBlock = false;
        for( int i = 0; i < dwgObjects.size(); i++ ) {
            try {
                DwgObject entity = (DwgObject) dwgObjects.get(i);
                if (entity instanceof DwgArc && !addingToBlock) {
                    dwgObjectsWithoutBlocks.add(entity);
                } else if (entity instanceof DwgEllipse && !addingToBlock) {
                    dwgObjectsWithoutBlocks.add(entity);
                } else if (entity instanceof DwgCircle && !addingToBlock) {
                    dwgObjectsWithoutBlocks.add(entity);
                } else if (entity instanceof DwgPolyline2D && !addingToBlock) {
                    dwgObjectsWithoutBlocks.add(entity);
                } else if (entity instanceof DwgPolyline3D && !addingToBlock) {
                    dwgObjectsWithoutBlocks.add(entity);
                } else if (entity instanceof DwgLwPolyline && !addingToBlock) {
                    dwgObjectsWithoutBlocks.add(entity);
                } else if (entity instanceof DwgSolid && !addingToBlock) {
                    dwgObjectsWithoutBlocks.add(entity);
                } else if (entity instanceof DwgLine && !addingToBlock) {
                    dwgObjectsWithoutBlocks.add(entity);
                } else if (entity instanceof DwgPoint && !addingToBlock) {
                    dwgObjectsWithoutBlocks.add(entity);
                } else if (entity instanceof DwgMText && !addingToBlock) {
                    dwgObjectsWithoutBlocks.add(entity);
                } else if (entity instanceof DwgText && !addingToBlock) {
                    dwgObjectsWithoutBlocks.add(entity);
                } else if (entity instanceof DwgAttrib && !addingToBlock) {
                    dwgObjectsWithoutBlocks.add(entity);
                } else if (entity instanceof DwgAttdef && !addingToBlock) {
                    dwgObjectsWithoutBlocks.add(entity);
                } else if (entity instanceof DwgBlock) {
                    addingToBlock = true;
                } else if (entity instanceof DwgEndblk) {
                    addingToBlock = false;
                } else if (entity instanceof DwgBlockHeader) {
                    addingToBlock = true;
                } else if (entity instanceof DwgInsert && !addingToBlock) {
                    /* double[] p = ((DwgInsert) entity).getInsertionPoint();
                     Point2D point = new Point2D.Double(p[0], p[1]);
                     double[] scale = ((DwgInsert) entity).getScale();
                     double rot = ((DwgInsert) entity).getRotation();
                     int blockHandle = ((DwgInsert) entity).getBlockHeaderHandle();
                     manageInsert(point, scale, rot, blockHandle, i,
                     dwgObjectsWithoutBlocks);*/
                } else {
                    // System.out.println("Detectado dwgObject pendiente de implementar");
                }
            } catch (StackOverflowError e) {
                e.printStackTrace();
                System.out.println("Overflowerror at object: " + i);
            }
        }
        dwgObjects = dwgObjectsWithoutBlocks;
    }
131980
private void addBlock(List<GenericCriteria> list, byte[] block, TestOperator operator)
   {
      GenericCriteria result = new GenericCriteria(m_properties);
      result.setOperator(operator);
      list.add(result);
      processBlock(result.getCriteriaList(), getChildBlock(block));
      processBlock(list, getListNextBlock(block));
   }
1213160
public void addBlock(Block block)
    {
        try {
            this.stack.getFirst().add(block);
        } catch (NoSuchElementException e) {
            throw new IllegalStateException("All container blocks are closed, too many calls to endBlockList().");
        }
    }
879296
boolean removeBlock(BlockInfo b) {
    blockList = b.listRemove(blockList, this);
    if ( b.removeNode(this) ) {
      numOfBlocks--;
      return true;
    } else {
      return false;
    }
  }
609048
@Override
	protected void writeDataBlock(byte[] data, int offset, int len, int blockHandle) throws DataStoreException
    {
    	try
        {
	        dataRandomAccessFile.seek((long)blockHandle*blockSize);
	        dataRandomAccessFile.write(data,offset,len);
        }
    	catch (IOException e)
    	{
    		throw new DataStoreException("Cannot write data block "+blockHandle+" : "+dataFile.getAbsolutePath(),e);
    	}
    }
847996
def add_basic_block(self, basic_block):
        """"""
        assert(isinstance(basic_block, BasicBlock))
        self.basic_block_list.append(basic_block)
439511
private void invalidateBlock(Block blk, DatanodeInfo dn, boolean ackRequired)
    throws IOException {
    NameNode.stateChangeLog.info("DIR* NameSystem.invalidateBlock: "
      + blk + " on "
      + dn.getName());
    DatanodeDescriptor node = getDatanode(dn);
    if (node == null) {
      throw new IOException("Cannot invalidate block " + blk +
        " because datanode " + dn.getName() +
        " does not exist.");
    }

    // Check how many copies we have of the block.  If we have at least one
    // copy on a live node, then we can delete it.
    int count = countNodes(blk).liveReplicas();
    if (count > 1) {
      // delete with ACK
      addToInvalidates(blk, dn, ackRequired);
      removeStoredBlock(blk, node);
      if (NameNode.stateChangeLog.isDebugEnabled()) {
        NameNode.stateChangeLog.debug("BLOCK* NameSystem.invalidateBlocks: "
          + blk + " on "
          + dn.getName() + " listed for deletion.");
      }
    } else {
      NameNode.stateChangeLog.info("BLOCK* NameSystem.invalidateBlocks: "
        + blk + " on "
        + dn.getName() + " is the only copy and was not deleted.");
    }
  }
403050
int numNodes(Block b) {
    BlockInfo info = blocks.get(b);
    return info == null ? 0 : info.numNodes();
  }
234217
boolean addNode(Block b, DatanodeDescriptor node, int replication) {
    // insert into the map if not there yet
    BlockInfo info = checkBlockInfo(b, replication);
    // add block to the data-node list and the node to the block info
    return node.addBlock(info);
  }
858271
void write(BlockId blk, IoBuffer buffer) {
		try {
			IoChannel fileChannel = getFileChannel(blk.fileName());

			// rewind the buffer
			buffer.rewind();

			// write the block to the file
			fileChannel.write(buffer, blk.number() * BLOCK_SIZE);
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException("cannot write block" + blk);
		}
	}