summaryrefslogtreecommitdiff
path: root/cpp/src/FreezeScript
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2004-04-22 21:12:37 +0000
committerMark Spruiell <mes@zeroc.com>2004-04-22 21:12:37 +0000
commita70e936cacb21eba2638f8a1d15c6359db0c10ff (patch)
tree0ea769fd8237c3d4c354f7445bc27ed68c67ce77 /cpp/src/FreezeScript
parentbug fix for Ice::Identity definition (diff)
downloadice-a70e936cacb21eba2638f8a1d15c6359db0c10ff.tar.bz2
ice-a70e936cacb21eba2638f8a1d15c6359db0c10ff.tar.xz
ice-a70e936cacb21eba2638f8a1d15c6359db0c10ff.zip
fixes for new evictor database format
Diffstat (limited to 'cpp/src/FreezeScript')
-rw-r--r--cpp/src/FreezeScript/DumpDB.cpp71
-rw-r--r--cpp/src/FreezeScript/transformdb.cpp125
2 files changed, 128 insertions, 68 deletions
diff --git a/cpp/src/FreezeScript/DumpDB.cpp b/cpp/src/FreezeScript/DumpDB.cpp
index 67f30332d52..654d19927c3 100644
--- a/cpp/src/FreezeScript/DumpDB.cpp
+++ b/cpp/src/FreezeScript/DumpDB.cpp
@@ -412,7 +412,6 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
DbEnv dbEnv(0);
DbTxn* txn = 0;
- Db* db = 0;
int status = EXIT_SUCCESS;
try
{
@@ -424,33 +423,71 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
#endif
//
- // Open the database environment.
+ // 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;
dbEnv.open(dbEnvName.c_str(), flags, FREEZE_SCRIPT_DB_MODE);
}
-
- //
- // Open the database in a transaction.
- //
- db = new Db(&dbEnv, 0);
dbEnv.txn_begin(0, &txn, 0);
- db->open(txn, dbName.c_str(), 0, DB_BTREE, DB_RDONLY, FREEZE_SCRIPT_DB_MODE);
-
- istringstream istr(descriptors);
FreezeScript::ErrorReporterPtr errorReporter = new FreezeScript::ErrorReporter(cerr, false);
-
try
{
FreezeScript::DataFactoryPtr factory = new FreezeScript::DataFactory(communicator, unit, errorReporter);
FreezeScript::DescriptorHandler dh(factory, unit, errorReporter);
+
+ istringstream istr(descriptors);
IceXML::Parser::parse(istr, dh);
FreezeScript::DumpDBDescriptorPtr descriptor = dh.descriptor();
descriptor->validate();
- descriptor->dump(communicator, db, txn);
+
+ if(evictor)
+ {
+ //
+ // Open the database and collect the names of the embedded databases.
+ //
+ vector<string> dbNames;
+ {
+ Db db(&dbEnv, 0);
+ db.open(txn, dbName.c_str(), 0, DB_UNKNOWN, DB_RDONLY, 0);
+ Dbt dbKey, dbValue;
+ dbKey.set_flags(DB_DBT_MALLOC);
+ dbValue.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL);
+
+ Dbc* dbc = 0;
+ db.cursor(0, &dbc, 0);
+
+ while(dbc->get(&dbKey, &dbValue, DB_NEXT) == 0)
+ {
+ string s(static_cast<char*>(dbKey.get_data()), dbKey.get_size());
+ if(s.find("$index:") != 0)
+ {
+ dbNames.push_back(s);
+ }
+ free(dbKey.get_data());
+ }
+
+ dbc->close();
+ db.close(0);
+ }
+
+ for(vector<string>::iterator p = dbNames.begin(); p != dbNames.end(); ++p)
+ {
+ Db db(&dbEnv, 0);
+ db.open(txn, dbName.c_str(), p->c_str(), DB_BTREE, DB_RDONLY, FREEZE_SCRIPT_DB_MODE);
+ descriptor->dump(communicator, &db, txn);
+ db.close(0);
+ }
+ }
+ else
+ {
+ Db db(&dbEnv, 0);
+ db.open(txn, dbName.c_str(), 0, DB_BTREE, DB_RDONLY, FREEZE_SCRIPT_DB_MODE);
+ descriptor->dump(communicator, &db, txn);
+ db.close(0);
+ }
}
catch(const IceXML::ParserException& ex)
{
@@ -468,11 +505,6 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
{
txn->abort();
}
- if(db)
- {
- db->close(0);
- delete db;
- }
dbEnv.close(0);
throw;
}
@@ -481,11 +513,6 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
{
txn->abort();
}
- if(db)
- {
- db->close(0);
- delete db;
- }
dbEnv.close(0);
return status;
diff --git a/cpp/src/FreezeScript/transformdb.cpp b/cpp/src/FreezeScript/transformdb.cpp
index 5e240d999b2..52ceda74782 100644
--- a/cpp/src/FreezeScript/transformdb.cpp
+++ b/cpp/src/FreezeScript/transformdb.cpp
@@ -525,8 +525,6 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
DbEnv dbEnvNew(0);
DbTxn* txn = 0;
DbTxn* txnNew = 0;
- Db* db = 0;
- Db* dbNew = 0;
int status = EXIT_SUCCESS;
try
{
@@ -539,7 +537,7 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
#endif
//
- // Open the old database environment. Use DB_RECOVER_FATAL if -c is specified.
+ // Open the old database environment and start a transaction. Use DB_RECOVER_FATAL if -c is specified.
//
{
u_int32_t flags = DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE;
@@ -553,40 +551,95 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
}
dbEnv.open(dbEnvName.c_str(), flags, FREEZE_SCRIPT_DB_MODE);
}
+ dbEnv.txn_begin(0, &txn, 0);
//
- // Open the new database environment.
+ // Open the new database environment and start a transaction.
//
{
u_int32_t flags = DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_RECOVER | DB_CREATE;
dbEnvNew.open(dbEnvNameNew.c_str(), flags, FREEZE_SCRIPT_DB_MODE);
}
+ dbEnvNew.txn_begin(0, &txnNew, 0);
- //
- // Open the old database in a transaction.
- //
- db = new Db(&dbEnv, 0);
- dbEnv.txn_begin(0, &txn, 0);
- db->open(txn, dbName.c_str(), 0, DB_BTREE, DB_RDONLY, FREEZE_SCRIPT_DB_MODE);
+ if(evictor)
+ {
+ //
+ // Open the old database in a transaction and collect the names of the embedded databases.
+ //
+ vector<string> dbNames;
+ {
+ Db db(&dbEnv, 0);
+ db.open(txn, dbName.c_str(), 0, DB_UNKNOWN, DB_RDONLY, 0);
+ Dbt dbKey, dbValue;
+ dbKey.set_flags(DB_DBT_MALLOC);
+ dbValue.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL);
- //
- // Open the new database in a transaction.
- //
- dbNew = new Db(&dbEnvNew, 0);
- dbEnvNew.txn_begin(0, &txnNew, 0);
- dbNew->open(txnNew, dbName.c_str(), 0, DB_BTREE, DB_CREATE | DB_EXCL, FREEZE_SCRIPT_DB_MODE);
+ Dbc* dbc = 0;
+ db.cursor(0, &dbc, 0);
- //
- // Execute the transformation descriptors.
- //
- istringstream istr(descriptors);
- FreezeScript::transformDatabase(communicator, oldUnit, newUnit, db, txn, dbNew, txnNew, purgeObjects, cerr,
- suppress, istr);
+ while(dbc->get(&dbKey, &dbValue, DB_NEXT) == 0)
+ {
+ string s(static_cast<char*>(dbKey.get_data()), dbKey.get_size());
+ if(s.find("$index:") != 0)
+ {
+ dbNames.push_back(s);
+ }
+ free(dbKey.get_data());
+ }
- //
- // Checkpoint to migrate changes from the log to the database.
- //
- dbEnvNew.txn_checkpoint(0, 0, DB_FORCE);
+ dbc->close();
+ db.close(0);
+ }
+
+ for(vector<string>::iterator p = dbNames.begin(); p != dbNames.end(); ++p)
+ {
+ Db db(&dbEnv, 0);
+ db.open(txn, dbName.c_str(), p->c_str(), DB_BTREE, DB_RDONLY, FREEZE_SCRIPT_DB_MODE);
+
+ Db dbNew(&dbEnvNew, 0);
+ dbNew.open(txnNew, dbName.c_str(), p->c_str(), DB_BTREE, DB_CREATE | DB_EXCL,
+ FREEZE_SCRIPT_DB_MODE);
+
+ //
+ // Execute the transformation descriptors.
+ //
+ istringstream istr(descriptors);
+ FreezeScript::transformDatabase(communicator, oldUnit, newUnit, &db, txn, &dbNew, txnNew,
+ purgeObjects, cerr, suppress, istr);
+
+ //
+ // Checkpoint to migrate changes from the log to the database.
+ //
+ dbEnvNew.txn_checkpoint(0, 0, DB_FORCE);
+
+ db.close(0);
+ dbNew.close(0);
+ }
+ }
+ else
+ {
+ Db db(&dbEnv, 0);
+ db.open(txn, dbName.c_str(), 0, DB_BTREE, DB_RDONLY, FREEZE_SCRIPT_DB_MODE);
+
+ Db dbNew(&dbEnvNew, 0);
+ dbNew.open(txnNew, dbName.c_str(), 0, DB_BTREE, DB_CREATE | DB_EXCL, FREEZE_SCRIPT_DB_MODE);
+
+ //
+ // Execute the transformation descriptors.
+ //
+ istringstream istr(descriptors);
+ FreezeScript::transformDatabase(communicator, oldUnit, newUnit, &db, txn, &dbNew, txnNew,
+ purgeObjects, cerr, suppress, istr);
+
+ //
+ // Checkpoint to migrate changes from the log to the database.
+ //
+ dbEnvNew.txn_checkpoint(0, 0, DB_FORCE);
+
+ db.close(0);
+ dbNew.close(0);
+ }
}
catch(const DbException& ex)
{
@@ -599,20 +652,10 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
{
txn->abort();
}
- if(db)
- {
- db->close(0);
- delete db;
- }
if(txnNew)
{
txnNew->abort();
}
- if(dbNew)
- {
- dbNew->close(0);
- delete dbNew;
- }
dbEnv.close(0);
dbEnvNew.close(0);
throw;
@@ -622,11 +665,6 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
{
txn->abort();
}
- if(db)
- {
- db->close(0);
- delete db;
- }
if(txnNew)
{
if(status == EXIT_FAILURE)
@@ -638,11 +676,6 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
txnNew->commit(0);
}
}
- if(dbNew)
- {
- dbNew->close(0);
- delete dbNew;
- }
dbEnv.close(0);
dbEnvNew.close(0);