@Override public ReplicaRecoveryInfo createInfo() { return new ReplicaRecoveryInfo(original.getBlockId(), original.getBytesOnDisk(), original.getGenerationStamp(), original.getState()); } }
info.getGenerationStamp() >= block.getGenerationStamp() && info.getNumBytes() > 0) { final BlockRecord existing = syncBlocks.get(blockId); if (existing == null || info.getNumBytes() > existing.rInfo.getNumBytes()) { int blockIndex = (int) (r.rInfo.getBlockId() & BLOCK_GROUP_INDEX_MASK); long newSize = getInternalBlockLength(safeLength, ecPolicy.getCellSize(), dataBlkNum, blockIndex); if (r.rInfo.getNumBytes() >= newSize) { rurList.add(r); int index = (int) (r.rInfo.getBlockId() & HdfsServerConstants.BLOCK_GROUP_INDEX_MASK); newLocs[index] = r.id;
ReplicaRecoveryInfo info = callInitReplicaRecovery(proxyDN, rBlock); if (info != null && info.getGenerationStamp() >= block.getGenerationStamp() && info.getNumBytes() > 0) { if (info.getOriginalReplicaState().getValue() <= ReplicaState.RWR.getValue()) { syncList.add(new BlockRecord(id, proxyDN, info));
long finalizedLength = -1; for (BlockRecord r : syncList) { assert r.rInfo.getNumBytes() > 0 : "zero length replica"; ReplicaState rState = r.rInfo.getOriginalReplicaState(); if (rState.getValue() < bestState.getValue()) { bestState = rState; if (finalizedLength > 0 && finalizedLength != r.rInfo.getNumBytes()) { throw new IOException("Inconsistent size of finalized replicas. " + "Replica " + r.rInfo + " expected size: " + finalizedLength); finalizedLength = r.rInfo.getNumBytes(); assert finalizedLength > 0 : "finalizedLength is not positive"; for(BlockRecord r : syncList) { ReplicaState rState = r.rInfo.getOriginalReplicaState(); if (rState == ReplicaState.FINALIZED || rState == ReplicaState.RBW && r.rInfo.getNumBytes() == finalizedLength) { participatingList.add(r); LOG.debug("syncBlock replicaInfo: block=" + block + ", from datanode " + r.id + ", receivedState=" + rState.name() + ", receivedLength=" + r.rInfo.getNumBytes() + ", bestState=FINALIZED, finalizedLength=" + finalizedLength); long minLength = Long.MAX_VALUE; for(BlockRecord r : syncList) { ReplicaState rState = r.rInfo.getOriginalReplicaState();
private static void assertEquals(ReplicaInfo originalInfo, ReplicaRecoveryInfo recoveryInfo) { Assert.assertEquals(originalInfo.getBlockId(), recoveryInfo.getBlockId()); Assert.assertEquals(originalInfo.getGenerationStamp(), recoveryInfo.getGenerationStamp()); Assert.assertEquals(originalInfo.getBytesOnDisk(), recoveryInfo.getNumBytes()); Assert.assertEquals(originalInfo.getState(), recoveryInfo.getOriginalReplicaState()); }
ReplicaRecoveryInfo info = callInitReplicaRecovery(datanode, rBlock); if (info != null && info.getGenerationStamp() >= block.getGenerationStamp() && info.getNumBytes() > 0) { syncList.add(new BlockRecord(id, datanode, info));
@Override public InitReplicaRecoveryResponseProto initReplicaRecovery( RpcController unused, InitReplicaRecoveryRequestProto request) throws ServiceException { RecoveringBlock b = PBHelper.convert(request.getBlock()); ReplicaRecoveryInfo r; try { r = impl.initReplicaRecovery(b); } catch (IOException e) { throw new ServiceException(e); } if (r == null) { return InitReplicaRecoveryResponseProto.newBuilder() .setReplicaFound(false) .build(); } else { return InitReplicaRecoveryResponseProto.newBuilder() .setReplicaFound(true) .setBlock(PBHelperClient.convert(r)) .setState(PBHelper.convert(r.getOriginalReplicaState())).build(); } }
/** * TODO: the current implementation depends on the assumption that the * parity cells are only generated based on the full stripe. This is not * true after we support hflush. */ @VisibleForTesting long getSafeLength(Map<Long, BlockRecord> syncBlocks) { final int dataBlkNum = ecPolicy.getNumDataUnits(); Preconditions.checkArgument(syncBlocks.size() >= dataBlkNum); long[] blockLengths = new long[syncBlocks.size()]; int i = 0; for (BlockRecord r : syncBlocks.values()) { ReplicaRecoveryInfo rInfo = r.getReplicaRecoveryInfo(); blockLengths[i++] = rInfo.getNumBytes(); } return StripedBlockUtil.getSafeLength(ecPolicy, blockLengths); }
public ReplicaRecoveryInfo(long blockId, long diskLen, long gs, ReplicaState rState) { set(blockId, diskLen, gs); originalState = rState; }
private void truncatePartialBlock(List<BlockRecord> rurList, long safeLength) throws IOException { int cellSize = ecPolicy.getCellSize(); int dataBlkNum = ecPolicy.getNumDataUnits(); List<DatanodeID> failedList = new ArrayList<>(); for (BlockRecord r : rurList) { int blockIndex = (int) (r.rInfo.getBlockId() & BLOCK_GROUP_INDEX_MASK); long newSize = getInternalBlockLength(safeLength, cellSize, dataBlkNum, blockIndex); try { r.updateReplicaUnderRecovery(bpid, recoveryId, r.rInfo.getBlockId(), newSize); } catch (IOException e) { InterDatanodeProtocol.LOG.warn("Failed to updateBlock (newblock=" + ", datanode=" + r.id + ")", e); failedList.add(r.id); } } // If any of the data-nodes failed, the recovery fails, because // we never know the actual state of the replica on failed data-nodes. // The recovery should be started over. if (!failedList.isEmpty()) { throw new IOException("Cannot recover " + block + ", the following datanodes failed: " + failedList); } }
private static void assertEquals(ReplicaInfo originalInfo, ReplicaRecoveryInfo recoveryInfo) { Assert.assertEquals(originalInfo.getBlockId(), recoveryInfo.getBlockId()); Assert.assertEquals(originalInfo.getGenerationStamp(), recoveryInfo.getGenerationStamp()); Assert.assertEquals(originalInfo.getBytesOnDisk(), recoveryInfo.getNumBytes()); Assert.assertEquals(originalInfo.getState(), recoveryInfo.getOriginalReplicaState()); }
long finalizedLength = -1; for(BlockRecord r : syncList) { assert r.rInfo.getNumBytes() > 0 : "zero length replica"; ReplicaState rState = r.rInfo.getOriginalReplicaState(); if(rState.getValue() < bestState.getValue()) bestState = rState; if(rState == ReplicaState.FINALIZED) { if(finalizedLength > 0 && finalizedLength != r.rInfo.getNumBytes()) throw new IOException("Inconsistent size of finalized replicas. " + "Replica " + r.rInfo + " expected size: " + finalizedLength); finalizedLength = r.rInfo.getNumBytes(); assert finalizedLength > 0 : "finalizedLength is not positive"; for(BlockRecord r : syncList) { ReplicaState rState = r.rInfo.getOriginalReplicaState(); if(rState == ReplicaState.FINALIZED || rState == ReplicaState.RBW && r.rInfo.getNumBytes() == finalizedLength) participatingList.add(r); long minLength = Long.MAX_VALUE; for(BlockRecord r : syncList) { ReplicaState rState = r.rInfo.getOriginalReplicaState(); if(rState == bestState) { minLength = Math.min(minLength, r.rInfo.getNumBytes()); participatingList.add(r);
ReplicaRecoveryInfo info = callInitReplicaRecovery(datanode, rBlock); if (info != null && info.getGenerationStamp() >= block.getGenerationStamp() && info.getNumBytes() > 0) { syncList.add(new BlockRecord(id, datanode, info));
@Override public InitReplicaRecoveryResponseProto initReplicaRecovery( RpcController unused, InitReplicaRecoveryRequestProto request) throws ServiceException { RecoveringBlock b = PBHelper.convert(request.getBlock()); ReplicaRecoveryInfo r; try { r = impl.initReplicaRecovery(b); } catch (IOException e) { throw new ServiceException(e); } if (r == null) { return InitReplicaRecoveryResponseProto.newBuilder() .setReplicaFound(false) .build(); } else { return InitReplicaRecoveryResponseProto.newBuilder() .setReplicaFound(true) .setBlock(PBHelper.convert(r)) .setState(PBHelper.convert(r.getOriginalReplicaState())).build(); } }
@Override public String toString() { return super.toString() + "[numBytes=" + this.getNumBytes() + ",originalReplicaState=" + this.originalState.name() + "]"; } }
public ReplicaRecoveryInfo(long blockId, long diskLen, long gs, ReplicaState rState) { set(blockId, diskLen, gs); originalState = rState; }
@Override public ReplicaRecoveryInfo initReplicaRecovery(RecoveringBlock rBlock) throws IOException { InitReplicaRecoveryRequestProto req = InitReplicaRecoveryRequestProto .newBuilder().setBlock(PBHelper.convert(rBlock)).build(); InitReplicaRecoveryResponseProto resp; try { resp = rpcProxy.initReplicaRecovery(NULL_CONTROLLER, req); } catch (ServiceException e) { throw ProtobufHelper.getRemoteException(e); } if (!resp.getReplicaFound()) { // No replica found on the remote node. return null; } else { if (!resp.hasBlock() || !resp.hasState()) { throw new IOException("Replica was found but missing fields. " + "Req: " + req + "\n" + "Resp: " + resp); } } BlockProto b = resp.getBlock(); return new ReplicaRecoveryInfo(b.getBlockId(), b.getNumBytes(), b.getGenStamp(), PBHelper.convert(resp.getState())); }
final Block tmp = new Block(rri.getBlockId(), rri.getNumBytes() - 1, rri.getGenerationStamp()); try {
long finalizedLength = -1; for(BlockRecord r : syncList) { assert r.rInfo.getNumBytes() > 0 : "zero length replica"; ReplicaState rState = r.rInfo.getOriginalReplicaState(); if(rState.getValue() < bestState.getValue()) bestState = rState; if(rState == ReplicaState.FINALIZED) { if(finalizedLength > 0 && finalizedLength != r.rInfo.getNumBytes()) throw new IOException("Inconsistent size of finalized replicas. " + "Replica " + r.rInfo + " expected size: " + finalizedLength); finalizedLength = r.rInfo.getNumBytes(); assert finalizedLength > 0 : "finalizedLength is not positive"; for(BlockRecord r : syncList) { ReplicaState rState = r.rInfo.getOriginalReplicaState(); if(rState == ReplicaState.FINALIZED || rState == ReplicaState.RBW && r.rInfo.getNumBytes() == finalizedLength) participatingList.add(r); long minLength = Long.MAX_VALUE; for(BlockRecord r : syncList) { ReplicaState rState = r.rInfo.getOriginalReplicaState(); if(rState == bestState) { minLength = Math.min(minLength, r.rInfo.getNumBytes()); participatingList.add(r);
@Override public InitReplicaRecoveryResponseProto initReplicaRecovery( RpcController unused, InitReplicaRecoveryRequestProto request) throws ServiceException { RecoveringBlock b = PBHelper.convert(request.getBlock()); ReplicaRecoveryInfo r; try { r = impl.initReplicaRecovery(b); } catch (IOException e) { throw new ServiceException(e); } if (r == null) { return InitReplicaRecoveryResponseProto.newBuilder() .setReplicaFound(false) .build(); } else { return InitReplicaRecoveryResponseProto.newBuilder() .setReplicaFound(true) .setBlock(PBHelper.convert(r)) .setState(PBHelper.convert(r.getOriginalReplicaState())).build(); } }