improve copying of Env in Options (#10666)

Summary:
Closes https://github.com/facebook/rocksdb/issues/9909

- Constructing an Options from a DBOptions should use the Env from the DBOptions
- DBOptions should be constructed with the default Env as the env_, rather than null. Why ever not ?

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10666

Reviewed By: riversand963

Differential Revision: D40515418

Pulled By: ajkr

fbshipit-source-id: 4122ba3f537660720262694c21ab4bfb13b6f8de
This commit is contained in:
Alan Paxton 2022-11-22 15:48:59 -08:00 committed by Facebook GitHub Bot
parent db9cbddc6f
commit ae115eff8f
3 changed files with 32 additions and 1 deletions

View file

@ -31,6 +31,7 @@ public class DBOptions extends RocksObject
public DBOptions() {
super(newDBOptions());
numShardBits_ = DEFAULT_NUM_SHARD_BITS;
env_ = Env.getDefault();
}
/**

View file

@ -66,7 +66,7 @@ public class Options extends RocksObject
final ColumnFamilyOptions columnFamilyOptions) {
super(newOptions(dbOptions.nativeHandle_,
columnFamilyOptions.nativeHandle_));
env_ = Env.getDefault();
env_ = dbOptions.getEnv() != null ? dbOptions.getEnv() : Env.getDefault();
}
/**

View file

@ -52,4 +52,34 @@ public class MixedOptionsTest {
}
}
}
@Test
public void mixedOptionsEnvTest() {
try (final ColumnFamilyOptions cfOptions = new ColumnFamilyOptions();
final DBOptions dbOptions = new DBOptions()) {
assertThat(dbOptions.getEnv()).isNotNull();
assertThat(dbOptions.getEnv()).isSameAs(Env.getDefault());
final Env memEnv = new RocksMemEnv(Env.getDefault());
try (final Options options = new Options(dbOptions, cfOptions)) {
assertThat(options.getEnv()).isSameAs(Env.getDefault());
}
dbOptions.setEnv(memEnv);
memEnv.setBackgroundThreads(4, Priority.LOW);
Env.getDefault().setBackgroundThreads(2, Priority.HIGH);
assertThat(dbOptions.getEnv().getBackgroundThreads(Priority.LOW)).isEqualTo(4);
assertThat(dbOptions.getEnv().getBackgroundThreads(Priority.HIGH)).isEqualTo(2);
assertThat(Env.getDefault().getBackgroundThreads(Priority.LOW)).isEqualTo(4);
assertThat(Env.getDefault().getBackgroundThreads(Priority.HIGH)).isEqualTo(2);
try (final Options options = new Options(dbOptions, cfOptions)) {
assertThat(options.getEnv().getBackgroundThreads(Priority.LOW)).isEqualTo(4);
assertThat(options.getEnv().getBackgroundThreads(Priority.HIGH)).isEqualTo(2);
assertThat(options.getEnv()).isNotSameAs(Env.getDefault());
assertThat(options.getEnv()).isSameAs(memEnv);
}
}
}
}