Ejemplo n.º 1
0
        public virtual void TestHedgedReadLoopTooManyTimes()
        {
            Configuration conf = new Configuration();
            int           numHedgedReadPoolThreads = 5;
            int           hedgedReadTimeoutMillis  = 50;

            conf.SetInt(DFSConfigKeys.DfsDfsclientHedgedReadThreadpoolSize, numHedgedReadPoolThreads
                        );
            conf.SetLong(DFSConfigKeys.DfsDfsclientHedgedReadThresholdMillis, hedgedReadTimeoutMillis
                         );
            conf.SetInt(DFSConfigKeys.DfsClientRetryWindowBase, 0);
            // Set up the InjectionHandler
            DFSClientFaultInjector.instance = Org.Mockito.Mockito.Mock <DFSClientFaultInjector
                                                                        >();
            DFSClientFaultInjector injector = DFSClientFaultInjector.instance;
            int sleepMs = 100;

            Org.Mockito.Mockito.DoAnswer(new _Answer_296(hedgedReadTimeoutMillis, sleepMs)).When
                (injector).FetchFromDatanodeException();
            Org.Mockito.Mockito.DoAnswer(new _Answer_309(sleepMs)).When(injector).ReadFromDatanodeDelay
                ();
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(2).Format(
                true).Build();
            DistributedFileSystem fileSys   = cluster.GetFileSystem();
            DFSClient             dfsClient = fileSys.GetClient();
            FSDataOutputStream    output    = null;
            DFSInputStream        input     = null;
            string filename = "/hedgedReadMaxOut.dat";

            try
            {
                Path file = new Path(filename);
                output = fileSys.Create(file, (short)2);
                byte[] data = new byte[64 * 1024];
                output.Write(data);
                output.Flush();
                output.Write(data);
                output.Flush();
                output.Write(data);
                output.Flush();
                output.Close();
                byte[] buffer = new byte[64 * 1024];
                input = dfsClient.Open(filename);
                input.Read(0, buffer, 0, 1024);
                input.Close();
                NUnit.Framework.Assert.AreEqual(3, input.GetHedgedReadOpsLoopNumForTesting());
            }
            catch (BlockMissingException)
            {
                NUnit.Framework.Assert.IsTrue(false);
            }
            finally
            {
                Org.Mockito.Mockito.Reset(injector);
                IOUtils.Cleanup(null, input);
                IOUtils.Cleanup(null, output);
                fileSys.Close();
                cluster.Shutdown();
            }
        }
Ejemplo n.º 2
0
        public virtual void TestBlockTokenInLastLocatedBlock()
        {
            Configuration conf = new HdfsConfiguration();

            conf.SetBoolean(DFSConfigKeys.DfsBlockAccessTokenEnableKey, true);
            conf.SetInt(DFSConfigKeys.DfsBlockSizeKey, 512);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();

            cluster.WaitActive();
            try
            {
                FileSystem         fs       = cluster.GetFileSystem();
                string             fileName = "/testBlockTokenInLastLocatedBlock";
                Path               filePath = new Path(fileName);
                FSDataOutputStream @out     = fs.Create(filePath, (short)1);
                @out.Write(new byte[1000]);
                // ensure that the first block is written out (see FSOutputSummer#flush)
                @out.Flush();
                LocatedBlocks locatedBlocks = cluster.GetNameNodeRpc().GetBlockLocations(fileName
                                                                                         , 0, 1000);
                while (locatedBlocks.GetLastLocatedBlock() == null)
                {
                    Sharpen.Thread.Sleep(100);
                    locatedBlocks = cluster.GetNameNodeRpc().GetBlockLocations(fileName, 0, 1000);
                }
                Org.Apache.Hadoop.Security.Token.Token <BlockTokenIdentifier> token = locatedBlocks
                                                                                      .GetLastLocatedBlock().GetBlockToken();
                NUnit.Framework.Assert.AreEqual(BlockTokenIdentifier.KindName, token.GetKind());
                @out.Close();
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Ejemplo n.º 3
0
        public virtual void TestComplexFlush()
        {
            Configuration conf = new HdfsConfiguration();

            fileContents = AppendTestUtil.InitBuffer(AppendTestUtil.FileSize);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).Build();
            FileSystem     fs      = cluster.GetFileSystem();

            try
            {
                // create a new file.
                Path file1             = new Path("/complexFlush.dat");
                FSDataOutputStream stm = AppendTestUtil.CreateFile(fs, file1, 1);
                System.Console.Out.WriteLine("Created file complexFlush.dat");
                int start = 0;
                for (start = 0; (start + 29) < AppendTestUtil.FileSize;)
                {
                    stm.Write(fileContents, start, 29);
                    stm.Hflush();
                    start += 29;
                }
                stm.Write(fileContents, start, AppendTestUtil.FileSize - start);
                // need to make sure we completely write out all full blocks before
                // the checkFile() call (see FSOutputSummer#flush)
                stm.Flush();
                // verify that full blocks are sane
                CheckFile(fs, file1, 1);
                stm.Close();
                // verify that entire file is good
                AppendTestUtil.CheckFullFile(fs, file1, AppendTestUtil.FileSize, fileContents, "Read 2"
                                             );
            }
            catch (IOException e)
            {
                System.Console.Out.WriteLine("Exception :" + e);
                throw;
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine("Throwable :" + e);
                Sharpen.Runtime.PrintStackTrace(e);
                throw new IOException("Throwable : " + e);
            }
            finally
            {
                fs.Close();
                cluster.Shutdown();
            }
        }
Ejemplo n.º 4
0
 /// <exception cref="System.IO.IOException"/>
 public virtual void Close()
 {
     // When IFile writer is created by BackupStore, we do not have
     // Key and Value classes set. So, check before closing the
     // serializers
     if (keyClass != null)
     {
         keySerializer.Close();
         valueSerializer.Close();
     }
     // Write EOF_MARKER for key/value length
     WritableUtils.WriteVInt(@out, EofMarker);
     WritableUtils.WriteVInt(@out, EofMarker);
     decompressedBytesWritten += 2 * WritableUtils.GetVIntSize(EofMarker);
     //Flush the stream
     @out.Flush();
     if (compressOutput)
     {
         // Flush
         compressedOut.Finish();
         compressedOut.ResetState();
     }
     // Close the underlying stream iff we own it...
     if (ownOutputStream)
     {
         @out.Close();
     }
     else
     {
         // Write the checksum
         checksumOut.Finish();
     }
     compressedBytesWritten = rawOut.GetPos() - start;
     if (compressOutput)
     {
         // Return back the compressor
         CodecPool.ReturnCompressor(compressor);
         compressor = null;
     }
     @out = null;
     if (writtenRecordsCounter != null)
     {
         writtenRecordsCounter.Increment(numRecordsWritten);
     }
 }
Ejemplo n.º 5
0
        /// <exception cref="System.IO.IOException"/>
        private FSDataOutputStream WriteIncompleteFile(FileSystem fileSys, Path name, short
                                                       repl)
        {
            // create and write a file that contains three blocks of data
            FSDataOutputStream stm = fileSys.Create(name, true, fileSys.GetConf().GetInt(CommonConfigurationKeys
                                                                                         .IoFileBufferSizeKey, 4096), repl, blockSize);

            byte[] buffer = new byte[fileSize];
            Random rand   = new Random(seed);

            rand.NextBytes(buffer);
            stm.Write(buffer);
            // need to make sure that we actually write out both file blocks
            // (see FSOutputSummer#flush)
            stm.Flush();
            // Do not close stream, return it
            // so that it is not garbage collected
            return(stm);
        }
Ejemplo n.º 6
0
        /// <exception cref="System.IO.IOException"/>
        internal virtual void WriteFile(Path file, FSDataOutputStream stm, int size)
        {
            long blocksBefore = stm.GetPos() / BlockSize;

            TestFileCreation.WriteFile(stm, BlockSize);
            // need to make sure the full block is completely flushed to the DataNodes
            // (see FSOutputSummer#flush)
            stm.Flush();
            int blocksAfter = 0;

            // wait until the block is allocated by DataStreamer
            BlockLocation[] locatedBlocks;
            while (blocksAfter <= blocksBefore)
            {
                locatedBlocks = DFSClientAdapter.GetDFSClient(hdfs).GetBlockLocations(file.ToString
                                                                                          (), 0L, BlockSize * NumBlocks);
                blocksAfter = locatedBlocks == null ? 0 : locatedBlocks.Length;
            }
        }
Ejemplo n.º 7
0
 /// <exception cref="System.IO.IOException"/>
 internal virtual void Flush()
 {
     encoder.Flush();
     @out.Flush();
     @out.Hflush();
 }