@Override boolean removeStorage(DatanodeStorageInfo storage) { int dnIndex = findStorageInfo(storage); if (dnIndex < 0) { // the node is not found return false; } // find the last not null node int lastNode = numNodes()-1; // replace current node entry by the lastNode one setStorageInfo(dnIndex, getStorageInfo(lastNode)); // set the last entry to null setStorageInfo(lastNode, null); return true; }
public BlockInfoContiguous next() { BlockInfoContiguous res = current; current = current.getNext(current.findStorageInfo(DatanodeStorageInfo.this)); return res; }
/** * Remove block from the list of blocks belonging to the data-node. Remove * data-node from the block. */ boolean removeBlock(BlockInfoContiguous b) { final DatanodeStorageInfo s = b.findStorageInfo(this); // if block exists on this datanode if (s != null) { return s.removeBlock(b); } return false; }
/** * Remove block from the list of blocks belonging to the data-node. Remove * data-node from the block. */ boolean removeBlock(BlockInfoContiguous b) { final DatanodeStorageInfo s = b.findStorageInfo(this); // if block exists on this datanode if (s != null) { return s.removeBlock(b); } return false; }
public BlockInfoContiguous next() { BlockInfoContiguous res = current; current = current.getNext(current.findStorageInfo(DatanodeStorageInfo.this)); return res; }
/** * Remove this block from the list of blocks * related to the specified DatanodeStorageInfo. * If this block is the head of the list then return the next block as * the new head. * @return the new head of the list or null if the list becomes * empy after deletion. */ BlockInfoContiguous listRemove(BlockInfoContiguous head, DatanodeStorageInfo storage) { if(head == null) return null; int dnIndex = this.findStorageInfo(storage); if(dnIndex < 0) // this block is not on the data-node list return head; BlockInfoContiguous next = this.getNext(dnIndex); BlockInfoContiguous prev = this.getPrevious(dnIndex); this.setNext(dnIndex, null); this.setPrevious(dnIndex, null); if(prev != null) prev.setNext(prev.findStorageInfo(storage), next); if(next != null) next.setPrevious(next.findStorageInfo(storage), prev); if(this == head) // removing the head head = next; return head; }
/** * Insert this block into the head of the list of blocks * related to the specified DatanodeStorageInfo. * If the head is null then form a new list. * @return current block as the new head of the list. */ BlockInfoContiguous listInsert(BlockInfoContiguous head, DatanodeStorageInfo storage) { int dnIndex = this.findStorageInfo(storage); assert dnIndex >= 0 : "Data node is not found: current"; assert getPrevious(dnIndex) == null && getNext(dnIndex) == null : "Block is already in the list and cannot be inserted."; this.setPrevious(dnIndex, null); this.setNext(dnIndex, head); if(head != null) head.setPrevious(head.findStorageInfo(storage), this); return this; }
/** * Remove this block from the list of blocks * related to the specified DatanodeStorageInfo. * If this block is the head of the list then return the next block as * the new head. * @return the new head of the list or null if the list becomes * empy after deletion. */ BlockInfoContiguous listRemove(BlockInfoContiguous head, DatanodeStorageInfo storage) { if(head == null) return null; int dnIndex = this.findStorageInfo(storage); if(dnIndex < 0) // this block is not on the data-node list return head; BlockInfoContiguous next = this.getNext(dnIndex); BlockInfoContiguous prev = this.getPrevious(dnIndex); this.setNext(dnIndex, null); this.setPrevious(dnIndex, null); if(prev != null) prev.setNext(prev.findStorageInfo(storage), next); if(next != null) next.setPrevious(next.findStorageInfo(storage), prev); if(this == head) // removing the head head = next; return head; }
/** * Insert this block into the head of the list of blocks * related to the specified DatanodeStorageInfo. * If the head is null then form a new list. * @return current block as the new head of the list. */ BlockInfoContiguous listInsert(BlockInfoContiguous head, DatanodeStorageInfo storage) { int dnIndex = this.findStorageInfo(storage); assert dnIndex >= 0 : "Data node is not found: current"; assert getPrevious(dnIndex) == null && getNext(dnIndex) == null : "Block is already in the list and cannot be inserted."; this.setPrevious(dnIndex, null); this.setNext(dnIndex, head); if(head != null) head.setPrevious(head.findStorageInfo(storage), this); return this; }
/** * Remove this block from the list of blocks related to the specified * DatanodeDescriptor. Insert it into the head of the list of blocks. * * @return the new head of the list. */ public BlockInfoContiguous moveBlockToHead(BlockInfoContiguous head, DatanodeStorageInfo storage, int curIndex, int headIndex) { if (head == this) { return this; } BlockInfoContiguous next = this.setNext(curIndex, head); BlockInfoContiguous prev = this.setPrevious(curIndex, null); head.setPrevious(headIndex, this); prev.setNext(prev.findStorageInfo(storage), next); if (next != null) { next.setPrevious(next.findStorageInfo(storage), prev); } return this; }
/** * Remove this block from the list of blocks related to the specified * DatanodeDescriptor. Insert it into the head of the list of blocks. * * @return the new head of the list. */ public BlockInfoContiguous moveBlockToHead(BlockInfoContiguous head, DatanodeStorageInfo storage, int curIndex, int headIndex) { if (head == this) { return this; } BlockInfoContiguous next = this.setNext(curIndex, head); BlockInfoContiguous prev = this.setPrevious(curIndex, null); head.setPrevious(headIndex, this); prev.setNext(prev.findStorageInfo(storage), next); if (next != null) { next.setPrevious(next.findStorageInfo(storage), prev); } return this; }
/** * Replace a block in the block map by a new block. * The new block and the old one have the same key. * @param newBlock - block for replacement * @return new block */ BlockInfoContiguous replaceBlock(BlockInfoContiguous newBlock) { BlockInfoContiguous currentBlock = blocks.get(newBlock); assert currentBlock != null : "the block if not in blocksMap"; // replace block in data-node lists for (int i = currentBlock.numNodes() - 1; i >= 0; i--) { final DatanodeDescriptor dn = currentBlock.getDatanode(i); final DatanodeStorageInfo storage = currentBlock.findStorageInfo(dn); final boolean removed = storage.removeBlock(currentBlock); Preconditions.checkState(removed, "currentBlock not found."); final AddBlockResult result = storage.addBlock(newBlock); Preconditions.checkState(result == AddBlockResult.ADDED, "newBlock already exists."); } // replace block in the map itself blocks.put(newBlock); return newBlock; } }
public AddBlockResult addBlock(BlockInfoContiguous b) { // First check whether the block belongs to a different storage // on the same DN. AddBlockResult result = AddBlockResult.ADDED; DatanodeStorageInfo otherStorage = b.findStorageInfo(getDatanodeDescriptor()); if (otherStorage != null) { if (otherStorage != this) { // The block belongs to a different storage. Remove it first. otherStorage.removeBlock(b); result = AddBlockResult.REPLACED; } else { // The block is already associated with this storage. return AddBlockResult.ALREADY_EXIST; } } // add to the head of the data-node list b.addStorage(this); blockList = b.listInsert(blockList, this); numBlocks++; return result; }
public AddBlockResult addBlock(BlockInfoContiguous b) { // First check whether the block belongs to a different storage // on the same DN. AddBlockResult result = AddBlockResult.ADDED; DatanodeStorageInfo otherStorage = b.findStorageInfo(getDatanodeDescriptor()); if (otherStorage != null) { if (otherStorage != this) { // The block belongs to a different storage. Remove it first. otherStorage.removeBlock(b); result = AddBlockResult.REPLACED; } else { // The block is already associated with this storage. return AddBlockResult.ALREADY_EXIST; } } // add to the head of the data-node list b.addStorage(this); blockList = b.listInsert(blockList, this); numBlocks++; return result; }
(curIndex = storedBlock.findStorageInfo(storageInfo)) >= 0) { headIndex = storageInfo.moveBlockToHead(storedBlock, curIndex, headIndex);
(curIndex = storedBlock.findStorageInfo(storageInfo)) >= 0) { headIndex = storageInfo.moveBlockToHead(storedBlock, curIndex, headIndex);
storage = storedBlock.findStorageInfo(node);
/** * Replace a block in the block map by a new block. * The new block and the old one have the same key. * @param newBlock - block for replacement * @return new block */ BlockInfoContiguous replaceBlock(BlockInfoContiguous newBlock) { BlockInfoContiguous currentBlock = blocks.get(newBlock); assert currentBlock != null : "the block if not in blocksMap"; // replace block in data-node lists for (int i = currentBlock.numNodes() - 1; i >= 0; i--) { final DatanodeDescriptor dn = currentBlock.getDatanode(i); final DatanodeStorageInfo storage = currentBlock.findStorageInfo(dn); final boolean removed = storage.removeBlock(currentBlock); Preconditions.checkState(removed, "currentBlock not found."); final AddBlockResult result = storage.addBlock(newBlock); Preconditions.checkState(result == AddBlockResult.ADDED, "newBlock already exists."); } // replace block in the map itself blocks.put(newBlock); return newBlock; } }
/** * Remove {@link DatanodeStorageInfo} location for a block */ boolean removeStorage(DatanodeStorageInfo storage) { int dnIndex = findStorageInfo(storage); if(dnIndex < 0) // the node is not found return false; assert getPrevious(dnIndex) == null && getNext(dnIndex) == null : "Block is still in the list and must be removed first."; // find the last not null node int lastNode = numNodes()-1; // replace current node triplet by the lastNode one setStorageInfo(dnIndex, getStorageInfo(lastNode)); setNext(dnIndex, getNext(lastNode)); setPrevious(dnIndex, getPrevious(lastNode)); // set the last triplet to null setStorageInfo(lastNode, null); setNext(lastNode, null); setPrevious(lastNode, null); return true; }
/** * Remove {@link DatanodeStorageInfo} location for a block */ boolean removeStorage(DatanodeStorageInfo storage) { int dnIndex = findStorageInfo(storage); if(dnIndex < 0) // the node is not found return false; assert getPrevious(dnIndex) == null && getNext(dnIndex) == null : "Block is still in the list and must be removed first."; // find the last not null node int lastNode = numNodes()-1; // replace current node triplet by the lastNode one setStorageInfo(dnIndex, getStorageInfo(lastNode)); setNext(dnIndex, getNext(lastNode)); setPrevious(dnIndex, getPrevious(lastNode)); // set the last triplet to null setStorageInfo(lastNode, null); setNext(lastNode, null); setPrevious(lastNode, null); return true; }