Example #1
0
 /// <summary>Dynamically remove a volume in the list.</summary>
 /// <param name="target">the volume instance to be removed.</param>
 private void RemoveVolume(FsVolumeImpl target)
 {
     while (true)
     {
         FsVolumeImpl[]       curVolumes = volumes.Get();
         IList <FsVolumeImpl> volumeList = Lists.NewArrayList(curVolumes);
         if (volumeList.Remove(target))
         {
             if (volumes.CompareAndSet(curVolumes, Sharpen.Collections.ToArray(volumeList, new
                                                                               FsVolumeImpl[volumeList.Count])))
             {
                 if (blockScanner != null)
                 {
                     blockScanner.RemoveVolumeScanner(target);
                 }
                 try
                 {
                     target.CloseAndWait();
                 }
                 catch (IOException e)
                 {
                     FsDatasetImpl.Log.Warn("Error occurs when waiting volume to close: " + target, e);
                 }
                 target.Shutdown();
                 FsDatasetImpl.Log.Info("Removed volume: " + target);
                 break;
             }
             else
             {
                 if (FsDatasetImpl.Log.IsDebugEnabled())
                 {
                     FsDatasetImpl.Log.Debug("The volume list has been changed concurrently, " + "retry to remove volume: "
                                             + target);
                 }
             }
         }
         else
         {
             if (FsDatasetImpl.Log.IsDebugEnabled())
             {
                 FsDatasetImpl.Log.Debug("Volume " + target + " does not exist or is removed by others."
                                         );
             }
             break;
         }
     }
 }