# HG changeset patch # User Sebastien Jodogne # Date 1715156975 -7200 # Node ID b2a97dfd719f16a80090481fdcdad4a9ffd49373 # Parent 3487684fd3312cde88f764341ba3e69a4fb1b067 monitoring of stable resources now also considers the resource type diff -r 3487684fd331 -r b2a97dfd719f NEWS --- a/NEWS Tue May 07 19:20:52 2024 +0200 +++ b/NEWS Wed May 08 10:29:35 2024 +0200 @@ -15,6 +15,8 @@ See https://discourse.orthanc-server.org/t/ignore-dimse-status-0x0111-when-sending-partial-duplicate-studies/4555/3 * Removed potential PHI from the logs when Orthanc encounters an error while creating a zip file. +* Monitoring of stable resources now also takes into consideration the + resource type, not only the resource identifier identifier. Bug Fixes --------- diff -r 3487684fd331 -r b2a97dfd719f OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp --- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Tue May 07 19:20:52 2024 +0200 +++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Wed May 08 10:29:35 2024 +0200 @@ -966,7 +966,7 @@ type == ResourceType_Study || type == ResourceType_Series) { - target.isStable_ = !transaction.GetTransactionContext().IsUnstableResource(internalId); + target.isStable_ = !transaction.GetTransactionContext().IsUnstableResource(type, internalId); if (LookupStringMetadata(tmp, target.metadata_, MetadataType_LastUpdate)) { @@ -3523,9 +3523,9 @@ transaction.LogChange(status.patientId_, ChangeType_NewChildInstance, ResourceType_Patient, hashPatient_); // Mark the parent resources of this instance as unstable - transaction.GetTransactionContext().MarkAsUnstable(status.seriesId_, ResourceType_Series, hashSeries_); - transaction.GetTransactionContext().MarkAsUnstable(status.studyId_, ResourceType_Study, hashStudy_); - transaction.GetTransactionContext().MarkAsUnstable(status.patientId_, ResourceType_Patient, hashPatient_); + transaction.GetTransactionContext().MarkAsUnstable(ResourceType_Series, status.seriesId_, hashSeries_); + transaction.GetTransactionContext().MarkAsUnstable(ResourceType_Study, status.studyId_, hashStudy_); + transaction.GetTransactionContext().MarkAsUnstable(ResourceType_Patient, status.patientId_, hashPatient_); transaction.GetTransactionContext().SignalAttachmentsAdded(instanceSize); storeStatus_ = StoreStatus_Success; diff -r 3487684fd331 -r b2a97dfd719f OrthancServer/Sources/Database/StatelessDatabaseOperations.h --- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.h Tue May 07 19:20:52 2024 +0200 +++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.h Wed May 08 10:29:35 2024 +0200 @@ -145,13 +145,14 @@ virtual int64_t GetCompressedSizeDelta() = 0; - virtual bool IsUnstableResource(int64_t id) = 0; + virtual bool IsUnstableResource(Orthanc::ResourceType type, + int64_t id) = 0; virtual bool LookupRemainingLevel(std::string& remainingPublicId /* out */, ResourceType& remainingLevel /* out */) = 0; - virtual void MarkAsUnstable(int64_t id, - Orthanc::ResourceType type, + virtual void MarkAsUnstable(Orthanc::ResourceType type, + int64_t id, const std::string& publicId) = 0; virtual void SignalAttachmentsAdded(uint64_t compressedSize) = 0; diff -r 3487684fd331 -r b2a97dfd719f OrthancServer/Sources/ServerIndex.cpp --- a/OrthancServer/Sources/ServerIndex.cpp Tue May 07 19:20:52 2024 +0200 +++ b/OrthancServer/Sources/ServerIndex.cpp Wed May 08 10:29:35 2024 +0200 @@ -185,16 +185,17 @@ } }; - virtual void MarkAsUnstable(int64_t id, - Orthanc::ResourceType type, + virtual void MarkAsUnstable(ResourceType type, + int64_t id, const std::string& publicId) ORTHANC_OVERRIDE { - context_.GetIndex().MarkAsUnstable(id, type, publicId); + context_.GetIndex().MarkAsUnstable(type, id, publicId); } - virtual bool IsUnstableResource(int64_t id) ORTHANC_OVERRIDE + virtual bool IsUnstableResource(ResourceType type, + int64_t id) ORTHANC_OVERRIDE { - return context_.GetIndex().IsUnstableResource(id); + return context_.GetIndex().IsUnstableResource(type, id); } virtual void Commit() ORTHANC_OVERRIDE @@ -239,18 +240,15 @@ class ServerIndex::UnstableResourcePayload { private: - ResourceType type_; std::string publicId_; boost::posix_time::ptime time_; public: - UnstableResourcePayload() : type_(ResourceType_Instance) + UnstableResourcePayload() { } - UnstableResourcePayload(Orthanc::ResourceType type, - const std::string& publicId) : - type_(type), + explicit UnstableResourcePayload(const std::string& publicId) : publicId_(publicId), time_(boost::posix_time::second_clock::local_time()) { @@ -260,11 +258,6 @@ { return (boost::posix_time::second_clock::local_time() - time_).total_seconds(); } - - ResourceType GetResourceType() const - { - return type_; - } const std::string& GetPublicId() const { @@ -309,10 +302,11 @@ } - bool ServerIndex::IsUnstableResource(int64_t id) + bool ServerIndex::IsUnstableResource(ResourceType type, + int64_t id) { boost::mutex::scoped_lock lock(monitoringMutex_); - return unstableResources_.Contains(id); + return unstableResources_.Contains(std::make_pair(type, id)); } @@ -460,7 +454,8 @@ for (;;) { - UnstableResourcePayload stableResource; + UnstableResourcePayload stablePayload; + ResourceType stableLevel; int64_t stableId; { @@ -471,8 +466,10 @@ { // This DICOM resource has not received any new instance for // some time. It can be considered as stable. - stableId = that->unstableResources_.RemoveOldest(stableResource); - //LOG(TRACE) << "Stable resource: " << EnumerationToString(stableResource.GetResourceType()) << " " << stableId; + std::pair stableResource = that->unstableResources_.RemoveOldest(stablePayload); + stableLevel = stableResource.first; + stableId = stableResource.second; + //LOG(TRACE) << "Stable resource: " << EnumerationToString(stablePayload.GetResourceType()) << " " << stableId; } else { @@ -490,18 +487,18 @@ * another thread, which leads to calls to "MarkAsUnstable()", * which leads to two lockings of "monitoringMutex_"). **/ - switch (stableResource.GetResourceType()) + switch (stableLevel) { case ResourceType_Patient: - that->LogChange(stableId, ChangeType_StablePatient, stableResource.GetPublicId(), ResourceType_Patient); + that->LogChange(stableId, ChangeType_StablePatient, stablePayload.GetPublicId(), ResourceType_Patient); break; case ResourceType_Study: - that->LogChange(stableId, ChangeType_StableStudy, stableResource.GetPublicId(), ResourceType_Study); + that->LogChange(stableId, ChangeType_StableStudy, stablePayload.GetPublicId(), ResourceType_Study); break; case ResourceType_Series: - that->LogChange(stableId, ChangeType_StableSeries, stableResource.GetPublicId(), ResourceType_Series); + that->LogChange(stableId, ChangeType_StableSeries, stablePayload.GetPublicId(), ResourceType_Series); break; default: @@ -519,18 +516,18 @@ } - void ServerIndex::MarkAsUnstable(int64_t id, - Orthanc::ResourceType type, + void ServerIndex::MarkAsUnstable(ResourceType type, + int64_t id, const std::string& publicId) { - assert(type == Orthanc::ResourceType_Patient || - type == Orthanc::ResourceType_Study || - type == Orthanc::ResourceType_Series); + assert(type == ResourceType_Patient || + type == ResourceType_Study || + type == ResourceType_Series); { boost::mutex::scoped_lock lock(monitoringMutex_); - UnstableResourcePayload payload(type, publicId); - unstableResources_.AddOrMakeMostRecent(id, payload); + UnstableResourcePayload payload(publicId); + unstableResources_.AddOrMakeMostRecent(std::make_pair(type, id), payload); //LOG(INFO) << "Unstable resource: " << EnumerationToString(type) << " " << id; } } diff -r 3487684fd331 -r b2a97dfd719f OrthancServer/Sources/ServerIndex.h --- a/OrthancServer/Sources/ServerIndex.h Tue May 07 19:20:52 2024 +0200 +++ b/OrthancServer/Sources/ServerIndex.h Wed May 08 10:29:35 2024 +0200 @@ -43,7 +43,7 @@ boost::thread flushThread_; boost::thread unstableResourcesMonitorThread_; - LeastRecentlyUsedIndex unstableResources_; + LeastRecentlyUsedIndex, UnstableResourcePayload> unstableResources_; MaxStorageMode maximumStorageMode_; uint64_t maximumStorageSize_; @@ -55,11 +55,12 @@ static void UnstableResourcesMonitorThread(ServerIndex* that, unsigned int threadSleep); - void MarkAsUnstable(int64_t id, - Orthanc::ResourceType type, + void MarkAsUnstable(ResourceType type, + int64_t id, const std::string& publicId); - bool IsUnstableResource(int64_t id); + bool IsUnstableResource(ResourceType type, + int64_t id); public: ServerIndex(ServerContext& context,