Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can RocksDB settings be changed with the java library while the database is open?

Using the java library, can any configuration changes take effect without requiring a reopen of the database? For example the level0SlowdownWritesTrigger.

More context: I'm trying to flip between a bulk-load mode and regular mode. e.g. Disable autocompaction when the app starts up, load the data, then enable autocompaction. In testing this has given me a 75% reduction in initial load time.
The problem is that changes to the Options don't take effect, at least in the way I'm making them. I don't want to have to reopen the database, because that complicates existing data flow handling.

Sample code I've tried. In this example, I'm changing the auto compaction settings in the options.

import org.rocksdb.ColumnFamilyOptions
import org.rocksdb.DBOptions
import org.rocksdb.Options
import org.rocksdb.RocksDB

class ExampleRocksDbStore(
    private val dataDirectory: String,
    private val configureOptions: (options: Options) -> Unit = {},
) {

    val db: RocksDB
    val options: Options

    init {
        RocksDB.loadLibrary()

        ColumnFamilyOptions().use { cfOpts ->
            val dbOptions = DBOptions()

            options = Options(dbOptions, cfOpts).apply {
                setCreateIfMissing(true)
                setCreateMissingColumnFamilies(true)
            }
            configureOptions(options)

            db = RocksDB.open(options, dataDirectory)
        }
    }

    fun enableAutoCompaction() {
        options.setDisableAutoCompactions(false)
    }

    fun disableAutoCompaction() {
        options.setDisableAutoCompactions(true)
    }
}
like image 419
Dan Tanner Avatar asked Jun 10 '26 16:06

Dan Tanner


1 Answers

Dynamically changeable options are a thing, the Basic Operations wiki mentions them:

Some options can be changed dynamically while DB is running. For example: ...

The only record I can find of which options these are is in options.h here, there are multiple options tagged with "// Dynamically changeable through SetOptions() API", and disable_automatic_compactions is one of them.

So I think you just need to change your Options object, then call setOptions() on your RocksDB instance, unless you're already doing that and it's not working?

like image 107
MyStackRunnethOver Avatar answered Jun 12 '26 11:06

MyStackRunnethOver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!