Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerIndex.cpp @ 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 |
comparison
equal
deleted
inserted
replaced
4580:49f6b9a2b9f5 | 4581:bb3c82b8f373 |
---|---|
474 count++; | 474 count++; |
475 | 475 |
476 if (count >= countThreshold) | 476 if (count >= countThreshold) |
477 { | 477 { |
478 Logging::Flush(); | 478 Logging::Flush(); |
479 | 479 |
480 boost::mutex::scoped_lock lock(that->monitoringMutex_); | 480 { |
481 boost::mutex::scoped_lock lock(that->databaseMutex_); | |
481 | 482 |
482 try | 483 try |
483 { | 484 { |
484 that->db_.FlushToDisk(); | 485 that->db_.FlushToDisk(); |
485 } | 486 } |
486 catch (OrthancException&) | 487 catch (OrthancException&) |
487 { | 488 { |
488 LOG(ERROR) << "Cannot flush the SQLite database to the disk (is your filesystem full?)"; | 489 LOG(ERROR) << "Cannot flush the SQLite database to the disk (is your filesystem full?)"; |
490 } | |
489 } | 491 } |
490 | 492 |
491 count = 0; | 493 count = 0; |
492 } | 494 } |
493 } | 495 } |
494 | 496 |
495 LOG(INFO) << "Stopping the database flushing thread"; | 497 LOG(INFO) << "Stopping the database flushing thread"; |
496 } | 498 } |
497 | 499 |
498 | 500 |
499 void ServerIndex::LogChange(int64_t internalId, | 501 void ServerIndex::ReadWriteTransaction::LogChange(int64_t internalId, |
500 ChangeType changeType, | 502 ChangeType changeType, |
501 ResourceType resourceType, | 503 ResourceType resourceType, |
502 const std::string& publicId) | 504 const std::string& publicId) |
503 { | 505 { |
504 ServerIndexChange change(changeType, resourceType, publicId); | 506 ServerIndexChange change(changeType, resourceType, publicId); |
505 | 507 |
506 if (changeType <= ChangeType_INTERNAL_LastLogged) | 508 if (changeType <= ChangeType_INTERNAL_LastLogged) |
507 { | 509 { |
508 db_.LogChange(internalId, change); | 510 db_.LogChange(internalId, change); |
509 } | 511 } |
510 | 512 |
511 assert(listener_.get() != NULL); | 513 listener_.SignalChange(change); |
512 listener_->SignalChange(change); | |
513 } | 514 } |
514 | 515 |
515 | 516 |
516 bool ServerIndex::IsUnstableResource(int64_t id) | 517 bool ServerIndex::IsUnstableResource(int64_t id) |
517 { | 518 { |
769 if (that->db_.IsExistingResource(id)) | 770 if (that->db_.IsExistingResource(id)) |
770 { | 771 { |
771 switch (payload.GetResourceType()) | 772 switch (payload.GetResourceType()) |
772 { | 773 { |
773 case ResourceType_Patient: | 774 case ResourceType_Patient: |
774 that->LogChange(id, ChangeType_StablePatient, ResourceType_Patient, payload.GetPublicId()); | 775 that->LogChange(ChangeType_StablePatient, payload.GetPublicId(), ResourceType_Patient); |
775 break; | 776 break; |
776 | 777 |
777 case ResourceType_Study: | 778 case ResourceType_Study: |
778 that->LogChange(id, ChangeType_StableStudy, ResourceType_Study, payload.GetPublicId()); | 779 that->LogChange(ChangeType_StableStudy, payload.GetPublicId(), ResourceType_Study); |
779 break; | 780 break; |
780 | 781 |
781 case ResourceType_Series: | 782 case ResourceType_Series: |
782 that->LogChange(id, ChangeType_StableSeries, ResourceType_Series, payload.GetPublicId()); | 783 that->LogChange(ChangeType_StableSeries, payload.GetPublicId(), ResourceType_Series); |
783 break; | 784 break; |
784 | 785 |
785 default: | 786 default: |
786 throw OrthancException(ErrorCode_InternalError); | 787 throw OrthancException(ErrorCode_InternalError); |
787 } | 788 } |
797 | 798 |
798 void ServerIndex::MarkAsUnstable(int64_t id, | 799 void ServerIndex::MarkAsUnstable(int64_t id, |
799 Orthanc::ResourceType type, | 800 Orthanc::ResourceType type, |
800 const std::string& publicId) | 801 const std::string& publicId) |
801 { | 802 { |
802 // WARNING: Before calling this method, "monitoringMutex_" must be locked. | |
803 | |
804 assert(type == Orthanc::ResourceType_Patient || | 803 assert(type == Orthanc::ResourceType_Patient || |
805 type == Orthanc::ResourceType_Study || | 804 type == Orthanc::ResourceType_Study || |
806 type == Orthanc::ResourceType_Series); | 805 type == Orthanc::ResourceType_Series); |
807 | 806 |
808 UnstableResourcePayload payload(type, publicId); | 807 { |
809 unstableResources_.AddOrMakeMostRecent(id, payload); | 808 boost::mutex::scoped_lock lock(monitoringMutex_); |
810 //LOG(INFO) << "Unstable resource: " << EnumerationToString(type) << " " << id; | 809 UnstableResourcePayload payload(type, publicId); |
811 | 810 unstableResources_.AddOrMakeMostRecent(id, payload); |
812 LogChange(id, ChangeType_NewChildInstance, type, publicId); | 811 //LOG(INFO) << "Unstable resource: " << EnumerationToString(type) << " " << id; |
812 } | |
813 } | 813 } |
814 | 814 |
815 | 815 |
816 | 816 |
817 void ServerIndex::NormalizeLookup(std::vector<DatabaseConstraint>& target, | 817 void ServerIndex::NormalizeLookup(std::vector<DatabaseConstraint>& target, |
1065 | 1065 |
1066 for (;;) | 1066 for (;;) |
1067 { | 1067 { |
1068 try | 1068 try |
1069 { | 1069 { |
1070 boost::mutex::scoped_lock lock(monitoringMutex_); // TODO - REMOVE | 1070 boost::mutex::scoped_lock lock(databaseMutex_); // TODO - REMOVE |
1071 | 1071 |
1072 if (readOperations != NULL) | 1072 if (readOperations != NULL) |
1073 { | 1073 { |
1074 /** | 1074 /** |
1075 * IMPORTANT: In Orthanc <= 1.9.1, there was no transaction | 1075 * IMPORTANT: In Orthanc <= 1.9.1, there was no transaction |
3488 if (seriesStatus == SeriesStatus_Complete) | 3488 if (seriesStatus == SeriesStatus_Complete) |
3489 { | 3489 { |
3490 transaction.LogChange(status.seriesId_, ChangeType_CompletedSeries, ResourceType_Series, hashSeries_); | 3490 transaction.LogChange(status.seriesId_, ChangeType_CompletedSeries, ResourceType_Series, hashSeries_); |
3491 } | 3491 } |
3492 } | 3492 } |
3493 | 3493 |
3494 | 3494 transaction.LogChange(status.seriesId_, ChangeType_NewChildInstance, ResourceType_Series, hashSeries_); |
3495 transaction.LogChange(status.studyId_, ChangeType_NewChildInstance, ResourceType_Study, hashStudy_); | |
3496 transaction.LogChange(status.patientId_, ChangeType_NewChildInstance, ResourceType_Patient, hashPatient_); | |
3497 | |
3495 // Mark the parent resources of this instance as unstable | 3498 // Mark the parent resources of this instance as unstable |
3496 index_.MarkAsUnstable(status.seriesId_, ResourceType_Series, hashSeries_); | 3499 index_.MarkAsUnstable(status.seriesId_, ResourceType_Series, hashSeries_); |
3497 index_.MarkAsUnstable(status.studyId_, ResourceType_Study, hashStudy_); | 3500 index_.MarkAsUnstable(status.studyId_, ResourceType_Study, hashStudy_); |
3498 index_.MarkAsUnstable(status.patientId_, ResourceType_Patient, hashPatient_); | 3501 index_.MarkAsUnstable(status.patientId_, ResourceType_Patient, hashPatient_); |
3499 | 3502 |