diff OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp @ 4801:23aeffecb8cb

Fix instances accumulating in DB while their attachments were not stored because of MaximumStorageSize limit reached with a single patient in DB.
author Alain Mazy <am@osimis.io>
date Tue, 19 Oct 2021 15:29:48 +0200
parents 569d9ef165b1
children 70d2a97ca8cb 7053502fbf97
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Mon Oct 18 21:55:06 2021 +0200
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Tue Oct 19 15:29:48 2021 +0200
@@ -2810,7 +2810,7 @@
         
         if (!ok)
         {
-          throw OrthancException(ErrorCode_FullStorage);
+          throw OrthancException(ErrorCode_FullStorage, "Cannot recycle more patients");
         }
       
         LOG(TRACE) << "Recycling one patient";
@@ -3264,11 +3264,18 @@
         {
           if (e.GetErrorCode() == ErrorCode_DatabaseCannotSerialize)
           {
-            throw;
+            throw;  // the transaction has failed -> do not commit the current transaction (and retry)
           }
           else
           {
-            LOG(ERROR) << "EXCEPTION [" << e.What() << "]";
+            LOG(ERROR) << "EXCEPTION [" << e.What() << " - " << e.GetDetails() << "]";
+
+            if (e.GetErrorCode() == ErrorCode_FullStorage)
+            {
+              throw; // do not commit the current transaction
+            }
+
+            // this is an expected failure, exit normaly and commit the current transaction
             storeStatus_ = StoreStatus_Failure;
           }
         }