Skip to content

GEODE-5565: Release off heap memory if unable to set value #2305

Merged
jhuynh1 merged 2 commits intoapache:developfrom
jhuynh1:feature/GEODE-5565
Sep 10, 2018
Merged

GEODE-5565: Release off heap memory if unable to set value #2305
jhuynh1 merged 2 commits intoapache:developfrom
jhuynh1:feature/GEODE-5565

Conversation

@jhuynh1
Copy link
Copy Markdown
Contributor

@jhuynh1 jhuynh1 commented Aug 10, 2018

  • If RegionDestroyedException is thrown while trying to set a value, but after memory has been allocated, we will now release the memory in a catch block.

Thank you for submitting a contribution to Apache Geode.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?

  • Has your PR been rebased against the latest commit within the target branch (typically develop)?

  • Is your initial contribution a single, squashed commit?

  • Does gradlew build run cleanly?

  • Have you written or updated unit tests to verify your changes?

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?

Note:

Please ensure that once the PR is submitted, you check travis-ci for build issues and
submit an update to your PR as soon as possible. If you need help, please send an
email to dev@geode.apache.org.

value = this.prepareValueForCache(region, newValueToWrite, false);
setValue(region, value);
} catch (RegionDestroyedException e) {
if (value != null && value instanceof StoredObject) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the null check is not needed because null is never an "instanceof" anything.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is actually the job of the "setValue" method to release the offheap value it is given if it can not store it in the entry.
I see it calls "releaseOffHeapRefIfRegionBeingClosedOrDestroyed" so why didn't that work?
Did the RegionDestroyedException come from somewhere else?

Doing it the way you have it could lead to extra releases. I suggest you figure out why setValue did not release it since it was responsible for doing so and not to change the code at this location.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The reguo destroyed exception is being thrown in _setValue. This is called before the releaseoffheap... Method is called. I can add the try catch to abstractregionentry instead. The problem was the release here was not getting a chance to execute. The stack trace is in the ticket.

Ill move the try catch lower and see if that resolves the issue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think it is _setValue.
I think the bug is in the disk implementation of setValue:
at org.apache.geode.internal.cache.entries.DiskEntry$Helper.update(DiskEntry.java:856)

and also in basicUpdate that this method calls.
If either of these throw an exception before storing the new value in the entry then they are responsible for releasing the new value if it is a StoredObject.

setValue(region, this.prepareValueForCache(region, newValueToWrite, false));
Object value = null;
try {
value = this.prepareValueForCache(region, newValueToWrite, false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not call prepareValueForCache on the line that declares value?
Object value = prepareValueForCache...
No need to catch anything from prepareValueForCache because in that case it did not return anything.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also you can remove "this." on the method call

@jhuynh1 jhuynh1 force-pushed the feature/GEODE-5565 branch from 73cb9d4 to c8cc2d5 Compare August 24, 2018 17:49
@jhuynh1 jhuynh1 force-pushed the feature/GEODE-5565 branch 2 times, most recently from 762d282 to ec9fe5f Compare September 5, 2018 16:46
@jhuynh1 jhuynh1 merged commit aaac1e5 into apache:develop Sep 10, 2018
@jhuynh1 jhuynh1 deleted the feature/GEODE-5565 branch September 10, 2018 20:36
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.

2 participants