示例#1
0
        /// <exception cref="System.IO.IOException"/>
        public override void Shuffle(MapHost host, InputStream input, long compressedLength
                                     , long decompressedLength, ShuffleClientMetrics metrics, Reporter reporter)
        {
            input = new IFileInputStream(input, compressedLength, conf);
            // Copy data to local-disk
            long bytesLeft = compressedLength;

            try
            {
                int    BytesToRead = 64 * 1024;
                byte[] buf         = new byte[BytesToRead];
                while (bytesLeft > 0)
                {
                    int n = ((IFileInputStream)input).ReadWithChecksum(buf, 0, (int)Math.Min(bytesLeft
                                                                                             , BytesToRead));
                    if (n < 0)
                    {
                        throw new IOException("read past end of stream reading " + GetMapId());
                    }
                    disk.Write(buf, 0, n);
                    bytesLeft -= n;
                    metrics.InputBytes(n);
                    reporter.Progress();
                }
                Log.Info("Read " + (compressedLength - bytesLeft) + " bytes from map-output for "
                         + GetMapId());
                disk.Close();
            }
            catch (IOException ioe)
            {
                // Close the streams
                IOUtils.Cleanup(Log, input, disk);
                // Re-throw
                throw;
            }
            // Sanity check
            if (bytesLeft != 0)
            {
                throw new IOException("Incomplete map output received for " + GetMapId() + " from "
                                      + host.GetHostName() + " (" + bytesLeft + " bytes missing of " + compressedLength
                                      + ")");
            }
            this.compressedSize = compressedLength;
        }
示例#2
0
        /// <exception cref="System.IO.IOException"/>
        public override void Shuffle(MapHost host, InputStream input, long compressedLength
                                     , long decompressedLength, ShuffleClientMetrics metrics, Reporter reporter)
        {
            IFileInputStream checksumIn = new IFileInputStream(input, compressedLength, conf);

            input = checksumIn;
            // Are map-outputs compressed?
            if (codec != null)
            {
                decompressor.Reset();
                input = codec.CreateInputStream(input, decompressor);
            }
            try
            {
                IOUtils.ReadFully(input, memory, 0, memory.Length);
                metrics.InputBytes(memory.Length);
                reporter.Progress();
                Log.Info("Read " + memory.Length + " bytes from map-output for " + GetMapId());
                if (input.Read() >= 0)
                {
                    throw new IOException("Unexpected extra bytes from input stream for " + GetMapId(
                                              ));
                }
            }
            catch (IOException ioe)
            {
                // Close the streams
                IOUtils.Cleanup(Log, input);
                // Re-throw
                throw;
            }
            finally
            {
                CodecPool.ReturnDecompressor(decompressor);
            }
        }
示例#3
0
        public virtual void TestCorruptedIFile()
        {
            int  fetcher             = 7;
            Path onDiskMapOutputPath = new Path(name.GetMethodName() + "/foo");
            Path shuffledToDisk      = OnDiskMapOutput.GetTempPath(onDiskMapOutputPath, fetcher);

            fs = FileSystem.GetLocal(job).GetRaw();
            MapOutputFile mof = Org.Mockito.Mockito.Mock <MapOutputFile>();
            OnDiskMapOutput <Text, Text> odmo = new OnDiskMapOutput <Text, Text>(map1ID, id, mm
                                                                                 , 100L, job, mof, fetcher, true, fs, onDiskMapOutputPath);
            string                mapData = "MAPDATA12345678901234567890";
            ShuffleHeader         header  = new ShuffleHeader(map1ID.ToString(), 14, 10, 1);
            ByteArrayOutputStream bout    = new ByteArrayOutputStream();
            DataOutputStream      dos     = new DataOutputStream(bout);
            IFileOutputStream     ios     = new IFileOutputStream(dos);

            header.Write(dos);
            int headerSize = dos.Size();

            try
            {
                ios.Write(Sharpen.Runtime.GetBytesForString(mapData));
            }
            finally
            {
                ios.Close();
            }
            int dataSize = bout.Size() - headerSize;
            // Ensure that the OnDiskMapOutput shuffler can successfully read the data.
            MapHost host             = new MapHost("TestHost", "http://test/url");
            ByteArrayInputStream bin = new ByteArrayInputStream(bout.ToByteArray());

            try
            {
                // Read past the shuffle header.
                bin.Read(new byte[headerSize], 0, headerSize);
                odmo.Shuffle(host, bin, dataSize, dataSize, metrics, Reporter.Null);
            }
            finally
            {
                bin.Close();
            }
            // Now corrupt the IFile data.
            byte[] corrupted = bout.ToByteArray();
            corrupted[headerSize + (dataSize / 2)] = unchecked ((int)(0x0));
            try
            {
                bin = new ByteArrayInputStream(corrupted);
                // Read past the shuffle header.
                bin.Read(new byte[headerSize], 0, headerSize);
                odmo.Shuffle(host, bin, dataSize, dataSize, metrics, Reporter.Null);
                NUnit.Framework.Assert.Fail("OnDiskMapOutput.shuffle didn't detect the corrupted map partition file"
                                            );
            }
            catch (ChecksumException e)
            {
                Log.Info("The expected checksum exception was thrown.", e);
            }
            finally
            {
                bin.Close();
            }
            // Ensure that the shuffled file can be read.
            IFileInputStream iFin = new IFileInputStream(fs.Open(shuffledToDisk), dataSize, job
                                                         );

            try
            {
                iFin.Read(new byte[dataSize], 0, dataSize);
            }
            finally
            {
                iFin.Close();
            }
        }