# HG changeset patch # User Sebastien Jodogne # Date 1544867838 -3600 # Node ID d207f6ac1f86d9144d84df7875c386c47195f73e # Parent 8336204d95dc89540b4cd03ef90ef664f1ccc857 tracking disk size by the database engine to ensure consistency across transactions diff -r 8336204d95dc -r d207f6ac1f86 OrthancServer/IDatabaseWrapper.h --- 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; }; } diff -r 8336204d95dc -r d207f6ac1f86 OrthancServer/SQLiteDatabaseWrapper.cpp --- 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; + } } diff -r 8336204d95dc -r d207f6ac1f86 OrthancServer/SQLiteDatabaseWrapper.h --- 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); }; } diff -r 8336204d95dc -r d207f6ac1f86 OrthancServer/ServerIndex.cpp --- 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(cs); target["TotalUncompressedSize"] = boost::lexical_cast(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; } diff -r 8336204d95dc -r d207f6ac1f86 OrthancServer/ServerIndex.h --- 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 unstableResources_; - uint64_t currentStorageSize_; uint64_t maximumStorageSize_; unsigned int maximumPatients_; bool overwrite_; diff -r 8336204d95dc -r d207f6ac1f86 Plugins/Engine/OrthancPluginDatabase.cpp --- 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(answer.type)); } } + + + bool OrthancPluginDatabase::IsDiskSizeAbove(uint64_t threshold) + { + if (fastGetTotalSize_) + { + return GetTotalCompressedSize() > threshold; + } + else + { + assert(GetTotalCompressedSize() == currentDiskSize_); + return currentDiskSize_ > threshold; + } + } } diff -r 8336204d95dc -r d207f6ac1f86 Plugins/Engine/OrthancPluginDatabase.h --- 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); }; }