Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-9385: [Python] Fix JPype tests and JVM buffer lifetime #7753

Closed
wants to merge 5 commits into from

Conversation

rymurr
Copy link
Contributor

@rymurr rymurr commented Jul 14, 2020

No description provided.

@github-actions
Copy link

@rymurr
Copy link
Contributor Author

rymurr commented Jul 14, 2020

@github-actions crossbow submit test-conda-python-3.8-jpype

@github-actions
Copy link

Revision: 68b92e9

Submitted crossbow builds: ursa-labs/crossbow @ actions-414

Task Status
test-conda-python-3.8-jpype Github Actions

Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, will merge

python/pyarrow/jvm.py Outdated Show resolved Hide resolved
@rymurr
Copy link
Contributor Author

rymurr commented Jul 14, 2020

@github-actions crossbow submit test-conda-python-3.8-jpype

@github-actions
Copy link

Revision: bcacea5

Submitted crossbow builds: ursa-labs/crossbow @ actions-415

Task Status
test-conda-python-3.8-jpype Github Actions

@pitrou
Copy link
Member

pitrou commented Jul 14, 2020

@xhochy Can you please validate the buffer handling changes?

@pitrou
Copy link
Member

pitrou commented Jul 14, 2020

Well, this should not go in if every buffer creates a Java memory leak, IMHO.

@xhochy
Copy link
Member

xhochy commented Jul 14, 2020

Well, this should not go in if every buffer creates a Java memory leak, IMHO.

AFAIK this isn't introducing a new leak :(

@pitrou
Copy link
Member

pitrou commented Jul 14, 2020

Oh, I see... then we can merge this anyway.

@rymurr
Copy link
Contributor Author

rymurr commented Jul 14, 2020

Raised https://issues.apache.org/jira/browse/ARROW-9468 to follow up on the memory leak

@wesm
Copy link
Member

wesm commented Jul 14, 2020

It just needs to call release() when it's done with the buffer, right?

@wesm
Copy link
Member

wesm commented Jul 14, 2020

I'm trying to add a nanny object with a custom dtor

@pitrou
Copy link
Member

pitrou commented Jul 14, 2020

@wesm Trying it as well...

@pitrou
Copy link
Member

pitrou commented Jul 14, 2020

@github-actions crossbow submit test-conda-python-3.8-jpype

ci/scripts/python_test.sh Outdated Show resolved Hide resolved
@github-actions
Copy link

Revision: 28f6500

Submitted crossbow builds: ursa-labs/crossbow @ actions-416

Task Status
test-conda-python-3.8-jpype Github Actions

@pitrou
Copy link
Member

pitrou commented Jul 14, 2020

Rebased. There were some Java changes in-between, hopefully they won't interfere.

Edit: of course they do...

@pitrou
Copy link
Member

pitrou commented Jul 14, 2020

@github-actions crossbow submit test-conda-python-3.8-jpype

@github-actions
Copy link

Revision: 4752024

Submitted crossbow builds: ursa-labs/crossbow @ actions-417

Task Status
test-conda-python-3.8-jpype Github Actions

@pitrou pitrou changed the title ARROW-9385: [Python] finish Fix JPype tests ARROW-9385: [Python] Fix JPype tests and JVM buffer lifetime Jul 14, 2020
@pitrou
Copy link
Member

pitrou commented Jul 14, 2020

JPype build is green, AppVeyor is green. Will merge :-)

@pitrou pitrou closed this in 16f6989 Jul 14, 2020
@rymurr rymurr deleted the ARROW-9385 branch July 22, 2020 11:58
An object that keeps a org.apache.arrow.memory.ArrowBuf's underlying
memory alive.
"""
ref_manager = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pitrou I was trying to understand why you used a static variable here instead of jvm_buf.retain() like before? I'm a little concerned about how this would behave with multiple threads and buffers that have different ReferenceManagers since retain() is called on the static var, but release() is called on the instance var..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are misunderstanding how this works. This is not C++, when you write:

        self.ref_manager = ref_manager

it creates an instance attribute which shadows the class attribute.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if you have multiple threads creating jvm_buffers with different backing reference manager instances, isn't it possible that one thread will overwrite the class attribute ref_manager being used in another thread, then both will call ref_manager.retain() using the same ref_manager class attribute?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, no. The class attribute ref_manager will always remain None.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ok. I think I was confused over having a local var ref_manager too. So why do you need a class attribute? Is it in case of an exception is thrown and the class instance doesn't get assigned?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, no, it's not needed. It's just a common idiom to write:

class A:
    attr = None

instead of:

class A:
    def __init__(self):
        self.attr = None

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, yes, I could have written self.ref_manager = None inside the constructor instead. Sorry for the confusion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, no problem, thanks for clearing that up for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants