/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> protected internal bool VerifyDeletedBlocks(LocatedBlocks locatedBlocks) { Log.Info("Verifying replica has no saved copy after deletion."); TriggerBlockReport(); while (DataNodeTestUtils.GetPendingAsyncDeletions(cluster.GetDataNodes()[0]) > 0L ) { Sharpen.Thread.Sleep(1000); } string bpid = cluster.GetNamesystem().GetBlockPoolId(); IList <FsVolumeSpi> volumes = cluster.GetDataNodes()[0].GetFSDataset().GetVolumes( ); // Make sure deleted replica does not have a copy on either finalized dir of // transient volume or finalized dir of non-transient volume foreach (FsVolumeSpi v in volumes) { FsVolumeImpl volume = (FsVolumeImpl)v; FilePath targetDir = (v.IsTransientStorage()) ? volume.GetBlockPoolSlice(bpid).GetFinalizedDir () : volume.GetBlockPoolSlice(bpid).GetLazypersistDir(); if (VerifyBlockDeletedFromDir(targetDir, locatedBlocks) == false) { return(false); } } return(true); }
/// <summary>Make sure at least one non-transient volume has a saved copy of the replica. /// </summary> /// <remarks> /// Make sure at least one non-transient volume has a saved copy of the replica. /// An infinite loop is used to ensure the async lazy persist tasks are completely /// done before verification. Caller of ensureLazyPersistBlocksAreSaved expects /// either a successful pass or timeout failure. /// </remarks> /// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> protected internal void EnsureLazyPersistBlocksAreSaved(LocatedBlocks locatedBlocks ) { string bpid = cluster.GetNamesystem().GetBlockPoolId(); IList <FsVolumeSpi> volumes = cluster.GetDataNodes()[0].GetFSDataset().GetVolumes( ); ICollection <long> persistedBlockIds = new HashSet <long>(); while (persistedBlockIds.Count < locatedBlocks.GetLocatedBlocks().Count) { // Take 1 second sleep before each verification iteration Sharpen.Thread.Sleep(1000); foreach (LocatedBlock lb in locatedBlocks.GetLocatedBlocks()) { foreach (FsVolumeSpi v in volumes) { if (v.IsTransientStorage()) { continue; } FsVolumeImpl volume = (FsVolumeImpl)v; FilePath lazyPersistDir = volume.GetBlockPoolSlice(bpid).GetLazypersistDir(); long blockId = lb.GetBlock().GetBlockId(); FilePath targetDir = DatanodeUtil.IdToBlockDir(lazyPersistDir, blockId); FilePath blockFile = new FilePath(targetDir, lb.GetBlock().GetBlockName()); if (blockFile.Exists()) { // Found a persisted copy for this block and added to the Set persistedBlockIds.AddItem(blockId); } } } } // We should have found a persisted copy for each located block. Assert.AssertThat(persistedBlockIds.Count, IS.Is(locatedBlocks.GetLocatedBlocks() .Count)); }