-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Add jni Support for API CreateColumnFamilyWithImport #11646
Conversation
24a4d37
to
70bd9af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a great start, thanks for your contribution :-)
I just have a few questions around object ownership please
/** | ||
* Called from JNI C++ | ||
*/ | ||
public ExportImportFilesMetaData(final byte[] dbComparatorName, final LiveFileMetaData[] files) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is only called from JNI, it can be made private
please
return Arrays.asList(files); | ||
} | ||
|
||
public long newExportImportFilesMetaDataHandle() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be in this class. I see it is called from RocksDB. I think it would be better if the processing was done in RocksDB as the native handles are not used here.
final List<ExportImportFilesMetaData> metadatas) throws RocksDBException { | ||
final int metadataNum = metadatas.size(); | ||
final long[] metadataHandeList = new long[metadataNum]; | ||
for (int i = 0; i < metadataNum; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit confused between the relationship you have chosen between the Java class org.rocksdb.ExportImportFilesMetaData
and the C++ class ROCKSDB_NAMESPACE::ExportImportFilesMetaData
.
Normally where there is a Java class that may need to have ownership of a C++ object, we typically follow the pattern of inheriting from RocksObject where possible, or if you need references to C++ objects which should not be owned by the Java Object then you may extend AbstractImmutableNativeReference.
I am wondering if there is a reason why you have chosen not to follow that pattern? It is important in RocksJava that we understand the ownership model so that we don't leak memory by not deleting C++ objects that we own, and/or causing crashes by deleting C++ objects that we don't own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for Review code, it is my honor to contribute code.
I‘v read your comment. Before I modify the code I would like to ask a question, PTAL
ExportImportFilesMetaData may be used in two places. One situation is that we can create ExportImportFilesMetaData through Checkpoint.exportColumnFamily, from here it seems that org.rocksdb.ExportImportFilesMetaData and org.rocksdb.LiveFileMetaData are similar, Called from JNI C++, so i did not to follow that pattern.
But in another case, ExportImportFilesMetaData needs to be passed in when calling createColumnFamilyWithImport. In this case we need to follow the pattern of inheriting from RocksObject.
So if this is the case, do LiveFileMetaData and SstFileMetaData also need to follow this pattern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
So in C++ when you call
Checkpoint::ExportColumnFamily
the caller will be the owner of the newExportImportFilesMetaData
object that is created and returned. So if you are calling this from Java, then the Java caller is now the owner of this, and is responsible for freeing it - for this something likeRocksObject
in Java is perfect. -
In C++ when you call
DB::CreateColumnFamilyWithImport
as the caller you have to provide anExportImportFilesMetaData
object. As you are in C++ you may choose to create this object either on the stack or on the heap. From Java though if you want to have a Java object which represents this C++ object, then you will need to call JNI and create the object on the heap, at which point you are the owner of that object, and so therefore againRocksObject
in Java again becomes the correct choice.
@mayuehappy Is that helpful?
@adamretter @cbi42 Ping~ , Can anyone help me look at this PR? |
@mayuehappy I just replied to your comment above - let me know if you need any more guidance... |
@adamretter |
private ExportImportFilesMetaData(final long nativeHandle) { | ||
super(nativeHandle); | ||
// We do not own the native object! | ||
disOwnNativeHandle(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mayuehappy can you explain why you are callng disOwnNativeHandle
here please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamretter Thanks for the reviewing, I thought about this place again. org.rocksdb.ExportImportFilesMetaData
should indeed own ROCKSDB_NAMESPACE::ExportImportFilesMetaData
's nativeHandle. My initial idea was a little wrong, so I deleted these two lines of code.
16fc045
to
57e2b16
Compare
Hi @mayuehappy and @adamretter. Thank you both for your efforts so far on this and other related PRs! I'm eagerly waiting for this feature to be merged. Is there something that I could do to help pushing this PR over the line? If there are still some issues to be resolved, me or my colleagues would be happy to help. |
@pnowojski Hi ~ Thank you for your attention. I alse hope this PR can be merged soon so that Flink can use this new feature to speed up state recovery! @adamretter .If there is anything that needs to be modified in this PR, please comment and I will fix it as soon as possible. |
@mayuehappy I think this looks good. I would like my colleague @alanpaxton to also give it a quick once over too. @alanpaxton could you just check the "ownership" semantics as discussed above, I am pretty certain we have them correct now - but a second pair of eyes is always valuable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamretter @mayuehappy I have looked at this w.r.t. "ownership" semantics, and it appears correct to me for that. I noticed a couple of small issues in passing that I commented..
final ImportColumnFamilyOptions importColumnFamilyOptions, | ||
final List<ExportImportFilesMetaData> metadatas) throws RocksDBException { | ||
final int metadataNum = metadatas.size(); | ||
final long[] metadataHandeList = new long[metadataNum]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo - metadataHandleList
/** | ||
* ImportColumnFamilyOptions is used by ImportColumnFamily() | ||
* <p> | ||
* Note that dispose() must be called before this instance become out-of-scope |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This behaves the same as any other RocksObject. If you need a specific comment, it should note that the should be close()
d (since close is the public method which ultimately calls disposeInternal()
), and ideally that should use a try-with-resources construct.
java/rocksjni/checkpoint.cc
Outdated
if (metadata != nullptr) { | ||
jexport_import_files_meta_data = | ||
ROCKSDB_NAMESPACE::ExportImportFilesMetaDataJni:: | ||
fromCppExportImportFilesMetaData(env, metadata); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it not be easier to return metadata
as a jlong
(GET_CPLUS_PLUS_PTR) and then call new ExportImportFilesMetaData(metadata_native_)
in Java ? Then you would not need to add the extra class to portal.h
, I believe ?
@cbi42 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
LGTM, I'll merge it once the other comments are addressed. |
@mayuehappy has updated the pull request. You must reimport the pull request before landing. |
@cbi42 @adamretter @alanpaxton
|
@mayuehappy has updated the pull request. You must reimport the pull request before landing. |
@mayuehappy has updated the pull request. You must reimport the pull request before landing. |
@cbi42 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@mayuehappy has updated the pull request. You must reimport the pull request before landing. |
@mayuehappy has updated the pull request. You must reimport the pull request before landing. |
@cbi42 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Summary: - Add the following missing options to src/main/java/org/rocksdb/ImportColumnFamilyOptions.java and in java/rocksjni/import_column_family_options.cc in RocksJava. - Add the struct to src/main/java/org/rocksdb/ExportImportFilesMetaData.java and in java/rocksjni/export_import_files_metadatajni.cc in RocksJava. - Add New Java API `createColumnFamilyWithImport` to src/main/java/org/rocksdb/RocksDB.java - Add New Java API `exportColumnFamily` to src/main/java/org/rocksdb/Checkpoint.java Pull Request resolved: facebook/rocksdb#11646 Test Plan: - added unit tests for exportColumnFamily in org.rocksdb.CheckpointTest - added unit tests for createColumnFamilyWithImport to org.rocksdb.ImportColumnFamilyTest Reviewed By: ajkr Differential Revision: D50889700 Pulled By: cbi42 fbshipit-source-id: d623b35e445bba62a0d3c007d74352e937678f6c
createColumnFamilyWithImport
to src/main/java/org/rocksdb/RocksDB.javaexportColumnFamily
to src/main/java/org/rocksdb/Checkpoint.javaTest plan: