Ejemplo n.º 1
0
        /// <summary>Scan a block.</summary>
        /// <param name="cblock">The block to scan.</param>
        /// <param name="bytesPerSec">The bytes per second to scan at.</param>
        /// <returns>
        /// The length of the block that was scanned, or
        /// -1 if the block could not be scanned.
        /// </returns>
        private long ScanBlock(ExtendedBlock cblock, long bytesPerSec)
        {
            // 'cblock' has a valid blockId and block pool id, but we don't yet know the
            // genstamp the block is supposed to have.  Ask the FsDatasetImpl for this
            // information.
            ExtendedBlock block = null;

            try
            {
                Block b = volume.GetDataset().GetStoredBlock(cblock.GetBlockPoolId(), cblock.GetBlockId
                                                                 ());
                if (b == null)
                {
                    Log.Info("FileNotFound while finding block {} on volume {}", cblock, volume.GetBasePath
                                 ());
                }
                else
                {
                    block = new ExtendedBlock(cblock.GetBlockPoolId(), b);
                }
            }
            catch (FileNotFoundException)
            {
                Log.Info("FileNotFoundException while finding block {} on volume {}", cblock, volume
                         .GetBasePath());
            }
            catch (IOException)
            {
                Log.Warn("I/O error while finding block {} on volume {}", cblock, volume.GetBasePath
                             ());
            }
            if (block == null)
            {
                return(-1);
            }
            // block not found.
            BlockSender blockSender = null;

            try
            {
                blockSender = new BlockSender(block, 0, -1, false, true, true, datanode, null, CachingStrategy
                                              .NewDropBehind());
                throttler.SetBandwidth(bytesPerSec);
                long bytesRead = blockSender.SendBlock(nullStream, null, throttler);
                resultHandler.Handle(block, null);
                return(bytesRead);
            }
            catch (IOException e)
            {
                resultHandler.Handle(block, e);
            }
            finally
            {
                IOUtils.Cleanup(null, blockSender);
            }
            return(-1);
        }
Ejemplo n.º 2
0
            public virtual void Handle(ExtendedBlock block, IOException e)
            {
                FsVolumeSpi volume = scanner.volume;

                if (e == null)
                {
                    Log.Trace("Successfully scanned {} on {}", block, volume.GetBasePath());
                    return;
                }
                // If the block does not exist anymore, then it's not an error.
                if (!volume.GetDataset().Contains(block))
                {
                    Log.Debug("Volume {}: block {} is no longer in the dataset.", volume.GetBasePath(
                                  ), block);
                    return;
                }
                // If the block exists, the exception may due to a race with write:
                // The BlockSender got an old block path in rbw. BlockReceiver removed
                // the rbw block from rbw to finalized but BlockSender tried to open the
                // file before BlockReceiver updated the VolumeMap. The state of the
                // block can be changed again now, so ignore this error here. If there
                // is a block really deleted by mistake, DirectoryScan should catch it.
                if (e is FileNotFoundException)
                {
                    Log.Info("Volume {}: verification failed for {} because of " + "FileNotFoundException.  This may be due to a race with write."
                             , volume.GetBasePath(), block);
                    return;
                }
                Log.Warn("Reporting bad {} on {}", block, volume.GetBasePath());
                try
                {
                    scanner.datanode.ReportBadBlocks(block);
                }
                catch (IOException)
                {
                    // This is bad, but not bad enough to shut down the scanner.
                    Log.Warn("Cannot report bad " + block.GetBlockId(), e);
                }
            }