# HG changeset patch # User Sebastien Jodogne # Date 1615297779 -3600 # Node ID 49f6b9a2b9f57cde233c1a1f27f5a9a085e11803 # Parent 5ee9a4f8a0f0254985ab29f2d64277eb59b0ac7a remove the only use of GlobalProperty_FlushSleep diff -r 5ee9a4f8a0f0 -r 49f6b9a2b9f5 OrthancServer/Sources/ServerEnumerations.h --- a/OrthancServer/Sources/ServerEnumerations.h Tue Mar 09 14:30:05 2021 +0100 +++ b/OrthancServer/Sources/ServerEnumerations.h Tue Mar 09 14:49:39 2021 +0100 @@ -125,7 +125,7 @@ enum GlobalProperty { GlobalProperty_DatabaseSchemaVersion = 1, // Unused in the Orthanc core as of Orthanc 0.9.5 - GlobalProperty_FlushSleep = 2, + GlobalProperty_FlushSleep = 2, // Unused in the Orthanc core if Orthanc > 1.9.1 GlobalProperty_AnonymizationSequence = 3, GlobalProperty_JobsRegistry = 5, GlobalProperty_GetTotalSizeIsFast = 6, // New in Orthanc 1.5.2 diff -r 5ee9a4f8a0f0 -r 49f6b9a2b9f5 OrthancServer/Sources/ServerIndex.cpp --- a/OrthancServer/Sources/ServerIndex.cpp Tue Mar 09 14:30:05 2021 +0100 +++ b/OrthancServer/Sources/ServerIndex.cpp Tue Mar 09 14:49:39 2021 +0100 @@ -453,157 +453,49 @@ void ServerIndex::FlushThread(ServerIndex* that, - unsigned int threadSleep) + unsigned int threadSleepGranularityMilliseconds) { // By default, wait for 10 seconds before flushing - unsigned int sleep = 10; - - // TODO - REMOVE THIS - try + static const unsigned int SLEEP_SECONDS = 10; + + if (threadSleepGranularityMilliseconds > 1000) { - boost::mutex::scoped_lock lock(that->monitoringMutex_); - std::string sleepString; - - if (that->db_.LookupGlobalProperty(sleepString, GlobalProperty_FlushSleep) && - Toolbox::IsInteger(sleepString)) - { - sleep = boost::lexical_cast(sleepString); - } + throw OrthancException(ErrorCode_ParameterOutOfRange); } - catch (boost::bad_lexical_cast&) - { - } - - LOG(INFO) << "Starting the database flushing thread (sleep = " << sleep << ")"; + + LOG(INFO) << "Starting the database flushing thread (sleep = " << SLEEP_SECONDS << " seconds)"; unsigned int count = 0; + unsigned int countThreshold = (1000 * SLEEP_SECONDS) / threadSleepGranularityMilliseconds; while (!that->done_) { - boost::this_thread::sleep(boost::posix_time::milliseconds(threadSleep)); + boost::this_thread::sleep(boost::posix_time::milliseconds(threadSleepGranularityMilliseconds)); count++; - if (count < sleep) + + if (count >= countThreshold) { - continue; + Logging::Flush(); + + boost::mutex::scoped_lock lock(that->monitoringMutex_); + + try + { + that->db_.FlushToDisk(); + } + catch (OrthancException&) + { + LOG(ERROR) << "Cannot flush the SQLite database to the disk (is your filesystem full?)"; + } + + count = 0; } - - Logging::Flush(); - - boost::mutex::scoped_lock lock(that->monitoringMutex_); - - try - { - that->db_.FlushToDisk(); - } - catch (OrthancException&) - { - LOG(ERROR) << "Cannot flush the SQLite database to the disk (is your filesystem full?)"; - } - - count = 0; } LOG(INFO) << "Stopping the database flushing thread"; } - static bool ComputeExpectedNumberOfInstances(int64_t& target, - const DicomMap& dicomSummary) - { - try - { - const DicomValue* value; - const DicomValue* value2; - - if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGES_IN_ACQUISITION)) != NULL && - !value->IsNull() && - !value->IsBinary() && - (value2 = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS)) != NULL && - !value2->IsNull() && - !value2->IsBinary()) - { - // Patch for series with temporal positions thanks to Will Ryder - int64_t imagesInAcquisition = boost::lexical_cast(value->GetContent()); - int64_t countTemporalPositions = boost::lexical_cast(value2->GetContent()); - target = imagesInAcquisition * countTemporalPositions; - return (target > 0); - } - - else if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_SLICES)) != NULL && - !value->IsNull() && - !value->IsBinary() && - (value2 = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_TIME_SLICES)) != NULL && - !value2->IsBinary() && - !value2->IsNull()) - { - // Support of Cardio-PET images - int64_t numberOfSlices = boost::lexical_cast(value->GetContent()); - int64_t numberOfTimeSlices = boost::lexical_cast(value2->GetContent()); - target = numberOfSlices * numberOfTimeSlices; - return (target > 0); - } - - else if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES)) != NULL && - !value->IsNull() && - !value->IsBinary()) - { - target = boost::lexical_cast(value->GetContent()); - return (target > 0); - } - } - catch (OrthancException&) - { - } - catch (boost::bad_lexical_cast&) - { - } - - return false; - } - - - - - static bool LookupStringMetadata(std::string& result, - const std::map& metadata, - MetadataType type) - { - std::map::const_iterator found = metadata.find(type); - - if (found == metadata.end()) - { - return false; - } - else - { - result = found->second; - return true; - } - } - - - static bool LookupIntegerMetadata(int64_t& result, - const std::map& metadata, - MetadataType type) - { - std::string s; - if (!LookupStringMetadata(s, metadata, type)) - { - return false; - } - - try - { - result = boost::lexical_cast(s); - return true; - } - catch (boost::bad_lexical_cast&) - { - return false; - } - } - - void ServerIndex::LogChange(int64_t internalId, ChangeType changeType, ResourceType resourceType, @@ -629,7 +521,7 @@ ServerIndex::ServerIndex(ServerContext& context, IDatabaseWrapper& db, - unsigned int threadSleep) : + unsigned int threadSleepGranularityMilliseconds) : done_(false), db_(db), maximumStorageSize_(0), @@ -646,11 +538,11 @@ if (db.HasFlushToDisk()) { - flushThread_ = boost::thread(FlushThread, this, threadSleep); + flushThread_ = boost::thread(FlushThread, this, threadSleepGranularityMilliseconds); } unstableResourcesMonitorThread_ = boost::thread - (UnstableResourcesMonitorThread, this, threadSleep); + (UnstableResourcesMonitorThread, this, threadSleepGranularityMilliseconds); } @@ -841,7 +733,7 @@ void ServerIndex::UnstableResourcesMonitorThread(ServerIndex* that, - unsigned int threadSleep) + unsigned int threadSleepGranularityMilliseconds) { int stableAge; @@ -860,7 +752,7 @@ while (!that->done_) { // Check for stable resources each few seconds - boost::this_thread::sleep(boost::posix_time::milliseconds(threadSleep)); + boost::this_thread::sleep(boost::posix_time::milliseconds(threadSleepGranularityMilliseconds)); boost::mutex::scoped_lock lock(that->monitoringMutex_); @@ -1263,6 +1155,46 @@ private: ServerIndex& index_; // TODO - REMOVE + static bool LookupStringMetadata(std::string& result, + const std::map& metadata, + MetadataType type) + { + std::map::const_iterator found = metadata.find(type); + + if (found == metadata.end()) + { + return false; + } + else + { + result = found->second; + return true; + } + } + + + static bool LookupIntegerMetadata(int64_t& result, + const std::map& metadata, + MetadataType type) + { + std::string s; + if (!LookupStringMetadata(s, metadata, type)) + { + return false; + } + + try + { + result = boost::lexical_cast(s); + return true; + } + catch (boost::bad_lexical_cast&) + { + return false; + } + } + + public: explicit Operations(ServerIndex& index) : index_(index) @@ -3217,6 +3149,60 @@ std::string hashSeries_; std::string hashInstance_; + static bool ComputeExpectedNumberOfInstances(int64_t& target, + const DicomMap& dicomSummary) + { + try + { + const DicomValue* value; + const DicomValue* value2; + + if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGES_IN_ACQUISITION)) != NULL && + !value->IsNull() && + !value->IsBinary() && + (value2 = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_TEMPORAL_POSITIONS)) != NULL && + !value2->IsNull() && + !value2->IsBinary()) + { + // Patch for series with temporal positions thanks to Will Ryder + int64_t imagesInAcquisition = boost::lexical_cast(value->GetContent()); + int64_t countTemporalPositions = boost::lexical_cast(value2->GetContent()); + target = imagesInAcquisition * countTemporalPositions; + return (target > 0); + } + + else if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_SLICES)) != NULL && + !value->IsNull() && + !value->IsBinary() && + (value2 = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_TIME_SLICES)) != NULL && + !value2->IsBinary() && + !value2->IsNull()) + { + // Support of Cardio-PET images + int64_t numberOfSlices = boost::lexical_cast(value->GetContent()); + int64_t numberOfTimeSlices = boost::lexical_cast(value2->GetContent()); + target = numberOfSlices * numberOfTimeSlices; + return (target > 0); + } + + else if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES)) != NULL && + !value->IsNull() && + !value->IsBinary()) + { + target = boost::lexical_cast(value->GetContent()); + return (target > 0); + } + } + catch (OrthancException&) + { + } + catch (boost::bad_lexical_cast&) + { + } + + return false; + } + public: Operations(std::map& instanceMetadata, ServerIndex& index, diff -r 5ee9a4f8a0f0 -r 49f6b9a2b9f5 OrthancServer/Sources/ServerIndex.h --- a/OrthancServer/Sources/ServerIndex.h Tue Mar 09 14:30:05 2021 +0100 +++ b/OrthancServer/Sources/ServerIndex.h Tue Mar 09 14:49:39 2021 +0100 @@ -100,7 +100,7 @@ public: ServerIndex(ServerContext& context, IDatabaseWrapper& database, - unsigned int threadSleep); + unsigned int threadSleepGranularityMilliseconds); ~ServerIndex();