diff options
author | Bernard Normier <bernard@zeroc.com> | 2007-02-01 17:09:49 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2007-02-01 17:09:49 +0000 |
commit | abada90e3f84dc703b8ddc9efcbed8a946fadead (patch) | |
tree | 2c6f9dccd510ea97cb927a7bd635422efaae547a /cpp/src/Freeze/MapI.cpp | |
parent | removing trace message (diff) | |
download | ice-abada90e3f84dc703b8ddc9efcbed8a946fadead.tar.bz2 ice-abada90e3f84dc703b8ddc9efcbed8a946fadead.tar.xz ice-abada90e3f84dc703b8ddc9efcbed8a946fadead.zip |
Expanded tabs into spaces
Diffstat (limited to 'cpp/src/Freeze/MapI.cpp')
-rw-r--r-- | cpp/src/Freeze/MapI.cpp | 1552 |
1 files changed, 776 insertions, 776 deletions
diff --git a/cpp/src/Freeze/MapI.cpp b/cpp/src/Freeze/MapI.cpp index a3e756725d2..37c894dad0c 100644 --- a/cpp/src/Freeze/MapI.cpp +++ b/cpp/src/Freeze/MapI.cpp @@ -86,12 +86,12 @@ Freeze::KeyCompareBase::compareEnabled() const Freeze::MapHelper* Freeze::MapHelper::create(const Freeze::ConnectionPtr& connection, - const string& dbName, - const string& key, - const string& value, - const Freeze::KeyCompareBasePtr& keyCompare, - const std::vector<MapIndexBasePtr>& indices, - bool createDb) + const string& dbName, + const string& key, + const string& value, + const Freeze::KeyCompareBasePtr& keyCompare, + const std::vector<MapIndexBasePtr>& indices, + bool createDb) { Freeze::ConnectionIPtr connectionI = Freeze::ConnectionIPtr::dynamicCast(connection.get()); return new MapHelperI(connectionI, dbName, key, value, keyCompare, indices, createDb); @@ -112,14 +112,14 @@ Freeze::IteratorHelper::create(const MapHelper& m, bool readOnly) const MapHelperI& actualMap = dynamic_cast<const MapHelperI&>(m); auto_ptr<IteratorHelperI> r(new IteratorHelperI(actualMap, readOnly, - 0, false)); + 0, false)); if(r->next()) { - return r.release(); + return r.release(); } else { - return 0; + return 0; } } @@ -134,8 +134,8 @@ Freeze::IteratorHelper::~IteratorHelper() // Freeze::IteratorHelperI::IteratorHelperI(const MapHelperI& m, bool readOnly, - const MapIndexBasePtr& index, - bool onlyDups) : + const MapIndexBasePtr& index, + bool onlyDups) : _map(m), _dbc(0), _indexed(index != 0), @@ -144,41 +144,41 @@ Freeze::IteratorHelperI::IteratorHelperI(const MapHelperI& m, bool readOnly, { if(_map._trace >= 2) { - Trace out(_map._connection->communicator()->getLogger(), "Freeze.Map"); - out << "opening iterator on Db \"" << _map._dbName << "\""; - if(index != 0) - { - out << " with index \"" << index->name() << "\""; - } + Trace out(_map._connection->communicator()->getLogger(), "Freeze.Map"); + out << "opening iterator on Db \"" << _map._dbName << "\""; + if(index != 0) + { + out << " with index \"" << index->name() << "\""; + } } DbTxn* txn = _map._connection->dbTxn(); if(txn == 0 && !readOnly) { - // - // Need to start a transaction - // - _tx = new Tx(_map); - txn = _tx->getTxn(); + // + // Need to start a transaction + // + _tx = new Tx(_map); + txn = _tx->getTxn(); } try { - if(index != 0) - { - index->_impl->db()->cursor(txn, &_dbc, 0); - } - else - { - _map._db->cursor(txn, &_dbc, 0); - } + if(index != 0) + { + index->_impl->db()->cursor(txn, &_dbc, 0); + } + else + { + _map._db->cursor(txn, &_dbc, 0); + } } catch(const ::DbException& dx) { - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; } _map._iteratorList.push_back(this); @@ -194,19 +194,19 @@ Freeze::IteratorHelperI::IteratorHelperI(const IteratorHelperI& it) : { if(_map._trace >= 2) { - Trace out(_map._connection->communicator()->getLogger(), "Freeze.Map"); - out << "duplicating iterator on Db \"" << _map._dbName << "\""; + Trace out(_map._connection->communicator()->getLogger(), "Freeze.Map"); + out << "duplicating iterator on Db \"" << _map._dbName << "\""; } try { - it._dbc->dup(&_dbc, DB_POSITION); + it._dbc->dup(&_dbc, DB_POSITION); } catch(const ::DbException& dx) { - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; } _tx = it._tx; @@ -241,31 +241,31 @@ Freeze::IteratorHelperI::find(const Key& key) const { try { - if(_dbc->get(&dbKey, &dbValue, DB_SET) == 0) - { - return true; - } - else - { - return false; - } + if(_dbc->get(&dbKey, &dbValue, DB_SET) == 0) + { + return true; + } + else + { + return false; + } } catch(const ::DbDeadlockException& dx) { - if(_tx != 0) - { - _tx->dead(); - } - - DeadlockException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + if(_tx != 0) + { + _tx->dead(); + } + + DeadlockException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; } catch(const ::DbException& dx) { - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; } } } @@ -289,42 +289,42 @@ Freeze::IteratorHelperI::lowerBound(const Key& key) const for(;;) { - try - { - int err = _dbc->get(&dbKey, &dbValue, DB_SET_RANGE); - if(err == 0) - { - _key.resize(dbKey.get_size()); - return true; - } - else if(err == DB_NOTFOUND) - { - return false; - } - else - { - // - // Bug in Freeze - // - assert(0); - throw DatabaseException(__FILE__, __LINE__); - } - } - catch(const ::DbDeadlockException& dx) - { - if(_tx != 0) - { - _tx->dead(); - } - - DeadlockException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; - } - catch(const ::DbException& dx) - { - handleDbException(dx, _key, dbKey, __FILE__, __LINE__); - } + try + { + int err = _dbc->get(&dbKey, &dbValue, DB_SET_RANGE); + if(err == 0) + { + _key.resize(dbKey.get_size()); + return true; + } + else if(err == DB_NOTFOUND) + { + return false; + } + else + { + // + // Bug in Freeze + // + assert(0); + throw DatabaseException(__FILE__, __LINE__); + } + } + catch(const ::DbDeadlockException& dx) + { + if(_tx != 0) + { + _tx->dead(); + } + + DeadlockException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } + catch(const ::DbException& dx) + { + handleDbException(dx, _key, dbKey, __FILE__, __LINE__); + } } } @@ -333,18 +333,18 @@ Freeze::IteratorHelperI::upperBound(const Key& key) const { if(lowerBound(key)) { - if(_key == key) - { - return next(true); - } - else - { - return true; - } + if(_key == key) + { + return next(true); + } + else + { + return true; + } } else { - return false; + return false; } } @@ -364,7 +364,7 @@ Freeze::IteratorHelperI::get(const Key*& key, const Value*& value) const size_t keySize = _key.capacity(); if(keySize < 1024) { - keySize = 1024; + keySize = 1024; } _key.resize(keySize); @@ -374,7 +374,7 @@ Freeze::IteratorHelperI::get(const Key*& key, const Value*& value) const size_t valueSize = _value.capacity(); if(valueSize < 1024) { - valueSize = 1024; + valueSize = 1024; } _value.resize(valueSize); Dbt dbValue; @@ -382,60 +382,60 @@ Freeze::IteratorHelperI::get(const Key*& key, const Value*& value) const for(;;) { - try - { - int err; - - if(_indexed) - { - // - // Not interested in getting the index's key - // - Dbt iKey; - iKey.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL); - - err = _dbc->pget(&iKey, &dbKey, &dbValue, DB_CURRENT); - } - else - { - err = _dbc->get(&dbKey, &dbValue, DB_CURRENT); - } - - if(err == 0) - { - _key.resize(dbKey.get_size()); - _value.resize(dbValue.get_size()); - break; // for(;;) - } - else if(err == DB_KEYEMPTY) - { - throw InvalidPositionException(__FILE__, __LINE__); - } - else - { - // - // Bug in Freeze - // - assert(0); - throw DatabaseException(__FILE__, __LINE__); - } - } - catch(const ::DbDeadlockException& dx) - { - if(_tx != 0) - { - _tx->dead(); - } - - DeadlockException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; - } - catch(const ::DbException& dx) - { - handleDbException(dx, _key, dbKey, _value, dbValue, - __FILE__, __LINE__); - } + try + { + int err; + + if(_indexed) + { + // + // Not interested in getting the index's key + // + Dbt iKey; + iKey.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL); + + err = _dbc->pget(&iKey, &dbKey, &dbValue, DB_CURRENT); + } + else + { + err = _dbc->get(&dbKey, &dbValue, DB_CURRENT); + } + + if(err == 0) + { + _key.resize(dbKey.get_size()); + _value.resize(dbValue.get_size()); + break; // for(;;) + } + else if(err == DB_KEYEMPTY) + { + throw InvalidPositionException(__FILE__, __LINE__); + } + else + { + // + // Bug in Freeze + // + assert(0); + throw DatabaseException(__FILE__, __LINE__); + } + } + catch(const ::DbDeadlockException& dx) + { + if(_tx != 0) + { + _tx->dead(); + } + + DeadlockException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } + catch(const ::DbException& dx) + { + handleDbException(dx, _key, dbKey, _value, dbValue, + __FILE__, __LINE__); + } } } @@ -445,7 +445,7 @@ Freeze::IteratorHelperI::get() const size_t keySize = _key.capacity(); if(keySize < 1024) { - keySize = 1024; + keySize = 1024; } _key.resize(keySize); @@ -460,57 +460,57 @@ Freeze::IteratorHelperI::get() const for(;;) { - try - { - int err; - if(_indexed) - { - // - // Not interested in getting the index's key - // - Dbt iKey; - iKey.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL); - - err = _dbc->pget(&iKey, &dbKey, &dbValue, DB_CURRENT); - } - else - { - err = _dbc->get(&dbKey, &dbValue, DB_CURRENT); - } - - if(err == 0) - { - _key.resize(dbKey.get_size()); - return &_key; - } - else if(err == DB_KEYEMPTY) - { - throw InvalidPositionException(__FILE__, __LINE__); - } - else - { - // - // Bug in Freeze - // - assert(0); - throw DatabaseException(__FILE__, __LINE__); - } - } - catch(const ::DbDeadlockException& dx) - { - if(_tx != 0) - { - _tx->dead(); - } - - DeadlockException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; - } - catch(const ::DbException& dx) - { - handleDbException(dx, _key, dbKey, __FILE__, __LINE__); - } + try + { + int err; + if(_indexed) + { + // + // Not interested in getting the index's key + // + Dbt iKey; + iKey.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL); + + err = _dbc->pget(&iKey, &dbKey, &dbValue, DB_CURRENT); + } + else + { + err = _dbc->get(&dbKey, &dbValue, DB_CURRENT); + } + + if(err == 0) + { + _key.resize(dbKey.get_size()); + return &_key; + } + else if(err == DB_KEYEMPTY) + { + throw InvalidPositionException(__FILE__, __LINE__); + } + else + { + // + // Bug in Freeze + // + assert(0); + throw DatabaseException(__FILE__, __LINE__); + } + } + catch(const ::DbDeadlockException& dx) + { + if(_tx != 0) + { + _tx->dead(); + } + + DeadlockException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } + catch(const ::DbException& dx) + { + handleDbException(dx, _key, dbKey, __FILE__, __LINE__); + } } } @@ -519,9 +519,9 @@ Freeze::IteratorHelperI::set(const Value& value) { if(_indexed) { - DatabaseException ex(__FILE__, __LINE__); - ex.message = "Cannot set an iterator retrieved through an index"; - throw ex; + DatabaseException ex(__FILE__, __LINE__); + ex.message = "Cannot set an iterator retrieved through an index"; + throw ex; } // @@ -535,31 +535,31 @@ Freeze::IteratorHelperI::set(const Value& value) if(_tx != 0) { - _map.closeAllIteratorsExcept(_tx); + _map.closeAllIteratorsExcept(_tx); } try { - int err; - err = _dbc->put(&dbKey, &dbValue, DB_CURRENT); - assert(err == 0); + int err; + err = _dbc->put(&dbKey, &dbValue, DB_CURRENT); + assert(err == 0); } catch(const ::DbDeadlockException& dx) { - if(_tx != 0) - { - _tx->dead(); - } + if(_tx != 0) + { + _tx->dead(); + } - DeadlockException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + DeadlockException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; } catch(const ::DbException& dx) { - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; } } @@ -568,34 +568,34 @@ Freeze::IteratorHelperI::erase() { if(_tx != 0) { - _map.closeAllIteratorsExcept(_tx); + _map.closeAllIteratorsExcept(_tx); } try { - int err = _dbc->del(0); - if(err == DB_KEYEMPTY) - { - throw InvalidPositionException(__FILE__, __LINE__); - } - assert(err == 0); + int err = _dbc->del(0); + if(err == DB_KEYEMPTY) + { + throw InvalidPositionException(__FILE__, __LINE__); + } + assert(err == 0); } catch(const ::DbDeadlockException& dx) { - if(_tx != 0) - { - _tx->dead(); - } + if(_tx != 0) + { + _tx->dead(); + } - DeadlockException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + DeadlockException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; } catch(const ::DbException& dx) { - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; } } @@ -619,40 +619,40 @@ Freeze::IteratorHelperI::next(bool skipDups) const int flags = DB_NEXT; if(skipDups) { - flags = DB_NEXT_NODUP; + flags = DB_NEXT_NODUP; } else if(_indexed && _onlyDups) { - flags = DB_NEXT_DUP; + flags = DB_NEXT_DUP; } try { - if(_dbc->get(&dbKey, &dbValue, flags) == 0) - { - return true; - } - else - { - return false; - } + if(_dbc->get(&dbKey, &dbValue, flags) == 0) + { + return true; + } + else + { + return false; + } } catch(const ::DbDeadlockException& dx) { - if(_tx != 0) - { - _tx->dead(); - } + if(_tx != 0) + { + _tx->dead(); + } - DeadlockException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + DeadlockException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; } catch(const ::DbException& dx) { - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; } } @@ -661,35 +661,35 @@ Freeze::IteratorHelperI::close() { if(_dbc != 0) { - if(_map._trace >= 2) - { - Trace out(_map._connection->communicator()->getLogger(), "Freeze.Map"); - out << "closing iterator on Db \"" << _map._dbName << "\""; - } - - try - { - _dbc->close(); - } - catch(const ::DbDeadlockException& dx) - { - bool raiseException = (_tx == 0); - cleanup(); - if(raiseException) - { - DeadlockException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; - } - } - catch(const ::DbException& dx) - { - cleanup(); - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; - } - cleanup(); + if(_map._trace >= 2) + { + Trace out(_map._connection->communicator()->getLogger(), "Freeze.Map"); + out << "closing iterator on Db \"" << _map._dbName << "\""; + } + + try + { + _dbc->close(); + } + catch(const ::DbDeadlockException& dx) + { + bool raiseException = (_tx == 0); + cleanup(); + if(raiseException) + { + DeadlockException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } + } + catch(const ::DbException& dx) + { + cleanup(); + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } + cleanup(); } } @@ -713,68 +713,68 @@ Freeze::IteratorHelperI::Tx::Tx(const MapHelperI& m) : { if(_map._trace >= 2) { - Trace out(_map._connection->communicator()->getLogger(), "Freeze.Map"); - out << "starting transaction for Db \"" << _map._dbName << "\""; + Trace out(_map._connection->communicator()->getLogger(), "Freeze.Map"); + out << "starting transaction for Db \"" << _map._dbName << "\""; } try { - _map._connection->dbEnv()->getEnv()->txn_begin(0, &_txn, 0); + _map._connection->dbEnv()->getEnv()->txn_begin(0, &_txn, 0); } catch(const ::DbException& dx) { - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; } } - + Freeze::IteratorHelperI::Tx::~Tx() { if(_dead) { - if(_map._trace >= 2) - { - Trace out(_map._connection->communicator()->getLogger(), ""); - out << "aborting transaction for Db \"" << _map._dbName << "\""; - } - - try - { - _txn->abort(); - } - catch(...) - { - // - // Ignore exceptions to avoid crash during stack unwinding - // - } + if(_map._trace >= 2) + { + Trace out(_map._connection->communicator()->getLogger(), ""); + out << "aborting transaction for Db \"" << _map._dbName << "\""; + } + + try + { + _txn->abort(); + } + catch(...) + { + // + // Ignore exceptions to avoid crash during stack unwinding + // + } } else { - if(_map._trace >= 2) - { - Trace out(_map._connection->communicator()->getLogger(), "Freeze.Map"); - out << "committing transaction for Db \"" << _map._dbName.c_str() << "\""; - } - - try - { - _txn->commit(0); - } - catch(const ::DbDeadlockException& dx) - { - DeadlockException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; - } - catch(const ::DbException& dx) - { - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; - } + if(_map._trace >= 2) + { + Trace out(_map._connection->communicator()->getLogger(), "Freeze.Map"); + out << "committing transaction for Db \"" << _map._dbName.c_str() << "\""; + } + + try + { + _txn->commit(0); + } + catch(const ::DbDeadlockException& dx) + { + DeadlockException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } + catch(const ::DbException& dx) + { + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } } } @@ -792,31 +792,31 @@ Freeze::IteratorHelperI::Tx::dead() Freeze::MapHelperI::MapHelperI(const ConnectionIPtr& connection, - const string& dbName, - const string& key, - const string& value, - const KeyCompareBasePtr& keyCompare, - const vector<MapIndexBasePtr>& indices, - bool createDb) : + const string& dbName, + const string& key, + const string& value, + const KeyCompareBasePtr& keyCompare, + const vector<MapIndexBasePtr>& indices, + bool createDb) : _connection(connection), _db(SharedDb::get(connection, dbName, key, value, keyCompare, indices, createDb)), _dbName(dbName), _trace(connection->trace()) { for(vector<MapIndexBasePtr>::const_iterator p = indices.begin(); - p != indices.end(); ++p) + p != indices.end(); ++p) { - const MapIndexBasePtr& indexBase = *p; - assert(indexBase->_impl != 0); - assert(indexBase->_communicator == _connection->communicator()); - assert(indexBase->_map == 0); - + const MapIndexBasePtr& indexBase = *p; + assert(indexBase->_impl != 0); + assert(indexBase->_communicator == _connection->communicator()); + assert(indexBase->_map == 0); + #ifndef NDEBUG - bool inserted = + bool inserted = #endif - _indices.insert(IndexMap::value_type(indexBase->name(), indexBase)).second; - assert(inserted); - indexBase->_map = this; + _indices.insert(IndexMap::value_type(indexBase->name(), indexBase)).second; + assert(inserted); + indexBase->_map = this; } _connection->registerMap(this); @@ -832,38 +832,38 @@ Freeze::MapHelperI::find(const Key& k, bool readOnly) const { for(;;) { - try - { - auto_ptr<IteratorHelperI> r(new IteratorHelperI(*this, readOnly, 0, false)); - if(r->find(k)) - { - return r.release(); - } - else - { - return 0; - } - } - catch(const DeadlockException&) - { - if(_connection->dbTxn() != 0) - { - throw; - } - else - { - if(_connection->deadlockWarning()) - { - Warning out(_connection->communicator()->getLogger()); - out << "Deadlock in Freeze::MapHelperI::find on Map \"" - << _dbName << "\"; retrying ..."; - } - - // - // Ignored, try again - // - } - } + try + { + auto_ptr<IteratorHelperI> r(new IteratorHelperI(*this, readOnly, 0, false)); + if(r->find(k)) + { + return r.release(); + } + else + { + return 0; + } + } + catch(const DeadlockException&) + { + if(_connection->dbTxn() != 0) + { + throw; + } + else + { + if(_connection->deadlockWarning()) + { + Warning out(_connection->communicator()->getLogger()); + out << "Deadlock in Freeze::MapHelperI::find on Map \"" + << _dbName << "\"; retrying ..."; + } + + // + // Ignored, try again + // + } + } } } @@ -872,38 +872,38 @@ Freeze::MapHelperI::lowerBound(const Key& k, bool readOnly) const { for(;;) { - try - { - auto_ptr<IteratorHelperI> r(new IteratorHelperI(*this, readOnly, 0, false)); - if(r->lowerBound(k)) - { - return r.release(); - } - else - { - return 0; - } - } - catch(const DeadlockException&) - { - if(_connection->dbTxn() != 0) - { - throw; - } - else - { - if(_connection->deadlockWarning()) - { - Warning out(_connection->communicator()->getLogger()); - out << "Deadlock in Freeze::MapHelperI::lowerBound on Map \"" - << _dbName << "\"; retrying ..."; - } - - // - // Ignored, try again - // - } - } + try + { + auto_ptr<IteratorHelperI> r(new IteratorHelperI(*this, readOnly, 0, false)); + if(r->lowerBound(k)) + { + return r.release(); + } + else + { + return 0; + } + } + catch(const DeadlockException&) + { + if(_connection->dbTxn() != 0) + { + throw; + } + else + { + if(_connection->deadlockWarning()) + { + Warning out(_connection->communicator()->getLogger()); + out << "Deadlock in Freeze::MapHelperI::lowerBound on Map \"" + << _dbName << "\"; retrying ..."; + } + + // + // Ignored, try again + // + } + } } } @@ -912,38 +912,38 @@ Freeze::MapHelperI::upperBound(const Key& k, bool readOnly) const { for(;;) { - try - { - auto_ptr<IteratorHelperI> r(new IteratorHelperI(*this, readOnly, 0, false)); - if(r->upperBound(k)) - { - return r.release(); - } - else - { - return 0; - } - } - catch(const DeadlockException&) - { - if(_connection->dbTxn() != 0) - { - throw; - } - else - { - if(_connection->deadlockWarning()) - { - Warning out(_connection->communicator()->getLogger()); - out << "Deadlock in Freeze::MapHelperI::upperBound on Map \"" - << _dbName << "\"; retrying ..."; - } - - // - // Ignored, try again - // - } - } + try + { + auto_ptr<IteratorHelperI> r(new IteratorHelperI(*this, readOnly, 0, false)); + if(r->upperBound(k)) + { + return r.release(); + } + else + { + return 0; + } + } + catch(const DeadlockException&) + { + if(_connection->dbTxn() != 0) + { + throw; + } + else + { + if(_connection->deadlockWarning()) + { + Warning out(_connection->communicator()->getLogger()); + out << "Deadlock in Freeze::MapHelperI::upperBound on Map \"" + << _dbName << "\"; retrying ..."; + } + + // + // Ignored, try again + // + } + } } } @@ -958,56 +958,56 @@ Freeze::MapHelperI::put(const Key& key, const Value& value) DbTxn* txn = _connection->dbTxn(); if(txn == 0) { - closeAllIterators(); + closeAllIterators(); } for(;;) { - try - { - int err = _db->put(txn, &dbKey, &dbValue, - txn != 0 ? 0 : DB_AUTO_COMMIT); - - if(err == 0) - { - break; - } - else - { - // - // Bug in Freeze - // - throw DatabaseException(__FILE__, __LINE__); - } - } - catch(const ::DbDeadlockException& dx) - { - if(txn != 0) - { - DeadlockException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; - } - else - { - if(_connection->deadlockWarning()) - { - Warning out(_connection->communicator()->getLogger()); - out << "Deadlock in Freeze::MapHelperI::put on Map \"" - << _dbName << "\"; retrying ..."; - } - - // - // Ignored, try again - // - } - } - catch(const ::DbException& dx) - { - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; - } + try + { + int err = _db->put(txn, &dbKey, &dbValue, + txn != 0 ? 0 : DB_AUTO_COMMIT); + + if(err == 0) + { + break; + } + else + { + // + // Bug in Freeze + // + throw DatabaseException(__FILE__, __LINE__); + } + } + catch(const ::DbDeadlockException& dx) + { + if(txn != 0) + { + DeadlockException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } + else + { + if(_connection->deadlockWarning()) + { + Warning out(_connection->communicator()->getLogger()); + out << "Deadlock in Freeze::MapHelperI::put on Map \"" + << _dbName << "\"; retrying ..."; + } + + // + // Ignored, try again + // + } + } + catch(const ::DbException& dx) + { + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } } } @@ -1020,57 +1020,57 @@ Freeze::MapHelperI::erase(const Key& key) DbTxn* txn = _connection->dbTxn(); if(txn == 0) { - closeAllIterators(); + closeAllIterators(); } for(;;) { - try - { - int err = _db->del(txn, &dbKey, txn != 0 ? 0 : DB_AUTO_COMMIT); - - if(err == 0) - { - return true; - } - else if(err == DB_NOTFOUND) - { - return false; - } - else - { - assert(0); - throw DatabaseException(__FILE__, __LINE__); - } - } - catch(const ::DbDeadlockException& dx) - { - if(txn != 0) - { - DeadlockException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; - } - else - { - if(_connection->deadlockWarning()) - { - Warning out(_connection->communicator()->getLogger()); - out << "Deadlock in Freeze::MapHelperI::erase on Map \"" - << _dbName << "\"; retrying ..."; - } - - // - // Ignored, try again - // - } - } - catch(const ::DbException& dx) - { - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; - } + try + { + int err = _db->del(txn, &dbKey, txn != 0 ? 0 : DB_AUTO_COMMIT); + + if(err == 0) + { + return true; + } + else if(err == DB_NOTFOUND) + { + return false; + } + else + { + assert(0); + throw DatabaseException(__FILE__, __LINE__); + } + } + catch(const ::DbDeadlockException& dx) + { + if(txn != 0) + { + DeadlockException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } + else + { + if(_connection->deadlockWarning()) + { + Warning out(_connection->communicator()->getLogger()); + out << "Deadlock in Freeze::MapHelperI::erase on Map \"" + << _dbName << "\"; retrying ..."; + } + + // + // Ignored, try again + // + } + } + catch(const ::DbException& dx) + { + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } } } @@ -1088,52 +1088,52 @@ Freeze::MapHelperI::count(const Key& key) const for(;;) { - try - { - int err = _db->get(_connection->dbTxn(), &dbKey, &dbValue, 0); - - if(err == 0) - { - return 1; - } - else if(err == DB_NOTFOUND) - { - return 0; - } - else - { - assert(0); - throw DatabaseException(__FILE__, __LINE__); - } - } - catch(const ::DbDeadlockException& dx) - { - if(_connection->dbTxn() != 0) - { - DeadlockException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; - } - else - { - if(_connection->deadlockWarning()) - { - Warning out(_connection->communicator()->getLogger()); - out << "Deadlock in Freeze::MapHelperI::count on Map \"" - << _dbName << "\"; retrying ..."; - } - - // - // Ignored, try again - // - } - } - catch(const ::DbException& dx) - { - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; - } + try + { + int err = _db->get(_connection->dbTxn(), &dbKey, &dbValue, 0); + + if(err == 0) + { + return 1; + } + else if(err == DB_NOTFOUND) + { + return 0; + } + else + { + assert(0); + throw DatabaseException(__FILE__, __LINE__); + } + } + catch(const ::DbDeadlockException& dx) + { + if(_connection->dbTxn() != 0) + { + DeadlockException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } + else + { + if(_connection->deadlockWarning()) + { + Warning out(_connection->communicator()->getLogger()); + out << "Deadlock in Freeze::MapHelperI::count on Map \"" + << _dbName << "\"; retrying ..."; + } + + // + // Ignored, try again + // + } + } + catch(const ::DbException& dx) + { + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } } } @@ -1143,47 +1143,47 @@ Freeze::MapHelperI::clear() DbTxn* txn = _connection->dbTxn(); if(txn == 0) { - closeAllIterators(); + closeAllIterators(); } for(;;) { - try - { - u_int32_t count; - int err; - err = _db->truncate(txn, &count, txn != 0 ? 0 : DB_AUTO_COMMIT); - assert(err == 0); - break; - } - catch(const ::DbDeadlockException& dx) - { - if(txn != 0) - { - DeadlockException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; - } - else - { - if(_connection->deadlockWarning()) - { - Warning out(_connection->communicator()->getLogger()); - out << "Deadlock in Freeze::MapHelperI::clear on Map \"" - << _dbName << "\"; retrying ..."; - } - - // - // Ignored, try again - // - } - } - catch(const ::DbException& dx) - { - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; - } + try + { + u_int32_t count; + int err; + err = _db->truncate(txn, &count, txn != 0 ? 0 : DB_AUTO_COMMIT); + assert(err == 0); + break; + } + catch(const ::DbDeadlockException& dx) + { + if(txn != 0) + { + DeadlockException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } + else + { + if(_connection->deadlockWarning()) + { + Warning out(_connection->communicator()->getLogger()); + out << "Deadlock in Freeze::MapHelperI::clear on Map \"" + << _dbName << "\"; retrying ..."; + } + + // + // Ignored, try again + // + } + } + catch(const ::DbException& dx) + { + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; + } } } @@ -1192,71 +1192,71 @@ Freeze::MapHelperI::destroy() { if(_dbName == catalogName()) { - DatabaseException ex(__FILE__, __LINE__); - ex.message = "You cannot destroy the " + catalogName() + " database"; - throw ex; + DatabaseException ex(__FILE__, __LINE__); + ex.message = "You cannot destroy the " + catalogName() + " database"; + throw ex; } TransactionPtr tx = _connection->currentTransaction(); bool ownTx = (tx == 0); if(ownTx) - { - tx = _connection->beginTransaction(); + { + tx = _connection->beginTransaction(); } DbTxn* txn = _connection->dbTxn(); try { - close(); + close(); - Catalog catalog(_connection, catalogName()); - catalog.erase(_dbName); - _connection->dbEnv()->getEnv()->dbremove(txn, _dbName.c_str(), 0, 0); + Catalog catalog(_connection, catalogName()); + catalog.erase(_dbName); + _connection->dbEnv()->getEnv()->dbremove(txn, _dbName.c_str(), 0, 0); - if(ownTx) - { - tx->commit(); - } + if(ownTx) + { + tx->commit(); + } } catch(const ::DbException& dx) { - if(ownTx) - { - tx = _connection->currentTransaction(); - if(tx != 0) - { - try - { - tx->rollback(); - } - catch(...) - { - } - } - } - - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + if(ownTx) + { + tx = _connection->currentTransaction(); + if(tx != 0) + { + try + { + tx->rollback(); + } + catch(...) + { + } + } + } + + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; } catch(...) { - if(ownTx) - { - tx = _connection->currentTransaction(); - if(tx != 0) - { - try - { - tx->rollback(); - } - catch(...) - { - } - } - } - throw; + if(ownTx) + { + tx = _connection->currentTransaction(); + if(tx != 0) + { + try + { + tx->rollback(); + } + catch(...) + { + } + } + } + throw; } } @@ -1282,9 +1282,9 @@ Freeze::MapHelperI::size() const } catch(const ::DbException& dx) { - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; } size_t num = s->bt_ndata; @@ -1298,7 +1298,7 @@ Freeze::MapHelperI::closeAllIterators() { while(!_iteratorList.empty()) { - (*_iteratorList.begin())->close(); + (*_iteratorList.begin())->close(); } } @@ -1308,9 +1308,9 @@ Freeze::MapHelperI::index(const string& name) const IndexMap::const_iterator p = _indices.find(name); if(p == _indices.end()) { - DatabaseException ex(__FILE__, __LINE__); - ex.message = "Cannot find index \"" + name + "\""; - throw ex; + DatabaseException ex(__FILE__, __LINE__); + ex.message = "Cannot find index \"" + name + "\""; + throw ex; } return p->second; } @@ -1320,16 +1320,16 @@ Freeze::MapHelperI::close() { if(_db != 0) { - _connection->unregisterMap(this); + _connection->unregisterMap(this); } _db = 0; for(IndexMap::iterator p = _indices.begin(); p != _indices.end(); ++p) { - MapIndexBasePtr& indexBase = p->second; + MapIndexBasePtr& indexBase = p->second; - indexBase->_impl = 0; - indexBase->_map = 0; + indexBase->_impl = 0; + indexBase->_map = 0; } _indices.clear(); } @@ -1343,15 +1343,15 @@ Freeze::MapHelperI::closeAllIteratorsExcept(const IteratorHelperI::TxPtr& tx) co while(q != _iteratorList.end()) { - if((*q)->tx().get() == tx.get()) - { - ++q; - } - else - { - (*q)->close(); - q = _iteratorList.begin(); - } + if((*q)->tx().get() == tx.get()) + { + ++q; + } + else + { + (*q)->close(); + q = _iteratorList.begin(); + } } } @@ -1385,7 +1385,7 @@ callback(Db* secondary, const Dbt* key, const Dbt* value, Dbt* result) Freeze::MapIndexI::MapIndexI(const ConnectionIPtr& connection, SharedDb& db, - DbTxn* txn, bool createDb, const MapIndexBasePtr& index) : + DbTxn* txn, bool createDb, const MapIndexBasePtr& index) : _index(index) { assert(txn != 0); @@ -1397,7 +1397,7 @@ Freeze::MapIndexI::MapIndexI(const ConnectionIPtr& connection, SharedDb& db, u_int32_t flags = 0; if(createDb) { - flags = DB_CREATE; + flags = DB_CREATE; } _dbName = db.dbName() + "." + _index->name(); @@ -1406,7 +1406,7 @@ Freeze::MapIndexI::MapIndexI(const ConnectionIPtr& connection, SharedDb& db, if(index->compareEnabled()) { - _db->set_bt_compare(&customIndexCompare); + _db->set_bt_compare(&customIndexCompare); } _db->open(txn, _dbName.c_str(), 0, DB_BTREE, flags, FREEZE_DB_MODE); @@ -1429,17 +1429,17 @@ Freeze::MapIndexI::~MapIndexI() IteratorHelper* Freeze::MapIndexI::untypedFind(const Key& k, bool ro, const MapHelperI& m, - bool onlyDups) const + bool onlyDups) const { auto_ptr<IteratorHelperI> r(new IteratorHelperI(m, ro, _index, onlyDups)); if(r->find(k)) { - return r.release(); + return r.release(); } else { - return 0; + return 0; } } @@ -1450,11 +1450,11 @@ Freeze::MapIndexI::untypedLowerBound(const Key& k, bool ro, const MapHelperI& m) if(r->lowerBound(k)) { - return r.release(); + return r.release(); } else { - return 0; + return 0; } } @@ -1465,11 +1465,11 @@ Freeze::MapIndexI::untypedUpperBound(const Key& k, bool ro, const MapHelperI& m) if(r->upperBound(k)) { - return r.release(); + return r.release(); } else { - return 0; + return 0; } } @@ -1493,81 +1493,81 @@ Freeze::MapIndexI::untypedCount(const Key& k, const ConnectionIPtr& connection) try { - for(;;) - { - Dbc* dbc = 0; - - try - { - // - // Move to the first record - // - _db->cursor(0, &dbc, 0); - bool found = (dbc->get(&dbKey, &dbValue, DB_SET) == 0); - - if(found) - { - db_recno_t count = 0; - dbc->count(&count, 0); - result = static_cast<int>(count); - } - - Dbc* toClose = dbc; - dbc = 0; - toClose->close(); - break; // for (;;) - } - catch(const DbDeadlockException&) - { - if(dbc != 0) - { - try - { - dbc->close(); - } - catch(const DbDeadlockException&) - { - // - // Ignored - // - } - } - - if(connection->deadlockWarning()) - { - Warning out(connection->communicator()->getLogger()); - out << "Deadlock in Freeze::MapIndexI::untypedCount while searching \"" - << _dbName << "\"; retrying ..."; - } - - // - // Retry - // - } - catch(...) - { - if(dbc != 0) - { - try - { - dbc->close(); - } - catch(const DbDeadlockException&) - { - // - // Ignored - // - } - } - throw; - } - } + for(;;) + { + Dbc* dbc = 0; + + try + { + // + // Move to the first record + // + _db->cursor(0, &dbc, 0); + bool found = (dbc->get(&dbKey, &dbValue, DB_SET) == 0); + + if(found) + { + db_recno_t count = 0; + dbc->count(&count, 0); + result = static_cast<int>(count); + } + + Dbc* toClose = dbc; + dbc = 0; + toClose->close(); + break; // for (;;) + } + catch(const DbDeadlockException&) + { + if(dbc != 0) + { + try + { + dbc->close(); + } + catch(const DbDeadlockException&) + { + // + // Ignored + // + } + } + + if(connection->deadlockWarning()) + { + Warning out(connection->communicator()->getLogger()); + out << "Deadlock in Freeze::MapIndexI::untypedCount while searching \"" + << _dbName << "\"; retrying ..."; + } + + // + // Retry + // + } + catch(...) + { + if(dbc != 0) + { + try + { + dbc->close(); + } + catch(const DbDeadlockException&) + { + // + // Ignored + // + } + } + throw; + } + } } catch(const DbException& dx) { - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + DatabaseException ex(__FILE__, __LINE__); + ex.message = dx.what(); + throw ex; } return result; @@ -1575,7 +1575,7 @@ Freeze::MapIndexI::untypedCount(const Key& k, const ConnectionIPtr& connection) int Freeze::MapIndexI::secondaryKeyCreate(Db* secondary, const Dbt* dbKey, - const Dbt* dbValue, Dbt* result) + const Dbt* dbValue, Dbt* result) { Byte* first = static_cast<Byte*>(dbValue->get_data()); Value value(first, first + dbValue->get_size()); |