diff options
-rw-r--r-- | cpp/include/Freeze/Map.h | 6 | ||||
-rw-r--r-- | cpp/src/Freeze/MapI.cpp | 48 | ||||
-rw-r--r-- | cpp/test/Freeze/dbmap/Client.cpp | 17 |
3 files changed, 53 insertions, 18 deletions
diff --git a/cpp/include/Freeze/Map.h b/cpp/include/Freeze/Map.h index 73206d9ec70..07459172e07 100644 --- a/cpp/include/Freeze/Map.h +++ b/cpp/include/Freeze/Map.h @@ -856,7 +856,7 @@ public: // equality is not necessarily correct in the context of a // transaction. // - if(count() != rhs.count()) + if(size() != rhs.size()) { return false; } @@ -1144,7 +1144,7 @@ public: const Ice::CommunicatorPtr& communicator() const { - return _communicator(); + return _communicator; } protected: @@ -1155,7 +1155,7 @@ protected: } std::auto_ptr<MapHelper> _helper; - const Ice::CommunicatorPtr _communicator; + Ice::CommunicatorPtr _communicator; }; diff --git a/cpp/src/Freeze/MapI.cpp b/cpp/src/Freeze/MapI.cpp index 37c894dad0c..1011606f336 100644 --- a/cpp/src/Freeze/MapI.cpp +++ b/cpp/src/Freeze/MapI.cpp @@ -1491,18 +1491,20 @@ Freeze::MapIndexI::untypedCount(const Key& k, const ConnectionIPtr& connection) int result = 0; + DbTxn * txn = connection->dbTxn(); + try { for(;;) { Dbc* dbc = 0; - + try { // // Move to the first record // - _db->cursor(0, &dbc, 0); + _db->cursor(txn, &dbc, 0); bool found = (dbc->get(&dbKey, &dbValue, DB_SET) == 0); if(found) @@ -1527,9 +1529,16 @@ Freeze::MapIndexI::untypedCount(const Key& k, const ConnectionIPtr& connection) } catch(const DbDeadlockException&) { - // - // Ignored - // + if(txn != 0) + { + throw; + } + else + { + // + // Ignored + // + } } } @@ -1537,11 +1546,15 @@ Freeze::MapIndexI::untypedCount(const Key& k, const ConnectionIPtr& connection) { Warning out(connection->communicator()->getLogger()); out << "Deadlock in Freeze::MapIndexI::untypedCount while searching \"" - << _dbName << "\"; retrying ..."; + << _dbName << "\""; } + if(txn != 0) + { + throw; + } // - // Retry + // Otherwise retry // } catch(...) @@ -1554,20 +1567,29 @@ Freeze::MapIndexI::untypedCount(const Key& k, const ConnectionIPtr& connection) } catch(const DbDeadlockException&) { - // - // Ignored - // + if(txn != 0) + { + throw; + } + else + { + // + // Ignored + // + } } } throw; } } } + catch(const DbDeadlockException& dx) + { + throw DeadlockException(__FILE__, __LINE__, dx.what()); + } catch(const DbException& dx) { - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + throw DatabaseException(__FILE__, __LINE__, dx.what()); } return result; diff --git a/cpp/test/Freeze/dbmap/Client.cpp b/cpp/test/Freeze/dbmap/Client.cpp index 09ab3c7d745..d8b69750bda 100644 --- a/cpp/test/Freeze/dbmap/Client.cpp +++ b/cpp/test/Freeze/dbmap/Client.cpp @@ -205,12 +205,25 @@ run(const CommunicatorPtr& communicator, const string& envName) { const string dbName = "binary"; Freeze::ConnectionPtr connection = createConnection(communicator, envName); - ByteIntMap m(connection, dbName); + ByteIntMap m1(connection, dbName); // // Populate the database with the alphabet // - populateDB(connection, m); + populateDB(connection, m1); + + // + // Test ==, swap and communicator() + // + ByteIntMap m(connection, dbName + "-tmp"); + test(!(m == m1)); + test(m != m1); + m.swap(m1); + test(!(m == m1)); + test(m != m1); + test(m1.size() == 0); + test(m.communicator() == m1.communicator() == communicator); + vector<Byte>::const_iterator j; ByteIntMap::iterator p; |