From 74581003486030ea874707085d5bf7cdce28f501 Mon Sep 17 00:00:00 2001 From: Mark Spruiell Date: Fri, 28 May 2010 15:21:24 -0700 Subject: bug 4714 - FreezeScript utilities do not work on an open environment --- cpp/src/FreezeScript/DumpDB.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'cpp/src/FreezeScript/DumpDB.cpp') diff --git a/cpp/src/FreezeScript/DumpDB.cpp b/cpp/src/FreezeScript/DumpDB.cpp index c4b0e715341..5f4b2175bc7 100755 --- a/cpp/src/FreezeScript/DumpDB.cpp +++ b/cpp/src/FreezeScript/DumpDB.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include #include @@ -169,6 +171,26 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator return EXIT_FAILURE; } + // + // Freeze creates a lock file by default to prevent multiple processes from opening + // the same database environment simultaneously. In the case of a read-only program + // such as dumpdb, however, we still want to be able to open the environment despite + // the lock. This assumes of course that the other process has opened the environment + // with DbPrivate=0. If DbPrivate=0 is also set for dumpdb, we disable the lock. + // + if(!args.empty()) + { + // + // If an argument is present, we assume it is the name of the database environment. + // + Ice::PropertiesPtr props = communicator->getProperties(); + string prefix = "Freeze.DbEnv." + args[0]; + if(props->getPropertyAsIntWithDefault(prefix + ".DbPrivate", 1) == 0) + { + props->setProperty(prefix + ".LockFile", "0"); + } + } + if(opts.isSet("h")) { usage(appName); @@ -457,6 +479,7 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator DbEnv dbEnv(0); DbTxn* txn = 0; + Freeze::ConnectionPtr connection; int status = EXIT_SUCCESS; try { @@ -471,9 +494,16 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator // Open the database environment and start a transaction. // { - u_int32_t flags = DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_RECOVER | DB_CREATE; + u_int32_t flags = 0; dbEnv.open(dbEnvName.c_str(), flags, FREEZE_SCRIPT_DB_MODE); } + + // + // We're creating a connection just to make sure the database environment + // isn't locked. + // + connection = Freeze::createConnection(communicator, dbEnvName, dbEnv); + dbEnv.txn_begin(0, &txn, 0); FreezeScript::ErrorReporterPtr errorReporter = new FreezeScript::ErrorReporter(cerr, false); @@ -570,6 +600,11 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator { cerr << appName << ": database error: " << ex.what() << endl; } + if(connection) + { + connection->close(); + connection = 0; + } throw; } @@ -579,6 +614,10 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator { txn->abort(); } + if(connection) + { + connection->close(); + } dbEnv.close(0); } catch(const DbException& ex) -- cgit v1.2.3