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

Simplify a test case in Java ReadOnlyTest #7608

Closed
wants to merge 9 commits into from
Closed

Simplify a test case in Java ReadOnlyTest #7608

wants to merge 9 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Oct 29, 2020

The original test nests a lot of try blocks. This PR flattens these blocks into independent blocks, so that each try block closes the DB before opening the next DB instance.

Test Plan:
watch the existing java tests to pass

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@Cheng-Chang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@Cheng-Chang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@zhichao-cao zhichao-cao left a comment

Choose a reason for hiding this comment

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

The refactor LGTM, thanks!

@adamretter
Copy link
Collaborator

adamretter commented Oct 29, 2020

@Cheng-Chang @zhichao-cao I am afraid that there are problems with this PR. Several RocksObjects are now never free'd.

Copy link
Collaborator

@adamretter adamretter left a comment

Choose a reason for hiding this comment

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

This PR has problems. Objects that were previously free'd no longer are. Please see the documentation about this here - https://github.com/facebook/rocksdb/wiki/RocksJava-Basics#memory-management

@zhichao-cao
Copy link
Contributor

This PR has problems. Objects that were previously free'd no longer are. Please see the documentation about this here - https://github.com/facebook/rocksdb/wiki/RocksJava-Basics#memory-management

Thanks for pointing out. I did not realize the issue.

@ghost
Copy link
Author

ghost commented Oct 29, 2020

This PR has problems. Objects that were previously free'd no longer are. Please see the documentation about this here - https://github.com/facebook/rocksdb/wiki/RocksJava-Basics#memory-management

@mrambacher Thanks for pointing out the link, I didn't realize every object needs to be closed manually. The db instances and column family handles are closed. I'm wondering is it necessary to close the options and descriptors objects manually? I checked the implementation, relying on GC for options and descriptors looks good to me.

@facebook-github-bot
Copy link
Contributor

@cheng-chang has updated the pull request. You must reimport the pull request before landing.

assertThat("value").isEqualTo(new String(db.get("key".getBytes())));
}

final ColumnFamilyOptions cfOpts = new ColumnFamilyOptions();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is never closed.

Copy link
Author

@ghost ghost Oct 30, 2020

Choose a reason for hiding this comment

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

It's weird to close an option object, but I understand the motivation behind this to free the memory asap.
But in the codebase, options are not explicitly closed everywhere, e.g. https://github.com/facebook/rocksdb/blob/master/java/src/main/java/org/rocksdb/ColumnFamilyDescriptor.java#L24.

assertThat(new String(db.get(readOnlyColumnFamilyHandleList2.get(1), "key2".getBytes())))
.isEqualTo("value2");
} finally {
for (ColumnFamilyHandle handle : readOnlyColumnFamilyHandleList2) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the latest codebase. Any column family handles created by a RocksDB#open call, will be auto-magically cleaned up in the corresponding RocksDB#close call.

So you may be able to benefit from that, and tidy this up further.

@facebook-github-bot
Copy link
Contributor

@cheng-chang has updated the pull request. You must reimport the pull request before landing.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@cheng-chang has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@cheng-chang has updated the pull request. You must reimport the pull request before landing.

2 similar comments
@facebook-github-bot
Copy link
Contributor

@cheng-chang has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@cheng-chang has updated the pull request. You must reimport the pull request before landing.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@Cheng-Chang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@cheng-chang has updated the pull request. You must reimport the pull request before landing.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@cheng-chang has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@cheng-chang has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@cheng-chang has updated the pull request. You must reimport the pull request before landing.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@Cheng-Chang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@cheng-chang has updated the pull request. You must reimport the pull request before landing.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@cheng-chang has updated the pull request. You must reimport the pull request before landing.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@Cheng-Chang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@cheng-chang has updated the pull request. You must reimport the pull request before landing.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@Cheng-Chang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@Cheng-Chang merged this pull request in 1f62721.

codingrhythm pushed a commit to SafetyCulture/rocksdb that referenced this pull request Mar 5, 2021
Summary:
The original test nests a lot of `try` blocks. This PR flattens these blocks into independent blocks, so that each `try` block closes the DB before opening the next DB instance.

Pull Request resolved: facebook#7608

Test Plan: watch the existing java tests to pass

Reviewed By: zhichao-cao

Differential Revision: D24611621

Pulled By: cheng-chang

fbshipit-source-id: d486c5d37ac25d4b860d739ef2cdd58e6064d42d
alluxio-bot pushed a commit to Alluxio/alluxio that referenced this pull request Jan 21, 2022
### What changes are proposed in this pull request?

Fixes facebook/rocksdb#9378
The `orgs.rocksdb.RocksObject` extends `AutoCloseable` so they should be
closed properly to avoid leaks.

### Why are the changes needed?

According to the [RocksDB
documentation](https://github.com/facebook/rocksdb/wiki/RocksJava-Basics#memory-management)
and a sample [PR
discussion](facebook/rocksdb#7608 (comment)),
the objects need to be closed or wrapped in a try-with-resource block.

### Does this PR introduce any user facing changes?

NA

pr-link: #14856
change-id: cid-69a164c547a14e0bb7710fc7a48731aecba4db88
Xenorith pushed a commit to Alluxio/alluxio that referenced this pull request Feb 7, 2022
### What changes are proposed in this pull request?

Fixes facebook/rocksdb#9378
The `orgs.rocksdb.RocksObject` extends `AutoCloseable` so they should be
closed properly to avoid leaks.

### Why are the changes needed?

According to the [RocksDB
documentation](https://github.com/facebook/rocksdb/wiki/RocksJava-Basics#memory-management)
and a sample [PR
discussion](facebook/rocksdb#7608 (comment)),
the objects need to be closed or wrapped in a try-with-resource block.

### Does this PR introduce any user facing changes?

NA

pr-link: #14856
change-id: cid-69a164c547a14e0bb7710fc7a48731aecba4db88
flaming-archer pushed a commit to flaming-archer/alluxio that referenced this pull request Sep 1, 2022
 Close RocksDB objects that are AutoCloseable

    ### What changes are proposed in this pull request?

    Fixes facebook/rocksdb#9378
    The `orgs.rocksdb.RocksObject` extends `AutoCloseable` so they should be
    closed properly to avoid leaks.

    ### Why are the changes needed?

    According to the [RocksDB
    documentation](https://github.com/facebook/rocksdb/wiki/RocksJava-Basics#memory-management)
    and a sample [PR
    discussion](facebook/rocksdb#7608 (comment)),
    the objects need to be closed or wrapped in a try-with-resource block.

    ### Does this PR introduce any user facing changes?

    NA

    pr-link: Alluxio#14856
    change-id: cid-69a164c547a14e0bb7710fc7a48731aecba4db88
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants