annotate OrthancFramework/Sources/FileStorage/StorageAccessor.cpp @ 5640:f7adfb22e20e

updated copyright, as Orthanc Team now replaces Osimis
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 30 May 2024 21:19:57 +0200
parents 48b8dae6dc77
children
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
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5420
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * 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
10 * 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
11 * 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
12 * the License, or (at your option) any later version.
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * 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
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * 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
17 * Lesser General Public License for more details.
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
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
19 * 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
20 * 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
21 * <http://www.gnu.org/licenses/>.
221
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
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
25 #include "../PrecompiledHeaders.h"
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "StorageAccessor.h"
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
27 #include "StorageCache.h"
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
29 #include "../Logging.h"
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
30 #include "../StringMemoryBuffer.h"
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
31 #include "../Compatibility.h"
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
32 #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
33 #include "../MetricsRegistry.h"
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
34 #include "../OrthancException.h"
2142
5a8840920121 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
35 #include "../Toolbox.h"
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
36
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
37 #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
38 # include "../HttpServer/HttpStreamTranscoder.h"
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
39 #endif
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
40
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
41
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
42 static const std::string METRICS_CREATE_DURATION = "orthanc_storage_create_duration_ms";
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
43 static const std::string METRICS_READ_DURATION = "orthanc_storage_read_duration_ms";
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
44 static const std::string METRICS_REMOVE_DURATION = "orthanc_storage_remove_duration_ms";
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
45 static const std::string METRICS_READ_BYTES = "orthanc_storage_read_bytes";
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
46 static const std::string METRICS_WRITTEN_BYTES = "orthanc_storage_written_bytes";
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
47
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
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 namespace Orthanc
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
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
51 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
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 private:
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
54 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
55
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 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
57 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
58 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
59 {
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 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
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 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
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 }
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
65 };
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
66
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
67
5184
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
68 StorageAccessor::StorageAccessor(IStorageArea& area) :
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
69 area_(area),
5184
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
70 cache_(NULL),
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
71 metrics_(NULL)
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 }
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
74
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
75
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
76 StorageAccessor::StorageAccessor(IStorageArea& area,
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
77 StorageCache& cache) :
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
78 area_(area),
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
79 cache_(&cache),
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
80 metrics_(NULL)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
81 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
82 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
83
5184
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
84
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
85 StorageAccessor::StorageAccessor(IStorageArea& area,
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
86 MetricsRegistry& metrics) :
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
87 area_(area),
5184
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
88 cache_(NULL),
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
89 metrics_(&metrics)
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
90 {
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
91 }
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
92
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
93 StorageAccessor::StorageAccessor(IStorageArea& area,
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
94 StorageCache& cache,
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
95 MetricsRegistry& metrics) :
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
96 area_(area),
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5059
diff changeset
97 cache_(&cache),
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
98 metrics_(&metrics)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
99 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
100 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
101
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
102
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
103 FileInfo StorageAccessor::Write(const void* data,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
104 size_t size,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
105 FileContentType type,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
106 CompressionType compression,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
107 bool storeMd5)
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
2512
4dcafa8d6633 SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
109 std::string uuid = Toolbox::GenerateUuid();
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
110
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
111 std::string md5;
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
112
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
113 if (storeMd5)
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 Toolbox::ComputeMD5(md5, data, size);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
116 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
117
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
118 switch (compression)
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
120 case CompressionType_None:
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
121 {
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
122 {
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
123 MetricsTimer timer(*this, METRICS_CREATE_DURATION);
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
124 area_.Create(uuid, data, size, type);
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
125 }
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
126
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
127 if (metrics_ != NULL)
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
128 {
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5329
diff changeset
129 metrics_->IncrementIntegerValue(METRICS_WRITTEN_BYTES, size);
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
130 }
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
131
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
132 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
133 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
134 StorageCache::Accessor cacheAccessor(*cache_);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
135 cacheAccessor.Add(uuid, type, data, size);
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
136 }
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
137
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
138 return FileInfo(uuid, type, size, md5);
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
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
141 case CompressionType_ZlibWithSize:
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
142 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
143 ZlibCompressor zlib;
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 std::string compressed;
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
146 zlib.Compress(compressed, data, size);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
147
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
148 std::string compressedMD5;
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
149
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
150 if (storeMd5)
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
151 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
152 Toolbox::ComputeMD5(compressedMD5, compressed);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
153 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
154
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
155 {
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
156 MetricsTimer timer(*this, METRICS_CREATE_DURATION);
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
157
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
158 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
159 {
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
160 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
161 }
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
162 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
163 {
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
164 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
165 }
1549
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
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
168 if (metrics_ != NULL)
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
169 {
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5329
diff changeset
170 metrics_->IncrementIntegerValue(METRICS_WRITTEN_BYTES, compressed.size());
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
171 }
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
172
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
173 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
174 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
175 StorageCache::Accessor cacheAccessor(*cache_);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
176 cacheAccessor.Add(uuid, type, data, size); // always add uncompressed data to cache
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
177 }
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
178
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
179 return FileInfo(uuid, type, size, md5,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
180 CompressionType_ZlibWithSize, compressed.size(), compressedMD5);
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
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
183 default:
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
184 throw OrthancException(ErrorCode_NotImplemented);
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
188 FileInfo StorageAccessor::Write(const std::string &data,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
189 FileContentType type,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
190 CompressionType compression,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
191 bool storeMd5)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
192 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
193 return Write((data.size() == 0 ? NULL : data.c_str()),
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
194 data.size(), type, compression, storeMd5);
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
195 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
196
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
197
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
198 void StorageAccessor::Read(std::string& content,
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
199 const FileInfo& info)
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
201 if (cache_ == NULL)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
202 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
203 ReadWholeInternal(content, info);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
204 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
205 else
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
207 StorageCache::Accessor cacheAccessor(*cache_);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
208
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
209 if (!cacheAccessor.Fetch(content, info.GetUuid(), info.GetContentType()))
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
210 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
211 ReadWholeInternal(content, info);
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
212
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
213 // always store the uncompressed data in cache
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
214 cacheAccessor.Add(info.GetUuid(), info.GetContentType(), content);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
215 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
216 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
217 }
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
218
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
219 void StorageAccessor::ReadWholeInternal(std::string& content,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
220 const FileInfo& info)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
221 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
222 switch (info.GetCompressionType())
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
223 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
224 case CompressionType_None:
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
225 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
226 std::unique_ptr<IMemoryBuffer> buffer;
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
227
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
228 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
229 MetricsTimer timer(*this, METRICS_READ_DURATION);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
230 buffer.reset(area_.Read(info.GetUuid(), info.GetContentType()));
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
231 }
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
232
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
233 if (metrics_ != NULL)
5046
2b3b0ab88c1d fix storage cache
Alain Mazy <am@osimis.io>
parents: 4912
diff changeset
234 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
235 metrics_->IncrementIntegerValue(METRICS_READ_BYTES, buffer->GetSize());
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
236 }
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
237
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
238 buffer->MoveToString(content);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
239
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
240 break;
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
241 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
242
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
243 case CompressionType_ZlibWithSize:
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
244 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
245 ZlibCompressor zlib;
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
246
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
247 std::unique_ptr<IMemoryBuffer> compressed;
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
248
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
249 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
250 MetricsTimer timer(*this, METRICS_READ_DURATION);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
251 compressed.reset(area_.Read(info.GetUuid(), info.GetContentType()));
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
252 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
253
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
254 if (metrics_ != NULL)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
255 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
256 metrics_->IncrementIntegerValue(METRICS_READ_BYTES, compressed->GetSize());
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
257 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
258
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
259 zlib.Uncompress(content, compressed->GetData(), compressed->GetSize());
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
260
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
261 break;
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
262 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
263
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
264 default:
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
265 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
266 throw OrthancException(ErrorCode_NotImplemented);
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
267 }
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 }
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
269
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
270 // TODO Check the validity of the uncompressed MD5?
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
271 }
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
272
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
273
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
274 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
275 const FileInfo& info)
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
276 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
277 if (cache_ == NULL || info.GetCompressionType() != CompressionType_None)
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
278 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
279 ReadRawInternal(content, info);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
280 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
281 else
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
282 {// use the cache only if the data is uncompressed.
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
283 StorageCache::Accessor cacheAccessor(*cache_);
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
284
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
285 if (!cacheAccessor.Fetch(content, info.GetUuid(), info.GetContentType()))
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
286 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
287 ReadRawInternal(content, info);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
288
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
289 cacheAccessor.Add(info.GetUuid(), info.GetContentType(), content);
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
290 }
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
291 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
292 }
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
293
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
294 void StorageAccessor::ReadRawInternal(std::string& content,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
295 const FileInfo& info)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
296 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
297 std::unique_ptr<IMemoryBuffer> buffer;
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
298
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
299 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
300 MetricsTimer timer(*this, METRICS_READ_DURATION);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
301 buffer.reset(area_.Read(info.GetUuid(), info.GetContentType()));
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
302 }
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
303
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
304 if (metrics_ != NULL)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
305 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
306 metrics_->IncrementIntegerValue(METRICS_READ_BYTES, buffer->GetSize());
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
307 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
308
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
309 buffer->MoveToString(content);
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
310 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
311
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
312
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
313 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
314 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
315 {
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
316 if (cache_ != NULL)
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
317 {
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
318 cache_->Invalidate(fileUuid, type);
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
319 }
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
320
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
321 {
5325
9c00e832985f refactoring MetricsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
322 MetricsTimer timer(*this, METRICS_REMOVE_DURATION);
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
323 area_.Remove(fileUuid, type);
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
324 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
325 }
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
326
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
327
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
328 void StorageAccessor::Remove(const FileInfo &info)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
329 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
330 Remove(info.GetUuid(), info.GetContentType());
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
331 }
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1550
diff changeset
332
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
333
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
334 void ReadStartRangeFromAreaInternal(std::string& target,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
335 IStorageArea& area,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
336 const std::string& fileUuid,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
337 FileContentType contentType,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
338 uint64_t end /* exclusive */)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
339 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
340
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
341 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
342
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
343 void StorageAccessor::ReadStartRange(std::string& target,
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
344 const FileInfo& info,
4900
ea5f1c6ed07e fix cache of storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
345 uint64_t end /* exclusive */)
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
346 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
347 if (cache_ == NULL)
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
348 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
349 ReadStartRangeInternal(target, info, end);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
350 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
351 else
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
352 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
353 StorageCache::Accessor accessorStartRange(*cache_);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
354 if (!accessorStartRange.FetchStartRange(target, info.GetUuid(), info.GetContentType(), end))
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
355 {
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
356 ReadStartRangeInternal(target, info, end);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
357 accessorStartRange.AddStartRange(info.GetUuid(), info.GetContentType(), target);
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
358 }
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
359 else
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
360 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
361 StorageCache::Accessor accessorWhole(*cache_);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
362 if (!accessorWhole.Fetch(target, info.GetUuid(), info.GetContentType()))
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
363 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
364 ReadWholeInternal(target, info);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
365 accessorWhole.Add(info.GetUuid(), info.GetContentType(), target);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
366 }
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
367
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
368 if (target.size() < end)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
369 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
370 throw OrthancException(ErrorCode_CorruptedFile);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
371 }
5329
d0752fd53aec added metrics "orthanc_storage_read_bytes" and "orthanc_storage_written_bytes"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5325
diff changeset
372
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
373 target.resize(end);
5048
22966345eaba skip StorageCache when verifying md5 or when re-compressing attachments
Alain Mazy <am@osimis.io>
parents: 5047
diff changeset
374 }
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
375 }
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
376 }
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
377
5420
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
378 void StorageAccessor::ReadStartRangeInternal(std::string& target,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
379 const FileInfo& info,
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
380 uint64_t end /* exclusive */)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
381 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
382 std::unique_ptr<IMemoryBuffer> buffer;
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
383
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
384 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
385 MetricsTimer timer(*this, METRICS_READ_DURATION);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
386 buffer.reset(area_.ReadRange(info.GetUuid(), info.GetContentType(), 0, end));
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
387 assert(buffer->GetSize() == end);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
388 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
389
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
390 if (metrics_ != NULL)
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
391 {
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
392 metrics_->IncrementIntegerValue(METRICS_READ_BYTES, buffer->GetSize());
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
393 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
394
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
395 buffer->MoveToString(target);
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
396 }
d37dff2c0028 Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents: 5337
diff changeset
397
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
398
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
399 #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
400 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
401 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
402 const std::string& mime)
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
403 {
5059
5c997c72603c Fix the Storage Cache for compressed files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents: 5048
diff changeset
404 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
405
1772
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
406 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
407
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
408 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
409 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
410 {
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
411 case FileContentType_Dicom:
4512
cff7fdfc83a4 added FileContentType_DicomUntilPixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
412 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
413 extension = ".dcm";
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
414 break;
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
415
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
416 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
417 extension = ".json";
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
418 break;
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
419
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
420 default:
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
421 // 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
422 extension = "";
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
423 }
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
424
53e045b5a8ec MIME content type can be associated to custom attachments (cf. "UserContentType")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
425 sender.SetContentFilename(info.GetUuid() + std::string(extension));
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
426 }
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
427 #endif
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
428
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
429
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
430 #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
431 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
432 const FileInfo& info,
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
433 MimeType mime)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
434 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
435 AnswerFile(output, info, EnumerationToString(mime));
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
436 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
437 #endif
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
438
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
439
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
440 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
441 void StorageAccessor::AnswerFile(HttpOutput& output,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
442 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
443 const std::string& mime)
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
444 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
445 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
446 SetupSender(sender, info, mime);
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
447
5059
5c997c72603c Fix the Storage Cache for compressed files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents: 5048
diff changeset
448 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
449 output.Answer(transcoder);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
450 }
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
451 #endif
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
452
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
453
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
454 #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
455 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
456 const FileInfo& info,
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
457 MimeType mime)
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
458 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
459 AnswerFile(output, info, EnumerationToString(mime));
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
460 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
461 #endif
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
462
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
463
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
464 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
465 void StorageAccessor::AnswerFile(RestApiOutput& output,
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
466 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
467 const std::string& mime)
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
468 {
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
469 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
470 SetupSender(sender, info, mime);
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
471
5059
5c997c72603c Fix the Storage Cache for compressed files (bug introduced in 1.11.0)
Alain Mazy <am@osimis.io>
parents: 5048
diff changeset
472 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
473 output.AnswerStream(transcoder);
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 }
2394
75c779ca948c fix compilation without Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
475 #endif
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 }