package org.rocksdb;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
+import java.nio.file.Paths;
+import java.util.*;
/**
* ColumnFamilyOptions to control the behavior of a database. It will be used
this.compactionOptionsFIFO_ = other.compactionOptionsFIFO_;
this.bottommostCompressionOptions_ = other.bottommostCompressionOptions_;
this.compressionOptions_ = other.compressionOptions_;
+ this.compactionThreadLimiter_ = other.compactionThreadLimiter_;
}
/**
*/
public static ColumnFamilyOptions getColumnFamilyOptionsFromProps(
final Properties properties) {
- if (properties == null || properties.size() == 0) {
- throw new IllegalArgumentException(
- "Properties value must contain at least one value.");
- }
ColumnFamilyOptions columnFamilyOptions = null;
- StringBuilder stringBuilder = new StringBuilder();
- for (final String name : properties.stringPropertyNames()){
- stringBuilder.append(name);
- stringBuilder.append("=");
- stringBuilder.append(properties.getProperty(name));
- stringBuilder.append(";");
+ final long handle =
+ getColumnFamilyOptionsFromProps(Options.getOptionStringFromProps(properties));
+ if (handle != 0) {
+ columnFamilyOptions = new ColumnFamilyOptions(handle);
}
- long handle = getColumnFamilyOptionsFromProps(
- stringBuilder.toString());
+ return columnFamilyOptions;
+ }
+
+ /**
+ * <p>Method to get a options instance by using pre-configured
+ * property values. If one or many values are undefined in
+ * the context of RocksDB the method will return a null
+ * value.</p>
+ *
+ * <p><strong>Note</strong>: Property keys can be derived from
+ * getter methods within the options class. Example: the method
+ * {@code writeBufferSize()} has a property key:
+ * {@code write_buffer_size}.</p>
+ *
+ * @param cfgOpts ConfigOptions controlling how the properties are parsed.
+ * @param properties {@link java.util.Properties} instance.
+ *
+ * @return {@link org.rocksdb.ColumnFamilyOptions instance}
+ * or null.
+ *
+ * @throws java.lang.IllegalArgumentException if null or empty
+ * {@link Properties} instance is passed to the method call.
+ */
+ public static ColumnFamilyOptions getColumnFamilyOptionsFromProps(
+ final ConfigOptions cfgOpts, final Properties properties) {
+ ColumnFamilyOptions columnFamilyOptions = null;
+ final long handle = getColumnFamilyOptionsFromProps(
+ cfgOpts.nativeHandle_, Options.getOptionStringFromProps(properties));
if (handle != 0){
columnFamilyOptions = new ColumnFamilyOptions(handle);
}
return columnFamilyOptions;
}
+ @Override
+ public ColumnFamilyOptions oldDefaults(final int majorVersion, final int minorVersion) {
+ oldDefaults(nativeHandle_, majorVersion, minorVersion);
+ return this;
+ }
+
@Override
public ColumnFamilyOptions optimizeForSmallDb() {
optimizeForSmallDb(nativeHandle_);
return this;
}
+ @Override
+ public ColumnFamilyOptions optimizeForSmallDb(final Cache cache) {
+ optimizeForSmallDb(nativeHandle_, cache.getNativeHandle());
+ return this;
+ }
+
@Override
public ColumnFamilyOptions optimizeForPointLookup(
final long blockCacheSizeMb) {
return tableFactoryName(nativeHandle_);
}
+ @Override
+ public ColumnFamilyOptions setCfPaths(final Collection<DbPath> cfPaths) {
+ assert (isOwningHandle());
+
+ final int len = cfPaths.size();
+ final String paths[] = new String[len];
+ final long targetSizes[] = new long[len];
+
+ int i = 0;
+ for (final DbPath dbPath : cfPaths) {
+ paths[i] = dbPath.path.toString();
+ targetSizes[i] = dbPath.targetSize;
+ i++;
+ }
+ setCfPaths(nativeHandle_, paths, targetSizes);
+ return this;
+ }
+
+ @Override
+ public List<DbPath> cfPaths() {
+ final int len = (int) cfPathsLen(nativeHandle_);
+
+ if (len == 0) {
+ return Collections.emptyList();
+ }
+
+ final String paths[] = new String[len];
+ final long targetSizes[] = new long[len];
+
+ cfPaths(nativeHandle_, paths, targetSizes);
+
+ final List<DbPath> cfPaths = new ArrayList<>();
+ for (int i = 0; i < len; i++) {
+ cfPaths.add(new DbPath(Paths.get(paths[i]), targetSizes[i]));
+ }
+
+ return cfPaths;
+ }
+
@Override
public ColumnFamilyOptions setInplaceUpdateSupport(
final boolean inplaceUpdateSupport) {
return forceConsistencyChecks(nativeHandle_);
}
+ @Override
+ public ColumnFamilyOptions setSstPartitionerFactory(SstPartitionerFactory sstPartitionerFactory) {
+ setSstPartitionerFactory(nativeHandle_, sstPartitionerFactory.nativeHandle_);
+ this.sstPartitionerFactory_ = sstPartitionerFactory;
+ return this;
+ }
+
+ @Override
+ public ColumnFamilyOptions setCompactionThreadLimiter(
+ final ConcurrentTaskLimiter compactionThreadLimiter) {
+ setCompactionThreadLimiter(nativeHandle_, compactionThreadLimiter.nativeHandle_);
+ this.compactionThreadLimiter_ = compactionThreadLimiter;
+ return this;
+ }
+
+ @Override
+ public ConcurrentTaskLimiter compactionThreadLimiter() {
+ assert (isOwningHandle());
+ return this.compactionThreadLimiter_;
+ }
+
+ @Override
+ public SstPartitionerFactory sstPartitionerFactory() {
+ return sstPartitionerFactory_;
+ }
+
private static native long getColumnFamilyOptionsFromProps(
- String optString);
+ final long cfgHandle, String optString);
+ private static native long getColumnFamilyOptionsFromProps(final String optString);
private static native long newColumnFamilyOptions();
private static native long copyColumnFamilyOptions(final long handle);
final long optionsHandle);
@Override protected final native void disposeInternal(final long handle);
+ private static native void oldDefaults(
+ final long handle, final int majorVersion, final int minorVersion);
private native void optimizeForSmallDb(final long handle);
+ private static native void optimizeForSmallDb(final long handle, final long cacheHandle);
private native void optimizeForPointLookup(long handle,
long blockCacheSizeMb);
private native void optimizeLevelStyleCompaction(long handle,
private native String memTableFactoryName(long handle);
private native void setTableFactory(long handle, long factoryHandle);
private native String tableFactoryName(long handle);
+ private static native void setCfPaths(
+ final long handle, final String[] paths, final long[] targetSizes);
+ private static native long cfPathsLen(final long handle);
+ private static native void cfPaths(
+ final long handle, final String[] paths, final long[] targetSizes);
private native void setInplaceUpdateSupport(
long handle, boolean inplaceUpdateSupport);
private native boolean inplaceUpdateSupport(long handle);
private native void setForceConsistencyChecks(final long handle,
final boolean forceConsistencyChecks);
private native boolean forceConsistencyChecks(final long handle);
+ private native void setSstPartitionerFactory(long nativeHandle_, long newFactoryHandle);
+ private static native void setCompactionThreadLimiter(
+ final long nativeHandle_, final long compactionThreadLimiterHandle);
// instance variables
// NOTE: If you add new member variables, please update the copy constructor above!
private CompactionOptionsFIFO compactionOptionsFIFO_;
private CompressionOptions bottommostCompressionOptions_;
private CompressionOptions compressionOptions_;
-
+ private SstPartitionerFactory sstPartitionerFactory_;
+ private ConcurrentTaskLimiter compactionThreadLimiter_;
}