Skip to content

Commit

Permalink
support set blob_gc_ratio, checkpoint_fake_flush; and createCheckpoin…
Browse files Browse the repository at this point in the history
…t can set log_size
  • Loading branch information
yapple committed Aug 8, 2022
1 parent f0fb9b7 commit b763f57
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/rocksdb/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions java/rocksjni/checkpoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<TERARKDB_NAMESPACE::Checkpoint*>(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);
}
}
56 changes: 56 additions & 0 deletions java/rocksjni/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,20 @@ jboolean Java_org_rocksdb_Options_allow2pc(JNIEnv* /*env*/, jobject /*jobj*/,
return static_cast<jboolean>(opt->allow_2pc);
}

void Java_org_rocksdb_Options_setCheckPointFakeFlush(
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle,
jboolean jcheck_point_fake_flush) {
auto* opt = reinterpret_cast<TERARKDB_NAMESPACE::Options*>(jhandle);
opt->check_point_fake_flush = static_cast<bool>(jcheck_point_fake_flush);
}

jboolean Java_org_rocksdb_Options_checkPointFakeFlush(JNIEnv* /*env*/,
jobject /*jobj*/,
jlong jhandle) {
auto* opt = reinterpret_cast<TERARKDB_NAMESPACE::Options*>(jhandle);
return static_cast<jboolean>(opt->check_point_fake_flush);
}

/*
* Class: org_rocksdb_Options
* Method: setRowCache
Expand Down Expand Up @@ -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<TERARKDB_NAMESPACE::Options*>(jhandle)->blob_gc_ratio =
static_cast<double>(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<TERARKDB_NAMESPACE::Options*>(jhandle)->blob_gc_ratio;
}

/*
* Class: org_rocksdb_Options
Expand Down Expand Up @@ -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<TERARKDB_NAMESPACE::ColumnFamilyOptions*>(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<TERARKDB_NAMESPACE::ColumnFamilyOptions*>(jhandle)
->blob_gc_ratio = static_cast<double>(jblob_gc_ratio);
}

/*
* Class: org_rocksdb_ColumnFamilyOptions
Expand Down
7 changes: 7 additions & 0 deletions java/src/main/java/org/rocksdb/Checkpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
12 changes: 12 additions & 0 deletions java/src/main/java/org/rocksdb/ColumnFamilyOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions java/src/main/java/org/rocksdb/DBOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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_;
Expand Down
5 changes: 5 additions & 0 deletions java/src/main/java/org/rocksdb/DBOptionsInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -1597,4 +1597,9 @@ T setEnableWriteThreadAdaptiveYield(
* @return true if we should avoid flush during shutdown
*/
boolean avoidFlushDuringShutdown();

T setCheckPointFakeFlush(boolean fakeFlush);

boolean checkPointFakeFlush();

}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ T setCompressionType(

long blobSize();

// T setBlobGcRatio(double blobGcRatio);
//
// double blobGcRatio();

T setTargetBlobFileSize(long blobSize);

long targetBlobFileSize();
Expand Down
26 changes: 26 additions & 0 deletions java/src/main/java/org/rocksdb/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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!
Expand Down
8 changes: 6 additions & 2 deletions options/db_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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",
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions options/db_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions options/options_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit b763f57

Please sign in to comment.