summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2005-10-03 16:57:34 +0000
committerBernard Normier <bernard@zeroc.com>2005-10-03 16:57:34 +0000
commitd3578a4742a4d46d9ee38aa37e18f5483759278c (patch)
tree790b53f267cb55d8f9993d9338cbbbafec9886af /cpp/src
parentFixed bogus dependency on Internal.h in icegridadmin (diff)
downloadice-d3578a4742a4d46d9ee38aa37e18f5483759278c.tar.bz2
ice-d3578a4742a4d46d9ee38aa37e18f5483759278c.tar.xz
ice-d3578a4742a4d46d9ee38aa37e18f5483759278c.zip
Refactored code to work-around DB 4.3's DB_BUFFER_SMALL bug
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Freeze/EvictorIteratorI.cpp12
-rw-r--r--cpp/src/Freeze/IndexI.cpp12
-rw-r--r--cpp/src/Freeze/MapI.cpp62
-rw-r--r--cpp/src/Freeze/ObjectStore.cpp8
-rw-r--r--cpp/src/Freeze/Util.cpp78
-rw-r--r--cpp/src/Freeze/Util.h17
6 files changed, 81 insertions, 108 deletions
diff --git a/cpp/src/Freeze/EvictorIteratorI.cpp b/cpp/src/Freeze/EvictorIteratorI.cpp
index efc3cb26d37..87ef034053d 100644
--- a/cpp/src/Freeze/EvictorIteratorI.cpp
+++ b/cpp/src/Freeze/EvictorIteratorI.cpp
@@ -150,9 +150,13 @@ Freeze::EvictorIteratorI::nextBatch()
}
break;
}
- catch(const DbMemoryException& dx)
+ catch(const DbDeadlockException&)
{
- handleMemoryException(dx, _key, dbKey);
+ throw;
+ }
+ catch(const DbException& dx)
+ {
+ handleDbException(dx, _key, dbKey, __FILE__, __LINE__);
}
}
}
@@ -204,9 +208,7 @@ Freeze::EvictorIteratorI::nextBatch()
}
catch(const DbException& dx)
{
- DatabaseException ex(__FILE__, __LINE__);
- ex.message = dx.what();
- throw ex;
+ handleDbException(dx, __FILE__, __LINE__);
}
if(_batch.size() == 0)
diff --git a/cpp/src/Freeze/IndexI.cpp b/cpp/src/Freeze/IndexI.cpp
index 1b6ee29b84e..cb7694b5906 100644
--- a/cpp/src/Freeze/IndexI.cpp
+++ b/cpp/src/Freeze/IndexI.cpp
@@ -100,9 +100,13 @@ Freeze::IndexI::untypedFindFirst(const Key& bytes, Int firstN) const
}
break; // for(;;)
}
- catch(const DbMemoryException& dx)
+ catch(const DbDeadlockException&)
{
- handleMemoryException(dx, pkey, pdbKey);
+ throw;
+ }
+ catch(const DbException& dx)
+ {
+ handleDbException(dx, pkey, pdbKey, __FILE__, __LINE__);
}
}
}
@@ -161,9 +165,7 @@ Freeze::IndexI::untypedFindFirst(const Key& bytes, Int firstN) const
}
catch(const DbException& dx)
{
- DatabaseException ex(__FILE__, __LINE__);
- ex.message = dx.what();
- throw ex;
+ handleDbException(dx, __FILE__, __LINE__);
}
return identities;
diff --git a/cpp/src/Freeze/MapI.cpp b/cpp/src/Freeze/MapI.cpp
index 0766bc034d0..f9473110012 100644
--- a/cpp/src/Freeze/MapI.cpp
+++ b/cpp/src/Freeze/MapI.cpp
@@ -299,39 +299,6 @@ Freeze::IteratorHelperI::get(const Key*& key, const Value*& value) const
throw DatabaseException(__FILE__, __LINE__);
}
}
- catch(const ::DbMemoryException dx)
- {
- bool resizing = false;
- if(dbKey.get_size() > dbKey.get_ulen())
- {
- //
- // Let's resize key
- //
- _key.resize(dbKey.get_size());
- initializeOutDbt(_key, dbKey);
- resizing = true;
- }
-
- if(dbValue.get_size() > dbValue.get_ulen())
- {
- //
- // Let's resize value
- //
- _value.resize(dbValue.get_size());
- initializeOutDbt(_value, dbValue);
- resizing = true;
- }
-
- if(!resizing)
- {
- //
- // Real problem
- //
- DatabaseException ex(__FILE__, __LINE__);
- ex.message = dx.what();
- throw ex;
- }
- }
catch(const ::DbDeadlockException& dx)
{
if(_tx != 0)
@@ -345,9 +312,8 @@ Freeze::IteratorHelperI::get(const Key*& key, const Value*& value) const
}
catch(const ::DbException& dx)
{
- DatabaseException ex(__FILE__, __LINE__);
- ex.message = dx.what();
- throw ex;
+ handleDbException(dx, _key, dbKey, _value, dbValue,
+ __FILE__, __LINE__);
}
}
}
@@ -409,26 +375,6 @@ Freeze::IteratorHelperI::get() const
throw DatabaseException(__FILE__, __LINE__);
}
}
- catch(const ::DbMemoryException dx)
- {
- if(dbKey.get_size() > dbKey.get_ulen())
- {
- //
- // Let's resize key
- //
- _key.resize(dbKey.get_size());
- initializeOutDbt(_key, dbKey);
- }
- else
- {
- //
- // Real problem
- //
- DatabaseException ex(__FILE__, __LINE__);
- ex.message = dx.what();
- throw ex;
- }
- }
catch(const ::DbDeadlockException& dx)
{
if(_tx != 0)
@@ -442,9 +388,7 @@ Freeze::IteratorHelperI::get() const
}
catch(const ::DbException& dx)
{
- DatabaseException ex(__FILE__, __LINE__);
- ex.message = dx.what();
- throw ex;
+ handleDbException(dx, _key, dbKey, __FILE__, __LINE__);
}
}
}
diff --git a/cpp/src/Freeze/ObjectStore.cpp b/cpp/src/Freeze/ObjectStore.cpp
index a8cc39c9079..4723bacdf69 100644
--- a/cpp/src/Freeze/ObjectStore.cpp
+++ b/cpp/src/Freeze/ObjectStore.cpp
@@ -336,10 +336,6 @@ Freeze::ObjectStore::load(const Identity& ident)
}
break; // for(;;)
}
- catch(const DbMemoryException& dx)
- {
- handleMemoryException(dx, value, dbValue);
- }
catch(const DbDeadlockException&)
{
if(_evictor->deadlockWarning())
@@ -354,9 +350,7 @@ Freeze::ObjectStore::load(const Identity& ident)
}
catch(const DbException& dx)
{
- DatabaseException ex(__FILE__, __LINE__);
- ex.message = dx.what();
- throw ex;
+ handleDbException(dx, value, dbValue, __FILE__, __LINE__);
}
}
diff --git a/cpp/src/Freeze/Util.cpp b/cpp/src/Freeze/Util.cpp
index e3d86328e58..73ef47cb4eb 100644
--- a/cpp/src/Freeze/Util.cpp
+++ b/cpp/src/Freeze/Util.cpp
@@ -15,9 +15,25 @@ using namespace Ice;
using namespace std;
void
-Freeze::handleMemoryException(const DbMemoryException& dx, Key& key, Dbt& dbKey)
+Freeze::handleDbException(const DbException& dx,
+ const char* file, int line)
{
- if(dbKey.get_size() > dbKey.get_ulen())
+ throw DatabaseException(file, line, dx.what());
+}
+
+void
+Freeze::handleDbException(const DbException& dx,
+ Key& key, Dbt& dbKey,
+ const char* file, int line)
+{
+ bool bufferSmallException =
+#if (DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR == 2)
+ (dx.get_errno() == ENOMEM);
+#else
+ (dx.get_errno() == DB_BUFFER_SMALL);
+#endif
+
+ if(bufferSmallException && (dbKey.get_size() > dbKey.get_ulen()))
{
//
// Keep the old key size in case it's used as input
@@ -30,43 +46,45 @@ Freeze::handleMemoryException(const DbMemoryException& dx, Key& key, Dbt& dbKey)
}
else
{
- //
- // Real problem
- //
- DatabaseException ex(__FILE__, __LINE__);
- ex.message = dx.what();
- throw ex;
+ handleDbException(dx, file, line);
}
}
void
-Freeze::handleMemoryException(const DbMemoryException& dx, Key& key, Dbt& dbKey,
- Value& value, Dbt& dbValue)
+Freeze::handleDbException(const DbException& dx,
+ Key& key, Dbt& dbKey,
+ Value& value, Dbt& dbValue,
+ const char* file, int line)
{
- bool resized = false;
- if(dbKey.get_size() > dbKey.get_ulen())
- {
- size_t oldKeySize = key.size();
- key.resize(dbKey.get_size());
- initializeOutDbt(key, dbKey);
- dbKey.set_size(static_cast<u_int32_t>(oldKeySize));
- resized = true;
- }
-
- if(dbValue.get_size() > dbValue.get_ulen())
+ bool bufferSmallException =
+#if (DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR == 2)
+ (dx.get_errno() == ENOMEM);
+#else
+ (dx.get_errno() == DB_BUFFER_SMALL);
+#endif
+
+ bool resized = false;
+ if(bufferSmallException)
{
- value.resize(dbValue.get_size());
- initializeOutDbt(value, dbValue);
- resized = true;
+ if(dbKey.get_size() > dbKey.get_ulen())
+ {
+ size_t oldKeySize = key.size();
+ key.resize(dbKey.get_size());
+ initializeOutDbt(key, dbKey);
+ dbKey.set_size(static_cast<u_int32_t>(oldKeySize));
+ resized = true;
+ }
+
+ if(dbValue.get_size() > dbValue.get_ulen())
+ {
+ value.resize(dbValue.get_size());
+ initializeOutDbt(value, dbValue);
+ resized = true;
+ }
}
if(!resized)
{
- //
- // Real problem
- //
- DatabaseException ex(__FILE__, __LINE__);
- ex.message = dx.what();
- throw ex;
+ handleDbException(dx, file, line);
}
}
diff --git a/cpp/src/Freeze/Util.h b/cpp/src/Freeze/Util.h
index caaf24bf229..1cef571bba1 100644
--- a/cpp/src/Freeze/Util.h
+++ b/cpp/src/Freeze/Util.h
@@ -48,11 +48,24 @@ initializeOutDbt(std::vector<Ice::Byte>& v, Dbt& dbt)
dbt.set_flags(DB_DBT_USERMEM);
}
+
+//
+// Handles a Berkeley DB DbException by resizing the
+// given key/value/dbt (when the exception's errno is
+// DB_SMALL_BUFFER) or by throwing a
+// Freeze::DatabaseException
+//
+
+void
+handleDbException(const DbException&, const char*, int);
+
void
-handleMemoryException(const DbMemoryException&, Key&, Dbt&);
+handleDbException(const DbException&, Key&, Dbt&,
+ const char*, int);
void
-handleMemoryException(const DbMemoryException&, Key&, Dbt&, Value&, Dbt&);
+handleDbException(const DbException&, Key&, Dbt&, Value&, Dbt&,
+ const char*, int);
}