/** * Add a {@link DatanodeStorageInfo} location for a block */ boolean addStorage(DatanodeStorageInfo storage) { // find the last null node int lastNode = ensureCapacity(1); setStorageInfo(lastNode, storage); setNext(lastNode, null); setPrevious(lastNode, null); return true; }
/** * Add a {@link DatanodeStorageInfo} location for a block */ boolean addStorage(DatanodeStorageInfo storage) { // find the last null node int lastNode = ensureCapacity(1); setStorageInfo(lastNode, storage); setNext(lastNode, null); setPrevious(lastNode, null); return true; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }