public virtual void TestConcurrentRead() { StartUpCluster(true, 2); string MethodName = GenericTestUtils.GetMethodName(); Path path1 = new Path("/" + MethodName + ".dat"); int Seed = unchecked ((int)(0xFADED)); int NumTasks = 5; MakeRandomTestFile(path1, BlockSize, true, Seed); EnsureFileReplicasOnStorageType(path1, StorageType.RamDisk); //Read from multiple clients CountDownLatch latch = new CountDownLatch(NumTasks); AtomicBoolean testFailed = new AtomicBoolean(false); Runnable readerRunnable = new _Runnable_564(this, path1, Seed, testFailed, latch); Sharpen.Thread[] threads = new Sharpen.Thread[NumTasks]; for (int i = 0; i < NumTasks; i++) { threads[i] = new Sharpen.Thread(readerRunnable); threads[i].Start(); } Sharpen.Thread.Sleep(500); for (int i_1 = 0; i_1 < NumTasks; i_1++) { Uninterruptibles.JoinUninterruptibly(threads[i_1]); } NUnit.Framework.Assert.IsFalse(testFailed.Get()); }
/// <summary> /// Waits uninterruptibly for <paramref name="new_value"/> to be loaded. /// </summary> /// <param name="key">The key associated with the laoding value.</param> /// <param name="loading_value_reference"></param> /// <param name="new_value"></param> /// <returns></returns> T GetUninterruptibly(string key, LoadingValueReference <T> loading_value_reference, IFuture <T> new_value) { T value = default(T); try { value = Uninterruptibles.GetUninterruptibly(new_value); // Cache loader should never returns null for reference types. if (IsNull(value)) { throw new InvalidCacheLoadException( "CacheLoader returned a null for key " + key + "."); } // TODO(neylor.silva): Record load success stats. StoreLoadedValue(key, loading_value_reference, value); return(value); } finally { if (IsNull(value)) { // TODO(neylor.silva): Record load exception stats. RemoveLoadingValue(key, loading_value_reference); } } }
//fc should be set appropriately by the deriving test. /// <exception cref="System.Exception"/> public virtual void TestStatisticsOperations() { FileSystem.Statistics stats = new FileSystem.Statistics("file"); Assert.Equal(0L, stats.GetBytesRead()); Assert.Equal(0L, stats.GetBytesWritten()); Assert.Equal(0, stats.GetWriteOps()); stats.IncrementBytesWritten(1000); Assert.Equal(1000L, stats.GetBytesWritten()); Assert.Equal(0, stats.GetWriteOps()); stats.IncrementWriteOps(123); Assert.Equal(123, stats.GetWriteOps()); Thread thread = new _Thread_61(stats); thread.Start(); Uninterruptibles.JoinUninterruptibly(thread); Assert.Equal(124, stats.GetWriteOps()); // Test copy constructor and reset function FileSystem.Statistics stats2 = new FileSystem.Statistics(stats); stats.Reset(); Assert.Equal(0, stats.GetWriteOps()); Assert.Equal(0L, stats.GetBytesWritten()); Assert.Equal(0L, stats.GetBytesRead()); Assert.Equal(124, stats2.GetWriteOps()); Assert.Equal(1000L, stats2.GetBytesWritten()); Assert.Equal(0L, stats2.GetBytesRead()); }
/// <summary>Close the DomainSocketWatcher and wait for its thread to terminate.</summary> /// <remarks> /// Close the DomainSocketWatcher and wait for its thread to terminate. /// If there is more than one close, all but the first will be ignored. /// </remarks> /// <exception cref="System.IO.IOException"/> public void Close() { Lock.Lock(); try { if (closed) { return; } if (Log.IsDebugEnabled()) { Log.Debug(this + ": closing"); } closed = true; } finally { Lock.Unlock(); } // Close notificationSockets[0], so that notificationSockets[1] gets an EOF // event. This will wake up the thread immediately if it is blocked inside // the select() system call. notificationSockets[0].Close(); // Wait for the select thread to terminate. Uninterruptibles.JoinUninterruptibly(watcherThread); }
/// <summary> /// Run a set of threads making changes to the deprecations /// concurrently with another set of threads calling get() /// and set() on Configuration objects. /// </summary> /// <exception cref="System.Exception"/> public virtual void TestConcurrentDeprecateAndManipulate() { int NumThreadIds = 10; int NumKeysPerThread = 1000; ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2 * NumThreadIds , new ThreadFactoryBuilder().SetDaemon(true).SetNameFormat("testConcurrentDeprecateAndManipulate modification thread %d" ).Build()); CountDownLatch latch = new CountDownLatch(1); AtomicInteger highestModificationThreadId = new AtomicInteger(1); IList <Future <Void> > futures = new List <Future <Void> >(); for (int i = 0; i < NumThreadIds; i++) { futures.AddItem(executor.Schedule(new _Callable_363(latch, highestModificationThreadId , NumKeysPerThread), 0, TimeUnit.Seconds)); } AtomicInteger highestAccessThreadId = new AtomicInteger(1); for (int i_1 = 0; i_1 < NumThreadIds; i_1++) { futures.AddItem(executor.Schedule(new _Callable_382(latch, highestAccessThreadId, NumKeysPerThread), 0, TimeUnit.Seconds)); } latch.CountDown(); // allow all threads to proceed foreach (Future <Void> future in futures) { Uninterruptibles.GetUninterruptibly(future); } }
/// <summary> /// Test that transitioning a service to the state that it is already /// in is a nop, specifically, an exception is not thrown. /// </summary> /// <exception cref="System.Exception"/> public virtual void TestTransitionToCurrentStateIsANop() { Configuration conf = new Configuration(); conf.SetLong(DFSConfigKeys.DfsNamenodePathBasedCacheRefreshIntervalMs, 1L); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NnTopology(MiniDFSNNTopology .SimpleHATopology()).NumDataNodes(1).Build(); List <Sharpen.Thread> crmThreads = new List <Sharpen.Thread>(); try { cluster.WaitActive(); AddCrmThreads(cluster, crmThreads); cluster.TransitionToActive(0); AddCrmThreads(cluster, crmThreads); cluster.TransitionToActive(0); AddCrmThreads(cluster, crmThreads); cluster.TransitionToStandby(0); AddCrmThreads(cluster, crmThreads); cluster.TransitionToStandby(0); AddCrmThreads(cluster, crmThreads); } finally { cluster.Shutdown(); } // Verify that all cacheReplicationMonitor threads shut down foreach (Sharpen.Thread thread in crmThreads) { Uninterruptibles.JoinUninterruptibly(thread); } }
/// <summary>Test that a java interruption can stop the watcher thread</summary> /// <exception cref="System.Exception"/> public virtual void TestInterruption() { DomainSocketWatcher watcher = NewDomainSocketWatcher(10); watcher.watcherThread.Interrupt(); Uninterruptibles.JoinUninterruptibly(watcher.watcherThread); watcher.Close(); }
public ShortCircuitReplicaInfo CreateShortCircuitReplicaInfo() { if (replicaCreationShouldFail.Get()) { Uninterruptibles.SleepUninterruptibly(2, TimeUnit.Seconds); return(new ShortCircuitReplicaInfo()); } return(null); }
public virtual void TestLastContactTime() { Configuration conf = new Configuration(); conf.SetInt(DFSConfigKeys.DfsHeartbeatIntervalKey, 1); conf.SetInt(DFSConfigKeys.DfsNamenodeHeartbeatRecheckIntervalKey, 1); MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(3).Build(); cluster.WaitActive(); FSNamesystem fsn = cluster.GetNameNode().namesystem; MBeanServer mbs = ManagementFactory.GetPlatformMBeanServer(); ObjectName mxbeanName = new ObjectName("Hadoop:service=NameNode,name=NameNodeInfo" ); // Define include file to generate deadNodes metrics FileSystem localFileSys = FileSystem.GetLocal(conf); Path workingDir = localFileSys.GetWorkingDirectory(); Path dir = new Path(workingDir, "build/test/data/temp/TestNameNodeMXBean"); Path includeFile = new Path(dir, "include"); NUnit.Framework.Assert.IsTrue(localFileSys.Mkdirs(dir)); StringBuilder includeHosts = new StringBuilder(); foreach (DataNode dn in cluster.GetDataNodes()) { includeHosts.Append(dn.GetDisplayName()).Append("\n"); } DFSTestUtil.WriteFile(localFileSys, includeFile, includeHosts.ToString()); conf.Set(DFSConfigKeys.DfsHosts, includeFile.ToUri().GetPath()); fsn.GetBlockManager().GetDatanodeManager().RefreshNodes(conf); cluster.StopDataNode(0); while (fsn.GetBlockManager().GetDatanodeManager().GetNumLiveDataNodes() != 2) { Uninterruptibles.SleepUninterruptibly(1, TimeUnit.Seconds); } // get attribute deadnodeinfo string deadnodeinfo = (string)(mbs.GetAttribute(mxbeanName, "DeadNodes")); NUnit.Framework.Assert.AreEqual(fsn.GetDeadNodes(), deadnodeinfo); IDictionary <string, IDictionary <string, object> > deadNodes = (IDictionary <string, IDictionary <string, object> >)JSON.Parse(deadnodeinfo); NUnit.Framework.Assert.IsTrue(deadNodes.Count > 0); foreach (IDictionary <string, object> deadNode in deadNodes.Values) { NUnit.Framework.Assert.IsTrue(deadNode.Contains("lastContact")); NUnit.Framework.Assert.IsTrue(deadNode.Contains("decommissioned")); NUnit.Framework.Assert.IsTrue(deadNode.Contains("xferaddr")); } } finally { if (cluster != null) { cluster.Shutdown(); } } }
public ShortCircuitReplicaInfo CreateShortCircuitReplicaInfo() { Uninterruptibles.AwaitUninterruptibly(latch); if (!creationIsBlocked.CompareAndSet(true, false)) { NUnit.Framework.Assert.Fail("there were multiple calls to " + "createShortCircuitReplicaInfo. Only one was expected." ); } return(null); }
/// <summary>Test that domain sockets are closed when the watcher is closed.</summary> /// <exception cref="System.Exception"/> public virtual void TestCloseSocketOnWatcherClose() { DomainSocketWatcher watcher = NewDomainSocketWatcher(10000000); DomainSocket[] pair = DomainSocket.Socketpair(); watcher.Add(pair[1], new _Handler_103()); watcher.Close(); Uninterruptibles.JoinUninterruptibly(watcher.watcherThread); NUnit.Framework.Assert.IsFalse(pair[1].IsOpen()); }
/// <summary> /// Test the case where we have a failure to complete a short circuit read /// that occurs, and then later on, we have a success. /// </summary> /// <remarks> /// Test the case where we have a failure to complete a short circuit read /// that occurs, and then later on, we have a success. /// Any thread waiting on a cache load should receive the failure (if it /// occurs); however, the failure result should not be cached. We want /// to be able to retry later and succeed. /// </remarks> /// <exception cref="System.Exception"/> public virtual void TestShortCircuitCacheTemporaryFailure() { BlockReaderTestUtil.EnableBlockReaderFactoryTracing(); AtomicBoolean replicaCreationShouldFail = new AtomicBoolean(true); AtomicBoolean testFailed = new AtomicBoolean(false); DFSInputStream.tcpReadsDisabledForTesting = true; BlockReaderFactory.createShortCircuitReplicaInfoCallback = new _ShortCircuitReplicaCreator_215 (replicaCreationShouldFail); // Insert a short delay to increase the chance that one client // thread waits for the other client thread's failure via // a condition variable. TemporarySocketDirectory sockDir = new TemporarySocketDirectory(); Configuration conf = CreateShortCircuitConf("testShortCircuitCacheTemporaryFailure" , sockDir); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build(); cluster.WaitActive(); DistributedFileSystem dfs = cluster.GetFileSystem(); string TestFile = "/test_file"; int TestFileLen = 4000; int NumThreads = 2; int Seed = unchecked ((int)(0xFADED)); CountDownLatch gotFailureLatch = new CountDownLatch(NumThreads); CountDownLatch shouldRetryLatch = new CountDownLatch(1); DFSTestUtil.CreateFile(dfs, new Path(TestFile), TestFileLen, (short)1, Seed); Runnable readerRunnable = new _Runnable_243(cluster, TestFile, TestFileLen, gotFailureLatch , shouldRetryLatch, testFailed); // First time should fail. // first block // keep findbugs happy // Second time should succeed. Sharpen.Thread[] threads = new Sharpen.Thread[NumThreads]; for (int i = 0; i < NumThreads; i++) { threads[i] = new Sharpen.Thread(readerRunnable); threads[i].Start(); } gotFailureLatch.Await(); replicaCreationShouldFail.Set(false); shouldRetryLatch.CountDown(); for (int i_1 = 0; i_1 < NumThreads; i_1++) { Uninterruptibles.JoinUninterruptibly(threads[i_1]); } cluster.Shutdown(); sockDir.Close(); NUnit.Framework.Assert.IsFalse(testFailed.Get()); }
/// <summary> /// Stops and removes all volume scanners.<p/> /// This function will block until all the volume scanners have stopped. /// </summary> public virtual void RemoveAllVolumeScanners() { lock (this) { foreach (KeyValuePair <string, VolumeScanner> entry in scanners) { entry.Value.Shutdown(); } foreach (KeyValuePair <string, VolumeScanner> entry_1 in scanners) { Uninterruptibles.JoinUninterruptibly(entry_1.Value, 5, TimeUnit.Minutes); } scanners.Clear(); } }
/// <exception cref="System.Exception"/> public virtual void TestStress() { int SocketNum = 250; ReentrantLock Lock = new ReentrantLock(); DomainSocketWatcher watcher = NewDomainSocketWatcher(10000000); AList <DomainSocket[]> pairs = new AList <DomainSocket[]>(); AtomicInteger handled = new AtomicInteger(0); Thread adderThread = new Thread(new _Runnable_122(SocketNum, watcher , Lock, pairs, handled)); Thread removerThread = new Thread(new _Runnable_149(handled, SocketNum , Lock, pairs, watcher)); adderThread.Start(); removerThread.Start(); Uninterruptibles.JoinUninterruptibly(adderThread); Uninterruptibles.JoinUninterruptibly(removerThread); watcher.Close(); }
/// <summary> /// Test the case where we have multiple threads waiting on the /// ShortCircuitCache delivering a certain ShortCircuitReplica. /// </summary> /// <remarks> /// Test the case where we have multiple threads waiting on the /// ShortCircuitCache delivering a certain ShortCircuitReplica. /// In this case, there should only be one call to /// createShortCircuitReplicaInfo. This one replica should be shared /// by all threads. /// </remarks> /// <exception cref="System.Exception"/> public virtual void TestMultipleWaitersOnShortCircuitCache() { CountDownLatch latch = new CountDownLatch(1); AtomicBoolean creationIsBlocked = new AtomicBoolean(true); AtomicBoolean testFailed = new AtomicBoolean(false); DFSInputStream.tcpReadsDisabledForTesting = true; BlockReaderFactory.createShortCircuitReplicaInfoCallback = new _ShortCircuitReplicaCreator_146 (latch, creationIsBlocked); TemporarySocketDirectory sockDir = new TemporarySocketDirectory(); Configuration conf = CreateShortCircuitConf("testMultipleWaitersOnShortCircuitCache" , sockDir); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build(); cluster.WaitActive(); DistributedFileSystem dfs = cluster.GetFileSystem(); string TestFile = "/test_file"; int TestFileLen = 4000; int Seed = unchecked ((int)(0xFADED)); int NumThreads = 10; DFSTestUtil.CreateFile(dfs, new Path(TestFile), TestFileLen, (short)1, Seed); Runnable readerRunnable = new _Runnable_170(dfs, TestFile, creationIsBlocked, Seed , TestFileLen, testFailed); Sharpen.Thread[] threads = new Sharpen.Thread[NumThreads]; for (int i = 0; i < NumThreads; i++) { threads[i] = new Sharpen.Thread(readerRunnable); threads[i].Start(); } Sharpen.Thread.Sleep(500); latch.CountDown(); for (int i_1 = 0; i_1 < NumThreads; i_1++) { Uninterruptibles.JoinUninterruptibly(threads[i_1]); } cluster.Shutdown(); sockDir.Close(); NUnit.Framework.Assert.IsFalse(testFailed.Get()); }
/// <summary> /// Stops and removes a volume scanner.<p/> /// This function will block until the volume scanner has stopped. /// </summary> /// <param name="volume">The volume to remove.</param> public virtual void RemoveVolumeScanner(FsVolumeSpi volume) { lock (this) { if (!IsEnabled()) { Log.Debug("Not removing volume scanner for {}, because the block " + "scanner is disabled." , volume.GetStorageID()); return; } VolumeScanner scanner = scanners[volume.GetStorageID()]; if (scanner == null) { Log.Warn("No scanner found to remove for volumeId {}", volume.GetStorageID()); return; } Log.Info("Removing scanner for volume {} (StorageID {})", volume.GetBasePath(), volume .GetStorageID()); scanner.Shutdown(); Sharpen.Collections.Remove(scanners, volume.GetStorageID()); Uninterruptibles.JoinUninterruptibly(scanner, 5, TimeUnit.Minutes); } }
public T WaitForValue() { return(Uninterruptibles.GetUninterruptibly(this)); }
/// <exception cref="System.IO.IOException"/> internal override int Run(IList <string> args) { if (args.Count == 0) { System.Console.Out.WriteLine(this.usageText); System.Console.Out.WriteLine(this.helpText + "\n"); return(1); } string pathStr = StringUtils.PopOptionWithArgument("-path", args); string retriesStr = StringUtils.PopOptionWithArgument("-retries", args); if (pathStr == null) { System.Console.Error.WriteLine("You must supply a -path argument to " + "recoverLease." ); return(1); } int maxRetries = 1; if (retriesStr != null) { try { maxRetries = System.Convert.ToInt32(retriesStr); } catch (FormatException e) { System.Console.Error.WriteLine("Failed to parse the argument to -retries: " + StringUtils .StringifyException(e)); return(1); } } FileSystem fs; try { fs = FileSystem.NewInstance(new URI(pathStr), this._enclosing.GetConf(), null); } catch (URISyntaxException e) { System.Console.Error.WriteLine("URISyntaxException for " + pathStr + ":" + StringUtils .StringifyException(e)); return(1); } catch (Exception e) { System.Console.Error.WriteLine("InterruptedException for " + pathStr + ":" + StringUtils .StringifyException(e)); return(1); } DistributedFileSystem dfs = null; try { dfs = (DistributedFileSystem)fs; } catch (InvalidCastException) { System.Console.Error.WriteLine("Invalid filesystem for path " + pathStr + ": " + "needed scheme hdfs, but got: " + fs.GetScheme()); return(1); } for (int retry = 0; true;) { bool recovered = false; IOException ioe = null; try { recovered = dfs.RecoverLease(new Path(pathStr)); } catch (IOException e) { ioe = e; } if (recovered) { System.Console.Out.WriteLine("recoverLease SUCCEEDED on " + pathStr); return(0); } if (ioe != null) { System.Console.Error.WriteLine("recoverLease got exception: "); Sharpen.Runtime.PrintStackTrace(ioe); } else { System.Console.Error.WriteLine("recoverLease returned false."); } retry++; if (retry >= maxRetries) { break; } System.Console.Error.WriteLine("Retrying in " + DebugAdmin.RecoverLeaseCommand.TimeoutMs + " ms..."); Uninterruptibles.SleepUninterruptibly(DebugAdmin.RecoverLeaseCommand.TimeoutMs, TimeUnit .Milliseconds); System.Console.Error.WriteLine("Retry #" + retry); } System.Console.Error.WriteLine("Giving up on recoverLease for " + pathStr + " after " + maxRetries + (maxRetries == 1 ? " try." : " tries.")); return(1); }