void clear() { legacyGenerationStamp.setCurrentValue(GenerationStamp.LAST_RESERVED_STAMP); generationStamp.setCurrentValue(GenerationStamp.LAST_RESERVED_STAMP); getBlockIdGenerator().setCurrentValue(SequentialBlockIdGenerator .LAST_RESERVED_BLOCK_ID); getBlockGroupIdGenerator().setCurrentValue(Long.MIN_VALUE); legacyGenerationStampLimit = HdfsConstants.GRANDFATHER_GENERATION_STAMP; }
public boolean isLegacyBlock(Block block) { return blockIdManager.isLegacyBlock(block); }
public long nextGenerationStamp(boolean legacyBlock) throws IOException { return blockIdManager.nextGenerationStamp(legacyBlock); }
/** * Return true if the block is a striped block. * * Before HDFS-4645, block ID was randomly generated (legacy), so it is * possible that legacy block ID to be negative, which should not be * considered as striped block ID. * * @see #isLegacyBlock(Block) detecting legacy block IDs. */ public boolean isStripedBlock(Block block) { return isStripedBlockID(block.getBlockId()) && !isLegacyBlock(block); }
boolean isGenStampInFuture(Block block) { if (isLegacyBlock(block)) { return block.getGenerationStamp() > getLegacyGenerationStamp(); } else { return block.getGenerationStamp() > getGenerationStamp(); } }
private void saveNameSystemSection(FileSummary.Builder summary) throws IOException { final FSNamesystem fsn = context.getSourceNamesystem(); OutputStream out = sectionOutputStream; BlockIdManager blockIdManager = fsn.getBlockIdManager(); NameSystemSection.Builder b = NameSystemSection.newBuilder() .setGenstampV1(blockIdManager.getGenerationStampV1()) .setGenstampV1Limit(blockIdManager.getGenerationStampV1Limit()) .setGenstampV2(blockIdManager.getGenerationStampV2()) .setLastAllocatedBlockId(blockIdManager.getLastAllocatedBlockId()) .setTransactionId(context.getTxId()); // We use the non-locked version of getNamespaceInfo here since // the coordinating thread of saveNamespace already has read-locked // the namespace for us. If we attempt to take another readlock // from the actual saver thread, there's a potential of a // fairness-related deadlock. See the comments on HDFS-2223. b.setNamespaceId(fsn.unprotectedGetNamespaceInfo().getNamespaceID()); if (fsn.isRollingUpgrade()) { b.setRollingUpgradeStartTime(fsn.getRollingUpgradeInfo().getStartTime()); } NameSystemSection s = b.build(); s.writeDelimitedTo(out); commitSection(summary, SectionName.NS_INFO); }
.getNamespaceID()); out.writeLong(numINodes); out.writeLong(sourceNamesystem.getBlockIdManager().getGenerationStampV1()); out.writeLong(sourceNamesystem.getBlockIdManager().getGenerationStampV2()); out.writeLong(sourceNamesystem.getBlockIdManager().getGenerationStampAtblockIdSwitch()); out.writeLong(sourceNamesystem.getBlockIdManager().getLastAllocatedBlockId()); out.writeLong(context.getTxId()); out.writeLong(sourceNamesystem.dir.getLastInodeId());
public boolean isGenStampInFuture(Block block) { if (isLegacyBlock(block)) { return block.getGenerationStamp() > getGenerationStampV1(); } else { return block.getGenerationStamp() > getGenerationStampV2(); } }
/** * Test that the generation stamp for legacy and new blocks is updated * as expected. * * @throws IOException */ @Test public void testGenerationStampUpdate() throws IOException { // Setup a mock object and stub out a few routines to // retrieve the generation stamp counters. BlockIdManager bid = mock(BlockIdManager.class); final long nextGenerationStampV1 = 5000; final long nextGenerationStampV2 = 20000; when(bid.getNextGenerationStampV1()) .thenReturn(nextGenerationStampV1); when(bid.getNextGenerationStampV2()) .thenReturn(nextGenerationStampV2); // Make sure that the generation stamp is set correctly for both // kinds of blocks. when(bid.nextGenerationStamp(anyBoolean())).thenCallRealMethod(); assertThat(bid.nextGenerationStamp(true), is(nextGenerationStampV1)); assertThat(bid.nextGenerationStamp(false), is(nextGenerationStampV2)); } }
/** * Increments, logs and then returns the stamp */ public long nextGenerationStamp(boolean legacyBlock) throws IOException { return legacyBlock ? getNextGenerationStampV1() : getNextGenerationStampV2(); }
/** * Test that the block type (legacy or not) can be correctly detected * based on its generation stamp. * * @throws IOException */ @Test public void testBlockTypeDetection() throws IOException { // Setup a mock object and stub out a few routines to // retrieve the generation stamp counters. BlockIdManager bid = mock(BlockIdManager.class); final long maxGenStampForLegacyBlocks = 10000; when(bid.getGenerationStampV1Limit()) .thenReturn(maxGenStampForLegacyBlocks); Block legacyBlock = spy(new Block()); when(legacyBlock.getGenerationStamp()) .thenReturn(maxGenStampForLegacyBlocks/2); Block newBlock = spy(new Block()); when(newBlock.getGenerationStamp()) .thenReturn(maxGenStampForLegacyBlocks+1); // Make sure that isLegacyBlock() can correctly detect // legacy and new blocks. when(bid.isLegacyBlock(any(Block.class))).thenCallRealMethod(); assertThat(bid.isLegacyBlock(legacyBlock), is(true)); assertThat(bid.isLegacyBlock(newBlock), is(false)); }
public void clear() { generationStampV1.setCurrentValue(GenerationStamp.LAST_RESERVED_STAMP); generationStampV2.setCurrentValue(GenerationStamp.LAST_RESERVED_STAMP); getBlockIdGenerator().setCurrentValue(SequentialBlockIdGenerator .LAST_RESERVED_BLOCK_ID); generationStampV1Limit = GenerationStamp.GRANDFATHER_GENERATION_STAMP; } }
final BlockIdManager blockIdManager = sourceNamesystem.getBlockManager() .getBlockIdManager(); out.writeLong(blockIdManager.getLegacyGenerationStamp()); out.writeLong(blockIdManager.getGenerationStamp()); out.writeLong(blockIdManager.getGenerationStampAtblockIdSwitch()); out.writeLong(blockIdManager.getLastAllocatedContiguousBlockId()); out.writeLong(context.getTxId()); out.writeLong(sourceNamesystem.dir.getLastInodeId());
public void clear() { blockIdManager.clear(); clearQueues(); blocksMap.clear(); }
datanodeManager = new DatanodeManager(this, namesystem, conf); heartbeatManager = datanodeManager.getHeartbeatManager(); this.blockIdManager = new BlockIdManager(this); blocksPerPostpondedRescan = (int)Math.min(Integer.MAX_VALUE, datanodeManager.getBlocksPerPostponedMisreplicatedBlocksRescan());
/** * Determine whether the block ID was randomly generated (legacy) or * sequentially generated. The generation stamp value is used to * make the distinction. * * @return true if the block ID was randomly generated, false otherwise. */ public boolean isLegacyBlock(Block block) { return block.getGenerationStamp() < getGenerationStampV1Limit(); }
BlockIdManager bid = spy(spyFsn.getBlockIdManager()); Whitebox.setInternalState(finalFsn, "blockIdManager", bid); doAnswer(delayer).when(bid).getGenerationStampV2();
private void saveNameSystemSection(FileSummary.Builder summary) throws IOException { final FSNamesystem fsn = context.getSourceNamesystem(); OutputStream out = sectionOutputStream; BlockIdManager blockIdManager = fsn.getBlockIdManager(); NameSystemSection.Builder b = NameSystemSection.newBuilder() .setGenstampV1(blockIdManager.getGenerationStampV1()) .setGenstampV1Limit(blockIdManager.getGenerationStampV1Limit()) .setGenstampV2(blockIdManager.getGenerationStampV2()) .setLastAllocatedBlockId(blockIdManager.getLastAllocatedBlockId()) .setTransactionId(context.getTxId()); // We use the non-locked version of getNamespaceInfo here since // the coordinating thread of saveNamespace already has read-locked // the namespace for us. If we attempt to take another readlock // from the actual saver thread, there's a potential of a // fairness-related deadlock. See the comments on HDFS-2223. b.setNamespaceId(fsn.unprotectedGetNamespaceInfo().getNamespaceID()); if (fsn.isRollingUpgrade()) { b.setRollingUpgradeStartTime(fsn.getRollingUpgradeInfo().getStartTime()); } NameSystemSection s = b.build(); s.writeDelimitedTo(out); commitSection(summary, SectionName.NS_INFO); }
.getNamespaceID()); out.writeLong(numINodes); out.writeLong(sourceNamesystem.getBlockIdManager().getGenerationStampV1()); out.writeLong(sourceNamesystem.getBlockIdManager().getGenerationStampV2()); out.writeLong(sourceNamesystem.getBlockIdManager().getGenerationStampAtblockIdSwitch()); out.writeLong(sourceNamesystem.getBlockIdManager().getLastAllocatedBlockId()); out.writeLong(context.getTxId()); out.writeLong(sourceNamesystem.dir.getLastInodeId());
public boolean isGenStampInFuture(Block block) { if (isLegacyBlock(block)) { return block.getGenerationStamp() > getGenerationStampV1(); } else { return block.getGenerationStamp() > getGenerationStampV2(); } }