Add support for Wide columns in Java#12334
Conversation
33d9052 to
a0a634e
Compare
47a2294 to
31e973b
Compare
31e973b to
6b75fb2
Compare
adamretter
left a comment
There was a problem hiding this comment.
I have done a partial review... There are three main things that you might want to look at IMHO:
-
Whether you really need
std::make_uniquefor a pointer that never escapes its function scope. It seems superfluous to me. -
Clean up of JNI resources you have allocated before you return from a function when an error condition occurs (or even when the function completes normally)
-
String conversion from JNI types to C++ standard types. There are functions in
portal.hto assist in doing this correctly. If they don't suit, we can consider adding an additional one for your use-case.
| "ByteBuffer)"); | ||
| return; | ||
| } | ||
| auto name = reinterpret_cast<char*>(_name) + namesOffset[i]; |
There was a problem hiding this comment.
There are utility methods in portal.h to go from jstring to std::string or char* - could we use those here instead?
There was a problem hiding this comment.
We are not working with jstring but with void* here. I cast it to char* so that I can add offset to it.
|
|
||
| const auto columns_len = static_cast<int>(env->GetArrayLength(jNames)); | ||
|
|
||
| auto namesOffset = std::make_unique<jint[]>(columns_len); |
There was a problem hiding this comment.
make_unique seems an unnecessary overhead here?
There was a problem hiding this comment.
Yes, that's true, but it allows me to automatically release all the memory allocated here and simplify return statements.
| auto j_value = | ||
| static_cast<jbyteArray>(env->GetObjectArrayElement(jvalues, i)); | ||
| if (env->ExceptionCheck()) { | ||
| return; |
There was a problem hiding this comment.
Do we need to free the JNI local references for name/jname here?
There was a problem hiding this comment.
As I understand it, GetObjectArrayElement returns a jobject and when you are finished with this (on either success or error paths), you should call DeleteLocalRef on that object. There are other examples of this pattern already in the existing code-base, for example: https://github.com/facebook/rocksdb/blob/main/java/rocksjni/rocksjni.cc#L462
| auto value = std::make_unique<jbyte[]>(jvalue_len); | ||
| env->GetByteArrayRegion(j_value, 0, jvalue_len, value.get()); | ||
| if (env->ExceptionCheck()) { | ||
| return; |
There was a problem hiding this comment.
Do we need to free the JNI local references for name/jname and value/jvalue here?
There was a problem hiding this comment.
No we don't need to. GetByteArrayRegion only copies data from java arrays to provide memory. This memory is allocated as a smart pointer and is automatically released when we exit the method.
| auto value = reinterpret_cast<char*>(_value) + valuesOffset[i]; | ||
| valuesRequiredSize[i] = static_cast<jint>(column.value().size()); | ||
| max_data_len = std::min(valuesRequiredSize[i], (valuesLen[i])); | ||
| std::memcpy(value, column.value().data(), max_data_len); |
There was a problem hiding this comment.
Is explicit memcpy needed?
There was a problem hiding this comment.
Yes, See previous comment
| env->SetIntArrayRegion(jnamesRequiredSize, 0, max_items, | ||
| namesRequiredSize.get()); | ||
| if (env->ExceptionCheck()) { | ||
| return nullptr; |
There was a problem hiding this comment.
Do we need to free the previous JNI array fetches and local-references here?
There was a problem hiding this comment.
No we don't need to. See previous comment
| env->SetIntArrayRegion(jvaluesRequiredSize, 0, max_items, | ||
| valuesRequiredSize.get()); | ||
| if (env->ExceptionCheck()) { | ||
| return nullptr; |
There was a problem hiding this comment.
Do we need to free the previous JNI array fetches and local-references here?
There was a problem hiding this comment.
No we don't need to. See previous comment
| "Invalid key argument (argument is not a valid direct ByteBuffer)"); | ||
| return nullptr; | ||
| } | ||
| auto key = reinterpret_cast<char*>(_key) + key_offset; |
There was a problem hiding this comment.
Could this use portal.h for string conversion
There was a problem hiding this comment.
No. See previous comment
| jlong jcf_handle) { | ||
| auto* db = reinterpret_cast<ROCKSDB_NAMESPACE::DB*>(jdb_handle); | ||
|
|
||
| auto key = std::make_unique<jbyte[]>(keyLength); |
There was a problem hiding this comment.
std::make_unique seems superfluous here
There was a problem hiding this comment.
Yes, See previous comment
239f9df to
a9f7753
Compare
a9f7753 to
aa1fd9a
Compare
|
Hello, after I finished compiling, the run encountered the following error: |
|
Hello @test-wangxiaoyu
This is a very strange error. Considering you have a macbook air 2022, these models have ARM CPU ( You can also check what native library is inside the jar archive. For example this is how it looks like on my linux machine. $ jar -t --file java/target/rocksdbjni-9.2.0-linux64.jar | grep librocksdbjni
librocksdbjni-linux64.soRadek |
aa1fd9a to
55716e0
Compare
|
@pdillinger @ajkr Can we get this one merged please? |
3a7a3ae to
a427a7f
Compare
|
Hi, Thank you for the great work on this feature! I am very interested in using wide columns in RocksDB. Could you please let me know if this feature is planned to be merged? Also, do you have an estimated timeline for when it might be available in a release? Thank you! |
1c944f2 to
e1d45d1
Compare
e1d45d1 to
9599cdf
Compare
3d0bd2c to
896c56a
Compare
Make it exactly as CI says Which isn’t how it ends up if you try to `make format` I strongly suspect `make format` is subtly borked on Mac
896c56a to
40a7af2
Compare
This PR adds support for wide columns in Java. First implementation is primarily focused on correctness rather than performance. We would like to merge this first and hear feedback from RocksDB Java community before refining it.
Fix #12113