# HG changeset patch # User Sebastien Jodogne # Date 1615299723 -3600 # Node ID bb3c82b8f373b2615b644ce5d63da6608ca0e21b # Parent 49f6b9a2b9f57cde233c1a1f27f5a9a085e11803 transient introduction of ServerIndex::databaseMutex_ diff -r 49f6b9a2b9f5 -r bb3c82b8f373 OrthancServer/Sources/ServerIndex.cpp --- a/OrthancServer/Sources/ServerIndex.cpp Tue Mar 09 14:49:39 2021 +0100 +++ b/OrthancServer/Sources/ServerIndex.cpp Tue Mar 09 15:22:03 2021 +0100 @@ -476,16 +476,18 @@ if (count >= countThreshold) { 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?)"; + boost::mutex::scoped_lock lock(that->databaseMutex_); + + try + { + that->db_.FlushToDisk(); + } + catch (OrthancException&) + { + LOG(ERROR) << "Cannot flush the SQLite database to the disk (is your filesystem full?)"; + } } count = 0; @@ -496,10 +498,10 @@ } - void ServerIndex::LogChange(int64_t internalId, - ChangeType changeType, - ResourceType resourceType, - const std::string& publicId) + void ServerIndex::ReadWriteTransaction::LogChange(int64_t internalId, + ChangeType changeType, + ResourceType resourceType, + const std::string& publicId) { ServerIndexChange change(changeType, resourceType, publicId); @@ -508,8 +510,7 @@ db_.LogChange(internalId, change); } - assert(listener_.get() != NULL); - listener_->SignalChange(change); + listener_.SignalChange(change); } @@ -771,15 +772,15 @@ switch (payload.GetResourceType()) { case ResourceType_Patient: - that->LogChange(id, ChangeType_StablePatient, ResourceType_Patient, payload.GetPublicId()); + that->LogChange(ChangeType_StablePatient, payload.GetPublicId(), ResourceType_Patient); break; case ResourceType_Study: - that->LogChange(id, ChangeType_StableStudy, ResourceType_Study, payload.GetPublicId()); + that->LogChange(ChangeType_StableStudy, payload.GetPublicId(), ResourceType_Study); break; case ResourceType_Series: - that->LogChange(id, ChangeType_StableSeries, ResourceType_Series, payload.GetPublicId()); + that->LogChange(ChangeType_StableSeries, payload.GetPublicId(), ResourceType_Series); break; default: @@ -799,17 +800,16 @@ Orthanc::ResourceType type, const std::string& publicId) { - // WARNING: Before calling this method, "monitoringMutex_" must be locked. - assert(type == Orthanc::ResourceType_Patient || type == Orthanc::ResourceType_Study || type == Orthanc::ResourceType_Series); - UnstableResourcePayload payload(type, publicId); - unstableResources_.AddOrMakeMostRecent(id, payload); - //LOG(INFO) << "Unstable resource: " << EnumerationToString(type) << " " << id; - - LogChange(id, ChangeType_NewChildInstance, type, publicId); + { + boost::mutex::scoped_lock lock(monitoringMutex_); + UnstableResourcePayload payload(type, publicId); + unstableResources_.AddOrMakeMostRecent(id, payload); + //LOG(INFO) << "Unstable resource: " << EnumerationToString(type) << " " << id; + } } @@ -1067,7 +1067,7 @@ { try { - boost::mutex::scoped_lock lock(monitoringMutex_); // TODO - REMOVE + boost::mutex::scoped_lock lock(databaseMutex_); // TODO - REMOVE if (readOperations != NULL) { @@ -3490,8 +3490,11 @@ transaction.LogChange(status.seriesId_, ChangeType_CompletedSeries, ResourceType_Series, hashSeries_); } } - - + + transaction.LogChange(status.seriesId_, ChangeType_NewChildInstance, ResourceType_Series, hashSeries_); + transaction.LogChange(status.studyId_, ChangeType_NewChildInstance, ResourceType_Study, hashStudy_); + transaction.LogChange(status.patientId_, ChangeType_NewChildInstance, ResourceType_Patient, hashPatient_); + // Mark the parent resources of this instance as unstable index_.MarkAsUnstable(status.seriesId_, ResourceType_Series, hashSeries_); index_.MarkAsUnstable(status.studyId_, ResourceType_Study, hashStudy_); diff -r 49f6b9a2b9f5 -r bb3c82b8f373 OrthancServer/Sources/ServerIndex.h --- a/OrthancServer/Sources/ServerIndex.h Tue Mar 09 14:49:39 2021 +0100 +++ b/OrthancServer/Sources/ServerIndex.h Tue Mar 09 15:22:03 2021 +0100 @@ -62,6 +62,7 @@ bool done_; boost::mutex monitoringMutex_; + boost::mutex databaseMutex_; // TODO - REMOVE boost::thread flushThread_; boost::thread unstableResourcesMonitorThread_; @@ -86,11 +87,6 @@ Orthanc::ResourceType type, const std::string& publicId); - void LogChange(int64_t internalId, - ChangeType changeType, - ResourceType resourceType, - const std::string& publicId); - void NormalizeLookup(std::vector& target, const DatabaseLookup& source, ResourceType level) const; @@ -379,10 +375,7 @@ void LogChange(int64_t internalId, ChangeType changeType, ResourceType resourceType, - const std::string& publicId) - { - index_.LogChange(internalId, changeType, resourceType, publicId); - } + const std::string& publicId); void LogExportedResource(const ExportedResource& resource) {