Github user JoshRosen commented on the pull request:

    https://github.com/apache/spark/pull/9477#issuecomment-153978941
  
    LGTM overall, but I'd like to address one concern before merging: I'm 
worried that passing both the `MemoryConsumer` and `TaskMemoryManager` to the 
sorter components will open the potential for bugs; I feel that those classes 
should allocate their memory using only the public `MemoryConsumer` methods.
    
    Note that the `MemoryConsumer` methods actually end up calling the 
`TaskMemoryManager` methods which your code calls directly: 
https://github.com/apache/spark/blob/81498dd5c86ca51d2fb351c8ef52cbb28e6844f4/core/src/main/java/org/apache/spark/memory/MemoryConsumer.java#L81
    
    I think that we should mark those TaskMemoryManager methods as methods that 
are only supposed to be called _by_ the memory consumer and not directly by 
developers. The problem with calling them directly is that the bookkeeping in 
the MemoryConsumer itself won't have been updated. This current API has such a 
high potential for this type of misuse that I think we should look at fancy 
Java-isms to restrict the visibility / callability of those methods such that 
they can only be called from MemoryConsumer.
    
    If you fix this by having those classes only allocate through their 
MemoryConsumers then feel free to merge as soon as this passes tests. I can 
take care of a followup to fix the documentation / code to avoid this type of 
misuse.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to