mirror of https://github.com/facebook/rocksdb.git
[RocksJava] LogLevel support in Options
It's now possible to set a LogLevel in Options and DBOptions to control LOG verbosity.
This commit is contained in:
parent
353303a765
commit
07cd3c42a2
|
@ -57,6 +57,7 @@ JAVA_TESTS = org.rocksdb.test.BackupableDBTest\
|
|||
org.rocksdb.test.DirectComparatorTest\
|
||||
org.rocksdb.test.FilterTest\
|
||||
org.rocksdb.test.FlushTest\
|
||||
org.rocksdb.test.InfoLogLevelTest\
|
||||
org.rocksdb.test.KeyMayExistTest\
|
||||
org.rocksdb.test.MemTableTest\
|
||||
org.rocksdb.test.MergeTest\
|
||||
|
|
|
@ -83,11 +83,26 @@ public class DBOptions extends RocksObject implements DBOptionsInterface {
|
|||
|
||||
@Override
|
||||
public DBOptions setRateLimiterConfig(RateLimiterConfig config) {
|
||||
assert(isInitialized());
|
||||
rateLimiterConfig_ = config;
|
||||
setRateLimiter(nativeHandle_, config.newRateLimiterHandle());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DBOptions setInfoLogLevel(InfoLogLevel infoLogLevel) {
|
||||
assert(isInitialized());
|
||||
setInfoLogLevel(nativeHandle_, infoLogLevel.getValue());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfoLogLevel infoLogLevel() {
|
||||
assert(isInitialized());
|
||||
return InfoLogLevel.getInfoLogLevel(
|
||||
infoLogLevel(nativeHandle_));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DBOptions setMaxOpenFiles(int maxOpenFiles) {
|
||||
assert(isInitialized());
|
||||
|
@ -487,6 +502,8 @@ public class DBOptions extends RocksObject implements DBOptionsInterface {
|
|||
private native boolean paranoidChecks(long handle);
|
||||
private native void setRateLimiter(long handle,
|
||||
long rateLimiterHandle);
|
||||
private native void setInfoLogLevel(long handle, byte logLevel);
|
||||
private native byte infoLogLevel(long handle);
|
||||
private native void setMaxOpenFiles(long handle, int maxOpenFiles);
|
||||
private native int maxOpenFiles(long handle);
|
||||
private native void setMaxTotalWalSize(long handle,
|
||||
|
|
|
@ -113,6 +113,20 @@ public interface DBOptionsInterface {
|
|||
*/
|
||||
Object setRateLimiterConfig(RateLimiterConfig config);
|
||||
|
||||
/**
|
||||
* <p>Sets the RocksDB log level. Default level is INFO</p>
|
||||
*
|
||||
* @param infoLogLevel log level to set.
|
||||
* @return the instance of the current Object.
|
||||
*/
|
||||
Object setInfoLogLevel(InfoLogLevel infoLogLevel);
|
||||
|
||||
/**
|
||||
* <p>Returns currently set log level.</p>
|
||||
* @return {@link org.rocksdb.InfoLogLevel} instance.
|
||||
*/
|
||||
InfoLogLevel infoLogLevel();
|
||||
|
||||
/**
|
||||
* Number of open files that can be used by the DB. You may need to
|
||||
* increase this if your database has a large working set. Value -1 means
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package org.rocksdb;
|
||||
|
||||
/**
|
||||
* RocksDB log levels.
|
||||
*/
|
||||
public enum InfoLogLevel {
|
||||
DEBUG_LEVEL((byte)0),
|
||||
INFO_LEVEL((byte)1),
|
||||
WARN_LEVEL((byte)2),
|
||||
ERROR_LEVEL((byte)3),
|
||||
FATAL_LEVEL((byte)4),
|
||||
NUM_INFO_LOG_LEVELS((byte)5);
|
||||
|
||||
private final byte value_;
|
||||
|
||||
private InfoLogLevel(byte value) {
|
||||
value_ = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the byte value of the enumerations value
|
||||
*
|
||||
* @return byte representation
|
||||
*/
|
||||
public byte getValue() {
|
||||
return value_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get InfoLogLevel by byte value.
|
||||
*
|
||||
* @param value byte representation of InfoLogLevel.
|
||||
*
|
||||
* @return {@link org.rocksdb.InfoLogLevel} instance or null.
|
||||
*/
|
||||
public static InfoLogLevel getInfoLogLevel(byte value) {
|
||||
for (InfoLogLevel infoLogLevel : InfoLogLevel.values()) {
|
||||
if (infoLogLevel.getValue() == value){
|
||||
return infoLogLevel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -604,6 +604,7 @@ public class Options extends RocksObject
|
|||
@Override
|
||||
public Options setMemTableConfig(MemTableConfig config)
|
||||
throws RocksDBException {
|
||||
assert(isInitialized());
|
||||
memTableConfig_ = config;
|
||||
setMemTableFactory(nativeHandle_, config.newMemTableFactoryHandle());
|
||||
return this;
|
||||
|
@ -611,11 +612,26 @@ public class Options extends RocksObject
|
|||
|
||||
@Override
|
||||
public Options setRateLimiterConfig(RateLimiterConfig config) {
|
||||
assert(isInitialized());
|
||||
rateLimiterConfig_ = config;
|
||||
setRateLimiter(nativeHandle_, config.newRateLimiterHandle());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Options setInfoLogLevel(InfoLogLevel infoLogLevel) {
|
||||
assert(isInitialized());
|
||||
setInfoLogLevel(nativeHandle_, infoLogLevel.getValue());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InfoLogLevel infoLogLevel() {
|
||||
assert(isInitialized());
|
||||
return InfoLogLevel.getInfoLogLevel(
|
||||
infoLogLevel(nativeHandle_));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String memTableFactoryName() {
|
||||
assert(isInitialized());
|
||||
|
@ -1025,6 +1041,8 @@ public class Options extends RocksObject
|
|||
private native boolean paranoidChecks(long handle);
|
||||
private native void setRateLimiter(long handle,
|
||||
long rateLimiterHandle);
|
||||
private native void setInfoLogLevel(long handle, byte logLevel);
|
||||
private native byte infoLogLevel(long handle);
|
||||
private native void setMaxOpenFiles(long handle, int maxOpenFiles);
|
||||
private native int maxOpenFiles(long handle);
|
||||
private native void setMaxTotalWalSize(long handle,
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
package org.rocksdb.test;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.rocksdb.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static java.nio.file.Files.readAllBytes;
|
||||
import static java.nio.file.Paths.get;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class InfoLogLevelTest {
|
||||
|
||||
@ClassRule
|
||||
public static final RocksMemoryResource rocksMemoryResource =
|
||||
new RocksMemoryResource();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder dbFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void testInfoLogLevel() throws RocksDBException,
|
||||
IOException {
|
||||
RocksDB db = null;
|
||||
try {
|
||||
db = RocksDB.open(dbFolder.getRoot().getAbsolutePath());
|
||||
db.put("key".getBytes(), "value".getBytes());
|
||||
assertThat(getLogContents()).isNotEmpty();
|
||||
} finally {
|
||||
if (db != null) {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFatalLogLevel() throws RocksDBException,
|
||||
IOException {
|
||||
RocksDB db = null;
|
||||
Options options = null;
|
||||
try {
|
||||
options = new Options().
|
||||
setCreateIfMissing(true).
|
||||
setInfoLogLevel(InfoLogLevel.FATAL_LEVEL);
|
||||
assertThat(options.infoLogLevel()).
|
||||
isEqualTo(InfoLogLevel.FATAL_LEVEL);
|
||||
db = RocksDB.open(options,
|
||||
dbFolder.getRoot().getAbsolutePath());
|
||||
db.put("key".getBytes(), "value".getBytes());
|
||||
assertThat(getLogContents()).isEmpty();
|
||||
} finally {
|
||||
if (db != null) {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFatalLogLevelWithDBOptions()
|
||||
throws RocksDBException, IOException {
|
||||
RocksDB db = null;
|
||||
Options options = null;
|
||||
DBOptions dbOptions = null;
|
||||
try {
|
||||
dbOptions = new DBOptions().
|
||||
setInfoLogLevel(InfoLogLevel.FATAL_LEVEL);
|
||||
options = new Options(dbOptions,
|
||||
new ColumnFamilyOptions()).
|
||||
setCreateIfMissing(true);
|
||||
assertThat(dbOptions.infoLogLevel()).
|
||||
isEqualTo(InfoLogLevel.FATAL_LEVEL);
|
||||
assertThat(options.infoLogLevel()).
|
||||
isEqualTo(InfoLogLevel.FATAL_LEVEL);
|
||||
db = RocksDB.open(options,
|
||||
dbFolder.getRoot().getAbsolutePath());
|
||||
db.put("key".getBytes(), "value".getBytes());
|
||||
assertThat(getLogContents()).isEmpty();
|
||||
} finally {
|
||||
if (db != null) {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read LOG file contents into String.
|
||||
*
|
||||
* @return LOG file contents as String.
|
||||
* @throws IOException if file is not found.
|
||||
*/
|
||||
private String getLogContents() throws IOException {
|
||||
return new String(readAllBytes(get(
|
||||
dbFolder.getRoot().getAbsolutePath()+ "/LOG")));
|
||||
}
|
||||
}
|
|
@ -625,6 +625,28 @@ void Java_org_rocksdb_Options_setRateLimiter(
|
|||
reinterpret_cast<rocksdb::RateLimiter*>(jrate_limiter_handle));
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_Options
|
||||
* Method: setInfoLogLevel
|
||||
* Signature: (JB)V
|
||||
*/
|
||||
void Java_org_rocksdb_Options_setInfoLogLevel(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle, jbyte jlog_level) {
|
||||
reinterpret_cast<rocksdb::Options*>(jhandle)->info_log_level =
|
||||
static_cast<rocksdb::InfoLogLevel>(jlog_level);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_Options
|
||||
* Method: infoLogLevel
|
||||
* Signature: (J)B
|
||||
*/
|
||||
jbyte Java_org_rocksdb_Options_infoLogLevel(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle) {
|
||||
return static_cast<jbyte>(
|
||||
reinterpret_cast<rocksdb::Options*>(jhandle)->info_log_level);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_Options
|
||||
* Method: tableCacheNumshardbits
|
||||
|
@ -2835,6 +2857,28 @@ void Java_org_rocksdb_DBOptions_setRateLimiter(
|
|||
reinterpret_cast<rocksdb::RateLimiter*>(jrate_limiter_handle));
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_DBOptions
|
||||
* Method: setInfoLogLevel
|
||||
* Signature: (JB)V
|
||||
*/
|
||||
void Java_org_rocksdb_DBOptions_setInfoLogLevel(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle, jbyte jlog_level) {
|
||||
reinterpret_cast<rocksdb::DBOptions*>(jhandle)->info_log_level =
|
||||
static_cast<rocksdb::InfoLogLevel>(jlog_level);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_DBOptions
|
||||
* Method: infoLogLevel
|
||||
* Signature: (J)B
|
||||
*/
|
||||
jbyte Java_org_rocksdb_DBOptions_infoLogLevel(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle) {
|
||||
return static_cast<jbyte>(
|
||||
reinterpret_cast<rocksdb::DBOptions*>(jhandle)->info_log_level);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_DBOptions
|
||||
* Method: setMaxTotalWalSize
|
||||
|
|
Loading…
Reference in New Issue