Example #1
0
        /// <summary>close opened files.</summary>
        /// <exception cref="System.IO.IOException"/>
        public virtual void Close()
        {
            if (blockInFd != null && ((dropCacheBehindAllReads) || (dropCacheBehindLargeReads &&
                                                                    IsLongRead())))
            {
                try
                {
                    NativeIO.POSIX.GetCacheManipulator().PosixFadviseIfPossible(block.GetBlockName(),
                                                                                blockInFd, lastCacheDropOffset, offset - lastCacheDropOffset, NativeIO.POSIX.PosixFadvDontneed
                                                                                );
                }
                catch (Exception e)
                {
                    Log.Warn("Unable to drop cache on file close", e);
                }
            }
            if (curReadahead != null)
            {
                curReadahead.Cancel();
            }
            IOException ioe = null;

            if (checksumIn != null)
            {
                try
                {
                    checksumIn.Close();
                }
                catch (IOException e)
                {
                    // close checksum file
                    ioe = e;
                }
                checksumIn = null;
            }
            if (blockIn != null)
            {
                try
                {
                    blockIn.Close();
                }
                catch (IOException e)
                {
                    // close data file
                    ioe = e;
                }
                blockIn   = null;
                blockInFd = null;
            }
            if (volumeRef != null)
            {
                IOUtils.Cleanup(null, volumeRef);
                volumeRef = null;
            }
            // throw IOException if there is any
            if (ioe != null)
            {
                throw ioe;
            }
        }
        /// <summary>Create a file with one block and corrupt some/all of the block replicas.
        ///     </summary>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Apache.Hadoop.Security.AccessControlException"/>
        /// <exception cref="System.IO.FileNotFoundException"/>
        /// <exception cref="Org.Apache.Hadoop.FS.UnresolvedLinkException"/>
        /// <exception cref="System.Exception"/>
        /// <exception cref="Sharpen.TimeoutException"/>
        private void CreateAFileWithCorruptedBlockReplicas(Path filePath, short repl, int
                                                           corruptBlockCount)
        {
            DFSTestUtil.CreateFile(dfs, filePath, BlockSize, repl, 0);
            DFSTestUtil.WaitReplication(dfs, filePath, repl);
            // Locate the file blocks by asking name node
            LocatedBlocks locatedblocks = dfs.dfs.GetNamenode().GetBlockLocations(filePath.ToString
                                                                                      (), 0L, BlockSize);

            NUnit.Framework.Assert.AreEqual(repl, locatedblocks.Get(0).GetLocations().Length);
            // The file only has one block
            LocatedBlock lblock = locatedblocks.Get(0);

            DatanodeInfo[] datanodeinfos = lblock.GetLocations();
            ExtendedBlock  block         = lblock.GetBlock();

            // corrupt some /all of the block replicas
            for (int i = 0; i < corruptBlockCount; i++)
            {
                DatanodeInfo dninfo = datanodeinfos[i];
                DataNode     dn     = cluster.GetDataNode(dninfo.GetIpcPort());
                CorruptBlock(block, dn);
                Log.Debug("Corrupted block " + block.GetBlockName() + " on data node " + dninfo);
            }
        }