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
RocksJava BytewiseComparator semantics? #2001
Comments
Thanks @mikhail-antonov for reporting the issue, I am not sure what is the purpose of us having a BytewiseComparator implementation in java. Is it possible to pass the native c++ comparator to SstFileWriter ? |
@IslamAbdelRahman I think conceptually being able to implement custom comparator in Java and pass it down to RocksDB is good; in this specific case it doesn't seem it's useful, I think best is to update JNI wrapper to allow param-less constructor as you mentioned, let me have a look at it. For now I've working that around by implementing custom comparator and passing it to SstFileWriter, but having to implement it seems unnecessary burden. |
So #2028 adds support for SstFileWriter constructor w/o explicit comparator to JNI api, I think with that current Bytewise comparator (both regular and reverse) should be obsolete? Having the only default comparator in Java that one is forced to use that's not compatibly with memcmp seems weird. |
@mikhail-antonov, Yes I think we should remove this comparator. It's confusing and we should remove it from the code base |
The Java implementations of
One of the important things about (1) is that they try to prove that they are directly compatible with the C++ equivalent comparators via the If you want to just use the Native C++ BytewiseComparator from Java. That is entirely possible, and certainly should be preferred over the Java version for performance (as documented in the Javadoc). If you look at There should likely be another constructor added for @mikhail-antonov The tests seem to show at present that the C++ and Java comparator implementations of Bytewise Comparator are equivalent. Do you believe you have found a bug in the Java BytewiseComparator implementation? |
Thanks for the detailed reply. I totally see the value of being able to implement custom comparators in Java and use it.
Well, unless I'm missing something, in the first post in this issue I've described how Java and native implementations are different? https://gist.github.com/mikhail-antonov/ef4fd053f8e47947fc59e6cd559aa77d - is a test that fails for me, Java comparator that is. |
@adamretter any thoughts? I think that with JNI wrapper supporting comparator-less constructor Bytewise comparator in Java isn't needed for the most part, and it does seem to be incompatible with memcmp semantics. |
Closing this via automation due to lack of activity. If discussion is still needed here, please re-open or create a new/updated issue. |
closes facebook#5891 closes facebook#2001 Java BytewiseComparator is now unsigned compliant, consistent with the default C++ comparator, which has always been thus. Consequently 2 tickets reporting the previous broken state can be closed. This test confirms that the following issues were in fact resolved by a change made between 6.2.2 and 6.22.1, to wit facebook@7242dae7 which as part of its effect, changed the Java bytewise comparators.
Hi, I'm using RocksJava to generate SST file from my Java code, and have been seeing an issue where I'm writing out the data that are lexicographically sorted, but getting occasional error, that I've narrowed down to an attempt to append out-of-order key.
The error I'm getting:
Caused by: org.rocksdb.RocksDBException: � at org.rocksdb.SstFileWriter.add(Native Method) at org.rocksdb.SstFileWriter.add(SstFileWriter.java:24)
This is code to repro:
Where fromHex conversion is done as in http://grepcode.com/file/repo1.maven.org/maven2/org.apache.hbase/hbase-common/1.1.1/org/apache/hadoop/hbase/util/Bytes.java#2357
I think there's something weird with the comparison here. BytewiseComparator in Java relies on ByteBuffer comparator semantics, which is:
Whereas the comparator semantics in my Java code is as (essentially same as in the class I've linked):
(to overcome byte signness in Java and make it more in line with memcmp).
Thoughts?
The text was updated successfully, but these errors were encountered: