Mercurial > hg > orthanc
changeset 4581:bb3c82b8f373 db-changes
transient introduction of ServerIndex::databaseMutex_
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 09 Mar 2021 15:22:03 +0100 |
parents | 49f6b9a2b9f5 |
children | fb0379abb4a7 |
files | OrthancServer/Sources/ServerIndex.cpp OrthancServer/Sources/ServerIndex.h |
diffstat | 2 files changed, 33 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- 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_);
--- 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<DatabaseConstraint>& 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) {