mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-30 22:41:48 +00:00
Address review comments
This commit is contained in:
parent
130581ff3e
commit
fa151f1e38
|
@ -134,9 +134,7 @@ jbyteArray JNICALL Java_org_rocksdb_TypeUtil_getInternalKeyJni(
|
|||
ROCKSDB_NAMESPACE::Slice key_slice = seek_key_buf;
|
||||
jbyteArray jkey = env->NewByteArray(static_cast<jsize>(key_slice.size()));
|
||||
if (jkey == nullptr) {
|
||||
jclass oom_class = env->FindClass("/java/lang/OutOfMemoryError");
|
||||
env->ThrowNew(oom_class,
|
||||
"Memory allocation failed in RocksDB JNI function");
|
||||
ROCKSDB_NAMESPACE::OutOfMemoryErrorJni::ThrowNew(env, "Memory allocation failed in RocksDB JNI function");
|
||||
return nullptr;
|
||||
}
|
||||
ROCKSDB_NAMESPACE::JniUtil::copyToIndirect(
|
||||
|
@ -264,9 +262,7 @@ jbyteArray JNICALL Java_org_rocksdb_TypeUtil_getInternalKeyForPrevJni(
|
|||
ROCKSDB_NAMESPACE::Slice key_slice = seek_key_buf;
|
||||
jbyteArray jkey = env->NewByteArray(static_cast<jsize>(key_slice.size()));
|
||||
if (jkey == nullptr) {
|
||||
jclass oom_class = env->FindClass("/java/lang/OutOfMemoryError");
|
||||
env->ThrowNew(oom_class,
|
||||
"Memory allocation failed in RocksDB JNI function");
|
||||
ROCKSDB_NAMESPACE::OutOfMemoryErrorJni::ThrowNew(env, "Memory allocation failed in RocksDB JNI function");
|
||||
return nullptr;
|
||||
}
|
||||
ROCKSDB_NAMESPACE::JniUtil::copyToIndirect(
|
||||
|
|
|
@ -25,11 +25,11 @@ public enum EntryType {
|
|||
}
|
||||
|
||||
public static EntryType getEntryType(final byte value) {
|
||||
for (EntryType entryType : EntryType.values()) {
|
||||
for (final EntryType entryType : EntryType.values()) {
|
||||
if (value == entryType.value) {
|
||||
return entryType;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid ValueType byte " + value);
|
||||
throw new IllegalArgumentException("Invalid EntryType byte " + value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under both the GPLv2 (found in the
|
||||
// COPYING file in the root directory) and Apache 2.0 License
|
||||
// (found in the LICENSE.Apache file in the root directory).
|
||||
|
||||
package org.rocksdb;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
@ -15,20 +20,34 @@ public class ParsedEntryInfo extends RocksObject {
|
|||
disposeInternalJni(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entryType of record in the sstFile.
|
||||
*/
|
||||
public EntryType getEntryType() {
|
||||
assert (isOwningHandle());
|
||||
return EntryType.getEntryType(getEntryTypeJni(nativeHandle_));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sequence number of the record in the sstFile.
|
||||
*/
|
||||
public long getSequenceNumber() {
|
||||
return getSequenceNumberJni(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user key of the record in the sstFile.
|
||||
*/
|
||||
public byte[] getUserKey() {
|
||||
assert (isOwningHandle());
|
||||
return userKeyJni(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param key Byte buffer to write the user key into.
|
||||
* @return length of the key.
|
||||
*/
|
||||
public int userKey(final ByteBuffer key) {
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("ByteBuffer parameters must not be null");
|
||||
|
@ -45,7 +64,12 @@ public class ParsedEntryInfo extends RocksObject {
|
|||
return result;
|
||||
}
|
||||
|
||||
public void parseEntry(Options options, byte[] internalKey) {
|
||||
/**
|
||||
* Parses internal key to get initialize the values in this class.
|
||||
* @param options options used while writing the sst file.
|
||||
* @param internalKey byte array containing the internal key.
|
||||
*/
|
||||
public final void parseEntry(Options options, byte[] internalKey) {
|
||||
if (options == null || internalKey == null) {
|
||||
throw new IllegalArgumentException("ByteBuffer and options parameters must not be null");
|
||||
}
|
||||
|
@ -53,7 +77,12 @@ public class ParsedEntryInfo extends RocksObject {
|
|||
parseEntry(nativeHandle_, options.getNativeHandle(), internalKey, internalKey.length);
|
||||
}
|
||||
|
||||
public void parseEntry(Options options, final ByteBuffer internalKey) {
|
||||
/**
|
||||
* Parses internal key to get initialize the values in this class.
|
||||
* @param options options used while writing the sst file.
|
||||
* @param internalKey ByteBuffer containing the internal key.
|
||||
*/
|
||||
public final void parseEntry(Options options, final ByteBuffer internalKey) {
|
||||
if (options == null || internalKey == null) {
|
||||
throw new IllegalArgumentException("ByteBuffer and options parameters must not be null");
|
||||
}
|
||||
|
|
|
@ -10,14 +10,14 @@ import java.nio.ByteBuffer;
|
|||
* Util class to get internal key for seeking from user key.
|
||||
*/
|
||||
public class TypeUtil {
|
||||
public static byte[] getInternalKey(byte[] userKey, Options options) {
|
||||
public static byte[] getInternalKey(final byte[] userKey, final Options options) {
|
||||
if (options == null || userKey == null) {
|
||||
throw new IllegalArgumentException("ByteBuffer and options parameters must not be null");
|
||||
}
|
||||
return getInternalKeyJni(userKey, userKey.length, options.getNativeHandle());
|
||||
}
|
||||
|
||||
public static int getInternalKey(ByteBuffer userKey, ByteBuffer internalKey, Options options) {
|
||||
public static int getInternalKey(final ByteBuffer userKey, final ByteBuffer internalKey, final Options options) {
|
||||
int result;
|
||||
if (options == null || userKey == null || internalKey == null) {
|
||||
throw new IllegalArgumentException("ByteBuffer and options parameters must not be null");
|
||||
|
@ -49,7 +49,7 @@ public class TypeUtil {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static byte[] getInternalKeyForPrev(byte[] userKey, Options options) {
|
||||
public static byte[] getInternalKeyForPrev(final byte[] userKey, final Options options) {
|
||||
if (options == null || userKey == null) {
|
||||
throw new IllegalArgumentException("Byte array and options parameters must not be null");
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class TypeUtil {
|
|||
}
|
||||
|
||||
public static int getInternalKeyForPrev(
|
||||
ByteBuffer userKey, ByteBuffer internalKey, Options options) {
|
||||
final ByteBuffer userKey, final ByteBuffer internalKey, final Options options) {
|
||||
if (options == null || userKey == null || internalKey == null) {
|
||||
throw new IllegalArgumentException("ByteBuffer and options parameters must not be null");
|
||||
}
|
||||
|
@ -89,33 +89,33 @@ public class TypeUtil {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static native int getInternalKeyDirect0(ByteBuffer userKey, int userKeyOffset,
|
||||
private static native int getInternalKeyDirect0(final ByteBuffer userKey, final int userKeyOffset,
|
||||
int userKeyLen, ByteBuffer internalKey, int internalKeyOffset, int internalKeyLen,
|
||||
long optionsHandle);
|
||||
private static native int getInternalKeyByteArray0(byte[] userKey, int userKeyOffset,
|
||||
int userKeyLen, ByteBuffer internalKey, int internalKeyOffset, int internalKeyLen,
|
||||
long optionsHandle);
|
||||
private static native int getInternalKeyDirect1(ByteBuffer userKey, int userKeyOffset,
|
||||
int userKeyLen, byte[] internalKey, int internalKeyOffset, int internalKeyLen,
|
||||
long optionsHandle);
|
||||
private static native int getInternalKeyByteArray1(byte[] userKey, int userKeyOffset,
|
||||
int userKeyLen, byte[] internalKey, int internalKeyOffset, int internalKeyLen,
|
||||
long optionsHandle);
|
||||
private static native int getInternalKeyByteArray0(final byte[] userKey, final int userKeyOffset,
|
||||
final int userKeyLen, final ByteBuffer internalKey, final int internalKeyOffset, final int internalKeyLen,
|
||||
final long optionsHandle);
|
||||
private static native int getInternalKeyDirect1(final ByteBuffer userKey, final int userKeyOffset,
|
||||
final int userKeyLen, final byte[] internalKey, final int internalKeyOffset, final int internalKeyLen,
|
||||
final long optionsHandle);
|
||||
private static native int getInternalKeyByteArray1(final byte[] userKey, final int userKeyOffset,
|
||||
final int userKeyLen, final byte[] internalKey, final int internalKeyOffset, final int internalKeyLen,
|
||||
final long optionsHandle);
|
||||
private static native byte[] getInternalKeyJni(
|
||||
byte[] userKey, int userKeyLen, long optionsHandle);
|
||||
final byte[] userKey, final int userKeyLen, final long optionsHandle);
|
||||
|
||||
private static native int getInternalKeyDirectForPrev0(ByteBuffer userKey, int userKeyOffset,
|
||||
int userKeyLen, ByteBuffer internalKey, int internalKeyOffset, int internalKeyLen,
|
||||
long optionsHandle);
|
||||
private static native int getInternalKeyByteArrayForPrev0(byte[] userKey, int userKeyOffset,
|
||||
int userKeyLen, ByteBuffer internalKey, int internalKeyOffset, int internalKeyLen,
|
||||
long optionsHandle);
|
||||
private static native int getInternalKeyDirectForPrev1(ByteBuffer userKey, int userKeyOffset,
|
||||
int userKeyLen, byte[] internalKey, int internalKeyOffset, int internalKeyLen,
|
||||
long optionsHandle);
|
||||
private static native int getInternalKeyByteArrayForPrev1(byte[] userKey, int userKeyOffset,
|
||||
int userKeyLen, byte[] internalKey, int internalKeyOffset, int internalKeyLen,
|
||||
long optionsHandle);
|
||||
private static native int getInternalKeyDirectForPrev0(final ByteBuffer userKey, final int userKeyOffset,
|
||||
final int userKeyLen, final ByteBuffer internalKey, final int internalKeyOffset, final int internalKeyLen,
|
||||
final long optionsHandle);
|
||||
private static native int getInternalKeyByteArrayForPrev0(final byte[] userKey, final int userKeyOffset,
|
||||
final int userKeyLen, final ByteBuffer internalKey, final int internalKeyOffset, final int internalKeyLen,
|
||||
final long optionsHandle);
|
||||
private static native int getInternalKeyDirectForPrev1(final ByteBuffer userKey, final int userKeyOffset,
|
||||
final int userKeyLen, final byte[] internalKey, final int internalKeyOffset, final int internalKeyLen,
|
||||
final long optionsHandle);
|
||||
private static native int getInternalKeyByteArrayForPrev1(final byte[] userKey, final int userKeyOffset,
|
||||
final int userKeyLen, final byte[] internalKey, final int internalKeyOffset, final int internalKeyLen,
|
||||
final long optionsHandle);
|
||||
private static native byte[] getInternalKeyForPrevJni(
|
||||
byte[] userKey, int userKeyLen, long optionsHandle);
|
||||
final byte[] userKey, final int userKeyLen, final long optionsHandle);
|
||||
}
|
||||
|
|
|
@ -220,15 +220,15 @@ public class SstFileReaderTest {
|
|||
}
|
||||
}
|
||||
|
||||
private void assertInternalKey(final Options options, ParsedEntryInfo parsedEntryInfo,
|
||||
byte[] internalKey, String expectedUserKey, EntryType expectedEntryType) {
|
||||
private void assertInternalKey(final Options options, final ParsedEntryInfo parsedEntryInfo,
|
||||
final byte[] internalKey, final String expectedUserKey, final EntryType expectedEntryType) {
|
||||
parsedEntryInfo.parseEntry(options, internalKey);
|
||||
assertThat(expectedUserKey.getBytes()).isEqualTo(parsedEntryInfo.getUserKey());
|
||||
assertEquals(expectedEntryType, parsedEntryInfo.getEntryType());
|
||||
}
|
||||
|
||||
private void seekTableIterator(
|
||||
SstFileReaderIterator iterator, ByteBuffer userKey, ByteBuffer internalKey, Options options) {
|
||||
private void seekTableIterator(final SstFileReaderIterator iterator, final ByteBuffer userKey,
|
||||
final ByteBuffer internalKey, final Options options) {
|
||||
int len = TypeUtil.getInternalKey(userKey, internalKey, options);
|
||||
assertEquals(len, internalKey.limit());
|
||||
iterator.seek(internalKey);
|
||||
|
@ -237,8 +237,8 @@ public class SstFileReaderTest {
|
|||
internalKey.clear();
|
||||
}
|
||||
|
||||
private void seekTableIteratorForPrev(
|
||||
SstFileReaderIterator iterator, ByteBuffer userKey, ByteBuffer internalKey, Options options) {
|
||||
private void seekTableIteratorForPrev(final SstFileReaderIterator iterator, final ByteBuffer userKey,
|
||||
final ByteBuffer internalKey, final Options options) {
|
||||
int len = TypeUtil.getInternalKeyForPrev(userKey, internalKey, options);
|
||||
assertEquals(len, internalKey.limit());
|
||||
iterator.seekForPrev(internalKey);
|
||||
|
|
Loading…
Reference in a new issue