Search in sources :

Example 1 with OpaqueMemoryResource

use of org.apache.flink.runtime.memory.OpaqueMemoryResource in project flink by apache.

the class RocksDBOperationUtils method allocateSharedCachesIfConfigured.

@Nullable
public static OpaqueMemoryResource<RocksDBSharedResources> allocateSharedCachesIfConfigured(RocksDBMemoryConfiguration memoryConfig, MemoryManager memoryManager, double memoryFraction, Logger logger) throws IOException {
    if (!memoryConfig.isUsingFixedMemoryPerSlot() && !memoryConfig.isUsingManagedMemory()) {
        return null;
    }
    final double highPriorityPoolRatio = memoryConfig.getHighPriorityPoolRatio();
    final double writeBufferRatio = memoryConfig.getWriteBufferRatio();
    final boolean usingPartitionedIndexFilters = memoryConfig.isUsingPartitionedIndexFilters();
    final LongFunctionWithException<RocksDBSharedResources, Exception> allocator = (size) -> RocksDBMemoryControllerUtils.allocateRocksDBSharedResources(size, writeBufferRatio, highPriorityPoolRatio, usingPartitionedIndexFilters);
    try {
        if (memoryConfig.isUsingFixedMemoryPerSlot()) {
            assert memoryConfig.getFixedMemoryPerSlot() != null;
            logger.info("Getting fixed-size shared cache for RocksDB.");
            return memoryManager.getExternalSharedMemoryResource(FIXED_SLOT_MEMORY_RESOURCE_ID, allocator, memoryConfig.getFixedMemoryPerSlot().getBytes());
        } else {
            logger.info("Getting managed memory shared cache for RocksDB.");
            return memoryManager.getSharedMemoryResourceForManagedMemory(MANAGED_MEMORY_RESOURCE_ID, allocator, memoryFraction);
        }
    } catch (Exception e) {
        throw new IOException("Failed to acquire shared cache resource for RocksDB", e);
    }
}
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) IOException(java.io.IOException) RocksDBException(org.rocksdb.RocksDBException) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) IOException(java.io.IOException) LongFunctionWithException(org.apache.flink.util.function.LongFunctionWithException) Nullable(javax.annotation.Nullable)

Example 2 with OpaqueMemoryResource

use of org.apache.flink.runtime.memory.OpaqueMemoryResource in project flink by apache.

the class RocksDBResourceContainerTest method testFreeSharedResourcesAfterClose.

@Test
public void testFreeSharedResourcesAfterClose() throws Exception {
    LRUCache cache = new LRUCache(1024L);
    WriteBufferManager wbm = new WriteBufferManager(1024L, cache);
    RocksDBSharedResources sharedResources = new RocksDBSharedResources(cache, wbm, 1024L, false);
    final ThrowingRunnable<Exception> disposer = sharedResources::close;
    OpaqueMemoryResource<RocksDBSharedResources> opaqueResource = new OpaqueMemoryResource<>(sharedResources, 1024L, disposer);
    RocksDBResourceContainer container = new RocksDBResourceContainer(PredefinedOptions.DEFAULT, null, opaqueResource);
    container.close();
    assertThat(cache.isOwningHandle(), is(false));
    assertThat(wbm.isOwningHandle(), is(false));
}
Also used : OpaqueMemoryResource(org.apache.flink.runtime.memory.OpaqueMemoryResource) LRUCache(org.rocksdb.LRUCache) WriteBufferManager(org.rocksdb.WriteBufferManager) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with OpaqueMemoryResource

use of org.apache.flink.runtime.memory.OpaqueMemoryResource in project flink by apache.

the class RocksDBResourceContainerTest method testGetColumnFamilyOptionsWithPartitionedIndex.

@Test
public void testGetColumnFamilyOptionsWithPartitionedIndex() throws Exception {
    LRUCache cache = new LRUCache(1024L);
    WriteBufferManager wbm = new WriteBufferManager(1024L, cache);
    RocksDBSharedResources sharedResources = new RocksDBSharedResources(cache, wbm, 1024L, true);
    final ThrowingRunnable<Exception> disposer = sharedResources::close;
    OpaqueMemoryResource<RocksDBSharedResources> opaqueResource = new OpaqueMemoryResource<>(sharedResources, 1024L, disposer);
    BloomFilter blockBasedFilter = new BloomFilter();
    RocksDBOptionsFactory blockBasedBloomFilterOptionFactory = new RocksDBOptionsFactory() {

        @Override
        public DBOptions createDBOptions(DBOptions currentOptions, Collection<AutoCloseable> handlesToClose) {
            return currentOptions;
        }

        @Override
        public ColumnFamilyOptions createColumnOptions(ColumnFamilyOptions currentOptions, Collection<AutoCloseable> handlesToClose) {
            TableFormatConfig tableFormatConfig = currentOptions.tableFormatConfig();
            BlockBasedTableConfig blockBasedTableConfig = tableFormatConfig == null ? new BlockBasedTableConfig() : (BlockBasedTableConfig) tableFormatConfig;
            blockBasedTableConfig.setFilter(blockBasedFilter);
            handlesToClose.add(blockBasedFilter);
            currentOptions.setTableFormatConfig(blockBasedTableConfig);
            return currentOptions;
        }
    };
    try (RocksDBResourceContainer container = new RocksDBResourceContainer(PredefinedOptions.DEFAULT, blockBasedBloomFilterOptionFactory, opaqueResource)) {
        ColumnFamilyOptions columnOptions = container.getColumnOptions();
        BlockBasedTableConfig actual = (BlockBasedTableConfig) columnOptions.tableFormatConfig();
        assertThat(actual.indexType(), is(IndexType.kTwoLevelIndexSearch));
        assertThat(actual.partitionFilters(), is(true));
        assertThat(actual.pinTopLevelIndexAndFilter(), is(true));
        assertThat(actual.filterPolicy(), not(blockBasedFilter));
    }
    assertFalse("Block based filter is left unclosed.", blockBasedFilter.isOwningHandle());
}
Also used : TableFormatConfig(org.rocksdb.TableFormatConfig) BlockBasedTableConfig(org.rocksdb.BlockBasedTableConfig) IOException(java.io.IOException) BloomFilter(org.rocksdb.BloomFilter) OpaqueMemoryResource(org.apache.flink.runtime.memory.OpaqueMemoryResource) ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) LRUCache(org.rocksdb.LRUCache) WriteBufferManager(org.rocksdb.WriteBufferManager) Collection(java.util.Collection) DBOptions(org.rocksdb.DBOptions) Test(org.junit.Test)

Example 4 with OpaqueMemoryResource

use of org.apache.flink.runtime.memory.OpaqueMemoryResource in project flink by apache.

the class RocksDBResourceContainerTest method getSharedResources.

private OpaqueMemoryResource<RocksDBSharedResources> getSharedResources() {
    final long cacheSize = 1024L, writeBufferSize = 512L;
    final LRUCache cache = new LRUCache(cacheSize, -1, false, 0.1);
    final WriteBufferManager wbm = new WriteBufferManager(writeBufferSize, cache);
    RocksDBSharedResources rocksDBSharedResources = new RocksDBSharedResources(cache, wbm, writeBufferSize, false);
    return new OpaqueMemoryResource<>(rocksDBSharedResources, cacheSize, rocksDBSharedResources::close);
}
Also used : OpaqueMemoryResource(org.apache.flink.runtime.memory.OpaqueMemoryResource) LRUCache(org.rocksdb.LRUCache) WriteBufferManager(org.rocksdb.WriteBufferManager)

Aggregations

OpaqueMemoryResource (org.apache.flink.runtime.memory.OpaqueMemoryResource)4 IOException (java.io.IOException)3 LRUCache (org.rocksdb.LRUCache)3 WriteBufferManager (org.rocksdb.WriteBufferManager)3 Test (org.junit.Test)2 ColumnFamilyOptions (org.rocksdb.ColumnFamilyOptions)2 DBOptions (org.rocksdb.DBOptions)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Nullable (javax.annotation.Nullable)1 ConfigConstants (org.apache.flink.configuration.ConfigConstants)1 MERGE_OPERATOR_NAME (org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackend.MERGE_OPERATOR_NAME)1 RocksDbTtlCompactFiltersManager (org.apache.flink.contrib.streaming.state.ttl.RocksDbTtlCompactFiltersManager)1 MemoryManager (org.apache.flink.runtime.memory.MemoryManager)1 RegisteredStateMetaInfoBase (org.apache.flink.runtime.state.RegisteredStateMetaInfoBase)1 FlinkRuntimeException (org.apache.flink.util.FlinkRuntimeException)1