[ 
https://issues.apache.org/jira/browse/HDFS-7758?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14319063#comment-14319063
 ] 

Colin Patrick McCabe commented on HDFS-7758:
--------------------------------------------

Thanks for taking this on, Eddy.  I agree with [~jpallas]'s comment here... 
please make a static method in {{FsVolumeReference}} like {{releaseAll}} if you 
need a helper method to release a collection of refs.

Do we have a plan for removing {{FsDatasetSpi#getVolume}}?  It seems that this 
interface has a lot of the same issues as {{FsDatasetImpl#getVolumes}}.  I 
think it's fine to do this in a follow-up JIRA, but we should figure out what 
we're doing with that.

I don't think we should have a {{FsDatasetSpi#getNumVolumes}} method.  It just 
encourages people to do bad things like rely on the number of volumes staying 
the same.  This is no longer true in a world of hotplug.  I see that you have 
made the same error here yourself:

{code}
+    int numVolumes = fds.getNumVolumes();
+    int index = rand.nextInt(numVolumes - 1);
     long id = getFreeBlockId();
+    try (FsVolumeReference ref = fds.getVolumeRef(index) ) {
+      File finalizedDir = ref.getVolume().getFinalizedDir(bpid);
+      File file = new File(finalizedDir, getBlockFile(id));
+      if (file.createNewFile()) {
+        LOG.info("Created block file " + file.getName());
+      }
{code}

What's going to happen here if the number of volumes changes in between 
{{getNumVolumes}} and {{getVolumeRef}}?  Instead of doing this, just add an 
FSDatasetSpi method to select a random volume (that returns a ref).

> Retire FsDatasetSpi#getVolumes() and use FsDatasetSpi#getVolumeRefs() instead
> -----------------------------------------------------------------------------
>
>                 Key: HDFS-7758
>                 URL: https://issues.apache.org/jira/browse/HDFS-7758
>             Project: Hadoop HDFS
>          Issue Type: Improvement
>          Components: datanode
>    Affects Versions: 2.6.0
>            Reporter: Lei (Eddy) Xu
>            Assignee: Lei (Eddy) Xu
>         Attachments: HDFS-7758.000.patch
>
>
> HDFS-7496 introduced reference-counting  the volume instances being used to 
> prevent race condition when hot swapping a volume.
> However, {{FsDatasetSpi#getVolumes()}} can still leak the volume instance 
> without increasing its reference count. In this JIRA, we retire the 
> {{FsDatasetSpi#getVolumes()}} and propose {{FsDatasetSpi#getVolumeRefs()}} 
> and etc. method to access {{FsVolume}}. Thus it makes sure that the consumer 
> of {{FsVolume}} always has correct reference count.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to