changeset 3020:d207f6ac1f86 db-changes

tracking disk size by the database engine to ensure consistency across transactions
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 15 Dec 2018 10:57:18 +0100
parents 8336204d95dc
children 5db446c6b2dd
files OrthancServer/IDatabaseWrapper.h OrthancServer/SQLiteDatabaseWrapper.cpp OrthancServer/SQLiteDatabaseWrapper.h OrthancServer/ServerIndex.cpp OrthancServer/ServerIndex.h Plugins/Engine/OrthancPluginDatabase.cpp Plugins/Engine/OrthancPluginDatabase.h
diffstat 7 files changed, 31 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/IDatabaseWrapper.h	Fri Dec 14 18:07:40 2018 +0100
+++ b/OrthancServer/IDatabaseWrapper.h	Sat Dec 15 10:57:18 2018 +0100
@@ -221,5 +221,7 @@
 
     virtual void Upgrade(unsigned int targetVersion,
                          IStorageArea& storageArea) = 0;
+
+    virtual bool IsDiskSizeAbove(uint64_t threshold) = 0;
   };
 }
--- a/OrthancServer/SQLiteDatabaseWrapper.cpp	Fri Dec 14 18:07:40 2018 +0100
+++ b/OrthancServer/SQLiteDatabaseWrapper.cpp	Sat Dec 15 10:57:18 2018 +0100
@@ -1195,4 +1195,10 @@
       target.push_back(statement.ColumnInt64(0));
     }    
   }
+
+
+  bool SQLiteDatabaseWrapper::IsDiskSizeAbove(uint64_t threshold)
+  {
+    return GetTotalCompressedSize() > threshold;
+  }
 }
--- a/OrthancServer/SQLiteDatabaseWrapper.h	Fri Dec 14 18:07:40 2018 +0100
+++ b/OrthancServer/SQLiteDatabaseWrapper.h	Sat Dec 15 10:57:18 2018 +0100
@@ -274,5 +274,7 @@
                                        const DicomTag& tag,
                                        const std::string& start,
                                        const std::string& end);
+
+    virtual bool IsDiskSizeAbove(uint64_t threshold);
   };
 }
--- a/OrthancServer/ServerIndex.cpp	Fri Dec 14 18:07:40 2018 +0100
+++ b/OrthancServer/ServerIndex.cpp	Sat Dec 15 10:57:18 2018 +0100
@@ -226,8 +226,6 @@
       transaction_.reset(index_.db_.StartTransaction());
       transaction_->Begin();
 
-      assert(index_.currentStorageSize_ == index_.db_.GetTotalCompressedSize());
-
       index_.listener_->StartTransaction();
     }
 
@@ -255,11 +253,6 @@
         // deleted because of recycling.
         index_.listener_->CommitFilesToRemove();
 
-        index_.currentStorageSize_ += sizeOfAddedFiles;
-
-        assert(index_.currentStorageSize_ >= index_.listener_->GetSizeOfFilesToRemove());
-        index_.currentStorageSize_ -= index_.listener_->GetSizeOfFilesToRemove();
-
         // Send all the pending changes to the Orthanc plugins
         index_.listener_->CommitChanges();
 
@@ -553,8 +546,6 @@
     listener_.reset(new Listener(context));
     db_.SetListener(*listener_);
 
-    currentStorageSize_ = db_.GetTotalCompressedSize();
-
     // Initial recycling if the parameters have changed since the last
     // execution of Orthanc
     StandaloneRecycling();
@@ -880,8 +871,7 @@
     boost::mutex::scoped_lock lock(mutex_);
     target = Json::objectValue;
 
-    uint64_t cs = currentStorageSize_;
-    assert(cs == db_.GetTotalCompressedSize());
+    uint64_t cs = db_.GetTotalCompressedSize();
     uint64_t us = db_.GetTotalUncompressedSize();
     target["TotalDiskSize"] = boost::lexical_cast<std::string>(cs);
     target["TotalUncompressedSize"] = boost::lexical_cast<std::string>(us);
@@ -1372,10 +1362,9 @@
   {
     if (maximumStorageSize_ != 0)
     {
-      uint64_t currentSize = currentStorageSize_ - listener_->GetSizeOfFilesToRemove();
-      assert(db_.GetTotalCompressedSize() == currentSize);
-
-      if (currentSize + instanceSize > maximumStorageSize_)
+      assert(maximumStorageSize_ >= instanceSize);
+      
+      if (db_.IsDiskSizeAbove(maximumStorageSize_ - instanceSize))
       {
         return true;
       }
--- a/OrthancServer/ServerIndex.h	Fri Dec 14 18:07:40 2018 +0100
+++ b/OrthancServer/ServerIndex.h	Sat Dec 15 10:57:18 2018 +0100
@@ -69,7 +69,6 @@
     IDatabaseWrapper& db_;
     LeastRecentlyUsedIndex<int64_t, UnstableResourcePayload>  unstableResources_;
 
-    uint64_t     currentStorageSize_;
     uint64_t     maximumStorageSize_;
     unsigned int maximumPatients_;
     bool         overwrite_;
--- a/Plugins/Engine/OrthancPluginDatabase.cpp	Fri Dec 14 18:07:40 2018 +0100
+++ b/Plugins/Engine/OrthancPluginDatabase.cpp	Sat Dec 15 10:57:18 2018 +0100
@@ -265,7 +265,7 @@
       else
       {
         // This is the case of database plugins using Orthanc SDK <= 1.5.2
-        LOG(WARNING) << "Consider upgrading your database index plugin for best performance";
+        LOG(WARNING) << "Your database index plugin is not compatible with multiple Orthanc writers";
         currentDiskSize_ = GetTotalCompressedSize();
       }
 
@@ -1146,4 +1146,18 @@
                                boost::lexical_cast<std::string>(answer.type));
     }
   }
+
+    
+  bool OrthancPluginDatabase::IsDiskSizeAbove(uint64_t threshold)
+  {
+    if (fastGetTotalSize_)
+    {
+      return GetTotalCompressedSize() > threshold;
+    }
+    else
+    {
+      assert(GetTotalCompressedSize() == currentDiskSize_);
+      return currentDiskSize_ > threshold;
+    }      
+  }
 }
--- a/Plugins/Engine/OrthancPluginDatabase.h	Fri Dec 14 18:07:40 2018 +0100
+++ b/Plugins/Engine/OrthancPluginDatabase.h	Sat Dec 15 10:57:18 2018 +0100
@@ -268,6 +268,8 @@
                          IStorageArea& storageArea);
 
     void AnswerReceived(const _OrthancPluginDatabaseAnswer& answer);
+
+    virtual bool IsDiskSizeAbove(uint64_t threshold);
   };
 }