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

Colin Patrick McCabe commented on HTRACE-119:
---------------------------------------------

OK, I looked at this more closely and identified a few patterns:

1. A Span can be detached from TraceScope, but we can't attach a new span to a 
TraceScope.  In other words, TraceScope is kind of like a FileDescriptor or 
DFSInputStream object in Java where there is a close method, but no reopen 
method.

2. TraceScope creations should be balanced with TraceScope#close calls.  Again, 
this is similar to DFSInputStream.

3. Since a TraceScope contains only one Span, a double detach can't possibly do 
anything useful.  The second time detach is called, we can simply return null.  
But it seems unlikely that this is what the calling code expects.

So what are the arguments in favor of allowing double detaches?  I guess if you 
have conditional logic that can detach in several places, you don't have to 
keep track of whether you already detached.  But this seems like a very weak 
argument.  I can't think of any case where we'd want to skip properly tracing 
one part of an operation based on the fact that an earlier part had been traced.

How about the argument against allowing double detaches?  This one is 
straightforward.  It seems like a programmer would expect that when calling 
detach, the trace span for the scope would be returned.  This is not possible 
if that trace scope has already been detached.  So the code is either 
misleading, or wrong, or both.

I think on balance, I am -1 on allowing double detach.  But maybe there is an 
argument that I've overlooked.  Do you have a code example of where double 
detach would be helpful rather than a beginner's trap?

> detach of NullScope singleton should not fail
> ---------------------------------------------
>
>                 Key: HTRACE-119
>                 URL: https://issues.apache.org/jira/browse/HTRACE-119
>             Project: HTrace
>          Issue Type: Bug
>    Affects Versions: master
>            Reporter: Masatake Iwasaki
>            Assignee: Masatake Iwasaki
>         Attachments: HTRACE-119.001.patch
>
>
> The {{detach}} method of NullScope singleton is possible to be called 
> multiple times by users avoiding conditionals by the assumption that 
> NullScope#close and NullScope#detach results in no-op. Calling {{detach}} of 
> NullScope singleton multiple times throws RuntimeException by HTRACE-101 now.



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

Reply via email to