Search in sources :

Example 1 with ColumnFamilyOptions

use of org.rocksdb.ColumnFamilyOptions 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 2 with ColumnFamilyOptions

use of org.rocksdb.ColumnFamilyOptions 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 3 with ColumnFamilyOptions

use of org.rocksdb.ColumnFamilyOptions 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)

Example 4 with ColumnFamilyOptions

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

the class RocksDBResource method before.

@Override
protected void before() throws Throwable {
    this.temporaryFolder = new TemporaryFolder();
    this.temporaryFolder.create();
    final File rocksFolder = temporaryFolder.newFolder();
    this.dbOptions = optionsFactory.createDBOptions(new DBOptions().setUseFsync(false).setInfoLogLevel(InfoLogLevel.HEADER_LEVEL).setStatsDumpPeriodSec(0), handlesToClose).setCreateIfMissing(true);
    this.columnFamilyOptions = optionsFactory.createColumnOptions(new ColumnFamilyOptions(), handlesToClose);
    this.writeOptions = new WriteOptions();
    this.writeOptions.disableWAL();
    this.readOptions = new ReadOptions();
    this.columnFamilyHandles = new ArrayList<>(1);
    this.rocksDB = RocksDB.open(dbOptions, rocksFolder.getAbsolutePath(), Collections.singletonList(new ColumnFamilyDescriptor("default".getBytes(), columnFamilyOptions)), columnFamilyHandles);
    this.batchWrapper = new RocksDBWriteBatchWrapper(rocksDB, writeOptions);
}
Also used : ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) WriteOptions(org.rocksdb.WriteOptions) ReadOptions(org.rocksdb.ReadOptions) TemporaryFolder(org.junit.rules.TemporaryFolder) DBOptions(org.rocksdb.DBOptions) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) File(java.io.File)

Example 5 with ColumnFamilyOptions

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

the class RocksDBResourceContainerTest method testGetColumnFamilyOptionsWithSharedResources.

/**
 * Guard that {@link RocksDBResourceContainer#getColumnOptions()} shares the same {@link Cache}
 * instance if the {@link RocksDBResourceContainer} instance is initiated with {@link
 * OpaqueMemoryResource}.
 *
 * @throws Exception if unexpected error happened.
 */
@Test
public void testGetColumnFamilyOptionsWithSharedResources() throws Exception {
    final int optionNumber = 20;
    OpaqueMemoryResource<RocksDBSharedResources> sharedResources = getSharedResources();
    RocksDBResourceContainer container = new RocksDBResourceContainer(PredefinedOptions.DEFAULT, null, sharedResources);
    HashSet<Cache> caches = new HashSet<>();
    for (int i = 0; i < optionNumber; i++) {
        ColumnFamilyOptions columnOptions = container.getColumnOptions();
        Cache cache = getBlockCache(columnOptions);
        caches.add(cache);
    }
    assertThat(caches.size(), is(1));
    assertThat(caches.iterator().next(), is(sharedResources.getResourceHandle().getCache()));
    container.close();
}
Also used : ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) LRUCache(org.rocksdb.LRUCache) Cache(org.rocksdb.Cache) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ColumnFamilyOptions (org.rocksdb.ColumnFamilyOptions)29 DBOptions (org.rocksdb.DBOptions)19 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)9 ColumnFamilyDescriptor (org.rocksdb.ColumnFamilyDescriptor)9 File (java.io.File)8 ColumnFamilyHandle (org.rocksdb.ColumnFamilyHandle)8 RocksDB (org.rocksdb.RocksDB)8 WriteOptions (org.rocksdb.WriteOptions)6 IOException (java.io.IOException)4 FlushOptions (org.rocksdb.FlushOptions)4 RocksDBException (org.rocksdb.RocksDBException)4 LRUCache (org.rocksdb.LRUCache)3 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