diff --git a/cmd/kava/opendb/opendb_rocksdb.go b/cmd/kava/opendb/opendb_rocksdb.go index 99e82043..6bd35636 100644 --- a/cmd/kava/opendb/opendb_rocksdb.go +++ b/cmd/kava/opendb/opendb_rocksdb.go @@ -74,6 +74,8 @@ const ( cacheIndexAndFilterBlocksBBTOOptName = "rocksdb.cache_index_and_filter_blocks" pinL0FilterAndIndexBlocksInCacheBBTOOptName = "rocksdb.pin_l0_filter_and_index_blocks_in_cache" formatVersionBBTOOptName = "rocksdb.format_version" + + asyncIOReadOptName = "rocksdb.read-async-io" ) func OpenDB(appOpts types.AppOptions, home string, backendType dbm.BackendType) (dbm.DB, error) { @@ -98,6 +100,7 @@ func openRocksdb(dir string, appOpts types.AppOptions) (dbm.DB, error) { cfOpts.SetBlockBasedTableFactory(bbtoOpts) dbOpts = overrideDBOpts(dbOpts, appOpts) cfOpts = overrideCFOpts(cfOpts, appOpts) + readOpts := readOptsFromAppOpts(appOpts) enableMetrics := cast.ToBool(appOpts.Get(enableMetricsOptName)) reportMetricsIntervalSecs := cast.ToInt64(appOpts.Get(reportMetricsIntervalSecsOptName)) @@ -105,7 +108,7 @@ func openRocksdb(dir string, appOpts types.AppOptions) (dbm.DB, error) { reportMetricsIntervalSecs = defaultReportMetricsIntervalSecs } - return newRocksDBWithOptions("application", dir, dbOpts, cfOpts, enableMetrics, reportMetricsIntervalSecs) + return newRocksDBWithOptions("application", dir, dbOpts, cfOpts, readOpts, enableMetrics, reportMetricsIntervalSecs) } // loadLatestOptions loads and returns database and column family options @@ -237,6 +240,16 @@ func overrideCFOpts(cfOpts *grocksdb.Options, appOpts types.AppOptions) *grocksd return cfOpts } +func readOptsFromAppOpts(appOpts types.AppOptions) *grocksdb.ReadOptions { + ro := grocksdb.NewDefaultReadOptions() + asyncIO := appOpts.Get(asyncIOReadOptName) + if asyncIO != nil { + ro.SetAsyncIO(cast.ToBool(asyncIO)) + } + + return ro +} + func bbtoFromAppOpts(appOpts types.AppOptions) *grocksdb.BlockBasedTableOptions { bbto := defaultBBTO() @@ -282,6 +295,7 @@ func newRocksDBWithOptions( dir string, dbOpts *grocksdb.Options, cfOpts *grocksdb.Options, + readOpts *grocksdb.ReadOptions, enableMetrics bool, reportMetricsIntervalSecs int64, ) (*dbm.RocksDB, error) { @@ -307,11 +321,10 @@ func newRocksDBWithOptions( go reportMetrics(db, time.Second*time.Duration(reportMetricsIntervalSecs)) } - ro := grocksdb.NewDefaultReadOptions() wo := grocksdb.NewDefaultWriteOptions() woSync := grocksdb.NewDefaultWriteOptions() woSync.SetSync(true) - return dbm.NewRocksDBWithRawDB(db, ro, wo, woSync), nil + return dbm.NewRocksDBWithRawDB(db, readOpts, wo, woSync), nil } // newDefaultOptions returns default tm-db options for RocksDB, see for details: diff --git a/cmd/kava/opendb/opendb_rocksdb_test.go b/cmd/kava/opendb/opendb_rocksdb_test.go index e8d1bb29..dcafdeae 100644 --- a/cmd/kava/opendb/opendb_rocksdb_test.go +++ b/cmd/kava/opendb/opendb_rocksdb_test.go @@ -186,7 +186,7 @@ func TestLoadLatestOptions(t *testing.T) { require.NoError(t, err) }() - db, err := newRocksDBWithOptions(name, dir, tc.dbOpts, tc.cfOpts, true, defaultReportMetricsIntervalSecs) + db, err := newRocksDBWithOptions(name, dir, tc.dbOpts, tc.cfOpts, grocksdb.NewDefaultReadOptions(), true, defaultReportMetricsIntervalSecs) require.NoError(t, err) require.NoError(t, db.Close()) @@ -321,6 +321,33 @@ func TestOverrideCFOpts(t *testing.T) { } } +func TestReadOptsFromAppOpts(t *testing.T) { + for _, tc := range []struct { + desc string + mockAppOptions *mockAppOptions + asyncIO bool + }{ + { + desc: "default options", + mockAppOptions: newMockAppOptions(map[string]interface{}{}), + asyncIO: false, + }, + { + desc: "set asyncIO option to true", + mockAppOptions: newMockAppOptions(map[string]interface{}{ + asyncIOReadOptName: true, + }), + asyncIO: true, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + readOpts := readOptsFromAppOpts(tc.mockAppOptions) + + require.Equal(t, tc.asyncIO, readOpts.IsAsyncIO()) + }) + } +} + func TestNewRocksDBWithOptions(t *testing.T) { defaultOpts := newDefaultOptions() @@ -337,7 +364,7 @@ func TestNewRocksDBWithOptions(t *testing.T) { cfOpts := newDefaultOptions() cfOpts.SetWriteBufferSize(999_999) - db, err := newRocksDBWithOptions(name, dir, dbOpts, cfOpts, true, defaultReportMetricsIntervalSecs) + db, err := newRocksDBWithOptions(name, dir, dbOpts, cfOpts, grocksdb.NewDefaultReadOptions(), true, defaultReportMetricsIntervalSecs) require.NoError(t, err) require.NoError(t, db.Close())