I'm trying to run two of the same applications using the same BDB environment. My understanding is that each process may only have a single handle to the env opened. I use the below code to open an env in the app, then pass it to multiple db's. I do not understand why the second time I run the application it fails on env->open with invalid argument... if I remove the runrecovery and register flags it opens fine...
public static DatabaseEnvironment OpenEnv(string envHome, uint cacheSizeMB, bool create = false, bool printStats = true)
* Env should be created, per process, in a single thread, and the
* handle shared among any other threads within said process.
DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig();
its my understanding that 'recovering' an environment should only be performed when no other processes are accessing the database files
Obviously in your case when you start the 2nd Application and it tries to 'recover' it does not have exsclusive access to the databases.
When you try to Open the Env it knows recovery isnt required and therefore errors out.
I think the best thing you can do is to set envConfig.RunRecovery to false once the first Application has started up so subsequent starts will not try to open in 'recovery' mode.
Register and RunRecovery should be used when running a multi-process application, that should not be the problem. What Register does is only run recovery when a process accessing the environment has crashed. Perhaps the issue is envConfig.LockSystemCfg.DeadlockResolution = DeadlockPolicy.MIN_WRITE;. The locking policy can only be set once, and returns an invalid argument error if set a second time.
Thank you for your responses. Your suggestion, regarding deadlock policy, is interesting but there does not seem to be an issue if the deadlock policy is set in multiple threads and run-recovery & register are not set, so I think that may not be the issue...