Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions java/rocksjni/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3816,6 +3816,29 @@ jint Java_org_rocksdb_Options_blobFileStartingLevel(JNIEnv*, jclass,
return static_cast<jint>(opts->blob_file_starting_level);
}

/*
* Class: org_rocksdb_Options
* Method: setMemtableProtectionBytesPerKey
* Signature: (JI)V
*/
void Java_org_rocksdb_Options_setMemtableProtectionBytesPerKey(
JNIEnv*, jclass, jlong jhandle, jint jmemtable_protection_bytes_per_key) {
auto* opts = reinterpret_cast<ROCKSDB_NAMESPACE::Options*>(jhandle);
opts->memtable_protection_bytes_per_key =
static_cast<uint32_t>(jmemtable_protection_bytes_per_key);
}

/*
* Class: org_rocksdb_Options
* Method: memtableProtectionBytesPerKey
* Signature: (J)I
*/
jint Java_org_rocksdb_Options_memtableProtectionBytesPerKey(
JNIEnv*, jclass, jlong jhandle) {
auto* opts = reinterpret_cast<ROCKSDB_NAMESPACE::Options*>(jhandle);
return static_cast<jint>(opts->memtable_protection_bytes_per_key);
}

/*
* Class: org_rocksdb_Options
* Method: setPrepopulateBlobCache
Expand Down Expand Up @@ -5728,6 +5751,31 @@ jint Java_org_rocksdb_ColumnFamilyOptions_blobFileStartingLevel(JNIEnv*, jclass,
return static_cast<jint>(opts->blob_file_starting_level);
}

/*
* Class: org_rocksdb_ColumnFamilyOptions
* Method: setMemtableProtectionBytesPerKey
* Signature: (JI)V
*/
void Java_org_rocksdb_ColumnFamilyOptions_setMemtableProtectionBytesPerKey(
JNIEnv*, jclass, jlong jhandle, jint jmemtable_protection_bytes_per_key) {
auto* opts =
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyOptions*>(jhandle);
opts->memtable_protection_bytes_per_key =
static_cast<uint32_t>(jmemtable_protection_bytes_per_key);
}

/*
* Class: org_rocksdb_ColumnFamilyOptions
* Method: memtableProtectionBytesPerKey
* Signature: (J)I
*/
jint Java_org_rocksdb_ColumnFamilyOptions_memtableProtectionBytesPerKey(
JNIEnv*, jclass, jlong jhandle) {
auto* opts =
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyOptions*>(jhandle);
return static_cast<jint>(opts->memtable_protection_bytes_per_key);
}

/*
* Class: org_rocksdb_ColumnFamilyOptions
* Method: setPrepopulateBlobCache
Expand Down Expand Up @@ -7966,6 +8014,29 @@ void Java_org_rocksdb_WriteOptions_setMemtableInsertHintPerBatch(
static_cast<bool>(jmemtable_insert_hint_per_batch);
}

/*
* Class: org_rocksdb_WriteOptions
* Method: setProtectionBytesPerKey
* Signature: (JJ)V
*/
void Java_org_rocksdb_WriteOptions_setProtectionBytesPerKey(
JNIEnv*, jclass, jlong jhandle, jlong jprotection_bytes_per_key) {
reinterpret_cast<ROCKSDB_NAMESPACE::WriteOptions*>(jhandle)
->protection_bytes_per_key = static_cast<size_t>(jprotection_bytes_per_key);
}

/*
* Class: org_rocksdb_WriteOptions
* Method: protectionBytesPerKey
* Signature: (J)J
*/
jlong Java_org_rocksdb_WriteOptions_protectionBytesPerKey(
JNIEnv*, jclass, jlong jhandle) {
return static_cast<jlong>(
reinterpret_cast<ROCKSDB_NAMESPACE::WriteOptions*>(jhandle)
->protection_bytes_per_key);
}

/////////////////////////////////////////////////////////////////////
// ROCKSDB_NAMESPACE::ReadOptions

Expand Down
17 changes: 17 additions & 0 deletions java/rocksjni/rocksjni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3380,6 +3380,23 @@ void Java_org_rocksdb_RocksDB_verifyChecksum(JNIEnv* env, jclass,
}
}

/*
* Class: org_rocksdb_RocksDB
* Method: verifyFileChecksums
* Signature: (JJ)V
*/
void Java_org_rocksdb_RocksDB_verifyFileChecksums(JNIEnv* env, jclass,
jlong jdb_handle,
jlong jread_options_handle) {
auto* db = reinterpret_cast<ROCKSDB_NAMESPACE::DB*>(jdb_handle);
auto* read_options =
reinterpret_cast<ROCKSDB_NAMESPACE::ReadOptions*>(jread_options_handle);
auto s = db->VerifyFileChecksums(*read_options);
if (!s.ok()) {
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
}
}

/*
* Class: org_rocksdb_RocksDB
* Method: getDefaultColumnFamily
Expand Down
14 changes: 14 additions & 0 deletions java/rocksjni/write_batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ jlong Java_org_rocksdb_WriteBatch_newWriteBatch__I(JNIEnv* /*env*/,
return GET_CPLUSPLUS_POINTER(wb);
}

/*
* Class: org_rocksdb_WriteBatch
* Method: newWriteBatch
* Signature: (IJ)J
*/
jlong Java_org_rocksdb_WriteBatch_newWriteBatch__IJ(
JNIEnv* /*env*/, jclass /*jcls*/, jint jreserved_bytes,
jlong jprotection_bytes_per_key) {
auto* wb = new ROCKSDB_NAMESPACE::WriteBatch(
static_cast<size_t>(jreserved_bytes), /*max_bytes=*/0,
static_cast<size_t>(jprotection_bytes_per_key), /*default_cf_ts_sz=*/0);
return GET_CPLUSPLUS_POINTER(wb);
}

/*
* Class: org_rocksdb_WriteBatch
* Method: newWriteBatch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,29 @@ T setReportBgIoStats(
*/
int blobFileStartingLevel();

/**
* Set the number of bytes per key-value checksum for memtables.
* Enables per-KV checksum protection in memtables to detect silent data corruption
* <p>
* Default: 0 (disabled)
* <p>
* Supported values: 0, 1, 2, 4, 8 - 8 bytes per key
*
* @param memtableProtectionBytesPerKey number of checksum bytes per key-value
*
* @return the reference to the current options
*/
T setMemtableProtectionBytesPerKey(final int memtableProtectionBytesPerKey);

/**
* Get the number of bytes per key-value checksum for memtables
* <p>
* Default: 0
*
* @return the number of checksum bytes per key-value
*/
int memtableProtectionBytesPerKey();

/**
* Set a certain prepopulate blob cache option.
* <p>
Expand Down
34 changes: 34 additions & 0 deletions java/src/main/java/org/rocksdb/ColumnFamilyOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,37 @@ public int blobFileStartingLevel() {
return blobFileStartingLevel(nativeHandle_);
}

/**
* Set the number of bytes per key-value checksum for memtables.
* Enables per-KV checksum protection in memtables to detect silent data corruption.
* <p>
* Default: 0 (disabled)
* <p>
* Supported values: 0, 1, 2, 4, 8 - 8 bytes per key
*
* @param memtableProtectionBytesPerKey number of checksum bytes per key-value
*
* @return the reference to the current options.
*/
@Override
public ColumnFamilyOptions setMemtableProtectionBytesPerKey(
final int memtableProtectionBytesPerKey) {
setMemtableProtectionBytesPerKey(nativeHandle_, memtableProtectionBytesPerKey);
return this;
}

/**
* Get the number of bytes per key-value checksum for memtables
* <p>
* Default: 0
*
* @return the number of checksum bytes per key-value
*/
@Override
public int memtableProtectionBytesPerKey() {
return memtableProtectionBytesPerKey(nativeHandle_);
}

/**
* Set a certain prepopulate blob cache option.
* <p>
Expand Down Expand Up @@ -1502,6 +1533,9 @@ private static native void setBlobCompactionReadaheadSize(
private static native void setBlobFileStartingLevel(
final long nativeHandle_, final int blobFileStartingLevel);
private static native int blobFileStartingLevel(final long nativeHandle_);
private static native void setMemtableProtectionBytesPerKey(
final long nativeHandle_, final int memtableProtectionBytesPerKey);
private static native int memtableProtectionBytesPerKey(final long nativeHandle_);
private static native void setPrepopulateBlobCache(
final long nativeHandle_, final byte prepopulateBlobCache);
private static native byte prepopulateBlobCache(final long nativeHandle_);
Expand Down
14 changes: 13 additions & 1 deletion java/src/main/java/org/rocksdb/MutableColumnFamilyOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public enum MiscOption implements MutableColumnFamilyOptionKey {
max_sequential_skip_in_iterations(ValueType.LONG),
paranoid_file_checks(ValueType.BOOLEAN),
report_bg_io_stats(ValueType.BOOLEAN),
compression(ValueType.ENUM);
compression(ValueType.ENUM),
memtable_protection_bytes_per_key(ValueType.INT);

private final ValueType valueType;
MiscOption(final ValueType valueType) {
Expand Down Expand Up @@ -617,5 +618,16 @@ public MutableColumnFamilyOptionsBuilder setPrepopulateBlobCache(
public PrepopulateBlobCache prepopulateBlobCache() {
return getEnum(BlobOption.prepopulate_blob_cache);
}

@Override
public MutableColumnFamilyOptionsBuilder setMemtableProtectionBytesPerKey(
final int memtableProtectionBytesPerKey) {
return setInt(MiscOption.memtable_protection_bytes_per_key, memtableProtectionBytesPerKey);
}

@Override
public int memtableProtectionBytesPerKey() {
return getInt(MiscOption.memtable_protection_bytes_per_key);
}
}
}
14 changes: 14 additions & 0 deletions java/src/main/java/org/rocksdb/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -2092,6 +2092,17 @@ public PrepopulateBlobCache prepopulateBlobCache() {
return PrepopulateBlobCache.getPrepopulateBlobCache(prepopulateBlobCache(nativeHandle_));
}

@Override
public Options setMemtableProtectionBytesPerKey(final int memtableProtectionBytesPerKey) {
setMemtableProtectionBytesPerKey(nativeHandle_, memtableProtectionBytesPerKey);
return this;
}

@Override
public int memtableProtectionBytesPerKey() {
return memtableProtectionBytesPerKey(nativeHandle_);
}

//
// END options for blobs (integrated BlobDB)
//
Expand Down Expand Up @@ -2500,6 +2511,9 @@ private static native void setBlobCompactionReadaheadSize(
private static native void setBlobFileStartingLevel(
final long nativeHandle_, final int blobFileStartingLevel);
private static native int blobFileStartingLevel(final long nativeHandle_);
private static native void setMemtableProtectionBytesPerKey(
final long nativeHandle_, final int memtableProtectionBytesPerKey);
private static native int memtableProtectionBytesPerKey(final long nativeHandle_);
private static native void setPrepopulateBlobCache(
final long nativeHandle_, final byte prepopulateBlobCache);
private static native byte prepopulateBlobCache(final long nativeHandle_);
Expand Down
15 changes: 15 additions & 0 deletions java/src/main/java/org/rocksdb/RocksDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -4522,6 +4522,19 @@ public void verifyChecksum() throws RocksDBException {
verifyChecksum(nativeHandle_);
}

/**
* Verify checksums of files in the db.
* This performs verification of the file checksum with the entire file data,
* as opposed to {@link #verifyChecksum()} which checks blocks of data read during operation.
*
* @param readOptions Read options for the verification
* @throws RocksDBException if the checksum fails
*
*/
public void verifyFileChecksums(final ReadOptions readOptions) throws RocksDBException {
verifyFileChecksums(nativeHandle_, readOptions.nativeHandle_);
}

/**
* Gets the handle for the default column family
*
Expand Down Expand Up @@ -5064,6 +5077,8 @@ private static native void ingestExternalFile(final long handle, final long colu
final String[] filePathList, final int filePathListLen,
final long ingestExternalFileOptionsHandle) throws RocksDBException;
private static native void verifyChecksum(final long handle) throws RocksDBException;
private static native void verifyFileChecksums(final long handle, final long readOptionsHandle)
throws RocksDBException;
private static native long getDefaultColumnFamily(final long handle);
private static native Map<String, TableProperties> getPropertiesOfAllTables(
final long handle, final long columnFamilyHandle) throws RocksDBException;
Expand Down
14 changes: 14 additions & 0 deletions java/src/main/java/org/rocksdb/WriteBatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ public WriteBatch(final int reserved_bytes) {
super(newWriteBatch(reserved_bytes));
}

/**
* Constructs a WriteBatch instance with a given size and per-KV checksum protection.
* <p>
* Supported values: 0, 8
*
* @param reserved_bytes reserved size for WriteBatch
* @param protectionBytesPerKey number of checksum bytes per key-value
*/
public WriteBatch(final int reserved_bytes, final long protectionBytesPerKey) {
super(newWriteBatch(reserved_bytes, protectionBytesPerKey));
}

/**
* Constructs a WriteBatch instance from a serialized representation
* as returned by {@link #data()}.
Expand Down Expand Up @@ -371,6 +383,8 @@ final void setMaxBytes(final long nativeHandle, final long maxBytes) {
private static native void setMaxBytesJni(final long nativeHandle, final long maxBytes);

private static native long newWriteBatch(final int reserved_bytes);
private static native long newWriteBatch(
final int reserved_bytes, final long protectionBytesPerKey);
private static native long newWriteBatch(final byte[] serialized, final int serializedLength);
private static native void iterate(final long handle, final long handlerHandle)
throws RocksDBException;
Expand Down
31 changes: 31 additions & 0 deletions java/src/main/java/org/rocksdb/WriteOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,34 @@ public WriteOptions setMemtableInsertHintPerBatch(final boolean memtableInsertHi
return this;
}

/**
* Set the number of bytes per key-value checksum for write batches.
* Enables per-KV checksum protection in write batches to detect silent data corruption.
* <p>
* Default: 0
* <p>
* Supported values: 0, 8
*
* @param protectionBytesPerKey number of checksum bytes per key-value
*
* @return the instance of the current WriteOptions.
*/
public WriteOptions setProtectionBytesPerKey(final long protectionBytesPerKey) {
setProtectionBytesPerKey(nativeHandle_, protectionBytesPerKey);
return this;
}

/**
* Get the number of bytes per key-value checksum for write batches.
* <p>
* Default: 0
*
* @return the number of checksum bytes per key-value
*/
public long protectionBytesPerKey() {
return protectionBytesPerKey(nativeHandle_);
}

private static native long newWriteOptions();
private static native long copyWriteOptions(long handle);
@Override
Expand All @@ -255,4 +283,7 @@ private static native void setIgnoreMissingColumnFamilies(
private static native boolean memtableInsertHintPerBatch(final long handle);
private static native void setMemtableInsertHintPerBatch(
final long handle, final boolean memtableInsertHintPerBatch);
private static native void setProtectionBytesPerKey(
final long handle, final long protectionBytesPerKey);
private static native long protectionBytesPerKey(final long handle);
}
15 changes: 15 additions & 0 deletions java/src/test/java/org/rocksdb/ColumnFamilyOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,19 @@ public void memtableMaxRangeDeletions() {
assertThat(options.memtableMaxRangeDeletions()).isEqualTo(val);
}
}

@Test
public void memtableProtectionBytesPerKey() {
try (final ColumnFamilyOptions options = new ColumnFamilyOptions()) {
// Default should be 0 (disabled)
assertThat(options.memtableProtectionBytesPerKey()).isEqualTo(0);

// Test each supported value: 0, 1, 2, 4, 8
final int[] supportedValues = {0, 1, 2, 4, 8};
for (int val : supportedValues) {
assertThat(options.setMemtableProtectionBytesPerKey(val)).isEqualTo(options);
assertThat(options.memtableProtectionBytesPerKey()).isEqualTo(val);
}
}
}
}
Loading
Loading