Fix crash in JNI getApproximateSizes (#6652)

Summary:
This change is fixing a crash happening in getApproximateSizes JNI implementation. It also reenables Java test that was crashing most likelly because if this bug.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6652

Reviewed By: cheng-chang

Differential Revision: D20874865

Pulled By: pdillinger

fbshipit-source-id: da95516f15e5df2efe1a4e5690a2ce172cb53f87
main
Tomas Kolda 5 years ago committed by Facebook GitHub Bot
parent 487ebe4fd5
commit 0b136308b0
  1. 3
      java/rocksjni/rocksjni.cc
  2. 3
      java/src/test/java/org/rocksdb/RocksDBTest.java

@ -2277,10 +2277,11 @@ jlongArray Java_org_rocksdb_RocksDB_getApproximateSizes(
auto ranges = std::unique_ptr<ROCKSDB_NAMESPACE::Range[]>(
new ROCKSDB_NAMESPACE::Range[range_count]);
size_t range_offset = 0;
for (jsize i = 0; i < jlen; ++i) {
auto* start = reinterpret_cast<ROCKSDB_NAMESPACE::Slice*>(jranges[i]);
auto* limit = reinterpret_cast<ROCKSDB_NAMESPACE::Slice*>(jranges[++i]);
ranges.get()[i] = ROCKSDB_NAMESPACE::Range(*start, *limit);
ranges.get()[range_offset++] = ROCKSDB_NAMESPACE::Range(*start, *limit);
}
auto* db = reinterpret_cast<ROCKSDB_NAMESPACE::DB*>(jdb_handle);

@ -1221,7 +1221,6 @@ public class RocksDBTest {
}
}
@Ignore("This test crashes. Re-enable after fixing.")
@Test
public void getApproximateSizes() throws RocksDBException {
final byte key1[] = "key1".getBytes(UTF_8);
@ -1236,7 +1235,7 @@ public class RocksDBTest {
final long[] sizes = db.getApproximateSizes(
Arrays.asList(
new Range(new Slice(key1), new Slice(key2)),
new Range(new Slice(key1), new Slice(key1)),
new Range(new Slice(key2), new Slice(key3))
),
SizeApproximationFlag.INCLUDE_FILES,

Loading…
Cancel
Save