Search in sources :

Example 1 with DBOptions

use of org.rocksdb.DBOptions in project flink by apache.

the class RocksDBStateBackend method getDbOptions.

/**
	 * Gets the RocksDB {@link DBOptions} to be used for all RocksDB instances.
	 */
public DBOptions getDbOptions() {
    // initial options from pre-defined profile
    DBOptions opt = predefinedOptions.createDBOptions();
    // add user-defined options, if specified
    if (optionsFactory != null) {
        opt = optionsFactory.createDBOptions(opt);
    }
    // add necessary default options
    opt = opt.setCreateIfMissing(true);
    return opt;
}
Also used : DBOptions(org.rocksdb.DBOptions)

Example 2 with DBOptions

use of org.rocksdb.DBOptions in project flink by apache.

the class KVStateRequestSerializerRocksDBTest method testListSerialization.

/**
	 * Tests list serialization and deserialization match.
	 *
	 * @see KvStateRequestSerializerTest#testListSerialization()
	 * KvStateRequestSerializerTest#testListSerialization() using the heap state back-end
	 * test
	 */
@Test
public void testListSerialization() throws Exception {
    final long key = 0L;
    // objects for RocksDB state list serialisation
    DBOptions dbOptions = PredefinedOptions.DEFAULT.createDBOptions();
    dbOptions.setCreateIfMissing(true);
    ColumnFamilyOptions columnFamilyOptions = PredefinedOptions.DEFAULT.createColumnOptions();
    final RocksDBKeyedStateBackend2<Long> longHeapKeyedStateBackend = new RocksDBKeyedStateBackend2<>(new JobID(), "no-op", ClassLoader.getSystemClassLoader(), temporaryFolder.getRoot(), dbOptions, columnFamilyOptions, mock(TaskKvStateRegistry.class), LongSerializer.INSTANCE, 1, new KeyGroupRange(0, 0), new ExecutionConfig());
    longHeapKeyedStateBackend.setCurrentKey(key);
    final InternalListState<VoidNamespace, Long> listState = longHeapKeyedStateBackend.createListState(VoidNamespaceSerializer.INSTANCE, new ListStateDescriptor<>("test", LongSerializer.INSTANCE));
    KvStateRequestSerializerTest.testListSerialization(key, listState);
}
Also used : KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) TaskKvStateRegistry(org.apache.flink.runtime.query.TaskKvStateRegistry) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) DBOptions(org.rocksdb.DBOptions) VoidNamespace(org.apache.flink.runtime.state.VoidNamespace) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test) KvStateRequestSerializerTest(org.apache.flink.runtime.query.netty.message.KvStateRequestSerializerTest)

Example 3 with DBOptions

use of org.rocksdb.DBOptions in project flink by apache.

the class RocksDBOperationsUtilsTest method testPathExceptionOnWindows.

@Test
public void testPathExceptionOnWindows() throws Exception {
    assumeTrue(OperatingSystem.isWindows());
    final File folder = TMP_DIR.newFolder();
    final File rocksDir = new File(folder, getLongString(247 - folder.getAbsolutePath().length()));
    Files.createDirectories(rocksDir.toPath());
    try (DBOptions dbOptions = new DBOptions().setCreateIfMissing(true);
        ColumnFamilyOptions colOptions = new ColumnFamilyOptions()) {
        RocksDB rocks = RocksDBOperationUtils.openDB(rocksDir.getAbsolutePath(), Collections.emptyList(), Collections.emptyList(), colOptions, dbOptions);
        rocks.close();
    // do not provoke a test failure if this passes, because some setups may actually
    // support long paths, in which case: great!
    } catch (IOException e) {
        assertThat(e.getMessage(), containsString("longer than the directory path length limit for Windows"));
    }
}
Also used : ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) RocksDB(org.rocksdb.RocksDB) DBOptions(org.rocksdb.DBOptions) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 4 with DBOptions

use of org.rocksdb.DBOptions in project flink by apache.

the class RocksDBKeyedStateBackendBuilder method getRocksDBRestoreOperation.

private RocksDBRestoreOperation getRocksDBRestoreOperation(int keyGroupPrefixBytes, CloseableRegistry cancelStreamRegistry, LinkedHashMap<String, RocksDBKeyedStateBackend.RocksDbKvStateInfo> kvStateInformation, LinkedHashMap<String, HeapPriorityQueueSnapshotRestoreWrapper<?>> registeredPQStates, RocksDbTtlCompactFiltersManager ttlCompactFiltersManager) {
    DBOptions dbOptions = optionsContainer.getDbOptions();
    if (restoreStateHandles.isEmpty()) {
        return new RocksDBNoneRestoreOperation<>(kvStateInformation, instanceRocksDBPath, dbOptions, columnFamilyOptionsFactory, nativeMetricOptions, metricGroup, ttlCompactFiltersManager, optionsContainer.getWriteBufferManagerCapacity());
    }
    KeyedStateHandle firstStateHandle = restoreStateHandles.iterator().next();
    if (firstStateHandle instanceof IncrementalKeyedStateHandle) {
        return new RocksDBIncrementalRestoreOperation<>(operatorIdentifier, keyGroupRange, keyGroupPrefixBytes, numberOfTransferingThreads, cancelStreamRegistry, userCodeClassLoader, kvStateInformation, keySerializerProvider, instanceBasePath, instanceRocksDBPath, dbOptions, columnFamilyOptionsFactory, nativeMetricOptions, metricGroup, restoreStateHandles, ttlCompactFiltersManager, writeBatchSize, optionsContainer.getWriteBufferManagerCapacity());
    } else if (priorityQueueStateType == EmbeddedRocksDBStateBackend.PriorityQueueStateType.HEAP) {
        return new RocksDBHeapTimersFullRestoreOperation<>(keyGroupRange, numberOfKeyGroups, userCodeClassLoader, kvStateInformation, registeredPQStates, createHeapQueueFactory(), keySerializerProvider, instanceRocksDBPath, dbOptions, columnFamilyOptionsFactory, nativeMetricOptions, metricGroup, restoreStateHandles, ttlCompactFiltersManager, writeBatchSize, optionsContainer.getWriteBufferManagerCapacity());
    } else {
        return new RocksDBFullRestoreOperation<>(keyGroupRange, userCodeClassLoader, kvStateInformation, keySerializerProvider, instanceRocksDBPath, dbOptions, columnFamilyOptionsFactory, nativeMetricOptions, metricGroup, restoreStateHandles, ttlCompactFiltersManager, writeBatchSize, optionsContainer.getWriteBufferManagerCapacity());
    }
}
Also used : IncrementalKeyedStateHandle(org.apache.flink.runtime.state.IncrementalKeyedStateHandle) RocksDBIncrementalRestoreOperation(org.apache.flink.contrib.streaming.state.restore.RocksDBIncrementalRestoreOperation) DBOptions(org.rocksdb.DBOptions) RocksDBNoneRestoreOperation(org.apache.flink.contrib.streaming.state.restore.RocksDBNoneRestoreOperation) IncrementalKeyedStateHandle(org.apache.flink.runtime.state.IncrementalKeyedStateHandle) KeyedStateHandle(org.apache.flink.runtime.state.KeyedStateHandle)

Example 5 with DBOptions

use of org.rocksdb.DBOptions in project flink by apache.

the class RocksDBOperationUtils method openDB.

public static RocksDB openDB(String path, List<ColumnFamilyDescriptor> stateColumnFamilyDescriptors, List<ColumnFamilyHandle> stateColumnFamilyHandles, ColumnFamilyOptions columnFamilyOptions, DBOptions dbOptions) throws IOException {
    List<ColumnFamilyDescriptor> columnFamilyDescriptors = new ArrayList<>(1 + stateColumnFamilyDescriptors.size());
    // we add the required descriptor for the default CF in FIRST position, see
    // https://github.com/facebook/rocksdb/wiki/RocksJava-Basics#opening-a-database-with-column-families
    columnFamilyDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, columnFamilyOptions));
    columnFamilyDescriptors.addAll(stateColumnFamilyDescriptors);
    RocksDB dbRef;
    try {
        dbRef = RocksDB.open(Preconditions.checkNotNull(dbOptions), Preconditions.checkNotNull(path), columnFamilyDescriptors, stateColumnFamilyHandles);
    } catch (RocksDBException e) {
        IOUtils.closeQuietly(columnFamilyOptions);
        columnFamilyDescriptors.forEach((cfd) -> IOUtils.closeQuietly(cfd.getOptions()));
        // improve error reporting on Windows
        throwExceptionIfPathLengthExceededOnWindows(path, e);
        throw new IOException("Error while opening RocksDB instance.", e);
    }
    // requested + default CF
    Preconditions.checkState(1 + stateColumnFamilyDescriptors.size() == stateColumnFamilyHandles.size(), "Not all requested column family handles have been created");
    return dbRef;
}
Also used : OpaqueMemoryResource(org.apache.flink.runtime.memory.OpaqueMemoryResource) Arrays(java.util.Arrays) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) LoggerFactory(org.slf4j.LoggerFactory) RocksDbTtlCompactFiltersManager(org.apache.flink.contrib.streaming.state.ttl.RocksDbTtlCompactFiltersManager) Function(java.util.function.Function) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) ArrayList(java.util.ArrayList) ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) RocksDB(org.rocksdb.RocksDB) Map(java.util.Map) ConfigConstants(org.apache.flink.configuration.ConfigConstants) RocksDBException(org.rocksdb.RocksDBException) MERGE_OPERATOR_NAME(org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackend.MERGE_OPERATOR_NAME) Nullable(javax.annotation.Nullable) ReadOptions(org.rocksdb.ReadOptions) IOUtils(org.apache.flink.util.IOUtils) Logger(org.slf4j.Logger) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) DBOptions(org.rocksdb.DBOptions) IOException(java.io.IOException) OperatingSystem(org.apache.flink.util.OperatingSystem) Preconditions(org.apache.flink.util.Preconditions) LongFunctionWithException(org.apache.flink.util.function.LongFunctionWithException) List(java.util.List) RegisteredStateMetaInfoBase(org.apache.flink.runtime.state.RegisteredStateMetaInfoBase) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle) RocksDBException(org.rocksdb.RocksDBException) RocksDB(org.rocksdb.RocksDB) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor)

Aggregations

DBOptions (org.rocksdb.DBOptions)29 ColumnFamilyOptions (org.rocksdb.ColumnFamilyOptions)19 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 ColumnFamilyDescriptor (org.rocksdb.ColumnFamilyDescriptor)10 ColumnFamilyHandle (org.rocksdb.ColumnFamilyHandle)9 File (java.io.File)7 RocksDB (org.rocksdb.RocksDB)7 RocksDBException (org.rocksdb.RocksDBException)5 WriteOptions (org.rocksdb.WriteOptions)5 IOException (java.io.IOException)4 FlushOptions (org.rocksdb.FlushOptions)4 Options (org.rocksdb.Options)3 RocksDbOptionsFactory (com.alibaba.jstorm.cache.rocksdb.RocksDbOptionsFactory)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)2 JobID (org.apache.flink.api.common.JobID)2