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
This commit is contained in:
Tomas Kolda 2020-04-07 20:16:08 -07:00 committed by Facebook GitHub Bot
parent 487ebe4fd5
commit 0b136308b0
2 changed files with 3 additions and 3 deletions

View File

@ -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);

View File

@ -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,