comparison OrthancServer/Sources/ServerContext.cpp @ 4792:434843934307 storage-cache

Added a StorageCache in the StorageAccessor
author Alain Mazy <am@osimis.io>
date Thu, 30 Sep 2021 12:14:19 +0200
parents 51ec061516c9
children 7afbb54bd028
comparison
equal deleted inserted replaced
4790:9754d5f2f38a 4792:434843934307
482 482
483 483
484 void ServerContext::RemoveFile(const std::string& fileUuid, 484 void ServerContext::RemoveFile(const std::string& fileUuid,
485 FileContentType type) 485 FileContentType type)
486 { 486 {
487 StorageAccessor accessor(area_, GetMetricsRegistry()); 487 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
488 accessor.Remove(fileUuid, type); 488 accessor.Remove(fileUuid, type);
489 } 489 }
490 490
491 491
492 StoreStatus ServerContext::StoreAfterTranscoding(std::string& resultPublicId, 492 StoreStatus ServerContext::StoreAfterTranscoding(std::string& resultPublicId,
524 dicom.GetSummary(summary); 524 dicom.GetSummary(summary);
525 525
526 try 526 try
527 { 527 {
528 MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms"); 528 MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms");
529 StorageAccessor accessor(area_, GetMetricsRegistry()); 529 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
530 530
531 DicomInstanceHasher hasher(summary); 531 DicomInstanceHasher hasher(summary);
532 resultPublicId = hasher.HashInstance(); 532 resultPublicId = hasher.HashInstance();
533 533
534 Json::Value dicomAsJson; 534 Json::Value dicomAsJson;
758 { 758 {
759 throw OrthancException(ErrorCode_UnknownResource); 759 throw OrthancException(ErrorCode_UnknownResource);
760 } 760 }
761 else 761 else
762 { 762 {
763 StorageAccessor accessor(area_, GetMetricsRegistry()); 763 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
764 accessor.AnswerFile(output, attachment, GetFileContentMime(content)); 764 accessor.AnswerFile(output, attachment, GetFileContentMime(content));
765 } 765 }
766 } 766 }
767 767
768 768
788 return; 788 return;
789 } 789 }
790 790
791 std::string content; 791 std::string content;
792 792
793 StorageAccessor accessor(area_, GetMetricsRegistry()); 793 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
794 accessor.Read(content, attachment); 794 accessor.Read(content, attachment);
795 795
796 FileInfo modified = accessor.Write(content.empty() ? NULL : content.c_str(), 796 FileInfo modified = accessor.Write(content.empty() ? NULL : content.c_str(),
797 content.size(), attachmentType, compression, storeMD5_); 797 content.size(), attachmentType, compression, storeMD5_);
798 798
844 if (index_.LookupAttachment(attachment, revision, instancePublicId, FileContentType_DicomUntilPixelData)) 844 if (index_.LookupAttachment(attachment, revision, instancePublicId, FileContentType_DicomUntilPixelData))
845 { 845 {
846 std::string dicom; 846 std::string dicom;
847 847
848 { 848 {
849 StorageAccessor accessor(area_, GetMetricsRegistry()); 849 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
850 accessor.Read(dicom, attachment); 850 accessor.Read(dicom, attachment);
851 } 851 }
852 852
853 ParsedDicomFile parsed(dicom); 853 ParsedDicomFile parsed(dicom);
854 OrthancConfiguration::DefaultDicomDatasetToJson(result, parsed, ignoreTagLength); 854 OrthancConfiguration::DefaultDicomDatasetToJson(result, parsed, ignoreTagLength);
909 * "true". 909 * "true".
910 **/ 910 **/
911 911
912 std::unique_ptr<IMemoryBuffer> dicom; 912 std::unique_ptr<IMemoryBuffer> dicom;
913 { 913 {
914 MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_storage_read_range_duration_ms"); 914 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
915 dicom.reset(area_.ReadRange(attachment.GetUuid(), FileContentType_Dicom, 0, pixelDataOffset)); 915 dicom.reset(accessor.ReadStartRange(attachment.GetUuid(), FileContentType_Dicom, pixelDataOffset, FileContentType_DicomUntilPixelData));
916 } 916 }
917 917
918 if (dicom.get() == NULL) 918 if (dicom.get() == NULL)
919 { 919 {
920 throw OrthancException(ErrorCode_InternalError); 920 throw OrthancException(ErrorCode_InternalError);
939 **/ 939 **/
940 940
941 std::string dicomAsJson; 941 std::string dicomAsJson;
942 942
943 { 943 {
944 StorageAccessor accessor(area_, GetMetricsRegistry()); 944 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
945 accessor.Read(dicomAsJson, attachment); 945 accessor.Read(dicomAsJson, attachment);
946 } 946 }
947 947
948 if (!Toolbox::ReadJson(result, dicomAsJson)) 948 if (!Toolbox::ReadJson(result, dicomAsJson))
949 { 949 {
1008 const std::string& instancePublicId) 1008 const std::string& instancePublicId)
1009 { 1009 {
1010 int64_t revision; 1010 int64_t revision;
1011 ReadAttachment(dicom, revision, instancePublicId, FileContentType_Dicom, true /* uncompress */); 1011 ReadAttachment(dicom, revision, instancePublicId, FileContentType_Dicom, true /* uncompress */);
1012 } 1012 }
1013 1013
1014 void ServerContext::ReadDicomForHeader(std::string& dicom,
1015 const std::string& instancePublicId)
1016 {
1017 if (!ReadDicomUntilPixelData(dicom, instancePublicId))
1018 {
1019 ReadDicom(dicom, instancePublicId);
1020 }
1021 }
1014 1022
1015 bool ServerContext::ReadDicomUntilPixelData(std::string& dicom, 1023 bool ServerContext::ReadDicomUntilPixelData(std::string& dicom,
1016 const std::string& instancePublicId) 1024 const std::string& instancePublicId)
1017 { 1025 {
1018 if (!area_.HasReadRange()) 1026 if (!area_.HasReadRange())
1037 { 1045 {
1038 try 1046 try
1039 { 1047 {
1040 uint64_t pixelDataOffset = boost::lexical_cast<uint64_t>(s); 1048 uint64_t pixelDataOffset = boost::lexical_cast<uint64_t>(s);
1041 1049
1050 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
1051
1042 std::unique_ptr<IMemoryBuffer> buffer( 1052 std::unique_ptr<IMemoryBuffer> buffer(
1043 area_.ReadRange(attachment.GetUuid(), attachment.GetContentType(), 0, pixelDataOffset)); 1053 accessor.ReadStartRange(attachment.GetUuid(), attachment.GetContentType(), pixelDataOffset, FileContentType_DicomUntilPixelData));
1044 buffer->MoveToString(dicom); 1054 buffer->MoveToString(dicom);
1045 return true; // Success 1055 return true; // Success
1046 } 1056 }
1047 catch (boost::bad_lexical_cast&) 1057 catch (boost::bad_lexical_cast&)
1048 { 1058 {
1069 } 1079 }
1070 1080
1071 assert(attachment.GetContentType() == content); 1081 assert(attachment.GetContentType() == content);
1072 1082
1073 { 1083 {
1074 StorageAccessor accessor(area_, GetMetricsRegistry()); 1084 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
1075 1085
1076 if (uncompressIfNeeded) 1086 if (uncompressIfNeeded)
1077 { 1087 {
1078 accessor.Read(result, attachment); 1088 accessor.Read(result, attachment);
1079 } 1089 }
1169 LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId; 1179 LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId;
1170 1180
1171 // TODO Should we use "gzip" instead? 1181 // TODO Should we use "gzip" instead?
1172 CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None); 1182 CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None);
1173 1183
1174 StorageAccessor accessor(area_, GetMetricsRegistry()); 1184 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry());
1175 FileInfo attachment = accessor.Write(data, size, attachmentType, compression, storeMD5_); 1185 FileInfo attachment = accessor.Write(data, size, attachmentType, compression, storeMD5_);
1176 1186
1177 try 1187 try
1178 { 1188 {
1179 StoreStatus status = index_.AddAttachment( 1189 StoreStatus status = index_.AddAttachment(