/// <exception cref="System.IO.IOException"/> private void TestRbwReplicas(MiniDFSCluster cluster, bool isCorrupt) { FSDataOutputStream @out = null; FileSystem fs = cluster.GetFileSystem(); Path src = new Path("/test.txt"); try { int fileLen = 515; // create some rbw replicas on disk byte[] writeBuf = new byte[fileLen]; new Random().NextBytes(writeBuf); @out = fs.Create(src); @out.Write(writeBuf); @out.Hflush(); DataNode dn = cluster.GetDataNodes()[0]; foreach (FsVolumeSpi v in Dataset(dn).GetVolumes()) { FsVolumeImpl volume = (FsVolumeImpl)v; FilePath currentDir = volume.GetCurrentDir().GetParentFile().GetParentFile(); FilePath rbwDir = new FilePath(currentDir, "rbw"); foreach (FilePath file in rbwDir.ListFiles()) { if (isCorrupt && Block.IsBlockFilename(file)) { new RandomAccessFile(file, "rw").SetLength(fileLen - 1); } } } // corrupt cluster.RestartDataNodes(); cluster.WaitActive(); dn = cluster.GetDataNodes()[0]; // check volumeMap: one rwr replica string bpid = cluster.GetNamesystem().GetBlockPoolId(); ReplicaMap replicas = Dataset(dn).volumeMap; NUnit.Framework.Assert.AreEqual(1, replicas.Size(bpid)); ReplicaInfo replica = replicas.Replicas(bpid).GetEnumerator().Next(); NUnit.Framework.Assert.AreEqual(HdfsServerConstants.ReplicaState.Rwr, replica.GetState ()); if (isCorrupt) { NUnit.Framework.Assert.AreEqual((fileLen - 1) / 512 * 512, replica.GetNumBytes()); } else { NUnit.Framework.Assert.AreEqual(fileLen, replica.GetNumBytes()); } Dataset(dn).Invalidate(bpid, new Block[] { replica }); } finally { IOUtils.CloseStream(@out); if (fs.Exists(src)) { fs.Delete(src, false); } fs.Close(); } }
public virtual void TestGetNextVolumeWithClosedVolume() { FsVolumeList volumeList = new FsVolumeList(Collections.EmptyList <VolumeFailureInfo >(), blockScanner, blockChooser); IList <FsVolumeImpl> volumes = new AList <FsVolumeImpl>(); for (int i = 0; i < 3; i++) { FilePath curDir = new FilePath(baseDir, "nextvolume-" + i); curDir.Mkdirs(); FsVolumeImpl volume = new FsVolumeImpl(dataset, "storage-id", curDir, conf, StorageType .Default); volume.SetCapacityForTesting(1024 * 1024 * 1024); volumes.AddItem(volume); volumeList.AddVolume(volume.ObtainReference()); } // Close the second volume. volumes[1].CloseAndWait(); for (int i_1 = 0; i_1 < 10; i_1++) { using (FsVolumeReference @ref = volumeList.GetNextVolume(StorageType.Default, 128 )) { // volume No.2 will not be chosen. Assert.AssertNotEquals(@ref.GetVolume(), volumes[1]); } } }
public virtual void TestDuplicateReplicaResolution() { FsVolumeImpl fsv1 = Org.Mockito.Mockito.Mock <FsVolumeImpl>(); FsVolumeImpl fsv2 = Org.Mockito.Mockito.Mock <FsVolumeImpl>(); FilePath f1 = new FilePath("d1/block"); FilePath f2 = new FilePath("d2/block"); ReplicaInfo replicaOlder = new FinalizedReplica(1, 1, 1, fsv1, f1); ReplicaInfo replica = new FinalizedReplica(1, 2, 2, fsv1, f1); ReplicaInfo replicaSame = new FinalizedReplica(1, 2, 2, fsv1, f1); ReplicaInfo replicaNewer = new FinalizedReplica(1, 3, 3, fsv1, f1); ReplicaInfo replicaOtherOlder = new FinalizedReplica(1, 1, 1, fsv2, f2); ReplicaInfo replicaOtherSame = new FinalizedReplica(1, 2, 2, fsv2, f2); ReplicaInfo replicaOtherNewer = new FinalizedReplica(1, 3, 3, fsv2, f2); // equivalent path so don't remove either NUnit.Framework.Assert.IsNull(BlockPoolSlice.SelectReplicaToDelete(replicaSame, replica )); NUnit.Framework.Assert.IsNull(BlockPoolSlice.SelectReplicaToDelete(replicaOlder, replica)); NUnit.Framework.Assert.IsNull(BlockPoolSlice.SelectReplicaToDelete(replicaNewer, replica)); // keep latest found replica NUnit.Framework.Assert.AreSame(replica, BlockPoolSlice.SelectReplicaToDelete(replicaOtherSame , replica)); NUnit.Framework.Assert.AreSame(replicaOtherOlder, BlockPoolSlice.SelectReplicaToDelete (replicaOtherOlder, replica)); NUnit.Framework.Assert.AreSame(replica, BlockPoolSlice.SelectReplicaToDelete(replicaOtherNewer , replica)); }
/// <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> /// Generate testing environment and return a collection of blocks /// on which to run the tests. /// </summary> /// <param name="bpid">Block pool ID to generate blocks for</param> /// <param name="dataSet">Namespace in which to insert blocks</param> /// <returns>Contrived blocks for further testing.</returns> /// <exception cref="System.IO.IOException"/> private ExtendedBlock[] Setup(string bpid, FsDatasetImpl dataSet) { // setup replicas map ExtendedBlock[] blocks = new ExtendedBlock[] { new ExtendedBlock(bpid, 1, 1, 2001 ), new ExtendedBlock(bpid, 2, 1, 2002), new ExtendedBlock(bpid, 3, 1, 2003), new ExtendedBlock(bpid, 4, 1, 2004), new ExtendedBlock(bpid, 5, 1, 2005), new ExtendedBlock (bpid, 6, 1, 2006) }; ReplicaMap replicasMap = dataSet.volumeMap; FsVolumeImpl vol = (FsVolumeImpl)dataSet.volumes.GetNextVolume(StorageType.Default , 0).GetVolume(); ReplicaInfo replicaInfo = new FinalizedReplica(blocks[Finalized].GetLocalBlock(), vol, vol.GetCurrentDir().GetParentFile()); replicasMap.Add(bpid, replicaInfo); replicaInfo.GetBlockFile().CreateNewFile(); replicaInfo.GetMetaFile().CreateNewFile(); replicasMap.Add(bpid, new ReplicaInPipeline(blocks[Temporary].GetBlockId(), blocks [Temporary].GetGenerationStamp(), vol, vol.CreateTmpFile(bpid, blocks[Temporary] .GetLocalBlock()).GetParentFile(), 0)); replicaInfo = new ReplicaBeingWritten(blocks[Rbw].GetLocalBlock(), vol, vol.CreateRbwFile (bpid, blocks[Rbw].GetLocalBlock()).GetParentFile(), null); replicasMap.Add(bpid, replicaInfo); replicaInfo.GetBlockFile().CreateNewFile(); replicaInfo.GetMetaFile().CreateNewFile(); replicasMap.Add(bpid, new ReplicaWaitingToBeRecovered(blocks[Rwr].GetLocalBlock() , vol, vol.CreateRbwFile(bpid, blocks[Rwr].GetLocalBlock()).GetParentFile())); replicasMap.Add(bpid, new ReplicaUnderRecovery(new FinalizedReplica(blocks[Rur].GetLocalBlock (), vol, vol.GetCurrentDir().GetParentFile()), 2007)); return(blocks); }
public virtual void TestAddVolumeFailureReleasesInUseLock() { FsDatasetImpl spyDataset = Org.Mockito.Mockito.Spy(dataset); FsVolumeImpl mockVolume = Org.Mockito.Mockito.Mock <FsVolumeImpl>(); FilePath badDir = new FilePath(BaseDir, "bad"); badDir.Mkdirs(); Org.Mockito.Mockito.DoReturn(mockVolume).When(spyDataset).CreateFsVolume(Matchers.AnyString (), Matchers.Any <FilePath>(), Matchers.Any <StorageType>()); Org.Mockito.Mockito.DoThrow(new IOException("Failed to getVolumeMap()")).When(mockVolume ).GetVolumeMap(Matchers.AnyString(), Matchers.Any <ReplicaMap>(), Matchers.Any <RamDiskReplicaLruTracker >()); Storage.StorageDirectory sd = CreateStorageDirectory(badDir); sd.Lock(); DataStorage.VolumeBuilder builder = new DataStorage.VolumeBuilder(storage, sd); Org.Mockito.Mockito.When(storage.PrepareVolume(Matchers.Eq(datanode), Matchers.Eq (badDir.GetAbsoluteFile()), Matchers.Any <IList <NamespaceInfo> >())).ThenReturn(builder ); StorageLocation location = StorageLocation.Parse(badDir.ToString()); IList <NamespaceInfo> nsInfos = Lists.NewArrayList(); foreach (string bpid in BlockPoolIds) { nsInfos.AddItem(new NamespaceInfo(0, ClusterId, bpid, 1)); } try { spyDataset.AddVolume(location, nsInfos); NUnit.Framework.Assert.Fail("Expect to throw MultipleIOException"); } catch (MultipleIOException) { } FsDatasetTestUtil.AssertFileLockReleased(badDir.ToString()); }
/// <summary>Get the next subdirectory within the block pool slice.</summary> /// <returns> /// The next subdirectory within the block pool slice, or /// null if there are no more. /// </returns> /// <exception cref="System.IO.IOException"/> private string GetNextSubDir(string prev, FilePath dir) { IList <string> children = IOUtils.ListDirectory(dir, FsVolumeImpl.SubdirFilter.Instance ); this.cache = null; this.cacheMs = 0; if (children.Count == 0) { FsVolumeImpl.Log.Trace("getNextSubDir({}, {}): no subdirectories found in {}", this ._enclosing.storageID, this.bpid, dir.GetAbsolutePath()); return(null); } children.Sort(); string nextSubDir = FsVolumeImpl.NextSorted(children, prev); if (nextSubDir == null) { FsVolumeImpl.Log.Trace("getNextSubDir({}, {}): no more subdirectories found in {}" , this._enclosing.storageID, this.bpid, dir.GetAbsolutePath()); } else { FsVolumeImpl.Log.Trace("getNextSubDir({}, {}): picking next subdirectory {} " + "within {}" , this._enclosing.storageID, this.bpid, nextSubDir, dir.GetAbsolutePath()); } return(nextSubDir); }
public virtual void TestDeletingBlocks() { MiniDFSCluster cluster = new MiniDFSCluster.Builder(new HdfsConfiguration()).Build (); try { cluster.WaitActive(); DataNode dn = cluster.GetDataNodes()[0]; FsDatasetImpl ds = (FsDatasetImpl)DataNodeTestUtils.GetFSDataset(dn); FsVolumeImpl vol = ds.GetVolumes()[0]; ExtendedBlock eb; ReplicaInfo info; IList <Block> blockList = new AList <Block>(); for (int i = 1; i <= 63; i++) { eb = new ExtendedBlock(Blockpool, i, 1, 1000 + i); info = new FinalizedReplica(eb.GetLocalBlock(), vol, vol.GetCurrentDir().GetParentFile ()); ds.volumeMap.Add(Blockpool, info); info.GetBlockFile().CreateNewFile(); info.GetMetaFile().CreateNewFile(); blockList.AddItem(info); } ds.Invalidate(Blockpool, Sharpen.Collections.ToArray(blockList, new Block[0])); try { Sharpen.Thread.Sleep(1000); } catch (Exception) { } // Nothing to do NUnit.Framework.Assert.IsTrue(ds.IsDeletingBlock(Blockpool, blockList[0].GetBlockId ())); blockList.Clear(); eb = new ExtendedBlock(Blockpool, 64, 1, 1064); info = new FinalizedReplica(eb.GetLocalBlock(), vol, vol.GetCurrentDir().GetParentFile ()); ds.volumeMap.Add(Blockpool, info); info.GetBlockFile().CreateNewFile(); info.GetMetaFile().CreateNewFile(); blockList.AddItem(info); ds.Invalidate(Blockpool, Sharpen.Collections.ToArray(blockList, new Block[0])); try { Sharpen.Thread.Sleep(1000); } catch (Exception) { } // Nothing to do NUnit.Framework.Assert.IsFalse(ds.IsDeletingBlock(Blockpool, blockList[0].GetBlockId ())); } finally { cluster.Shutdown(); } }
/// <param name="blockSize"/> /// <param name="perVolumeCapacity"> /// limit the capacity of each volume to the given /// value. If negative, then don't limit. /// </param> /// <exception cref="System.IO.IOException"/> private void StartCluster(int blockSize, int numDatanodes, long perVolumeCapacity ) { InitConfig(blockSize); cluster = new MiniDFSCluster.Builder(conf).StoragesPerDatanode(StoragesPerDatanode ).NumDataNodes(numDatanodes).Build(); fs = cluster.GetFileSystem(); client = fs.GetClient(); cluster.WaitActive(); if (perVolumeCapacity >= 0) { foreach (DataNode dn in cluster.GetDataNodes()) { foreach (FsVolumeSpi volume in dn.GetFSDataset().GetVolumes()) { ((FsVolumeImpl)volume).SetCapacityForTesting(perVolumeCapacity); } } } if (numDatanodes == 1) { IList <FsVolumeSpi> volumes = cluster.GetDataNodes()[0].GetFSDataset().GetVolumes( ); Assert.AssertThat(volumes.Count, IS.Is(1)); singletonVolume = ((FsVolumeImpl)volumes[0]); } }
public _Thread_399(FsVolumeImpl v, string bpid, Configuration conf, IList <IOException > exceptions) { this.v = v; this.bpid = bpid; this.conf = conf; this.exceptions = exceptions; }
internal BlockIteratorImpl(FsVolumeImpl _enclosing, string bpid, string name) { this._enclosing = _enclosing; this.bpidDir = new FilePath(this._enclosing.currentDir, bpid); this.name = name; this.bpid = bpid; this.Rewind(); }
public _Thread_186(FsVolumeImpl v, string bpid, ReplicaMap volumeMap, RamDiskReplicaTracker ramDiskReplicaMap, IList <IOException> exceptions) { this.v = v; this.bpid = bpid; this.volumeMap = volumeMap; this.ramDiskReplicaMap = ramDiskReplicaMap; this.exceptions = exceptions; }
internal RamDiskReplica(string bpid, long blockId, FsVolumeImpl ramDiskVolume) { this.bpid = bpid; this.blockId = blockId; this.ramDiskVolume = ramDiskVolume; lazyPersistVolume = null; savedMetaFile = null; savedBlockFile = null; creationTime = Time.MonotonicNow(); isPersisted = false; }
internal override void RecordStartLazyPersist(string bpid, long blockId, FsVolumeImpl checkpointVolume) { lock (this) { IDictionary <long, RamDiskReplicaLruTracker.RamDiskReplicaLru> map = replicaMaps[bpid ]; RamDiskReplicaLruTracker.RamDiskReplicaLru ramDiskReplicaLru = map[blockId]; ramDiskReplicaLru.SetLazyPersistVolume(checkpointVolume); } }
internal ReplicaFileDeleteTask(FsDatasetAsyncDiskService _enclosing, FsVolumeReference volumeRef, FilePath blockFile, FilePath metaFile, ExtendedBlock block, string trashDirectory ) { this._enclosing = _enclosing; this.volumeRef = volumeRef; this.volume = (FsVolumeImpl)volumeRef.GetVolume(); this.blockFile = blockFile; this.metaFile = metaFile; this.block = block; this.trashDirectory = trashDirectory; }
/// <exception cref="System.IO.IOException"/> public virtual void TestChangeVolumeWithRunningCheckDirs() { RoundRobinVolumeChoosingPolicy <FsVolumeImpl> blockChooser = new RoundRobinVolumeChoosingPolicy <FsVolumeImpl>(); conf.SetLong(DFSConfigKeys.DfsDatanodeScanPeriodHoursKey, -1); BlockScanner blockScanner = new BlockScanner(datanode, conf); FsVolumeList volumeList = new FsVolumeList(Sharpen.Collections.EmptyList <VolumeFailureInfo >(), blockScanner, blockChooser); IList <FsVolumeImpl> oldVolumes = new AList <FsVolumeImpl>(); // Initialize FsVolumeList with 5 mock volumes. int NumVolumes = 5; for (int i = 0; i < NumVolumes; i++) { FsVolumeImpl volume = Org.Mockito.Mockito.Mock <FsVolumeImpl>(); oldVolumes.AddItem(volume); Org.Mockito.Mockito.When(volume.GetBasePath()).ThenReturn("data" + i); FsVolumeReference @ref = Org.Mockito.Mockito.Mock <FsVolumeReference>(); Org.Mockito.Mockito.When(@ref.GetVolume()).ThenReturn(volume); volumeList.AddVolume(@ref); } // When call checkDirs() on the 2nd volume, anther "thread" removes the 5th // volume and add another volume. It does not affect checkDirs() running. FsVolumeImpl newVolume = Org.Mockito.Mockito.Mock <FsVolumeImpl>(); FsVolumeReference newRef = Org.Mockito.Mockito.Mock <FsVolumeReference>(); Org.Mockito.Mockito.When(newRef.GetVolume()).ThenReturn(newVolume); Org.Mockito.Mockito.When(newVolume.GetBasePath()).ThenReturn("data4"); FsVolumeImpl blockedVolume = volumeList.GetVolumes()[1]; Org.Mockito.Mockito.DoAnswer(new _Answer_295(volumeList, newRef)).When(blockedVolume ).CheckDirs(); FsVolumeImpl brokenVolume = volumeList.GetVolumes()[2]; Org.Mockito.Mockito.DoThrow(new DiskChecker.DiskErrorException("broken")).When(brokenVolume ).CheckDirs(); volumeList.CheckDirs(); // Since FsVolumeImpl#checkDirs() get a snapshot of the list of volumes // before running removeVolume(), it is supposed to run checkDirs() on all // the old volumes. foreach (FsVolumeImpl volume_1 in oldVolumes) { Org.Mockito.Mockito.Verify(volume_1).CheckDirs(); } // New volume is not visible to checkDirs() process. Org.Mockito.Mockito.Verify(newVolume, Org.Mockito.Mockito.Never()).CheckDirs(); NUnit.Framework.Assert.IsTrue(volumeList.GetVolumes().Contains(newVolume)); NUnit.Framework.Assert.IsFalse(volumeList.GetVolumes().Contains(brokenVolume)); NUnit.Framework.Assert.AreEqual(NumVolumes - 1, volumeList.GetVolumes().Count); }
/// <summary> /// Get the next block.<p/> /// Each volume has a hierarchical structure.<p/> /// <code> /// BPID B0 /// finalized/ /// subdir0 /// subdir0 /// blk_000 /// blk_001 /// ... /// </summary> /// <remarks> /// Get the next block.<p/> /// Each volume has a hierarchical structure.<p/> /// <code> /// BPID B0 /// finalized/ /// subdir0 /// subdir0 /// blk_000 /// blk_001 /// ... /// subdir1 /// subdir0 /// ... /// rbw/ /// </code> /// When we run out of entries at one level of the structure, we search /// progressively higher levels. For example, when we run out of blk_ /// entries in a subdirectory, we search for the next subdirectory. /// And so on. /// </remarks> /// <exception cref="System.IO.IOException"/> public virtual ExtendedBlock NextBlock() { if (this.state.atEnd) { return(null); } try { while (true) { IList <string> entries = this.GetSubdirEntries(); if (entries != null) { this.state.curEntry = FsVolumeImpl.NextSorted(entries, this.state.curEntry); if (this.state.curEntry == null) { FsVolumeImpl.Log.Trace("nextBlock({}, {}): advancing from {} to next " + "subdirectory." , this._enclosing.storageID, this.bpid, this.state.curFinalizedSubDir); } else { ExtendedBlock block = new ExtendedBlock(this.bpid, Block.Filename2id(this.state.curEntry )); FsVolumeImpl.Log.Trace("nextBlock({}, {}): advancing to {}", this._enclosing.storageID , this.bpid, block); return(block); } } this.state.curFinalizedSubDir = this.GetNextFinalizedSubDir(); if (this.state.curFinalizedSubDir == null) { this.state.curFinalizedDir = this.GetNextFinalizedDir(); if (this.state.curFinalizedDir == null) { this.state.atEnd = true; return(null); } } } } catch (IOException e) { this.state.atEnd = true; FsVolumeImpl.Log.Error("nextBlock({}, {}): I/O error", this._enclosing.storageID, this.bpid, e); throw; } }
/// <summary>Dynamically remove a volume in the list.</summary> /// <param name="target">the volume instance to be removed.</param> private void RemoveVolume(FsVolumeImpl target) { while (true) { FsVolumeImpl[] curVolumes = volumes.Get(); IList <FsVolumeImpl> volumeList = Lists.NewArrayList(curVolumes); if (volumeList.Remove(target)) { if (volumes.CompareAndSet(curVolumes, Sharpen.Collections.ToArray(volumeList, new FsVolumeImpl[volumeList.Count]))) { if (blockScanner != null) { blockScanner.RemoveVolumeScanner(target); } try { target.CloseAndWait(); } catch (IOException e) { FsDatasetImpl.Log.Warn("Error occurs when waiting volume to close: " + target, e); } target.Shutdown(); FsDatasetImpl.Log.Info("Removed volume: " + target); break; } else { if (FsDatasetImpl.Log.IsDebugEnabled()) { FsDatasetImpl.Log.Debug("The volume list has been changed concurrently, " + "retry to remove volume: " + target); } } } else { if (FsDatasetImpl.Log.IsDebugEnabled()) { FsDatasetImpl.Log.Debug("Volume " + target + " does not exist or is removed by others." ); } break; } } }
/// <summary> /// Calls /// <see cref="FsVolumeImpl.CheckDirs()"/> /// on each volume. /// Use checkDirsMutext to allow only one instance of checkDirs() call /// </summary> /// <returns>list of all the failed volumes.</returns> internal virtual ICollection <FilePath> CheckDirs() { lock (checkDirsMutex) { ICollection <FilePath> failedVols = null; // Make a copy of volumes for performing modification IList <FsVolumeImpl> volumeList = GetVolumes(); for (IEnumerator <FsVolumeImpl> i = volumeList.GetEnumerator(); i.HasNext();) { FsVolumeImpl fsv = i.Next(); try { using (FsVolumeReference @ref = fsv.ObtainReference()) { fsv.CheckDirs(); } } catch (DiskChecker.DiskErrorException e) { FsDatasetImpl.Log.Warn("Removing failed volume " + fsv + ": ", e); if (failedVols == null) { failedVols = new HashSet <FilePath>(1); } failedVols.AddItem(new FilePath(fsv.GetBasePath()).GetAbsoluteFile()); AddVolumeFailureInfo(fsv); RemoveVolume(fsv); } catch (ClosedChannelException e) { FsDatasetImpl.Log.Debug("Caught exception when obtaining " + "reference count on closed volume" , e); } catch (IOException e) { FsDatasetImpl.Log.Error("Unexpected IOException", e); } } if (failedVols != null && failedVols.Count > 0) { FsDatasetImpl.Log.Warn("Completed checkDirs. Found " + failedVols.Count + " failure volumes." ); } return(failedVols); } }
/// <exception cref="System.IO.IOException"/> private FsVolumeReference ChooseVolume(IList <FsVolumeImpl> list, long blockSize) { while (true) { FsVolumeImpl volume = blockChooser.ChooseVolume(list, blockSize); try { return(volume.ObtainReference()); } catch (ClosedChannelException) { FsDatasetImpl.Log.Warn("Chosen a closed volume: " + volume); // blockChooser.chooseVolume returns DiskOutOfSpaceException when the list // is empty, indicating that all volumes are closed. list.Remove(volume); } } }
internal override void AddReplica(string bpid, long blockId, FsVolumeImpl transientVolume ) { lock (this) { IDictionary <long, RamDiskReplicaLruTracker.RamDiskReplicaLru> map = replicaMaps[bpid ]; if (map == null) { map = new Dictionary <long, RamDiskReplicaLruTracker.RamDiskReplicaLru>(); replicaMaps[bpid] = map; } RamDiskReplicaLruTracker.RamDiskReplicaLru ramDiskReplicaLru = new RamDiskReplicaLruTracker.RamDiskReplicaLru (this, bpid, blockId, transientVolume); map[blockId] = ramDiskReplicaLru; replicasNotPersisted.AddItem(ramDiskReplicaLru); } }
public virtual void TestCheckDirsWithClosedVolume() { FsVolumeList volumeList = new FsVolumeList(Sharpen.Collections.EmptyList <VolumeFailureInfo >(), blockScanner, blockChooser); IList <FsVolumeImpl> volumes = new AList <FsVolumeImpl>(); for (int i = 0; i < 3; i++) { FilePath curDir = new FilePath(baseDir, "volume-" + i); curDir.Mkdirs(); FsVolumeImpl volume = new FsVolumeImpl(dataset, "storage-id", curDir, conf, StorageType .Default); volumes.AddItem(volume); volumeList.AddVolume(volume.ObtainReference()); } // Close the 2nd volume. volumes[1].CloseAndWait(); // checkDirs() should ignore the 2nd volume since it is closed. volumeList.CheckDirs(); }
// os2.close() will fail as no block was allocated. /// <summary> /// Ensure that reserved space is released when the client goes away /// unexpectedly. /// </summary> /// <remarks> /// Ensure that reserved space is released when the client goes away /// unexpectedly. /// The verification is done for each replica in the write pipeline. /// </remarks> /// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> /// <exception cref="Sharpen.TimeoutException"/> public virtual void TestSpaceReleasedOnUnexpectedEof() { short replication = 3; StartCluster(BlockSize, replication, -1); string methodName = GenericTestUtils.GetMethodName(); Path file = new Path("/" + methodName + ".01.dat"); // Write 1 byte to the file and kill the writer. FSDataOutputStream os = fs.Create(file, replication); os.Write(new byte[1]); os.Hsync(); DFSTestUtil.AbortStream((DFSOutputStream)os.GetWrappedStream()); // Ensure all space reserved for the replica was released on each // DataNode. foreach (DataNode dn in cluster.GetDataNodes()) { FsVolumeImpl volume = (FsVolumeImpl)dn.GetFSDataset().GetVolumes()[0]; GenericTestUtils.WaitFor(new _Supplier_276(volume), 500, int.MaxValue); } }
public virtual void TestReleaseVolumeRefIfNoBlockScanner() { FsVolumeList volumeList = new FsVolumeList(Sharpen.Collections.EmptyList <VolumeFailureInfo >(), null, blockChooser); FilePath volDir = new FilePath(baseDir, "volume-0"); volDir.Mkdirs(); FsVolumeImpl volume = new FsVolumeImpl(dataset, "storage-id", volDir, conf, StorageType .Default); FsVolumeReference @ref = volume.ObtainReference(); volumeList.AddVolume(@ref); try { @ref.Close(); NUnit.Framework.Assert.Fail("Should throw exception because the reference is closed in " + "VolumeList#addVolume()."); } catch (InvalidOperationException) { } }
/// <summary>Asynchronously lazy persist the block from the RamDisk to Disk.</summary> /// <exception cref="System.IO.IOException"/> internal virtual void SubmitLazyPersistTask(string bpId, long blockId, long genStamp , long creationTime, FilePath metaFile, FilePath blockFile, FsVolumeReference target ) { if (Log.IsDebugEnabled()) { Log.Debug("LazyWriter schedule async task to persist RamDisk block pool id: " + bpId + " block id: " + blockId); } FsVolumeImpl volume = (FsVolumeImpl)target.GetVolume(); FilePath lazyPersistDir = volume.GetLazyPersistDir(bpId); if (!lazyPersistDir.Exists() && !lazyPersistDir.Mkdirs()) { FsDatasetImpl.Log.Warn("LazyWriter failed to create " + lazyPersistDir); throw new IOException("LazyWriter fail to find or create lazy persist dir: " + lazyPersistDir .ToString()); } RamDiskAsyncLazyPersistService.ReplicaLazyPersistTask lazyPersistTask = new RamDiskAsyncLazyPersistService.ReplicaLazyPersistTask (this, bpId, blockId, genStamp, creationTime, blockFile, metaFile, target, lazyPersistDir ); Execute(volume.GetCurrentDir(), lazyPersistTask); }
/// <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)); }
// Wait until the test times out. /// <exception cref="System.Exception"/> public virtual void TestRBWFileCreationError() { short replication = 1; StartCluster(BlockSize, replication, -1); FsVolumeImpl fsVolumeImpl = (FsVolumeImpl)cluster.GetDataNodes()[0].GetFSDataset( ).GetVolumes()[0]; string methodName = GenericTestUtils.GetMethodName(); Path file = new Path("/" + methodName + ".01.dat"); // Mock BlockPoolSlice so that RBW file creation gives IOExcception BlockPoolSlice blockPoolSlice = Org.Mockito.Mockito.Mock <BlockPoolSlice>(); Org.Mockito.Mockito.When(blockPoolSlice.CreateRbwFile((Block)Org.Mockito.Mockito. Any())).ThenThrow(new IOException("Synthetic IO Exception Throgh MOCK")); FieldInfo field = Sharpen.Runtime.GetDeclaredField(typeof(FsVolumeImpl), "bpSlices" ); IDictionary <string, BlockPoolSlice> bpSlices = (IDictionary <string, BlockPoolSlice >)field.GetValue(fsVolumeImpl); bpSlices[fsVolumeImpl.GetBlockPoolList()[0]] = blockPoolSlice; try { // Write 1 byte to the file FSDataOutputStream os = fs.Create(file, replication); os.Write(new byte[1]); os.Hsync(); os.Close(); NUnit.Framework.Assert.Fail("Expecting IOException file creation failure"); } catch (IOException) { } // Exception can be ignored (expected) // Ensure RBW space reserved is released NUnit.Framework.Assert.IsTrue("Expected ZERO but got " + fsVolumeImpl.GetReservedForRbw (), fsVolumeImpl.GetReservedForRbw() == 0); }
/// <summary>Dynamically remove volume in the list.</summary> /// <param name="volume">the volume to be removed.</param> /// <param name="clearFailure">set true to remove failure info for this volume.</param> internal virtual void RemoveVolume(FilePath volume, bool clearFailure) { // Make a copy of volumes to remove one volume. FsVolumeImpl[] curVolumes = volumes.Get(); IList <FsVolumeImpl> volumeList = Lists.NewArrayList(curVolumes); for (IEnumerator <FsVolumeImpl> it = volumeList.GetEnumerator(); it.HasNext();) { FsVolumeImpl fsVolume = it.Next(); string basePath; string targetPath; basePath = new FilePath(fsVolume.GetBasePath()).GetAbsolutePath(); targetPath = volume.GetAbsolutePath(); if (basePath.Equals(targetPath)) { // Make sure the removed volume is the one in the curVolumes. RemoveVolume(fsVolume); } } if (clearFailure) { RemoveVolumeFailureInfo(volume); } }
/// <exception cref="Sharpen.ClosedChannelException"/> internal FsVolumeReferenceImpl(FsVolumeImpl volume) { this.volume = volume; volume.Reference(); }
private void AddVolumeFailureInfo(FsVolumeImpl vol) { AddVolumeFailureInfo(new VolumeFailureInfo(new FilePath(vol.GetBasePath()).GetAbsolutePath (), Time.Now(), vol.GetCapacity())); }