コード例 #1
0
        public virtual void TestShortCircuitCacheShutdown()
        {
            TemporarySocketDirectory sockDir = new TemporarySocketDirectory();
            Configuration            conf    = CreateShortCircuitConf("testShortCircuitCacheShutdown", sockDir
                                                                      );

            conf.Set(DFSConfigKeys.DfsClientContext, "testShortCircuitCacheShutdown");
            Configuration serverConf = new Configuration(conf);

            DFSInputStream.tcpReadsDisabledForTesting = true;
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(serverConf).NumDataNodes(1).Build
                                         ();

            cluster.WaitActive();
            DistributedFileSystem fs = (DistributedFileSystem)FileSystem.Get(cluster.GetURI(0
                                                                                            ), conf);
            string TestFile    = "/test_file";
            int    TestFileLen = 4000;
            int    Seed        = unchecked ((int)(0xFADEC));

            DFSTestUtil.CreateFile(fs, new Path(TestFile), TestFileLen, (short)1, Seed);
            byte[] contents = DFSTestUtil.ReadFileBuffer(fs, new Path(TestFile));
            byte[] expected = DFSTestUtil.CalculateFileContentsFromSeed(Seed, TestFileLen);
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(contents, expected));
            ShortCircuitCache cache = fs.dfs.GetClientContext().GetShortCircuitCache();

            cache.Close();
            NUnit.Framework.Assert.IsTrue(cache.GetDfsClientShmManager().GetDomainSocketWatcher
                                              ().IsClosed());
            cluster.Shutdown();
            sockDir.Close();
        }
コード例 #2
0
        /// <summary>
        /// If we have a UNIX domain socket configured,
        /// and we have dfs.client.domain.socket.data.traffic set to true,
        /// and short-circuit access fails, we should still be able to pass
        /// data traffic over the UNIX domain socket.
        /// </summary>
        /// <remarks>
        /// If we have a UNIX domain socket configured,
        /// and we have dfs.client.domain.socket.data.traffic set to true,
        /// and short-circuit access fails, we should still be able to pass
        /// data traffic over the UNIX domain socket.  Test this.
        /// </remarks>
        /// <exception cref="System.Exception"/>
        public virtual void TestFallbackFromShortCircuitToUnixDomainTraffic()
        {
            DFSInputStream.tcpReadsDisabledForTesting = true;
            TemporarySocketDirectory sockDir = new TemporarySocketDirectory();
            // The server is NOT configured with short-circuit local reads;
            // the client is.  Both support UNIX domain reads.
            Configuration clientConf = CreateShortCircuitConf("testFallbackFromShortCircuitToUnixDomainTraffic"
                                                              , sockDir);

            clientConf.Set(DFSConfigKeys.DfsClientContext, "testFallbackFromShortCircuitToUnixDomainTraffic_clientContext"
                           );
            clientConf.SetBoolean(DFSConfigKeys.DfsClientDomainSocketDataTraffic, true);
            Configuration serverConf = new Configuration(clientConf);

            serverConf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitKey, false);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(serverConf).NumDataNodes(1).Build
                                         ();

            cluster.WaitActive();
            FileSystem dfs         = FileSystem.Get(cluster.GetURI(0), clientConf);
            string     TestFile    = "/test_file";
            int        TestFileLen = 8193;
            int        Seed        = unchecked ((int)(0xFADED));

            DFSTestUtil.CreateFile(dfs, new Path(TestFile), TestFileLen, (short)1, Seed);
            byte[] contents = DFSTestUtil.ReadFileBuffer(dfs, new Path(TestFile));
            byte[] expected = DFSTestUtil.CalculateFileContentsFromSeed(Seed, TestFileLen);
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(contents, expected));
            cluster.Shutdown();
            sockDir.Close();
        }
コード例 #3
0
 public void Run()
 {
     try
     {
         byte[] contents = DFSTestUtil.ReadFileBuffer(dfs, new Path(TestFile));
         NUnit.Framework.Assert.IsFalse(creationIsBlocked.Get());
         byte[] expected = DFSTestUtil.CalculateFileContentsFromSeed(Seed, TestFileLen);
         NUnit.Framework.Assert.IsTrue(Arrays.Equals(contents, expected));
     }
     catch (Exception e)
     {
         TestBlockReaderFactory.Log.Error("readerRunnable error", e);
         testFailed.Set(true);
     }
 }
コード例 #4
0
        /// <summary>Test unlinking a file whose blocks we are caching in the DFSClient.</summary>
        /// <remarks>
        /// Test unlinking a file whose blocks we are caching in the DFSClient.
        /// The DataNode will notify the DFSClient that the replica is stale via the
        /// ShortCircuitShm.
        /// </remarks>
        /// <exception cref="System.Exception"/>
        public virtual void TestUnlinkingReplicasInFileDescriptorCache()
        {
            BlockReaderTestUtil.EnableShortCircuitShmTracing();
            TemporarySocketDirectory sockDir = new TemporarySocketDirectory();
            Configuration            conf    = CreateShortCircuitConf("testUnlinkingReplicasInFileDescriptorCache"
                                                                      , sockDir);

            // We don't want the CacheCleaner to time out short-circuit shared memory
            // segments during the test, so set the timeout really high.
            conf.SetLong(DFSConfigKeys.DfsClientReadShortcircuitStreamsCacheExpiryMsKey, 1000000000L
                         );
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();

            cluster.WaitActive();
            DistributedFileSystem fs    = cluster.GetFileSystem();
            ShortCircuitCache     cache = fs.GetClient().GetClientContext().GetShortCircuitCache(
                );

            cache.GetDfsClientShmManager().Visit(new _Visitor_556());
            // The ClientShmManager starts off empty.
            Path TestPath    = new Path("/test_file");
            int  TestFileLen = 8193;
            int  Seed        = unchecked ((int)(0xFADE0));

            DFSTestUtil.CreateFile(fs, TestPath, TestFileLen, (short)1, Seed);
            byte[] contents = DFSTestUtil.ReadFileBuffer(fs, TestPath);
            byte[] expected = DFSTestUtil.CalculateFileContentsFromSeed(Seed, TestFileLen);
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(contents, expected));
            // Loading this file brought the ShortCircuitReplica into our local
            // replica cache.
            DatanodeInfo datanode = new DatanodeInfo(cluster.GetDataNodes()[0].GetDatanodeId(
                                                         ));

            cache.GetDfsClientShmManager().Visit(new _Visitor_577(datanode));
            // Remove the file whose blocks we just read.
            fs.Delete(TestPath, false);
            // Wait for the replica to be purged from the DFSClient's cache.
            GenericTestUtils.WaitFor(new _Supplier_593(this, cache, datanode), 10, 60000);
            // Check that all slots have been invalidated.
            cluster.Shutdown();
            sockDir.Close();
        }
コード例 #5
0
        /// <summary>
        /// Support for layout version change with rolling upgrade was
        /// added by HDFS-6800 and HDFS-6981.
        /// </summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestWithLayoutChangeAndRollback()
        {
            long seed = unchecked ((int)(0x600DF00D));

            try
            {
                StartCluster();
                Path[]     paths      = new Path[3];
                FilePath[] blockFiles = new FilePath[3];
                // Create two files in DFS.
                for (int i = 0; i < 2; ++i)
                {
                    paths[i] = new Path("/" + GenericTestUtils.GetMethodName() + "." + i + ".dat");
                    DFSTestUtil.CreateFile(fs, paths[i], BlockSize, (short)1, seed);
                }
                StartRollingUpgrade();
                // Delete the first file. The DN will save its block files in trash.
                blockFiles[0] = GetBlockForFile(paths[0], true);
                FilePath trashFile0 = GetTrashFileForBlock(blockFiles[0], false);
                DeleteAndEnsureInTrash(paths[0], blockFiles[0], trashFile0);
                // Restart the DN with a new layout version to trigger layout upgrade.
                Log.Info("Shutting down the Datanode");
                MiniDFSCluster.DataNodeProperties dnprop = cluster.StopDataNode(0);
                DFSTestUtil.AddDataNodeLayoutVersion(DataNodeLayoutVersion.CurrentLayoutVersion -
                                                     1, "Test Layout for TestDataNodeRollingUpgrade");
                Log.Info("Restarting the DataNode");
                cluster.RestartDataNode(dnprop, true);
                cluster.WaitActive();
                dn0 = cluster.GetDataNodes()[0];
                Log.Info("The DN has been restarted");
                NUnit.Framework.Assert.IsFalse(trashFile0.Exists());
                NUnit.Framework.Assert.IsFalse(dn0.GetStorage().GetBPStorage(blockPoolId).IsTrashAllowed
                                                   (blockFiles[0]));
                // Ensure that the block file for the first file was moved from 'trash' to 'previous'.
                NUnit.Framework.Assert.IsTrue(IsBlockFileInPrevious(blockFiles[0]));
                NUnit.Framework.Assert.IsFalse(IsTrashRootPresent());
                // Delete the second file. Ensure that its block file is in previous.
                blockFiles[1] = GetBlockForFile(paths[1], true);
                fs.Delete(paths[1], false);
                NUnit.Framework.Assert.IsTrue(IsBlockFileInPrevious(blockFiles[1]));
                NUnit.Framework.Assert.IsFalse(IsTrashRootPresent());
                // Create and delete a third file. Its block file should not be
                // in either trash or previous after deletion.
                paths[2] = new Path("/" + GenericTestUtils.GetMethodName() + ".2.dat");
                DFSTestUtil.CreateFile(fs, paths[2], BlockSize, (short)1, seed);
                blockFiles[2] = GetBlockForFile(paths[2], true);
                fs.Delete(paths[2], false);
                NUnit.Framework.Assert.IsFalse(IsBlockFileInPrevious(blockFiles[2]));
                NUnit.Framework.Assert.IsFalse(IsTrashRootPresent());
                // Rollback and ensure that the first two file contents were restored.
                RollbackRollingUpgrade();
                for (int i_1 = 0; i_1 < 2; ++i_1)
                {
                    byte[] actual     = DFSTestUtil.ReadFileBuffer(fs, paths[i_1]);
                    byte[] calculated = DFSTestUtil.CalculateFileContentsFromSeed(seed, BlockSize);
                    Assert.AssertArrayEquals(actual, calculated);
                }
                // And none of the block files must be in previous or trash.
                NUnit.Framework.Assert.IsFalse(IsTrashRootPresent());
                for (int i_2 = 0; i_2 < 3; ++i_2)
                {
                    NUnit.Framework.Assert.IsFalse(IsBlockFileInPrevious(blockFiles[i_2]));
                }
            }
            finally
            {
                ShutdownCluster();
            }
        }
コード例 #6
0
        /// <summary>
        /// When an InterruptedException is sent to a thread calling
        /// FileChannel#read, the FileChannel is immediately closed and the
        /// thread gets an exception.
        /// </summary>
        /// <remarks>
        /// When an InterruptedException is sent to a thread calling
        /// FileChannel#read, the FileChannel is immediately closed and the
        /// thread gets an exception.  This effectively means that we might have
        /// someone asynchronously calling close() on the file descriptors we use
        /// in BlockReaderLocal.  So when unreferencing a ShortCircuitReplica in
        /// ShortCircuitCache#unref, we should check if the FileChannel objects
        /// are still open.  If not, we should purge the replica to avoid giving
        /// it out to any future readers.
        /// This is a regression test for HDFS-6227: Short circuit read failed
        /// due to ClosedChannelException.
        /// Note that you may still get ClosedChannelException errors if two threads
        /// are reading from the same replica and an InterruptedException is delivered
        /// to one of them.
        /// </remarks>
        /// <exception cref="System.Exception"/>
        public virtual void TestPurgingClosedReplicas()
        {
            BlockReaderTestUtil.EnableBlockReaderFactoryTracing();
            AtomicInteger replicasCreated = new AtomicInteger(0);
            AtomicBoolean testFailed      = new AtomicBoolean(false);

            DFSInputStream.tcpReadsDisabledForTesting = true;
            BlockReaderFactory.createShortCircuitReplicaInfoCallback = new _ShortCircuitReplicaCreator_443
                                                                           (replicasCreated);
            TemporarySocketDirectory sockDir = new TemporarySocketDirectory();
            Configuration            conf    = CreateShortCircuitConf("testPurgingClosedReplicas", sockDir);
            MiniDFSCluster           cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();

            cluster.WaitActive();
            DistributedFileSystem dfs = cluster.GetFileSystem();
            string TestFile           = "/test_file";
            int    TestFileLen        = 4095;
            int    Seed = unchecked ((int)(0xFADE0));
            DistributedFileSystem fs = (DistributedFileSystem)FileSystem.Get(cluster.GetURI(0
                                                                                            ), conf);

            DFSTestUtil.CreateFile(fs, new Path(TestFile), TestFileLen, (short)1, Seed);
            Semaphore            sem           = Sharpen.Extensions.CreateSemaphore(0);
            IList <LocatedBlock> locatedBlocks = cluster.GetNameNode().GetRpcServer().GetBlockLocations
                                                     (TestFile, 0, TestFileLen).GetLocatedBlocks();
            LocatedBlock lblock = locatedBlocks[0];

            // first block
            byte[]   buf            = new byte[TestFileLen];
            Runnable readerRunnable = new _Runnable_471(cluster, lblock, TestFileLen, sem, buf
                                                        , testFailed);

            Sharpen.Thread thread = new Sharpen.Thread(readerRunnable);
            thread.Start();
            // While the thread is reading, send it interrupts.
            // These should trigger a ClosedChannelException.
            while (thread.IsAlive())
            {
                sem.AcquireUninterruptibly();
                thread.Interrupt();
                sem.Release();
            }
            NUnit.Framework.Assert.IsFalse(testFailed.Get());
            // We should be able to read from the file without
            // getting a ClosedChannelException.
            BlockReader blockReader = null;

            try
            {
                blockReader = BlockReaderTestUtil.GetBlockReader(cluster, lblock, 0, TestFileLen);
                blockReader.ReadFully(buf, 0, TestFileLen);
            }
            finally
            {
                if (blockReader != null)
                {
                    blockReader.Close();
                }
            }
            byte[] expected = DFSTestUtil.CalculateFileContentsFromSeed(Seed, TestFileLen);
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(buf, expected));
            // Another ShortCircuitReplica object should have been created.
            NUnit.Framework.Assert.AreEqual(2, replicasCreated.Get());
            dfs.Close();
            cluster.Shutdown();
            sockDir.Close();
        }
コード例 #7
0
 /// <exception cref="System.IO.IOException"/>
 protected internal bool VerifyReadRandomFile(Path path, int fileLength, int seed)
 {
     byte[] contents = DFSTestUtil.ReadFileBuffer(fs, path);
     byte[] expected = DFSTestUtil.CalculateFileContentsFromSeed(seed, fileLength);
     return(Arrays.Equals(contents, expected));
 }
コード例 #8
0
        /// <summary>
        /// Test that we can zero-copy read cached data even without disabling
        /// checksums.
        /// </summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestZeroCopyReadOfCachedData()
        {
            BlockReaderTestUtil.EnableShortCircuitShmTracing();
            BlockReaderTestUtil.EnableBlockReaderFactoryTracing();
            BlockReaderTestUtil.EnableHdfsCachingTracing();
            int  TestFileLength    = BlockSize;
            Path TestPath          = new Path("/a");
            int  RandomSeed        = 23453;
            HdfsConfiguration conf = InitZeroCopyTest();

            conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitSkipChecksumKey, false);
            string Context = "testZeroCopyReadOfCachedData";

            conf.Set(DFSConfigKeys.DfsClientContext, Context);
            conf.SetLong(DFSConfigKeys.DfsDatanodeMaxLockedMemoryKey, DFSTestUtil.RoundUpToMultiple
                             (TestFileLength, (int)NativeIO.POSIX.GetCacheManipulator().GetOperatingSystemPageSize
                                 ()));
            MiniDFSCluster cluster = null;
            ByteBuffer     result  = null;
            ByteBuffer     result2 = null;

            cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();
            cluster.WaitActive();
            FsDatasetSpi <object> fsd = cluster.GetDataNodes()[0].GetFSDataset();
            DistributedFileSystem fs  = cluster.GetFileSystem();

            DFSTestUtil.CreateFile(fs, TestPath, TestFileLength, (short)1, RandomSeed);
            DFSTestUtil.WaitReplication(fs, TestPath, (short)1);
            byte[] original = DFSTestUtil.CalculateFileContentsFromSeed(RandomSeed, TestFileLength
                                                                        );
            // Prior to caching, the file can't be read via zero-copy
            FSDataInputStream fsIn = fs.Open(TestPath);

            try
            {
                result = fsIn.Read(null, TestFileLength / 2, EnumSet.NoneOf <ReadOption>());
                NUnit.Framework.Assert.Fail("expected UnsupportedOperationException");
            }
            catch (NotSupportedException)
            {
            }
            // expected
            // Cache the file
            fs.AddCachePool(new CachePoolInfo("pool1"));
            long directiveId = fs.AddCacheDirective(new CacheDirectiveInfo.Builder().SetPath(
                                                        TestPath).SetReplication((short)1).SetPool("pool1").Build());
            int numBlocks = (int)Math.Ceil((double)TestFileLength / BlockSize);

            DFSTestUtil.VerifyExpectedCacheUsage(DFSTestUtil.RoundUpToMultiple(TestFileLength
                                                                               , BlockSize), numBlocks, cluster.GetDataNodes()[0].GetFSDataset());
            try
            {
                result = fsIn.Read(null, TestFileLength, EnumSet.NoneOf <ReadOption>());
            }
            catch (NotSupportedException)
            {
                NUnit.Framework.Assert.Fail("expected to be able to read cached file via zero-copy"
                                            );
            }
            Assert.AssertArrayEquals(Arrays.CopyOfRange(original, 0, BlockSize), ByteBufferToArray
                                         (result));
            // Test that files opened after the cache operation has finished
            // still get the benefits of zero-copy (regression test for HDFS-6086)
            FSDataInputStream fsIn2 = fs.Open(TestPath);

            try
            {
                result2 = fsIn2.Read(null, TestFileLength, EnumSet.NoneOf <ReadOption>());
            }
            catch (NotSupportedException)
            {
                NUnit.Framework.Assert.Fail("expected to be able to read cached file via zero-copy"
                                            );
            }
            Assert.AssertArrayEquals(Arrays.CopyOfRange(original, 0, BlockSize), ByteBufferToArray
                                         (result2));
            fsIn2.ReleaseBuffer(result2);
            fsIn2.Close();
            // check that the replica is anchored
            ExtendedBlock     firstBlock = DFSTestUtil.GetFirstBlock(fs, TestPath);
            ShortCircuitCache cache      = ClientContext.Get(Context, new DFSClient.Conf(conf)).GetShortCircuitCache
                                               ();

            WaitForReplicaAnchorStatus(cache, firstBlock, true, true, 1);
            // Uncache the replica
            fs.RemoveCacheDirective(directiveId);
            WaitForReplicaAnchorStatus(cache, firstBlock, false, true, 1);
            fsIn.ReleaseBuffer(result);
            WaitForReplicaAnchorStatus(cache, firstBlock, false, false, 1);
            DFSTestUtil.VerifyExpectedCacheUsage(0, 0, fsd);
            fsIn.Close();
            fs.Close();
            cluster.Shutdown();
        }