Exemple #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestFadviseSkippedForSmallReads()
        {
            // start a cluster
            Log.Info("testFadviseSkippedForSmallReads");
            tracker.Clear();
            Configuration conf = new HdfsConfiguration();

            conf.SetBoolean(DFSConfigKeys.DfsDatanodeDropCacheBehindReadsKey, true);
            conf.SetBoolean(DFSConfigKeys.DfsDatanodeDropCacheBehindWritesKey, true);
            MiniDFSCluster    cluster     = null;
            string            TestPath    = "/test";
            int               TestPathLen = MaxTestFileLen;
            FSDataInputStream fis         = null;

            try
            {
                cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();
                cluster.WaitActive();
                FileSystem fs = cluster.GetFileSystem();
                // create new file
                CreateHdfsFile(fs, new Path(TestPath), TestPathLen, null);
                // Since the DataNode was configured with drop-behind, and we didn't
                // specify any policy, we should have done drop-behind.
                ExtendedBlock block = cluster.GetNameNode().GetRpcServer().GetBlockLocations(TestPath
                                                                                             , 0, long.MaxValue).Get(0).GetBlock();
                string fadvisedFileName         = cluster.GetBlockFile(0, block).GetName();
                TestCachingStrategy.Stats stats = tracker.GetStats(fadvisedFileName);
                stats.AssertDroppedInRange(0, TestPathLen - WritePacketSize);
                stats.Clear();
                stats.AssertNotDroppedInRange(0, TestPathLen);
                // read file
                fis = fs.Open(new Path(TestPath));
                byte[] buf = new byte[17];
                fis.ReadFully(4096, buf, 0, buf.Length);
                // we should not have dropped anything because of the small read.
                stats = tracker.GetStats(fadvisedFileName);
                stats.AssertNotDroppedInRange(0, TestPathLen - WritePacketSize);
            }
            finally
            {
                IOUtils.Cleanup(null, fis);
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Test the scenario where the DataNode defaults to not dropping the cache,
        /// but our client defaults are set.
        /// </summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestClientDefaults()
        {
            // start a cluster
            Log.Info("testClientDefaults");
            tracker.Clear();
            Configuration conf = new HdfsConfiguration();

            conf.SetBoolean(DFSConfigKeys.DfsDatanodeDropCacheBehindReadsKey, false);
            conf.SetBoolean(DFSConfigKeys.DfsDatanodeDropCacheBehindWritesKey, false);
            conf.SetBoolean(DFSConfigKeys.DfsClientCacheDropBehindReads, true);
            conf.SetBoolean(DFSConfigKeys.DfsClientCacheDropBehindWrites, true);
            MiniDFSCluster cluster     = null;
            string         TestPath    = "/test";
            int            TestPathLen = MaxTestFileLen;

            try
            {
                cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();
                cluster.WaitActive();
                FileSystem fs = cluster.GetFileSystem();
                // create new file
                CreateHdfsFile(fs, new Path(TestPath), TestPathLen, null);
                // verify that we dropped everything from the cache during file creation.
                ExtendedBlock block = cluster.GetNameNode().GetRpcServer().GetBlockLocations(TestPath
                                                                                             , 0, long.MaxValue).Get(0).GetBlock();
                string fadvisedFileName         = cluster.GetBlockFile(0, block).GetName();
                TestCachingStrategy.Stats stats = tracker.GetStats(fadvisedFileName);
                stats.AssertDroppedInRange(0, TestPathLen - WritePacketSize);
                stats.Clear();
                // read file
                ReadHdfsFile(fs, new Path(TestPath), long.MaxValue, null);
                // verify that we dropped everything from the cache.
                NUnit.Framework.Assert.IsNotNull(stats);
                stats.AssertDroppedInRange(0, TestPathLen - WritePacketSize);
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Shutdown();
                }
            }
        }