// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
-// This source code is licensed under the BSD-style license found in the
-// LICENSE file in the root directory of this source tree. An additional grant
-// of patent rights can be found in the PATENTS file in the same directory.
+// 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;
* during the creation of a {@link org.rocksdb.RocksDB} (i.e., RocksDB.open()).
*
* If {@link #dispose()} function is not called, then it will be GC'd
- * automaticallyand native resources will be released as part of the process.
+ * automatically and native resources will be released as part of the process.
*/
public class Options extends RocksObject
- implements DBOptionsInterface<Options>, ColumnFamilyOptionsInterface<Options>,
+ implements DBOptionsInterface<Options>,
+ MutableDBOptionsInterface<Options>,
+ ColumnFamilyOptionsInterface<Options>,
MutableColumnFamilyOptionsInterface<Options> {
static {
RocksDB.loadLibrary();
env_ = Env.getDefault();
}
+ /**
+ * Copy constructor for ColumnFamilyOptions.
+ *
+ * NOTE: This does a shallow copy, which means comparator, merge_operator
+ * and other pointers will be cloned!
+ *
+ * @param other The Options to copy.
+ */
+ public Options(Options other) {
+ super(copyOptions(other.nativeHandle_));
+ this.env_ = other.env_;
+ this.memTableConfig_ = other.memTableConfig_;
+ this.tableFormatConfig_ = other.tableFormatConfig_;
+ this.rateLimiter_ = other.rateLimiter_;
+ this.comparator_ = other.comparator_;
+ this.compactionFilter_ = other.compactionFilter_;
+ this.compactionFilterFactory_ = other.compactionFilterFactory_;
+ this.compactionOptionsUniversal_ = other.compactionOptionsUniversal_;
+ this.compactionOptionsFIFO_ = other.compactionOptionsFIFO_;
+ this.compressionOptions_ = other.compressionOptions_;
+ this.rowCache_ = other.rowCache_;
+ this.writeBufferManager_ = other.writeBufferManager_;
+ }
+
@Override
public Options setIncreaseParallelism(final int totalThreads) {
assert(isOwningHandle());
@Override
public Options setComparator(
- final AbstractComparator<? extends AbstractSlice<?>> comparator) {
+ final AbstractComparator comparator) {
assert(isOwningHandle());
- setComparatorHandle(nativeHandle_, comparator.getNativeHandle());
+ setComparatorHandle(nativeHandle_, comparator.nativeHandle_,
+ comparator.getComparatorType().getValue());
comparator_ = comparator;
return this;
}
return this;
}
+ @Override
+ public Options setCompactionFilter(
+ final AbstractCompactionFilter<? extends AbstractSlice<?>>
+ compactionFilter) {
+ setCompactionFilterHandle(nativeHandle_, compactionFilter.nativeHandle_);
+ compactionFilter_ = compactionFilter;
+ return this;
+ }
+
+ @Override
+ public AbstractCompactionFilter<? extends AbstractSlice<?>> compactionFilter() {
+ assert (isOwningHandle());
+ return compactionFilter_;
+ }
+
+ @Override
+ public Options setCompactionFilterFactory(final AbstractCompactionFilterFactory<? extends AbstractCompactionFilter<?>> compactionFilterFactory) {
+ assert (isOwningHandle());
+ setCompactionFilterFactoryHandle(nativeHandle_, compactionFilterFactory.nativeHandle_);
+ compactionFilterFactory_ = compactionFilterFactory;
+ return this;
+ }
+
+ @Override
+ public AbstractCompactionFilterFactory<? extends AbstractCompactionFilter<?>> compactionFilterFactory() {
+ assert (isOwningHandle());
+ return compactionFilterFactory_;
+ }
+
@Override
public Options setWriteBufferSize(final long writeBufferSize) {
assert(isOwningHandle());
}
@Override
+ @Deprecated
public int maxBackgroundCompactions() {
assert(isOwningHandle());
return maxBackgroundCompactions(nativeHandle_);
}
@Override
- public Options createStatistics() {
+ public Options setStatistics(final Statistics statistics) {
assert(isOwningHandle());
- createStatistics(nativeHandle_);
+ setStatistics(nativeHandle_, statistics.nativeHandle_);
return this;
}
@Override
- public Statistics statisticsPtr() {
+ public Statistics statistics() {
assert(isOwningHandle());
-
- long statsPtr = statisticsPtr(nativeHandle_);
- if(statsPtr == 0) {
- createStatistics();
- statsPtr = statisticsPtr(nativeHandle_);
+ final long statisticsNativeHandle = statistics(nativeHandle_);
+ if(statisticsNativeHandle == 0) {
+ return null;
+ } else {
+ return new Statistics(statisticsNativeHandle);
}
-
- return new Statistics(statsPtr);
}
@Override
+ @Deprecated
public void setBaseBackgroundCompactions(
final int baseBackgroundCompactions) {
assert(isOwningHandle());
}
@Override
+ @Deprecated
public Options setMaxBackgroundCompactions(
final int maxBackgroundCompactions) {
assert(isOwningHandle());
}
@Override
- public void setMaxSubcompactions(final int maxSubcompactions) {
+ public Options setMaxSubcompactions(final int maxSubcompactions) {
assert(isOwningHandle());
setMaxSubcompactions(nativeHandle_, maxSubcompactions);
+ return this;
}
@Override
}
@Override
+ @Deprecated
public int maxBackgroundFlushes() {
assert(isOwningHandle());
return maxBackgroundFlushes(nativeHandle_);
}
@Override
+ @Deprecated
public Options setMaxBackgroundFlushes(
final int maxBackgroundFlushes) {
assert(isOwningHandle());
return this;
}
+ @Override
+ public int maxBackgroundJobs() {
+ assert(isOwningHandle());
+ return maxBackgroundJobs(nativeHandle_);
+ }
+
+ @Override
+ public Options setMaxBackgroundJobs(final int maxBackgroundJobs) {
+ assert(isOwningHandle());
+ setMaxBackgroundJobs(nativeHandle_, maxBackgroundJobs);
+ return this;
+ }
+
@Override
public long maxLogFileSize() {
assert(isOwningHandle());
return this;
}
+ @Override
+ public Options setStatsPersistPeriodSec(
+ final int statsPersistPeriodSec) {
+ assert(isOwningHandle());
+ setStatsPersistPeriodSec(nativeHandle_, statsPersistPeriodSec);
+ return this;
+ }
+
+ @Override
+ public int statsPersistPeriodSec() {
+ assert(isOwningHandle());
+ return statsPersistPeriodSec(nativeHandle_);
+ }
+
+ @Override
+ public Options setStatsHistoryBufferSize(
+ final long statsHistoryBufferSize) {
+ assert(isOwningHandle());
+ setStatsHistoryBufferSize(nativeHandle_, statsHistoryBufferSize);
+ return this;
+ }
+
+ @Override
+ public long statsHistoryBufferSize() {
+ assert(isOwningHandle());
+ return statsHistoryBufferSize(nativeHandle_);
+ }
+
@Override
public boolean adviseRandomOnOpen() {
return adviseRandomOnOpen(nativeHandle_);
}
@Override
+ public Options setWriteBufferManager(final WriteBufferManager writeBufferManager) {
+ assert(isOwningHandle());
+ setWriteBufferManager(nativeHandle_, writeBufferManager.nativeHandle_);
+ this.writeBufferManager_ = writeBufferManager;
+ return this;
+ }
+
+ @Override
+ public WriteBufferManager writeBufferManager() {
+ assert(isOwningHandle());
+ return this.writeBufferManager_;
+ }
+
+ @Override
public long dbWriteBufferSize() {
assert(isOwningHandle());
return dbWriteBufferSize(nativeHandle_);
return walBytesPerSync(nativeHandle_);
}
+ @Override
+ public Options setStrictBytesPerSync(final boolean strictBytesPerSync) {
+ assert(isOwningHandle());
+ setStrictBytesPerSync(nativeHandle_, strictBytesPerSync);
+ return this;
+ }
+
+ @Override
+ public boolean strictBytesPerSync() {
+ assert(isOwningHandle());
+ return strictBytesPerSync(nativeHandle_);
+ }
+
@Override
public Options setEnableThreadTracking(final boolean enableThreadTracking) {
assert(isOwningHandle());
return delayedWriteRate(nativeHandle_);
}
+ @Override
+ public Options setEnablePipelinedWrite(final boolean enablePipelinedWrite) {
+ setEnablePipelinedWrite(nativeHandle_, enablePipelinedWrite);
+ return this;
+ }
+
+ @Override
+ public boolean enablePipelinedWrite() {
+ return enablePipelinedWrite(nativeHandle_);
+ }
+
+ @Override
+ public Options setUnorderedWrite(final boolean unorderedWrite) {
+ setUnorderedWrite(nativeHandle_, unorderedWrite);
+ return this;
+ }
+
+ @Override
+ public boolean unorderedWrite() {
+ return unorderedWrite(nativeHandle_);
+ }
+
@Override
public Options setAllowConcurrentMemtableWrite(
final boolean allowConcurrentMemtableWrite) {
return this.rowCache_;
}
+ @Override
+ public Options setWalFilter(final AbstractWalFilter walFilter) {
+ assert(isOwningHandle());
+ setWalFilter(nativeHandle_, walFilter.nativeHandle_);
+ this.walFilter_ = walFilter;
+ return this;
+ }
+
+ @Override
+ public WalFilter walFilter() {
+ assert(isOwningHandle());
+ return this.walFilter_;
+ }
+
@Override
public Options setFailIfOptionsFileError(final boolean failIfOptionsFileError) {
assert(isOwningHandle());
return avoidFlushDuringShutdown(nativeHandle_);
}
+ @Override
+ public Options setAllowIngestBehind(final boolean allowIngestBehind) {
+ assert(isOwningHandle());
+ setAllowIngestBehind(nativeHandle_, allowIngestBehind);
+ return this;
+ }
+
+ @Override
+ public boolean allowIngestBehind() {
+ assert(isOwningHandle());
+ return allowIngestBehind(nativeHandle_);
+ }
+
+ @Override
+ public Options setPreserveDeletes(final boolean preserveDeletes) {
+ assert(isOwningHandle());
+ setPreserveDeletes(nativeHandle_, preserveDeletes);
+ return this;
+ }
+
+ @Override
+ public boolean preserveDeletes() {
+ assert(isOwningHandle());
+ return preserveDeletes(nativeHandle_);
+ }
+
+ @Override
+ public Options setTwoWriteQueues(final boolean twoWriteQueues) {
+ assert(isOwningHandle());
+ setTwoWriteQueues(nativeHandle_, twoWriteQueues);
+ return this;
+ }
+
+ @Override
+ public boolean twoWriteQueues() {
+ assert(isOwningHandle());
+ return twoWriteQueues(nativeHandle_);
+ }
+
+ @Override
+ public Options setManualWalFlush(final boolean manualWalFlush) {
+ assert(isOwningHandle());
+ setManualWalFlush(nativeHandle_, manualWalFlush);
+ return this;
+ }
+
+ @Override
+ public boolean manualWalFlush() {
+ assert(isOwningHandle());
+ return manualWalFlush(nativeHandle_);
+ }
+
@Override
public MemTableConfig memTableConfig() {
return this.memTableConfig_;
return this;
}
+ @Override
+ public Options setSstFileManager(final SstFileManager sstFileManager) {
+ assert(isOwningHandle());
+ setSstFileManager(nativeHandle_, sstFileManager.nativeHandle_);
+ return this;
+ }
+
@Override
public Options setLogger(final Logger logger) {
assert(isOwningHandle());
bottommostCompressionType(nativeHandle_));
}
+ @Override
+ public Options setBottommostCompressionOptions(
+ final CompressionOptions bottommostCompressionOptions) {
+ setBottommostCompressionOptions(nativeHandle_,
+ bottommostCompressionOptions.nativeHandle_);
+ this.bottommostCompressionOptions_ = bottommostCompressionOptions;
+ return this;
+ }
+
+ @Override
+ public CompressionOptions bottommostCompressionOptions() {
+ return this.bottommostCompressionOptions_;
+ }
+
@Override
public Options setCompressionOptions(
final CompressionOptions compressionOptions) {
@Override
public CompactionStyle compactionStyle() {
- return CompactionStyle.values()[compactionStyle(nativeHandle_)];
+ return CompactionStyle.fromValue(compactionStyle(nativeHandle_));
}
@Override
return reportBgIoStats(nativeHandle_);
}
+ @Override
+ public Options setTtl(final long ttl) {
+ setTtl(nativeHandle_, ttl);
+ return this;
+ }
+
+ @Override
+ public long ttl() {
+ return ttl(nativeHandle_);
+ }
+
@Override
public Options setCompactionOptionsUniversal(
final CompactionOptionsUniversal compactionOptionsUniversal) {
return forceConsistencyChecks(nativeHandle_);
}
+ @Override
+ public Options setAtomicFlush(final boolean atomicFlush) {
+ setAtomicFlush(nativeHandle_, atomicFlush);
+ return this;
+ }
+
+ @Override
+ public boolean atomicFlush() {
+ return atomicFlush(nativeHandle_);
+ }
+
private native static long newOptions();
private native static long newOptions(long dbOptHandle,
long cfOptHandle);
+ private native static long copyOptions(long handle);
@Override protected final native void disposeInternal(final long handle);
private native void setEnv(long optHandle, long envHandle);
private native void prepareForBulkLoad(long handle);
private native boolean paranoidChecks(long handle);
private native void setRateLimiter(long handle,
long rateLimiterHandle);
+ private native void setSstFileManager(final long handle,
+ final long sstFileManagerHandle);
private native void setLogger(long handle,
long loggerHandle);
private native void setInfoLogLevel(long handle, byte logLevel);
final int maxFileOpeningThreads);
private native int maxFileOpeningThreads(final long handle);
private native long maxTotalWalSize(long handle);
- private native void createStatistics(long optHandle);
- private native long statisticsPtr(long optHandle);
+ private native void setStatistics(final long handle, final long statisticsHandle);
+ private native long statistics(final long handle);
private native boolean useFsync(long handle);
private native void setUseFsync(long handle, boolean useFsync);
private native void setDbPaths(final long handle, final String[] paths,
private native void setMaxBackgroundFlushes(
long handle, int maxBackgroundFlushes);
private native int maxBackgroundFlushes(long handle);
+ private native void setMaxBackgroundJobs(long handle, int maxMaxBackgroundJobs);
+ private native int maxBackgroundJobs(long handle);
private native void setMaxLogFileSize(long handle, long maxLogFileSize)
throws IllegalArgumentException;
private native long maxLogFileSize(long handle);
private native void setStatsDumpPeriodSec(
long handle, int statsDumpPeriodSec);
private native int statsDumpPeriodSec(long handle);
+ private native void setStatsPersistPeriodSec(
+ final long handle, final int statsPersistPeriodSec);
+ private native int statsPersistPeriodSec(
+ final long handle);
+ private native void setStatsHistoryBufferSize(
+ final long handle, final long statsHistoryBufferSize);
+ private native long statsHistoryBufferSize(
+ final long handle);
private native void setAdviseRandomOnOpen(
long handle, boolean adviseRandomOnOpen);
private native boolean adviseRandomOnOpen(long handle);
private native void setDbWriteBufferSize(final long handle,
final long dbWriteBufferSize);
+ private native void setWriteBufferManager(final long handle,
+ final long writeBufferManagerHandle);
private native long dbWriteBufferSize(final long handle);
private native void setAccessHintOnCompactionStart(final long handle,
final byte accessHintOnCompactionStart);
private native long bytesPerSync(long handle);
private native void setWalBytesPerSync(long handle, long walBytesPerSync);
private native long walBytesPerSync(long handle);
+ private native void setStrictBytesPerSync(
+ final long handle, final boolean strictBytesPerSync);
+ private native boolean strictBytesPerSync(
+ final long handle);
private native void setEnableThreadTracking(long handle,
boolean enableThreadTracking);
private native boolean enableThreadTracking(long handle);
private native void setDelayedWriteRate(long handle, long delayedWriteRate);
private native long delayedWriteRate(long handle);
+ private native void setEnablePipelinedWrite(final long handle,
+ final boolean pipelinedWrite);
+ private native boolean enablePipelinedWrite(final long handle);
+ private native void setUnorderedWrite(final long handle,
+ final boolean unorderedWrite);
+ private native boolean unorderedWrite(final long handle);
private native void setAllowConcurrentMemtableWrite(long handle,
boolean allowConcurrentMemtableWrite);
private native boolean allowConcurrentMemtableWrite(long handle);
final boolean allow2pc);
private native boolean allow2pc(final long handle);
private native void setRowCache(final long handle,
- final long row_cache_handle);
+ final long rowCacheHandle);
+ private native void setWalFilter(final long handle,
+ final long walFilterHandle);
private native void setFailIfOptionsFileError(final long handle,
final boolean failIfOptionsFileError);
private native boolean failIfOptionsFileError(final long handle);
private native void setAvoidFlushDuringShutdown(final long handle,
final boolean avoidFlushDuringShutdown);
private native boolean avoidFlushDuringShutdown(final long handle);
+ private native void setAllowIngestBehind(final long handle,
+ final boolean allowIngestBehind);
+ private native boolean allowIngestBehind(final long handle);
+ private native void setPreserveDeletes(final long handle,
+ final boolean preserveDeletes);
+ private native boolean preserveDeletes(final long handle);
+ private native void setTwoWriteQueues(final long handle,
+ final boolean twoWriteQueues);
+ private native boolean twoWriteQueues(final long handle);
+ private native void setManualWalFlush(final long handle,
+ final boolean manualWalFlush);
+ private native boolean manualWalFlush(final long handle);
+
// CF native handles
private native void optimizeForSmallDb(final long handle);
long memtableMemoryBudget);
private native void setComparatorHandle(long handle, int builtinComparator);
private native void setComparatorHandle(long optHandle,
- long comparatorHandle);
+ long comparatorHandle, byte comparatorType);
private native void setMergeOperatorName(
long handle, String name);
private native void setMergeOperator(
long handle, long mergeOperatorHandle);
+ private native void setCompactionFilterHandle(
+ long handle, long compactionFilterHandle);
+ private native void setCompactionFilterFactoryHandle(
+ long handle, long compactionFilterFactoryHandle);
private native void setWriteBufferSize(long handle, long writeBufferSize)
throws IllegalArgumentException;
private native long writeBufferSize(long handle);
private native void setBottommostCompressionType(long handle,
byte bottommostCompressionType);
private native byte bottommostCompressionType(long handle);
+ private native void setBottommostCompressionOptions(final long handle,
+ final long bottommostCompressionOptionsHandle);
private native void setCompressionOptions(long handle,
long compressionOptionsHandle);
private native void useFixedLengthPrefixExtractor(
private native void setReportBgIoStats(final long handle,
final boolean reportBgIoStats);
private native boolean reportBgIoStats(final long handle);
+ private native void setTtl(final long handle, final long ttl);
+ private native long ttl(final long handle);
private native void setCompactionOptionsUniversal(final long handle,
final long compactionOptionsUniversalHandle);
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 setAtomicFlush(final long handle,
+ final boolean atomicFlush);
+ private native boolean atomicFlush(final long handle);
// instance variables
+ // NOTE: If you add new member variables, please update the copy constructor above!
private Env env_;
private MemTableConfig memTableConfig_;
private TableFormatConfig tableFormatConfig_;
private RateLimiter rateLimiter_;
- private AbstractComparator<? extends AbstractSlice<?>> comparator_;
+ private AbstractComparator comparator_;
+ private AbstractCompactionFilter<? extends AbstractSlice<?>> compactionFilter_;
+ private AbstractCompactionFilterFactory<? extends AbstractCompactionFilter<?>>
+ compactionFilterFactory_;
private CompactionOptionsUniversal compactionOptionsUniversal_;
private CompactionOptionsFIFO compactionOptionsFIFO_;
+ private CompressionOptions bottommostCompressionOptions_;
private CompressionOptions compressionOptions_;
private Cache rowCache_;
+ private WalFilter walFilter_;
+ private WriteBufferManager writeBufferManager_;
}