Skip to content

Commit

Permalink
Fix GetPrimitiveArrayCritical
Browse files Browse the repository at this point in the history
(Sometimes) when the function is NOT returning
a copy and the array is released with JNI_ABORT mode,
the writes to the array will be rolled back
(maybe always).
  • Loading branch information
alucarded committed Oct 28, 2020
1 parent f5d247f commit cf2891b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions java/rocksjni/rocksjni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1216,9 +1216,8 @@ jint rocksdb_get_unsafe_helper(
return kStatusError;
}

jboolean is_copy;
jlong* ret_arr = reinterpret_cast<jlong*>(
env->GetPrimitiveArrayCritical(jret_data, &is_copy));
env->GetPrimitiveArrayCritical(jret_data, nullptr));
if (nullptr == ret_arr) {
// Exception occurred
*has_exception = true;
Expand All @@ -1227,8 +1226,7 @@ jint rocksdb_get_unsafe_helper(
ret_arr[0] = reinterpret_cast<jlong>(value_slice);
ret_arr[1] = reinterpret_cast<jlong>(value_slice->data());

env->ReleasePrimitiveArrayCritical(jret_data, ret_arr,
is_copy ? 0 : JNI_ABORT);
env->ReleasePrimitiveArrayCritical(jret_data, ret_arr, 0);

*has_exception = false;

Expand Down
2 changes: 1 addition & 1 deletion java/src/test/java/org/rocksdb/RocksDBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public void getUnsafe() throws RocksDBException {
final ReadOptions optr = new ReadOptions()) {
final byte[] key1 = "key1".getBytes();
final byte[] value1 = "value1".getBytes();
db.put(key1, value1);
db.put(db.getDefaultColumnFamily(), key1, value1);
try (PinnableSlice pinnableSlice = db.getUnsafe(db.getDefaultColumnFamily(), optr, key1)) {
for (int i = 0; i < pinnableSlice.capacity(); ++i) {
assertEquals(value1[i], pinnableSlice.get());
Expand Down

0 comments on commit cf2891b

Please sign in to comment.