From 497c78326d8fd4088a0f4908ec581b718f65d73c Mon Sep 17 00:00:00 2001 From: Mark Spruiell Date: Fri, 16 Jan 2009 10:51:04 -0800 Subject: bug 2545 - transformdb error handling --- cpp/src/FreezeScript/transformdb.cpp | 74 +++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 13 deletions(-) (limited to 'cpp/src') diff --git a/cpp/src/FreezeScript/transformdb.cpp b/cpp/src/FreezeScript/transformdb.cpp index 6b8f3cc3536..432cf673029 100644 --- a/cpp/src/FreezeScript/transformdb.cpp +++ b/cpp/src/FreezeScript/transformdb.cpp @@ -707,6 +707,7 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator) DbEnv dbEnv(0); DbEnv dbEnvNew(0); Freeze::TransactionPtr txNew = 0; + Freeze::ConnectionPtr connectionNew = 0; vector dbs; int status = EXIT_SUCCESS; try @@ -756,7 +757,7 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator) // // Open the catalog of the new environment, and start a transaction. // - Freeze::ConnectionPtr connectionNew = Freeze::createConnection(communicator, dbEnvNameNew, dbEnvNew); + connectionNew = Freeze::createConnection(communicator, dbEnvNameNew, dbEnvNew); txNew = connectionNew->beginTransaction(); DbTxn* txnNew = Freeze::getTxn(txNew); @@ -789,6 +790,12 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator) if(txNew != 0) { txNew->rollback(); + txNew = 0; + } + if(connectionNew) + { + connectionNew->close(); + connectionNew = 0; } for(vector::iterator p = dbs.begin(); p != dbs.end(); ++p) { @@ -796,8 +803,20 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator) db->close(0); delete db; } - dbEnv.close(0); - dbEnvNew.close(0); + try + { + dbEnv.close(0); + } + catch(const DbException&) + { + } + try + { + dbEnvNew.close(0); + } + catch(const DbException&) + { + } } catch(const DbException& ex) { @@ -822,13 +841,13 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator) // Checkpoint to migrate changes from the log to the database(s). // dbEnvNew.txn_checkpoint(0, 0, DB_FORCE); + } - for(vector::iterator p = dbs.begin(); p != dbs.end(); ++p) - { - Db* db = *p; - db->close(0); - delete db; - } + for(vector::iterator p = dbs.begin(); p != dbs.end(); ++p) + { + Db* db = *p; + db->close(0); + delete db; } } catch(const DbException& ex) @@ -840,8 +859,27 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator) // Clear the transaction before closing the database environment. txNew = 0; - dbEnv.close(0); - dbEnvNew.close(0); + if(connectionNew) + { + connectionNew->close(); + connectionNew = 0; + } + + try + { + dbEnv.close(0); + } + catch(const DbException&) + { + } + + try + { + dbEnvNew.close(0); + } + catch(const DbException&) + { + } return status; } @@ -864,12 +902,22 @@ main(int argc, char* argv[]) { cerr << endl; } - return EXIT_FAILURE; + status = EXIT_FAILURE; } catch(const IceUtil::Exception& ex) { cerr << argv[0] << ": " << ex << endl; - return EXIT_FAILURE; + status = EXIT_FAILURE; + } + catch(const std::exception& ex) + { + cerr << argv[0] << ": " << ex.what() << endl; + status = EXIT_FAILURE; + } + catch(...) + { + cerr << argv[0] << ": unknown exception" << endl; + status = EXIT_FAILURE; } if(communicator) -- cgit v1.2.3