From 29b53449cf30463b35ac7405c3e986322f9adbd8 Mon Sep 17 00:00:00 2001 From: "wangyi.ywq" Date: Mon, 8 Aug 2022 17:03:31 +0800 Subject: [PATCH] support set blob_gc_ratio, checkpoint_fake_flush; and createCheckpoint can set log_size --- include/rocksdb/options.h | 2 +- java/rocksjni/checkpoint.cc | 20 +++++++ java/rocksjni/options.cc | 56 +++++++++++++++++++ .../src/main/java/org/rocksdb/Checkpoint.java | 7 +++ .../java/org/rocksdb/ColumnFamilyOptions.java | 12 ++++ java/src/main/java/org/rocksdb/DBOptions.java | 15 +++++ .../java/org/rocksdb/DBOptionsInterface.java | 5 ++ .../MutableColumnFamilyOptionsInterface.java | 4 ++ java/src/main/java/org/rocksdb/Options.java | 26 +++++++++ options/db_options.cc | 8 ++- options/db_options.h | 1 + options/options_helper.cc | 1 + 12 files changed, 154 insertions(+), 3 deletions(-) diff --git a/include/rocksdb/options.h b/include/rocksdb/options.h index 07ab6d0e74..0b48a058fe 100644 --- a/include/rocksdb/options.h +++ b/include/rocksdb/options.h @@ -993,7 +993,7 @@ struct DBOptions { // transaction is encountered in the WAL bool allow_2pc = false; - bool check_point_fake_flush = true; + bool check_point_fake_flush = false; // A global cache for table-level rows. // Default: nullptr (disabled) diff --git a/java/rocksjni/checkpoint.cc b/java/rocksjni/checkpoint.cc index 66e6134bb4..ee9fe5dc24 100644 --- a/java/rocksjni/checkpoint.cc +++ b/java/rocksjni/checkpoint.cc @@ -65,3 +65,23 @@ void Java_org_rocksdb_Checkpoint_createCheckpoint(JNIEnv* env, jobject /*jobj*/, TERARKDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s); } } + +void Java_org_rocksdb_Checkpoint_createCheckpoint(JNIEnv* env, jobject /*jobj*/, + jlong jcheckpoint_handle, + jstring jcheckpoint_path, + jlong jcheckpoint_log_size,) { + const char* checkpoint_path = env->GetStringUTFChars(jcheckpoint_path, 0); + if (checkpoint_path == nullptr) { + // exception thrown: OutOfMemoryError + return; + } + + auto* checkpoint = reinterpret_cast(jcheckpoint_handle); + TERARKDB_NAMESPACE::Status s = checkpoint->CreateCheckpoint(checkpoint_path,jcheckpoint_log_size); + + env->ReleaseStringUTFChars(jcheckpoint_path, checkpoint_path); + + if (!s.ok()) { + TERARKDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s); + } +} \ No newline at end of file diff --git a/java/rocksjni/options.cc b/java/rocksjni/options.cc index 0b25ddf22b..aa597a18b9 100644 --- a/java/rocksjni/options.cc +++ b/java/rocksjni/options.cc @@ -1807,6 +1807,20 @@ jboolean Java_org_rocksdb_Options_allow2pc(JNIEnv* /*env*/, jobject /*jobj*/, return static_cast(opt->allow_2pc); } +void Java_org_rocksdb_Options_setCheckPointFakeFlush( + JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle, + jboolean jcheck_point_fake_flush) { + auto* opt = reinterpret_cast(jhandle); + opt->check_point_fake_flush = static_cast(jcheck_point_fake_flush); +} + +jboolean Java_org_rocksdb_Options_checkPointFakeFlush(JNIEnv* /*env*/, + jobject /*jobj*/, + jlong jhandle) { + auto* opt = reinterpret_cast(jhandle); + return static_cast(opt->check_point_fake_flush); +} + /* * Class: org_rocksdb_Options * Method: setRowCache @@ -2536,6 +2550,27 @@ jlong Java_org_rocksdb_Options_blobSize(JNIEnv* /*env*/, jobject /*jobj*/, ->blob_size; } +/* + * Class: org_rocksdb_Options + * Method: setBlobGcRatio + * Signature: (JJ)V + */ +void Java_org_rocksdb_Options_setBlobGcRatio(JNIEnv* env, jobject /*jobj*/, + jlong jhandle, + jdouble jblob_gc_ratio) { + reinterpret_cast(jhandle)->blob_gc_ratio = + static_cast(jblob_gc_ratio); +} + +/* + * Class: org_rocksdb_Options + * Method: blobGcRatio + * Signature: (J)J + */ +jdouble Java_org_rocksdb_Options_blobGcRatio(JNIEnv* /*env*/, jobject /*jobj*/, + jlong jhandle) { + return reinterpret_cast(jhandle)->blob_gc_ratio; +} /* * Class: org_rocksdb_Options @@ -3409,6 +3444,27 @@ void Java_org_rocksdb_ColumnFamilyOptions_setBlobSize(JNIEnv* env, jobject /*job } } +/* + * Class: org_rocksdb_ColumnFamilyOptions + * Method: blobGcRatio + * Signature: (J)J + */ +jdouble Java_org_rocksdb_ColumnFamilyOptions_blobGcRatio(JNIEnv* /*env*/, + jobject /*jobj*/, + jlong jhandle) { + return reinterpret_cast(jhandle) + ->blob_gc_ratio; +} +/* + * Class: org_rocksdb_ColumnFamilyOptions + * Method: setBlobGcRatio + * Signature: (JJ)V + */ +void Java_org_rocksdb_ColumnFamilyOptions_setBlobGcRatio( + JNIEnv* env, jobject /*jobj*/, jlong jhandle, jdouble jblob_gc_ratio) { + reinterpret_cast(jhandle) + ->blob_gc_ratio = static_cast(jblob_gc_ratio); +} /* * Class: org_rocksdb_ColumnFamilyOptions diff --git a/java/src/main/java/org/rocksdb/Checkpoint.java b/java/src/main/java/org/rocksdb/Checkpoint.java index 0009699325..0c693a6189 100644 --- a/java/src/main/java/org/rocksdb/Checkpoint.java +++ b/java/src/main/java/org/rocksdb/Checkpoint.java @@ -51,6 +51,11 @@ public void createCheckpoint(final String checkpointPath) createCheckpoint(nativeHandle_, checkpointPath); } + public void createCheckpoint(final String checkpointPath, final long logSize) + throws RocksDBException { + createCheckpoint(nativeHandle_, checkpointPath, logSize); + } + private Checkpoint(final RocksDB db) { super(newCheckpoint(db.nativeHandle_)); this.db_ = db; @@ -63,4 +68,6 @@ private Checkpoint(final RocksDB db) { private native void createCheckpoint(long handle, String checkpointPath) throws RocksDBException; + private native void createCheckpoint(long handle, String checkpointPath, long logSize) + throws RocksDBException; } diff --git a/java/src/main/java/org/rocksdb/ColumnFamilyOptions.java b/java/src/main/java/org/rocksdb/ColumnFamilyOptions.java index 8563c41368..9b3f98b083 100644 --- a/java/src/main/java/org/rocksdb/ColumnFamilyOptions.java +++ b/java/src/main/java/org/rocksdb/ColumnFamilyOptions.java @@ -507,6 +507,16 @@ public long blobSize() { return blobSize(nativeHandle_); } + public ColumnFamilyOptions setBlobGcRatio( + final double blobGcRatio) { + setBlobGcRatio(nativeHandle_, blobGcRatio); + return this; + } + + public double blobGcRatio() { + return blobGcRatio(nativeHandle_); + } + @Override public ColumnFamilyOptions setCompactionStyle( final CompactionStyle compactionStyle) { @@ -908,6 +918,8 @@ private native void setDisableAutoCompactions( private native boolean disableAutoCompactions(long handle); private native void setBlobSize(long handle, long blobSize); private native long blobSize(long handle); + private native void setBlobGcRatio(long handle, double blobGcRatio); + private native double blobGcRatio(long handle); private native void setTargetBlobFileSize(long handle, long targetBlobFileSize); private native long targetBlobFileSize(long handle); private native void setCompactionStyle(long handle, byte compactionStyle); diff --git a/java/src/main/java/org/rocksdb/DBOptions.java b/java/src/main/java/org/rocksdb/DBOptions.java index f987381b5a..ea5c17d7e3 100644 --- a/java/src/main/java/org/rocksdb/DBOptions.java +++ b/java/src/main/java/org/rocksdb/DBOptions.java @@ -976,6 +976,17 @@ private DBOptions(final long nativeHandle) { super(nativeHandle); } + @Override + public DBOptions setCheckPointFakeFlush(final boolean checkPointFakeFlush) { + setCheckPointFakeFlush(nativeHandle_, checkPointFakeFlush); + return this; + } + + @Override + public boolean checkPointFakeFlush(){ + return checkPointFakeFlush(nativeHandle_); + } + private static native long getDBOptionsFromProps( String optString); @@ -1155,6 +1166,10 @@ private native void setAvoidFlushDuringShutdown(final long handle, final boolean avoidFlushDuringShutdown); private native boolean avoidFlushDuringShutdown(final long handle); + private native void setCheckPointFakeFlush(final long handle, + final boolean checkPointFakeFlush); + private native boolean checkPointFakeFlush(final long handle); + // instance variables // NOTE: If you add new member variables, please update the copy constructor above! private Env env_; diff --git a/java/src/main/java/org/rocksdb/DBOptionsInterface.java b/java/src/main/java/org/rocksdb/DBOptionsInterface.java index 55541316f8..2210aff56b 100644 --- a/java/src/main/java/org/rocksdb/DBOptionsInterface.java +++ b/java/src/main/java/org/rocksdb/DBOptionsInterface.java @@ -1597,4 +1597,9 @@ T setEnableWriteThreadAdaptiveYield( * @return true if we should avoid flush during shutdown */ boolean avoidFlushDuringShutdown(); + + T setCheckPointFakeFlush(boolean fakeFlush); + + boolean checkPointFakeFlush(); + } diff --git a/java/src/main/java/org/rocksdb/MutableColumnFamilyOptionsInterface.java b/java/src/main/java/org/rocksdb/MutableColumnFamilyOptionsInterface.java index 345d2c9fa2..5040e7186a 100644 --- a/java/src/main/java/org/rocksdb/MutableColumnFamilyOptionsInterface.java +++ b/java/src/main/java/org/rocksdb/MutableColumnFamilyOptionsInterface.java @@ -161,6 +161,10 @@ T setCompressionType( long blobSize(); +// T setBlobGcRatio(double blobGcRatio); +// +// double blobGcRatio(); + T setTargetBlobFileSize(long blobSize); long targetBlobFileSize(); diff --git a/java/src/main/java/org/rocksdb/Options.java b/java/src/main/java/org/rocksdb/Options.java index 5415cec84e..e2ea74d480 100644 --- a/java/src/main/java/org/rocksdb/Options.java +++ b/java/src/main/java/org/rocksdb/Options.java @@ -1337,6 +1337,15 @@ public long blobSize(){ return blobSize(nativeHandle_); } + public Options setBlobGcRatio(final double blobGcRatio){ + setBlobGcRatio(nativeHandle_, blobGcRatio); + return this; + } + + public double blobGcRatio(){ + return blobGcRatio(nativeHandle_); + } + @Override public Options setTargetBlobFileSize(final long targetBlobFileSize){ setTargetBlobFileSize(nativeHandle_,targetBlobFileSize); @@ -1598,6 +1607,17 @@ public boolean forceConsistencyChecks() { return forceConsistencyChecks(nativeHandle_); } + @Override + public Options setCheckPointFakeFlush(final boolean checkPointFakeFlush) { + setCheckPointFakeFlush(nativeHandle_, checkPointFakeFlush); + return this; + } + + @Override + public boolean checkPointFakeFlush(){ + return checkPointFakeFlush(nativeHandle_); + } + private native static long newOptions(); private native static long newOptions(long dbOptHandle, long cfOptHandle); @@ -1857,6 +1877,8 @@ private native void setDisableAutoCompactions( private native boolean disableAutoCompactions(long handle); private native void setBlobSize(long handle, long blobSize); private native long blobSize(long handle); + private native void setBlobGcRatio(long handle, double blobGcRatio); + private native double blobGcRatio(long handle); private native void setTargetBlobFileSize(long handle, long blobSize); private native long targetBlobFileSize(long handle); private native void setCompactionStyle(long handle, byte compactionStyle); @@ -1928,6 +1950,10 @@ private native void setCompactionOptionsFIFO(final long handle, private native void setForceConsistencyChecks(final long handle, final boolean forceConsistencyChecks); private native boolean forceConsistencyChecks(final long handle); + private native void setCheckPointFakeFlush(final long handle, + final boolean checkPointFakeFlush); + private native boolean checkPointFakeFlush(final long handle); + // instance variables // NOTE: If you add new member variables, please update the copy constructor above! diff --git a/options/db_options.cc b/options/db_options.cc index 649196ee69..0c250ec47a 100644 --- a/options/db_options.cc +++ b/options/db_options.cc @@ -269,7 +269,8 @@ MutableDBOptions::MutableDBOptions() compaction_readahead_size(0), zenfs_low_gc_ratio(0.25), zenfs_high_gc_ratio(0.6), - zenfs_force_gc_ratio(0.9) {} + zenfs_force_gc_ratio(0.9), + check_point_fake_flush(false) {} MutableDBOptions::MutableDBOptions(const DBOptions& options) : max_background_jobs(options.max_background_jobs), @@ -293,7 +294,8 @@ MutableDBOptions::MutableDBOptions(const DBOptions& options) compaction_readahead_size(options.compaction_readahead_size), zenfs_low_gc_ratio(options.zenfs_low_gc_ratio), zenfs_high_gc_ratio(options.zenfs_high_gc_ratio), - zenfs_force_gc_ratio(options.zenfs_force_gc_ratio) {} + zenfs_force_gc_ratio(options.zenfs_force_gc_ratio), + check_point_fake_flush(options.check_point_fake_flush) {} void MutableDBOptions::Dump(Logger* log) const { ROCKS_LOG_HEADER(log, " Options.max_background_jobs: %d", @@ -342,6 +344,8 @@ void MutableDBOptions::Dump(Logger* log) const { zenfs_high_gc_ratio); ROCKS_LOG_HEADER(log, " Options.zenfs_force_ratio: %lf", zenfs_force_gc_ratio); + ROCKS_LOG_HEADER(log, " Options.checkpoint_fake_flush: %lf", + check_point_fake_flush); } } // namespace TERARKDB_NAMESPACE diff --git a/options/db_options.h b/options/db_options.h index caa67ab463..36456664c6 100644 --- a/options/db_options.h +++ b/options/db_options.h @@ -116,6 +116,7 @@ struct MutableDBOptions { double zenfs_low_gc_ratio; double zenfs_high_gc_ratio; double zenfs_force_gc_ratio; + bool check_point_fake_flush; }; } // namespace TERARKDB_NAMESPACE diff --git a/options/options_helper.cc b/options/options_helper.cc index 93f18d9273..7fe54676cc 100644 --- a/options/options_helper.cc +++ b/options/options_helper.cc @@ -107,6 +107,7 @@ DBOptions BuildDBOptions(const ImmutableDBOptions& immutable_db_options, options.zenfs_low_gc_ratio = mutable_db_options.zenfs_low_gc_ratio; options.zenfs_high_gc_ratio = mutable_db_options.zenfs_high_gc_ratio; options.zenfs_force_gc_ratio = mutable_db_options.zenfs_force_gc_ratio; + options.check_point_fake_flush = mutable_db_options.check_point_fake_flush; options.random_access_max_buffer_size = immutable_db_options.random_access_max_buffer_size; options.writable_file_max_buffer_size =