Beispiel #1
0
 DatanodeDescriptor getDatanode(int index) {
   assert this.triplets != null : "BlockInfo is not initialized";
   assert index >= 0 && index * 3 < triplets.length : "Index is out of bound";
   DatanodeDescriptor node = (DatanodeDescriptor) triplets[index * 3];
   assert node == null || DatanodeDescriptor.class.getName().equals(node.getClass().getName())
       : "DatanodeDescriptor is expected at " + index * 3;
   return node;
 }
Beispiel #2
0
 /**
  * Remove the block from the block map; remove it from all data-node lists it belongs to; and
  * remove all data-node locations associated with the block.
  */
 void removeBlock(BlockInfo blockInfo) {
   if (blockInfo == null) return;
   blockInfo.inode = null;
   for (int idx = blockInfo.numNodes() - 1; idx >= 0; idx--) {
     DatanodeDescriptor dn = blockInfo.getDatanode(idx);
     dn.removeBlock(blockInfo); // remove from the list and wipe the location
   }
   map.remove(blockInfo); // remove block from the map
   System.out.println("BLOCKSMAP removes block : " + blockInfo);
 }
Beispiel #3
0
  /**
   * Remove data-node reference from the block. Remove the block from the block map only if it does
   * not belong to any file and data-nodes.
   */
  boolean removeNode(Block b, DatanodeDescriptor node) {
    BlockInfo info = map.get(b);
    if (info == null) return false;

    // remove block from the data-node list and the node from the block info
    boolean removed = node.removeBlock(info);

    if (info.getDatanode(0) == null // no datanodes left
        && info.inode == null) { // does not belong to a file
      map.remove(b); // remove block from the map
      System.out.println("BLOCKSMAP removes block : " + b);
    }
    return removed;
  }
Beispiel #4
0
 /**
  * returns true if the node does not already exists and is added. false if the node already
  * exists.
  */
 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);
 }
Beispiel #5
0
    /** @return index of free triplet */
    private int ensureSpace(DatanodeDescriptor newNode) {

      assert this.triplets != null : "BlockInfo is not initialized";
      int index = 0;

      int last = numNodes();

      DatanodeDescriptor node = (DatanodeDescriptor) triplets[index * 3];

      // System.out.println("ensureSpace 1");
      while (node != null && node.compareTo(newNode) < 0 && index < (triplets.length / 3) - 1) {
        index++;
        node = (DatanodeDescriptor) triplets[index * 3];
      }
      // System.out.println("ensureSpace 2");
      if (node == null) {
        return index;
      } else {
        assert node.compareTo(newNode) != 0;
      }
      // System.out.println("ensureSpace 3");

      // --------
      int j = 1;
      if (triplets.length >= (last + 1) * 3) {
        j += last + 1 * 4;
        for (int i = last * 3 + 2; i >= (index + 1) * 3; i--) {
          triplets[i] = triplets[i - 3];
        }
        // System.out.println("ensureSpace 4");

        // System.out.println("ensureSpace 5");
      } else {
        j += 24 * last;
        // System.out.println("ensureSpace 6");
        // Not enough space. create a larger array
        Object[] old = triplets;
        triplets = new Object[3 * (last + 1)];
        // copy datanode that precedes the new node
        for (int i = 0; i < index * 3; i++) {
          triplets[i] = old[i];
        }
        // System.out.println("ensureSpace 7");
        for (int i = index * 3; i < old.length; i++) {
          j = j - 2;
          triplets[i + 3] = old[i];
        }
        // System.out.println("ensureSpace 8");

      }
      triplets[index * 3] = null;
      triplets[index * 3 + 1] = null;
      triplets[index * 3 + 2] = null;

      // --------
      /*
      if((triplets.length/3) > last ){
      	// we already have enough space
      	for(int i=last; i>index; i--){
      		triplets[3*i] = triplets[3*(i-1)];
      		triplets[3*i +1] = triplets[3*(i-1) +1];
      		triplets[3*i +2] = triplets[3*(i-1) +2];
      	}
      	triplets[index*3] = null;
      	triplets[index*3+1] = null;
      	triplets[index*3+2] = null;
      } else {
      	// Not enough space. create a larger array
      	Object[] old = triplets;
      	triplets = new Object[3*(last+1)];
      	// copy datanode that precedes the new node
      	for(int i=0; i < index*3; i++){
      		triplets[i] = old[i];
      	}
      	for(int i=index*3; i < old.length; i++){
      		triplets[i+3] = old[i];
      	}
      }
      */
      // System.out.println("ensureSpace 9");
      return index;
    }