summaryrefslogtreecommitdiff
path: root/cpp/src/Freeze/MapI.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2013-01-29 09:26:34 +0100
committerBenoit Foucher <benoit@zeroc.com>2013-01-29 09:26:34 +0100
commit0c86c3b2013261eb55347317474310831892a8fa (patch)
treec8b61f87cd4235b02a41c2b76c8939e9ef9f039d /cpp/src/Freeze/MapI.cpp
parentFixed Ice for Python/Ruby/PHP to not copy data from output stream (diff)
downloadice-0c86c3b2013261eb55347317474310831892a8fa.tar.bz2
ice-0c86c3b2013261eb55347317474310831892a8fa.tar.xz
ice-0c86c3b2013261eb55347317474310831892a8fa.zip
Fixed ICE-5128: Freeze map clear failure
Diffstat (limited to 'cpp/src/Freeze/MapI.cpp')
-rw-r--r--cpp/src/Freeze/MapI.cpp114
1 files changed, 90 insertions, 24 deletions
diff --git a/cpp/src/Freeze/MapI.cpp b/cpp/src/Freeze/MapI.cpp
index c8f329fd5a2..2b739e0a6d8 100644
--- a/cpp/src/Freeze/MapI.cpp
+++ b/cpp/src/Freeze/MapI.cpp
@@ -1379,29 +1379,65 @@ Freeze::MapHelperI::clear()
closeAllIterators();
}
- for(;;)
+ Dbt dbKey;
+ dbKey.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL);
+
+ Dbt dbValue;
+ dbValue.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL);
+
+ try
{
- try
+ for(;;)
{
- u_int32_t count;
-#ifndef NDEBUG
- int err = _db->truncate(txn, &count, txn != 0 ? 0 : DB_AUTO_COMMIT);
- assert(err == 0);
+ Dbc* dbc = 0;
+
+ try
+ {
+ IteratorHelperI::TxPtr tx;
+ if(txn == 0)
+ {
+#ifdef ICE_CPP11
+ tx.reset(new IteratorHelperI::Tx(*this));
#else
- _db->truncate(txn, &count, txn != 0 ? 0 : DB_AUTO_COMMIT);
+ tx = new IteratorHelperI::Tx(*this);
#endif
- break;
- }
- catch(const ::DbDeadlockException& dx)
- {
- if(txn != 0)
- {
- DeadlockException ex(__FILE__, __LINE__);
- ex.message = dx.what();
- throw ex;
+ txn = tx->getTxn();
+ }
+
+ _db->cursor(txn, &dbc, 0);
+ while(dbc->get(&dbKey, &dbValue, DB_NEXT | DB_RMW) == 0)
+ {
+ dbc->del(0);
+ }
+
+ Dbc* toClose = dbc;
+ dbc = 0;
+ toClose->close();
+ break; // for (;;)
}
- else
+ catch(const DbDeadlockException&)
{
+ if(dbc != 0)
+ {
+ try
+ {
+ dbc->close();
+ }
+ catch(const DbDeadlockException&)
+ {
+ if(txn != 0)
+ {
+ throw;
+ }
+ else
+ {
+ //
+ // Ignored
+ //
+ }
+ }
+ }
+
if(_connection->deadlockWarning())
{
Warning out(_connection->communicator()->getLogger());
@@ -1409,17 +1445,47 @@ Freeze::MapHelperI::clear()
<< _dbName << "\"; retrying ...";
}
+ if(txn != 0)
+ {
+ throw;
+ }
//
- // Ignored, try again
+ // Otherwise retry
//
}
+ catch(...)
+ {
+ if(dbc != 0)
+ {
+ try
+ {
+ dbc->close();
+ }
+ catch(const DbDeadlockException&)
+ {
+ if(txn != 0)
+ {
+ throw;
+ }
+ else
+ {
+ //
+ // Ignored
+ //
+ }
+ }
+ }
+ throw;
+ }
}
- catch(const ::DbException& dx)
- {
- DatabaseException ex(__FILE__, __LINE__);
- ex.message = dx.what();
- throw ex;
- }
+ }
+ catch(const DbDeadlockException& dx)
+ {
+ throw DeadlockException(__FILE__, __LINE__, dx.what(), _connection->currentTransaction());
+ }
+ catch(const DbException& dx)
+ {
+ throw DatabaseException(__FILE__, __LINE__, dx.what());
}
}