scalaapache-flinkflink-streamingrocksdbrocksdb-java

Flink RocksDB custom options factory config error disable block cache


I am running Flink 1.15.2 and am trying to define a custom options factory in RocksDB to disable the block cache.

Following the example from this blog post: https://shopify.engineering/optimizing-apache-flink-applications-tips

However, my Flink application refuses to start after adding the OptionsFactory to my env. The error seems to come from this line https://github.com/facebook/rocksdb/blob/main/table/block_based/block_based_table_factory.cc#L599

Enable cache_index_and_filter_blocks, , but block cache is disabled

I have no idea what is gone wrong here, something must be overriding/ignoring my column options, but I don't know what.

Any help is much appreciated.


The config is here:

class NoBlockCacheRocksDbOptionsFactory extends ConfigurableRocksDBOptionsFactory {
  override def createDBOptions(currentOptions: DBOptions, handlesToClose: util.Collection[AutoCloseable]): DBOptions = {
    currentOptions.setMaxBackgroundJobs(20) // state.backend.rocksdb.thread.num
    currentOptions
  }

  override def createColumnOptions(
      currentOptions: ColumnFamilyOptions,
      handlesToClose: util.Collection[AutoCloseable]): ColumnFamilyOptions = {

    val blockBasedTableConfig = new BlockBasedTableConfig()
      .setNoBlockCache(true)
      .setBlockCache(null)
      .setCacheIndexAndFilterBlocks(false)
      .setCacheIndexAndFilterBlocksWithHighPriority(false)
      .setPinL0FilterAndIndexBlocksInCache(false)

    currentOptions.setTableFormatConfig(blockBasedTableConfig)
  }

  override def configure(configuration: ReadableConfig): RocksDBOptionsFactory = {
    this
  }
}

Error and stack trace:

Caused by: org.apache.flink.util.SerializedThrowable: Enable cache_index_and_filter_blocks, , but block cache is disabled
    at org.rocksdb.RocksDB.open(Native Method) ~[flink-dist-1.15.2.jar:1.15.2]
    at org.rocksdb.RocksDB.open(RocksDB.java:306) ~[flink-dist-1.15.2.jar:1.15.2]
    at org.apache.flink.contrib.streaming.state.RocksDBOperationUtils.openDB(RocksDBOperationUtils.java:80) ~[flink-dist-1.15.2.jar:1.15.2]
    at org.apache.flink.contrib.streaming.state.restore.RocksDBHandle.loadDb(RocksDBHandle.java:134) ~[flink-dist-1.15.2.jar:1.15.2]
    at org.apache.flink.contrib.streaming.state.restore.RocksDBHandle.openDB(RocksDBHandle.java:113) ~[flink-dist-1.15.2.jar:1.15.2]
    at org.apache.flink.contrib.streaming.state.restore.RocksDBNoneRestoreOperation.restore(RocksDBNoneRestoreOperation.java:62) ~[flink-dist-1.15.2.jar:1.15.2]
    at org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackendBuilder.build(RocksDBKeyedStateBackendBuilder.java:315) ~[flink-dist-1.15.2.jar:1.15.2]
    at org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend.createKeyedStateBackend(EmbeddedRocksDBStateBackend.java:483) ~[flink-dist-1.15.2.jar:1.15.2]
    at org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend.createKeyedStateBackend(EmbeddedRocksDBStateBackend.java:97) ~[flink-dist-1.15.2.jar:1.15.2]
    at org.apache.flink.streaming.api.operators.StreamTaskStateInitializerImpl.lambda$keyedStatedBackend$1(StreamTaskStateInitializerImpl.java:329) ~[flink-dist-1.15.2.jar:1.15.2]
    at org.apache.flink.streaming.api.operators.BackendRestorerProcedure.attemptCreateAndRestore(BackendRestorerProcedure.java:168) ~[flink-dist-1.15.2.jar:1.15.2]
    at org.apache.flink.streaming.api.operators.BackendRestorerProcedure.createAndRestore(BackendRestorerProcedure.java:135) ~[flink-dist-1.15.2.jar:1.15.2]
    at org.apache.flink.streaming.api.operators.StreamTaskStateInitializerImpl.keyedStatedBackend(StreamTaskStateInitializerImpl.java:346) ~[flink-dist-1.15.2.jar:1.15.2]
    at org.apache.flink.streaming.api.operators.StreamTaskStateInitializerImpl.streamOperatorStateContext(StreamTaskStateInitializerImpl.java:164) ~[flink-dist-1.15.2.jar:1.15.2]
    ... 11 more

Solution

  • try setting the flink config state.backend.rocksdb.memory.managed to false from its default value of true. This setting override configs set as a part of the rocksdb options factory. I was able to run the job post disabling changing this value.