annotate OrthancFramework/Sources/FileStorage/StorageAccessor.cpp @ 5195:32df369198ac

fix /tools/reset crashing when ExtraMainDicomTags were defined
author Alain Mazy <am@osimis.io>
date Tue, 28 Mar 2023 10:48:13 +0200
parents 0ea402b4d901
children 9c00e832985f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1772
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
4 * Department, University Hospital of Liege, Belgium
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5184
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5184
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 * the License, or (at your option) any later version.
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
16 * Lesser General Public License for more details.
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 * <http://www.gnu.org/licenses/>.
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
24 #include "../PrecompiledHeaders.h"
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "StorageAccessor.h"
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
26 #include "StorageCache.h"
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
28 #include "../Logging.h"
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
29 #include "../StringMemoryBuffer.h"
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
30 #include "../Compatibility.h"
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
31 #include "../Compression/ZlibCompressor.h"
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
32 #include "../MetricsRegistry.h"
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
33 #include "../OrthancException.h"
2142
5a8840920121 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
34 #include "../Toolbox.h"
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
35
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
36 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
37 # include "../HttpServer/HttpStreamTranscoder.h"
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
38 #endif
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
39
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
40
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
41 static const std::string METRICS_CREATE = "orthanc_storage_create_duration_ms";
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
42 static const std::string METRICS_READ = "orthanc_storage_read_duration_ms";
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
43 static const std::string METRICS_REMOVE = "orthanc_storage_remove_duration_ms";
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
44
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
45
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 namespace Orthanc
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
48 class StorageAccessor::MetricsTimer : public boost::noncopyable
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
49 {
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
50 private:
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
51 std::unique_ptr<MetricsRegistry::Timer> timer_;
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
52
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
53 public:
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
54 MetricsTimer(StorageAccessor& that,
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
55 const std::string& name)
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
56 {
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
57 if (that.metrics_ != NULL)
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
58 {
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
59 timer_.reset(new MetricsRegistry::Timer(*that.metrics_, name));
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
60 }
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
61 }
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
62 };
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
63
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
64
5184
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
65 StorageAccessor::StorageAccessor(IStorageArea& area) :
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
66 area_(area),
5184
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
67 cache_(NULL),
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
68 metrics_(NULL)
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
69 {
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
70 }
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
71
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
72
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
73 StorageAccessor::StorageAccessor(IStorageArea& area,
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
74 StorageCache& cache) :
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
75 area_(area),
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
76 cache_(&cache),
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
77 metrics_(NULL)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
78 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
79 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
80
5184
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
81
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
82 StorageAccessor::StorageAccessor(IStorageArea& area,
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
83 MetricsRegistry& metrics) :
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
84 area_(area),
5184
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
85 cache_(NULL),
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
86 metrics_(&metrics)
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
87 {
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
88 }
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
89
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
90 StorageAccessor::StorageAccessor(IStorageArea& area,
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
91 StorageCache& cache,
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
92 MetricsRegistry& metrics) :
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
93 area_(area),
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
94 cache_(&cache),
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
95 metrics_(&metrics)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
96 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
97 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
98
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
99
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
100 FileInfo StorageAccessor::Write(const void* data,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
101 size_t size,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
102 FileContentType type,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
103 CompressionType compression,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
104 bool storeMd5)
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
2512
4dcafa8d6633 SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
106 std::string uuid = Toolbox::GenerateUuid();
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
107
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
108 std::string md5;
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
109
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
110 if (storeMd5)
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
111 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
112 Toolbox::ComputeMD5(md5, data, size);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
113 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
114
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
115 switch (compression)
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
117 case CompressionType_None:
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
118 {
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
119 MetricsTimer timer(*this, METRICS_CREATE);
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
120
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
121 area_.Create(uuid, data, size, type);
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
122
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
123 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
124 {
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
125 cache_->Add(uuid, type, data, size);
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
126 }
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
127
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
128 return FileInfo(uuid, type, size, md5);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
129 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
130
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
131 case CompressionType_ZlibWithSize:
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
132 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
133 ZlibCompressor zlib;
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
134
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
135 std::string compressed;
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
136 zlib.Compress(compressed, data, size);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
137
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
138 std::string compressedMD5;
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
139
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
140 if (storeMd5)
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
141 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
142 Toolbox::ComputeMD5(compressedMD5, compressed);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
143 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
144
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
145 {
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
146 MetricsTimer timer(*this, METRICS_CREATE);
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
147
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
148 if (compressed.size() > 0)
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
149 {
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
150 area_.Create(uuid, &compressed[0], compressed.size(), type);
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
151 }
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
152 else
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
153 {
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
154 area_.Create(uuid, NULL, 0, type);
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
155 }
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
156 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
157
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
158 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
159 {
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
160 cache_->Add(uuid, type, data, size); // always add uncompressed data to cache
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
161 }
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
162
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
163 return FileInfo(uuid, type, size, md5,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
164 CompressionType_ZlibWithSize, compressed.size(), compressedMD5);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
165 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
166
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
167 default:
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
168 throw OrthancException(ErrorCode_NotImplemented);
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 }
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
172 FileInfo StorageAccessor::Write(const std::string &data,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
173 FileContentType type,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
174 CompressionType compression,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
175 bool storeMd5)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
176 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
177 return Write((data.size() == 0 ? NULL : data.c_str()),
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
178 data.size(), type, compression, storeMd5);
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
179 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
180
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
181
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
182 void StorageAccessor::Read(std::string& content,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
183 const FileInfo& info)
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
185 if (cache_ == NULL ||
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
186 !cache_->Fetch(content, info.GetUuid(), info.GetContentType()))
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 {
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
188 switch (info.GetCompressionType())
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
189 {
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
190 case CompressionType_None:
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
191 {
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
192 MetricsTimer timer(*this, METRICS_READ);
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
193 std::unique_ptr<IMemoryBuffer> buffer(area_.Read(info.GetUuid(), info.GetContentType()));
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
194 buffer->MoveToString(content);
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
195
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
196 break;
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
197 }
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
198
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
199 case CompressionType_ZlibWithSize:
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
200 {
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
201 ZlibCompressor zlib;
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
202
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
203 std::unique_ptr<IMemoryBuffer> compressed;
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
204
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
205 {
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
206 MetricsTimer timer(*this, METRICS_READ);
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
207 compressed.reset(area_.Read(info.GetUuid(), info.GetContentType()));
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
208 }
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
209
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
210 zlib.Uncompress(content, compressed->GetData(), compressed->GetSize());
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
211
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
212 break;
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
213 }
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
214
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
215 default:
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
216 {
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
217 throw OrthancException(ErrorCode_NotImplemented);
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
218 }
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
219 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
220
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
221 // always store the uncompressed data in cache
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
222 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
223 {
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
224 cache_->Add(info.GetUuid(), info.GetContentType(), content);
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
225 }
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 }
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
227
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
228 // TODO Check the validity of the uncompressed MD5?
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
229 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
230
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
231
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
232 void StorageAccessor::ReadRaw(std::string& content,
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
233 const FileInfo& info)
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
234 {
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
235 if (cache_ == NULL || !cache_->Fetch(content, info.GetUuid(), info.GetContentType()))
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
236 {
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
237 MetricsTimer timer(*this, METRICS_READ);
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
238 std::unique_ptr<IMemoryBuffer> buffer(area_.Read(info.GetUuid(), info.GetContentType()));
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
239 buffer->MoveToString(content);
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
240 }
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
241 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
242
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
243
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
244 void StorageAccessor::Remove(const std::string& fileUuid,
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
245 FileContentType type)
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
246 {
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
247 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
248 {
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
249 cache_->Invalidate(fileUuid, type);
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
250 }
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
251
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
252 {
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
253 MetricsTimer timer(*this, METRICS_REMOVE);
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
254 area_.Remove(fileUuid, type);
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
255 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
256 }
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
257
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
258
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
259 void StorageAccessor::Remove(const FileInfo &info)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
260 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
261 Remove(info.GetUuid(), info.GetContentType());
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
262 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
263
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
264
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
265 void StorageAccessor::ReadStartRange(std::string& target,
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
266 const std::string& fileUuid,
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
267 FileContentType contentType,
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
268 uint64_t end /* exclusive */)
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
269 {
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
270 if (cache_ == NULL || !cache_->FetchStartRange(target, fileUuid, contentType, end))
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
271 {
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
272 MetricsTimer timer(*this, METRICS_READ);
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
273 std::unique_ptr<IMemoryBuffer> buffer(area_.ReadRange(fileUuid, contentType, 0, end));
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
274 assert(buffer->GetSize() == end);
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
275 buffer->MoveToString(target);
4906
f656fb878b50 reintroduced storage cache for StartRange files
Alain Mazy <am@osimis.io>
parents: 4901
diff changeset
276
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
277 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
278 {
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
279 cache_->AddStartRange(fileUuid, contentType, target);
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
280 }
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
281 }
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
282 }
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
283
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
284
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
285 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
286 void StorageAccessor::SetupSender(BufferHttpSender& sender,
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
287 const FileInfo& info,
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
288 const std::string& mime)
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
289 {
5059
5c997c72603c Fix the Storage Cache for compressed files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents: 5048
diff changeset
290 Read(sender.GetBuffer(), info);
3175
574890d14c92 new metrics: orthanc_store_dicom_duration_ms, orthanc_storage_[create|read|remove]_duration_ms
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
291
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
292 sender.SetContentType(mime);
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
293
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
294 const char* extension;
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
295 switch (info.GetContentType())
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
296 {
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
297 case FileContentType_Dicom:
4512
cff7fdfc83a4 added FileContentType_DicomUntilPixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
298 case FileContentType_DicomUntilPixelData:
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
299 extension = ".dcm";
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
300 break;
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
301
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
302 case FileContentType_DicomAsJson:
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
303 extension = ".json";
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
304 break;
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
305
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
306 default:
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
307 // Non-standard content type
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
308 extension = "";
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
309 }
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
310
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
311 sender.SetContentFilename(info.GetUuid() + std::string(extension));
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
312 }
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
313 #endif
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
314
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
315
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
316 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
317 void StorageAccessor::AnswerFile(HttpOutput& output,
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
318 const FileInfo& info,
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
319 MimeType mime)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
320 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
321 AnswerFile(output, info, EnumerationToString(mime));
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
322 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
323 #endif
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
324
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
325
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
326 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
327 void StorageAccessor::AnswerFile(HttpOutput& output,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
328 const FileInfo& info,
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
329 const std::string& mime)
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
330 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
331 BufferHttpSender sender;
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
332 SetupSender(sender, info, mime);
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
333
5059
5c997c72603c Fix the Storage Cache for compressed files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents: 5048
diff changeset
334 HttpStreamTranscoder transcoder(sender, CompressionType_None); // since 1.11.2, the storage accessor only returns uncompressed buffers
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
335 output.Answer(transcoder);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
336 }
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
337 #endif
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
338
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
339
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
340 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
341 void StorageAccessor::AnswerFile(RestApiOutput& output,
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
342 const FileInfo& info,
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
343 MimeType mime)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
344 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
345 AnswerFile(output, info, EnumerationToString(mime));
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
346 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
347 #endif
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
348
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
349
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
350 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
351 void StorageAccessor::AnswerFile(RestApiOutput& output,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
352 const FileInfo& info,
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
353 const std::string& mime)
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
354 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
355 BufferHttpSender sender;
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
356 SetupSender(sender, info, mime);
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
357
5059
5c997c72603c Fix the Storage Cache for compressed files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents: 5048
diff changeset
358 HttpStreamTranscoder transcoder(sender, CompressionType_None); // since 1.11.2, the storage accessor only returns uncompressed buffers
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
359 output.AnswerStream(transcoder);
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 }
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
361 #endif
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 }