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
Java API consistency between RocksDB.put() , .merge() and Transaction.put() , .merge() #11019
Java API consistency between RocksDB.put() , .merge() and Transaction.put() , .merge() #11019
Conversation
ca49c01
to
7db31d6
Compare
9e8129c
to
27eaf01
Compare
848d1e6
to
4b92030
Compare
4b92030
to
b3c2e98
Compare
@alanpaxton Please rebase. A lot of new merge conflicts due to #10951 getting merged, I think. |
b3c2e98
to
9c9fa99
Compare
9c9fa99
to
2bd1093
Compare
@anand1976 @adamretter rebased and once again ready for review/import. |
@anand1976 rebased and once again ready for review/import. |
2bd1093
to
e5ec8ce
Compare
e5ec8ce
to
a57d1eb
Compare
@anand1976 rebased and once again ready for review/import. |
a57d1eb
to
f06e2b7
Compare
@anand1976 rebased and once again ready for review/import. |
76c6b46
to
eeb799c
Compare
@anand1976 I have rebased, and this is now passing except for the known vs2019 issue on main which @rhubner is addressing. Are you happy to review/merge it at this point ? |
MS compiler doesn’t like it.
Wrap steps in try { … } catch (ROCKSDB_NAMESPACE::KVException&) { } A KVException is thrown if something goes wrong at any stage, RAII takes care of cleanup in which case we return the appropriate type of error value.
Implement testing for put() to indirect ByteBuffer which needs default CF handle.
Missing get(ro, cf, byte[], byte[]) so add that. Test that, and add tests for other new get() methods missing tests. Re-order params in 1 method for consistency. Fix some holes in RocksDB.defaultColumnFamily; initialization was missed by some open() calls and TransactionDB.
- there’s no assumeTracked flag in mergeUntracked - Add ByteBuffer methods - rationalise and clean up native support methods
To conform to the general pattern of get() / merge() … methods we are trying to enforce across the codebase. Methods to return key / value in provided byte[], in addition to existing method where the API creates a new one. Move shared CheckBounds method to new BufferUtil class.
Replace with new-style slice wrappers.
Having changed some of the Java APIs to store the default column family handle as a singleton from the DB, it turns out we missed a couple of places where this needed to be copied. Thanks, tests.
Add missing API methods to Transaction.getIterator() class to match those in RocksDB.newIterator(..) Fix all the C++ support to go through a single JNI method for the Transaction class. Fix all the C++ support to go through a single JNI method for the RocksDB class.
Writing HISTORY.md for public facing APIs I discovered that I had not implemented the orthogonal set of methods for Transaction.getForUpdate(). Add consequent tests and documentation comments. Testing showed some ByteBuffer methods were not updating position/limit appropriately, or at all. Fix them. Fix consequently broken tests.
Allow key / value size parameters Add byte buffer tests as well as byte[]
Implemented/extended PutBenchmark java/jmh sanity test to confirm that the branch/PR changes do not materially alter put performance. Remove questionable/unrepro short Mac benchmark from documentation of java/jmh performance tests. Add BEFORE results Add AFTER results
happens in quite obvious patterns
7726049
to
30cd7a6
Compare
@jowlyzhang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@jowlyzhang merged this pull request in 5a063ec. |
Implement new Java API get()/put()/merge() methods, and transactional variants.
The Java API methods are very inconsistent in terms of how they pass parameters (byte[], ByteBuffer), and what variants and defaulted parameters they support. We try to bring some consistency to this.
API Additions
Support Changes (C++)
The current JNI code in C++ supports multiple variants of methods through a number of helper functions. There are numerous TODO suggestions in the code proposing that the helpers be re-factored/shared.
We have taken a different approach for the new methods; we have created wrapper classes
JDirectBufferSlice
,JDirectBufferPinnableSlice
,JByteArraySlice
andJByteArrayPinnableSlice
RAII classes which construct slices from JNI parameters and can then be passed directly to RocksDB methods. For instance, theJava_org_rocksdb_Transaction_getDirect
method is implemented like this:Notice the try/catch mechanism with the
KVException
class, which combined with RAII and the wrapper classes means that there is no ad-hoc cleanup necessary in the JNI methods.We propose to extend this mechanism to existing JNI methods as further work.
Support Changes (Java)
Where there are multiple parameter-variant versions of the same method, we use fewer or just one supporting native method for all of them. This makes maintenance a bit easier and reduces the opportunity for coding errors mixing up (untyped) object handles.
In order to support this efficiently, some classes need to have default values for column families and read options added and cached so that they are not re-constructed on every method call.
This PR closes #9776