示例#1
0
 internal virtual VolumeScanner.Statistics GetVolumeStats(string volumeId)
 {
     lock (this)
     {
         VolumeScanner scanner = scanners[volumeId];
         if (scanner == null)
         {
             return(null);
         }
         return(scanner.GetStatistics());
     }
 }
示例#2
0
 /// <exception cref="System.Exception"/>
 public virtual void TestCalculateNeededBytesPerSec()
 {
     // If we didn't check anything the last hour, we should scan now.
     NUnit.Framework.Assert.IsTrue(VolumeScanner.CalculateShouldScan("test", 100, 0, 0
                                                                     , 60));
     // If, on average, we checked 101 bytes/s checked during the last hour,
     // stop checking now.
     NUnit.Framework.Assert.IsFalse(VolumeScanner.CalculateShouldScan("test", 100, 101
                                                                      * 3600, 1000, 5000));
     // Target is 1 byte / s, but we didn't scan anything in the last minute.
     // Should scan now.
     NUnit.Framework.Assert.IsTrue(VolumeScanner.CalculateShouldScan("test", 1, 3540,
                                                                     0, 60));
     // Target is 1000000 byte / s, but we didn't scan anything in the last
     // minute.  Should scan now.
     NUnit.Framework.Assert.IsTrue(VolumeScanner.CalculateShouldScan("test", 100000L,
                                                                     354000000L, 0, 60));
     NUnit.Framework.Assert.IsFalse(VolumeScanner.CalculateShouldScan("test", 100000L,
                                                                      365000000L, 0, 60));
 }
示例#3
0
 public override void Setup(VolumeScanner scanner)
 {
     this.scanner = scanner;
     TestBlockScanner.TestScanResultHandler.Info info = GetInfo(scanner.volume);
     Log.Info("about to start scanning.");
     lock (info)
     {
         while (!info.shouldRun)
         {
             try
             {
                 Sharpen.Runtime.Wait(info);
             }
             catch (Exception)
             {
             }
         }
     }
     Log.Info("starting scanning.");
 }
示例#4
0
 /// <summary>Set up a scanner for the given block pool and volume.</summary>
 /// <param name="ref">A reference to the volume.</param>
 public virtual void AddVolumeScanner(FsVolumeReference @ref)
 {
     lock (this)
     {
         bool success = false;
         try
         {
             FsVolumeSpi volume = @ref.GetVolume();
             if (!IsEnabled())
             {
                 Log.Debug("Not adding volume scanner for {}, because the block " + "scanner is disabled."
                           , volume.GetBasePath());
                 return;
             }
             VolumeScanner scanner = scanners[volume.GetStorageID()];
             if (scanner != null)
             {
                 Log.Error("Already have a scanner for volume {}.", volume.GetBasePath());
                 return;
             }
             Log.Debug("Adding scanner for volume {} (StorageID {})", volume.GetBasePath(), volume
                       .GetStorageID());
             scanner = new VolumeScanner(conf, datanode, @ref);
             scanner.Start();
             scanners[volume.GetStorageID()] = scanner;
             success = true;
         }
         finally
         {
             if (!success)
             {
                 // If we didn't create a new VolumeScanner object, we don't
                 // need this reference to the volume.
                 IOUtils.Cleanup(null, @ref);
             }
         }
     }
 }
示例#5
0
 /// <summary>
 /// Stops and removes a volume scanner.<p/>
 /// This function will block until the volume scanner has stopped.
 /// </summary>
 /// <param name="volume">The volume to remove.</param>
 public virtual void RemoveVolumeScanner(FsVolumeSpi volume)
 {
     lock (this)
     {
         if (!IsEnabled())
         {
             Log.Debug("Not removing volume scanner for {}, because the block " + "scanner is disabled."
                       , volume.GetStorageID());
             return;
         }
         VolumeScanner scanner = scanners[volume.GetStorageID()];
         if (scanner == null)
         {
             Log.Warn("No scanner found to remove for volumeId {}", volume.GetStorageID());
             return;
         }
         Log.Info("Removing scanner for volume {} (StorageID {})", volume.GetBasePath(), volume
                  .GetStorageID());
         scanner.Shutdown();
         Sharpen.Collections.Remove(scanners, volume.GetStorageID());
         Uninterruptibles.JoinUninterruptibly(scanner, 5, TimeUnit.Minutes);
     }
 }
示例#6
0
 /// <summary>
 /// Mark a block as "suspect."
 /// This means that we should try to rescan it soon.
 /// </summary>
 /// <remarks>
 /// Mark a block as "suspect."
 /// This means that we should try to rescan it soon.  Note that the
 /// VolumeScanner keeps a list of recently suspicious blocks, which
 /// it uses to avoid rescanning the same block over and over in a short
 /// time frame.
 /// </remarks>
 /// <param name="storageId">
 /// The ID of the storage where the block replica
 /// is being stored.
 /// </param>
 /// <param name="block">The block's ID and block pool id.</param>
 internal virtual void MarkSuspectBlock(string storageId, ExtendedBlock block)
 {
     lock (this)
     {
         if (!IsEnabled())
         {
             Log.Debug("Not scanning suspicious block {} on {}, because the block " + "scanner is disabled."
                       , block, storageId);
             return;
         }
         VolumeScanner scanner = scanners[storageId];
         if (scanner == null)
         {
             // This could happen if the volume is in the process of being removed.
             // The removal process shuts down the VolumeScanner, but the volume
             // object stays around as long as there are references to it (which
             // should not be that long.)
             Log.Info("Not scanning suspicious block {} on {}, because there is no " + "volume scanner for that storageId."
                      , block, storageId);
             return;
         }
         scanner.MarkSuspectBlock(block);
     }
 }
示例#7
0
 public virtual void Setup(VolumeScanner scanner)
 {
     Log.Trace("Starting VolumeScanner {}", scanner.volume.GetBasePath());
     this.scanner = scanner;
 }