]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2541] Catch and log exception in transaction rollback
authorJelte Jansen <jelte@isc.org>
Wed, 12 Dec 2012 10:30:56 +0000 (11:30 +0100)
committerJelte Jansen <jelte@isc.org>
Wed, 12 Dec 2012 10:30:56 +0000 (11:30 +0100)
src/lib/datasrc/database.cc
src/lib/datasrc/database.h
src/lib/datasrc/datasrc_messages.mes

index b83c4011b7e96dac97cd072171e826d2463ec4c6..62da2e0d44bd103524b63c2a16f62cf9d5e132b9 100644 (file)
@@ -55,7 +55,18 @@ public:
     }
     ~TransactionHolder() {
         if (!committed_) {
-            accessor_.rollback();
+            try {
+                accessor_.rollback();
+            } catch (const DataSourceError& e) {
+                // We generally expect that rollback always succeeds, and
+                // it should in fact succeed in a way we execute it.  But
+                // as the public API allows rollback() to fail and
+                // throw, we should expect it.  Obviously we cannot re-throw
+                // it.  The best we can do is to log it as a critical error.
+                logger.error(DATASRC_DATABASE_TRANSACTION_ROLLBACKFAIL).
+                            arg(accessor_.getDBName()).
+                            arg(e.what());
+            }
         }
     }
     void commit() {
index 84373315b65467ccec129f2158acf7a3854a20d6..9db8a8fa66e79861252563f445672f91cb08a762 100644 (file)
@@ -186,8 +186,8 @@ public:
     /// responsibility of the caller to do so.
     ///
     /// Callers must also start a transaction before calling this method,
-    /// implementations may throw DataSourceError if this has not been done.
-    /// Callers should also expect DataSourceErrors for other potential
+    /// implementations should throw DataSourceError if this has not been
+    /// done. Callers should also expect DataSourceErrors for other potential
     /// problems.
     ///
     /// \param name The (fully qualified) domain name of the zone to add.
@@ -1399,9 +1399,6 @@ public:
     /// does not, creates it, commits, and returns true. If the zone
     /// does exist already, it does nothing (except abort the transaction)
     /// and returns false.
-    ///
-    /// \param name The (fully qualified) name of the zone to create
-    /// \return True if the zone was added, false if it already existed
     virtual bool createZone(const isc::dns::Name& name);
 
     /// \brief Get the zone iterator
index e7cb9d3f9d8ce9492c3cc39a82740a8f7efefda4..e9b4c908af7bcdaf9d4dfe84ea0b384ebbb48af6 100644 (file)
@@ -216,6 +216,16 @@ to find any invalid data and fix it.
 No match (not even a wildcard) was found in the named data source for the given
 name/type/class in the data source.
 
+% DATASRC_DATABASE_TRANSACTION_ROLLBACKFAIL failed to roll back transaction on %1: %2
+A transaction on the database was rolled back without committing the
+changes to the database, but the rollback itself unexpectedly fails.
+The higher level implementation does not expect it to fail, so this means
+either a serious operational error in the underlying data source (such as a
+system failure of a database) or software bug in the underlying data source
+implementation.  In either case if this message is logged the administrator
+should carefully examine the underlying data source to see what exactly
+happens and whether the data is still valid.
+
 % DATASRC_DATABASE_UPDATER_COMMIT updates committed for '%1/%2' on %3
 Debug information.  A set of updates to a zone has been successfully
 committed to the corresponding database backend.  The zone name,