Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerContext.cpp @ 4810:7afbb54bd028
merge storage-cache
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 23 Nov 2021 09:22:11 +0100 |
parents | 0bd98c52474b 434843934307 |
children | 70d2a97ca8cb 7053502fbf97 |
comparison
equal
deleted
inserted
replaced
4809:2ca4213fb50a | 4810:7afbb54bd028 |
---|---|
490 | 490 |
491 | 491 |
492 void ServerContext::RemoveFile(const std::string& fileUuid, | 492 void ServerContext::RemoveFile(const std::string& fileUuid, |
493 FileContentType type) | 493 FileContentType type) |
494 { | 494 { |
495 StorageAccessor accessor(area_, GetMetricsRegistry()); | 495 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); |
496 accessor.Remove(fileUuid, type); | 496 accessor.Remove(fileUuid, type); |
497 } | 497 } |
498 | 498 |
499 | 499 |
500 ServerContext::StoreResult ServerContext::StoreAfterTranscoding(std::string& resultPublicId, | 500 ServerContext::StoreResult ServerContext::StoreAfterTranscoding(std::string& resultPublicId, |
532 dicom.GetSummary(summary); | 532 dicom.GetSummary(summary); |
533 | 533 |
534 try | 534 try |
535 { | 535 { |
536 MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms"); | 536 MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms"); |
537 StorageAccessor accessor(area_, GetMetricsRegistry()); | 537 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); |
538 | 538 |
539 DicomInstanceHasher hasher(summary); | 539 DicomInstanceHasher hasher(summary); |
540 resultPublicId = hasher.HashInstance(); | 540 resultPublicId = hasher.HashInstance(); |
541 | 541 |
542 Json::Value dicomAsJson; | 542 Json::Value dicomAsJson; |
779 { | 779 { |
780 throw OrthancException(ErrorCode_UnknownResource); | 780 throw OrthancException(ErrorCode_UnknownResource); |
781 } | 781 } |
782 else | 782 else |
783 { | 783 { |
784 StorageAccessor accessor(area_, GetMetricsRegistry()); | 784 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); |
785 accessor.AnswerFile(output, attachment, GetFileContentMime(content)); | 785 accessor.AnswerFile(output, attachment, GetFileContentMime(content)); |
786 } | 786 } |
787 } | 787 } |
788 | 788 |
789 | 789 |
809 return; | 809 return; |
810 } | 810 } |
811 | 811 |
812 std::string content; | 812 std::string content; |
813 | 813 |
814 StorageAccessor accessor(area_, GetMetricsRegistry()); | 814 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); |
815 accessor.Read(content, attachment); | 815 accessor.Read(content, attachment); |
816 | 816 |
817 FileInfo modified = accessor.Write(content.empty() ? NULL : content.c_str(), | 817 FileInfo modified = accessor.Write(content.empty() ? NULL : content.c_str(), |
818 content.size(), attachmentType, compression, storeMD5_); | 818 content.size(), attachmentType, compression, storeMD5_); |
819 | 819 |
865 if (index_.LookupAttachment(attachment, revision, instancePublicId, FileContentType_DicomUntilPixelData)) | 865 if (index_.LookupAttachment(attachment, revision, instancePublicId, FileContentType_DicomUntilPixelData)) |
866 { | 866 { |
867 std::string dicom; | 867 std::string dicom; |
868 | 868 |
869 { | 869 { |
870 StorageAccessor accessor(area_, GetMetricsRegistry()); | 870 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); |
871 accessor.Read(dicom, attachment); | 871 accessor.Read(dicom, attachment); |
872 } | 872 } |
873 | 873 |
874 ParsedDicomFile parsed(dicom); | 874 ParsedDicomFile parsed(dicom); |
875 OrthancConfiguration::DefaultDicomDatasetToJson(result, parsed, ignoreTagLength); | 875 OrthancConfiguration::DefaultDicomDatasetToJson(result, parsed, ignoreTagLength); |
930 * "true". | 930 * "true". |
931 **/ | 931 **/ |
932 | 932 |
933 std::unique_ptr<IMemoryBuffer> dicom; | 933 std::unique_ptr<IMemoryBuffer> dicom; |
934 { | 934 { |
935 MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_storage_read_range_duration_ms"); | 935 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); |
936 dicom.reset(area_.ReadRange(attachment.GetUuid(), FileContentType_Dicom, 0, pixelDataOffset)); | 936 dicom.reset(accessor.ReadStartRange(attachment.GetUuid(), FileContentType_Dicom, pixelDataOffset, FileContentType_DicomUntilPixelData)); |
937 } | 937 } |
938 | 938 |
939 if (dicom.get() == NULL) | 939 if (dicom.get() == NULL) |
940 { | 940 { |
941 throw OrthancException(ErrorCode_InternalError); | 941 throw OrthancException(ErrorCode_InternalError); |
960 **/ | 960 **/ |
961 | 961 |
962 std::string dicomAsJson; | 962 std::string dicomAsJson; |
963 | 963 |
964 { | 964 { |
965 StorageAccessor accessor(area_, GetMetricsRegistry()); | 965 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); |
966 accessor.Read(dicomAsJson, attachment); | 966 accessor.Read(dicomAsJson, attachment); |
967 } | 967 } |
968 | 968 |
969 if (!Toolbox::ReadJson(result, dicomAsJson)) | 969 if (!Toolbox::ReadJson(result, dicomAsJson)) |
970 { | 970 { |
1029 const std::string& instancePublicId) | 1029 const std::string& instancePublicId) |
1030 { | 1030 { |
1031 int64_t revision; | 1031 int64_t revision; |
1032 ReadAttachment(dicom, revision, instancePublicId, FileContentType_Dicom, true /* uncompress */); | 1032 ReadAttachment(dicom, revision, instancePublicId, FileContentType_Dicom, true /* uncompress */); |
1033 } | 1033 } |
1034 | 1034 |
1035 void ServerContext::ReadDicomForHeader(std::string& dicom, | |
1036 const std::string& instancePublicId) | |
1037 { | |
1038 if (!ReadDicomUntilPixelData(dicom, instancePublicId)) | |
1039 { | |
1040 ReadDicom(dicom, instancePublicId); | |
1041 } | |
1042 } | |
1035 | 1043 |
1036 bool ServerContext::ReadDicomUntilPixelData(std::string& dicom, | 1044 bool ServerContext::ReadDicomUntilPixelData(std::string& dicom, |
1037 const std::string& instancePublicId) | 1045 const std::string& instancePublicId) |
1038 { | 1046 { |
1039 if (!area_.HasReadRange()) | 1047 if (!area_.HasReadRange()) |
1058 { | 1066 { |
1059 try | 1067 try |
1060 { | 1068 { |
1061 uint64_t pixelDataOffset = boost::lexical_cast<uint64_t>(s); | 1069 uint64_t pixelDataOffset = boost::lexical_cast<uint64_t>(s); |
1062 | 1070 |
1071 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); | |
1072 | |
1063 std::unique_ptr<IMemoryBuffer> buffer( | 1073 std::unique_ptr<IMemoryBuffer> buffer( |
1064 area_.ReadRange(attachment.GetUuid(), attachment.GetContentType(), 0, pixelDataOffset)); | 1074 accessor.ReadStartRange(attachment.GetUuid(), attachment.GetContentType(), pixelDataOffset, FileContentType_DicomUntilPixelData)); |
1065 buffer->MoveToString(dicom); | 1075 buffer->MoveToString(dicom); |
1066 return true; // Success | 1076 return true; // Success |
1067 } | 1077 } |
1068 catch (boost::bad_lexical_cast&) | 1078 catch (boost::bad_lexical_cast&) |
1069 { | 1079 { |
1090 } | 1100 } |
1091 | 1101 |
1092 assert(attachment.GetContentType() == content); | 1102 assert(attachment.GetContentType() == content); |
1093 | 1103 |
1094 { | 1104 { |
1095 StorageAccessor accessor(area_, GetMetricsRegistry()); | 1105 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); |
1096 | 1106 |
1097 if (uncompressIfNeeded) | 1107 if (uncompressIfNeeded) |
1098 { | 1108 { |
1099 accessor.Read(result, attachment); | 1109 accessor.Read(result, attachment); |
1100 } | 1110 } |
1190 LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId; | 1200 LOG(INFO) << "Adding attachment " << EnumerationToString(attachmentType) << " to resource " << resourceId; |
1191 | 1201 |
1192 // TODO Should we use "gzip" instead? | 1202 // TODO Should we use "gzip" instead? |
1193 CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None); | 1203 CompressionType compression = (compressionEnabled_ ? CompressionType_ZlibWithSize : CompressionType_None); |
1194 | 1204 |
1195 StorageAccessor accessor(area_, GetMetricsRegistry()); | 1205 StorageAccessor accessor(area_, storageCache_, GetMetricsRegistry()); |
1196 FileInfo attachment = accessor.Write(data, size, attachmentType, compression, storeMD5_); | 1206 FileInfo attachment = accessor.Write(data, size, attachmentType, compression, storeMD5_); |
1197 | 1207 |
1198 try | 1208 try |
1199 { | 1209 { |
1200 StoreStatus status = index_.AddAttachment( | 1210 StoreStatus status = index_.AddAttachment( |