Search in sources :

Example 1 with FlinkCompactionFilterFactory

use of org.rocksdb.FlinkCompactionFilter.FlinkCompactionFilterFactory in project flink by apache.

the class RocksDbTtlCompactFiltersManager method configCompactFilter.

public void configCompactFilter(@Nonnull StateDescriptor<?, ?> stateDesc, TypeSerializer<?> stateSerializer) {
    StateTtlConfig ttlConfig = stateDesc.getTtlConfig();
    if (ttlConfig.isEnabled() && ttlConfig.getCleanupStrategies().inRocksdbCompactFilter()) {
        FlinkCompactionFilterFactory compactionFilterFactory = compactionFilterFactories.get(stateDesc.getName());
        Preconditions.checkNotNull(compactionFilterFactory);
        long ttl = ttlConfig.getTtl().toMilliseconds();
        StateTtlConfig.RocksdbCompactFilterCleanupStrategy rocksdbCompactFilterCleanupStrategy = ttlConfig.getCleanupStrategies().getRocksdbCompactFilterCleanupStrategy();
        Preconditions.checkNotNull(rocksdbCompactFilterCleanupStrategy);
        long queryTimeAfterNumEntries = rocksdbCompactFilterCleanupStrategy.getQueryTimeAfterNumEntries();
        FlinkCompactionFilter.Config config;
        if (stateDesc instanceof ListStateDescriptor) {
            TypeSerializer<?> elemSerializer = ((ListSerializer<?>) stateSerializer).getElementSerializer();
            int len = elemSerializer.getLength();
            if (len > 0) {
                config = FlinkCompactionFilter.Config.createForFixedElementList(ttl, queryTimeAfterNumEntries, // plus one byte for list element delimiter
                len + 1);
            } else {
                config = FlinkCompactionFilter.Config.createForList(ttl, queryTimeAfterNumEntries, new ListElementFilterFactory<>(elemSerializer.duplicate()));
            }
        } else if (stateDesc instanceof MapStateDescriptor) {
            config = FlinkCompactionFilter.Config.createForMap(ttl, queryTimeAfterNumEntries);
        } else {
            config = FlinkCompactionFilter.Config.createForValue(ttl, queryTimeAfterNumEntries);
        }
        compactionFilterFactory.configure(config);
    }
}
Also used : FlinkCompactionFilterFactory(org.rocksdb.FlinkCompactionFilter.FlinkCompactionFilterFactory) ListSerializer(org.apache.flink.api.common.typeutils.base.ListSerializer) MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) StateTtlConfig(org.apache.flink.api.common.state.StateTtlConfig) FlinkCompactionFilter(org.rocksdb.FlinkCompactionFilter)

Example 2 with FlinkCompactionFilterFactory

use of org.rocksdb.FlinkCompactionFilter.FlinkCompactionFilterFactory in project flink by apache.

the class RocksDbTtlCompactFiltersManager method createAndSetCompactFilterFactory.

private void createAndSetCompactFilterFactory(String stateName, @Nonnull ColumnFamilyOptions options) {
    FlinkCompactionFilterFactory compactionFilterFactory = new FlinkCompactionFilterFactory(new TimeProviderWrapper(ttlTimeProvider), createRocksDbNativeLogger());
    // noinspection resource
    options.setCompactionFilterFactory(compactionFilterFactory);
    compactionFilterFactories.put(stateName, compactionFilterFactory);
}
Also used : FlinkCompactionFilterFactory(org.rocksdb.FlinkCompactionFilter.FlinkCompactionFilterFactory)

Aggregations

FlinkCompactionFilterFactory (org.rocksdb.FlinkCompactionFilter.FlinkCompactionFilterFactory)2 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)1 MapStateDescriptor (org.apache.flink.api.common.state.MapStateDescriptor)1 StateTtlConfig (org.apache.flink.api.common.state.StateTtlConfig)1 ListSerializer (org.apache.flink.api.common.typeutils.base.ListSerializer)1 FlinkCompactionFilter (org.rocksdb.FlinkCompactionFilter)1