Mercurial > hg > orthanc
annotate OrthancServer/Sources/ServerIndex.cpp @ 5822:ca5622c27d6c attach-custom-data tip
merged find-refactoring -> attach-custom-data
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 01 Oct 2024 16:01:50 +0200 |
parents | 023a99146dd0 7c2b4fa94633 |
children |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1286
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:
5603
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:
5603
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5467
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 8 * |
9 * This program is free software: you can redistribute it and/or | |
10 * modify it under the terms of the GNU General Public License as | |
11 * published by the Free Software Foundation, either version 3 of the | |
12 * License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
24 #include "PrecompiledHeadersServer.h" |
0 | 25 #include "ServerIndex.h" |
26 | |
6 | 27 #ifndef NOMINMAX |
2 | 28 #define NOMINMAX |
6 | 29 #endif |
30 | |
4045 | 31 #include "../../OrthancFramework/Sources/Logging.h" |
32 #include "../../OrthancFramework/Sources/Toolbox.h" | |
3094
61da3c9b4121
cont reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
33 |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
34 #include "OrthancConfiguration.h" |
3094
61da3c9b4121
cont reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
35 #include "ServerContext.h" |
61da3c9b4121
cont reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
36 #include "ServerIndexChange.h" |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1555
diff
changeset
|
37 #include "ServerToolbox.h" |
0 | 38 |
39 | |
62 | 40 namespace Orthanc |
0 | 41 { |
4590
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
42 class ServerIndex::TransactionContext : public StatelessDatabaseOperations::ITransactionContext |
0 | 43 { |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
44 private: |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
45 struct FileToRemove |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
46 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
47 private: |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
5061
diff
changeset
|
48 std::string uuid_; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
5061
diff
changeset
|
49 std::string customData_; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
5061
diff
changeset
|
50 FileContentType type_; |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
51 |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
52 public: |
4205 | 53 explicit FileToRemove(const FileInfo& info) : |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
5061
diff
changeset
|
54 uuid_(info.GetUuid()), |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
5061
diff
changeset
|
55 customData_(info.GetCustomData()), |
4205 | 56 type_(info.GetContentType()) |
1191
d49505e377e3
demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1189
diff
changeset
|
57 { |
d49505e377e3
demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1189
diff
changeset
|
58 } |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
59 |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
60 const std::string& GetUuid() const |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
61 { |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
62 return uuid_; |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
63 } |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
64 |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
5061
diff
changeset
|
65 const std::string& GetCustomData() const |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
5061
diff
changeset
|
66 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
5061
diff
changeset
|
67 return customData_; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
5061
diff
changeset
|
68 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
5061
diff
changeset
|
69 |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
70 FileContentType GetContentType() const |
264
5b8e8b74bc8b
remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
240
diff
changeset
|
71 { |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
72 return type_; |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
73 } |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
74 }; |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
75 |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
76 ServerContext& context_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
77 bool hasRemainingLevel_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
78 ResourceType remainingType_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
79 std::string remainingPublicId_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
80 std::list<FileToRemove> pendingFilesToRemove_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
81 std::list<ServerIndexChange> pendingChanges_; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
82 uint64_t sizeOfFilesToRemove_; |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
83 uint64_t sizeOfAddedAttachments_; |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
84 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
85 void Reset() |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
86 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
87 sizeOfFilesToRemove_ = 0; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
88 hasRemainingLevel_ = false; |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4590
diff
changeset
|
89 remainingType_ = ResourceType_Instance; // dummy initialization |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
90 pendingFilesToRemove_.clear(); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
91 pendingChanges_.clear(); |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
92 sizeOfAddedAttachments_ = 0; |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
93 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
94 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
95 void CommitFilesToRemove() |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
96 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
97 for (std::list<FileToRemove>::const_iterator |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
98 it = pendingFilesToRemove_.begin(); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
99 it != pendingFilesToRemove_.end(); ++it) |
1189
6b9b02a16e99
NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1177
diff
changeset
|
100 { |
3702
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
101 try |
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
102 { |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
5061
diff
changeset
|
103 context_.RemoveFile(it->GetUuid(), it->GetContentType(), it->GetCustomData()); |
3702
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
104 } |
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
105 catch (OrthancException& e) |
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
106 { |
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
107 LOG(ERROR) << "Unable to remove an attachment from the storage area: " |
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
108 << it->GetUuid() << " (type: " << EnumerationToString(it->GetContentType()) << ")"; |
643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3699
diff
changeset
|
109 } |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
110 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
111 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
112 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
113 void CommitChanges() |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
114 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
115 for (std::list<ServerIndexChange>::const_iterator |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
116 it = pendingChanges_.begin(); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
117 it != pendingChanges_.end(); ++it) |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
118 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
119 context_.SignalChange(*it); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
120 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
121 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
122 |
4590
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
123 public: |
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
124 explicit TransactionContext(ServerContext& context) : |
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
125 context_(context) |
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
126 { |
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
127 Reset(); |
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
128 assert(ResourceType_Patient < ResourceType_Study && |
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
129 ResourceType_Study < ResourceType_Series && |
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
130 ResourceType_Series < ResourceType_Instance); |
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
131 } |
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
132 |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
133 virtual void SignalRemainingAncestor(ResourceType parentType, |
4571
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
134 const std::string& publicId) ORTHANC_OVERRIDE |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
135 { |
4268
0ae2ca210077
new macro TLOG() to replace VLOG() for trace logs with a category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4263
diff
changeset
|
136 LOG(TRACE) << "Remaining ancestor \"" << publicId << "\" (" << parentType << ")"; |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
137 |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
138 if (hasRemainingLevel_) |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
139 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
140 if (parentType < remainingType_) |
1189
6b9b02a16e99
NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1177
diff
changeset
|
141 { |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
142 remainingType_ = parentType; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
143 remainingPublicId_ = publicId; |
1191
d49505e377e3
demo of OnChangeCallback in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1189
diff
changeset
|
144 } |
1158 | 145 } |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
146 else |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
147 { |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
148 hasRemainingLevel_ = true; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
149 remainingType_ = parentType; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
150 remainingPublicId_ = publicId; |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
151 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
152 } |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
153 |
4571
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
154 virtual void SignalAttachmentDeleted(const FileInfo& info) ORTHANC_OVERRIDE |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
155 { |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
156 assert(Toolbox::IsUuid(info.GetUuid())); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
157 pendingFilesToRemove_.push_back(FileToRemove(info)); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
158 sizeOfFilesToRemove_ += info.GetCompressedSize(); |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
159 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
160 |
4571
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
161 virtual void SignalResourceDeleted(ResourceType type, |
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
162 const std::string& publicId) ORTHANC_OVERRIDE |
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
163 { |
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
164 SignalChange(ServerIndexChange(ChangeType_Deleted, type, publicId)); |
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
165 } |
9224e107d613
simplifying IDatabaseListener::SignalChange() as IDatabaseListener::SignalResourceDeleted()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4570
diff
changeset
|
166 |
4584
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
167 virtual void SignalChange(const ServerIndexChange& change) ORTHANC_OVERRIDE |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
168 { |
4268
0ae2ca210077
new macro TLOG() to replace VLOG() for trace logs with a category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4263
diff
changeset
|
169 LOG(TRACE) << "Change related to resource " << change.GetPublicId() << " of type " |
0ae2ca210077
new macro TLOG() to replace VLOG() for trace logs with a category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4263
diff
changeset
|
170 << EnumerationToString(change.GetResourceType()) << ": " |
0ae2ca210077
new macro TLOG() to replace VLOG() for trace logs with a category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4263
diff
changeset
|
171 << EnumerationToString(change.GetChangeType()); |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
172 |
4590
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
173 pendingChanges_.push_back(change); |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
174 } |
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
175 |
4584
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
176 virtual void SignalAttachmentsAdded(uint64_t compressedSize) ORTHANC_OVERRIDE |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
177 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
178 sizeOfAddedAttachments_ += compressedSize; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
179 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
180 |
4584
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
181 virtual bool LookupRemainingLevel(std::string& remainingPublicId /* out */, |
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
182 ResourceType& remainingLevel /* out */) ORTHANC_OVERRIDE |
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
183 { |
4590
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
184 if (hasRemainingLevel_) |
4584
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
185 { |
4590
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
186 remainingPublicId = remainingPublicId_; |
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
187 remainingLevel = remainingType_; |
4584
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
188 return true; |
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
189 } |
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
190 else |
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
191 { |
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
192 return false; |
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
193 } |
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
194 }; |
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
195 |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
196 virtual void MarkAsUnstable(ResourceType type, |
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
197 int64_t id, |
4584
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
198 const std::string& publicId) ORTHANC_OVERRIDE |
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
199 { |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
200 context_.GetIndex().MarkAsUnstable(type, id, publicId); |
4584
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
201 } |
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
202 |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
203 virtual bool IsUnstableResource(ResourceType type, |
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
204 int64_t id) ORTHANC_OVERRIDE |
4584
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
205 { |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
206 return context_.GetIndex().IsUnstableResource(type, id); |
4584
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
207 } |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
208 |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
209 virtual void Commit() ORTHANC_OVERRIDE |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
210 { |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
211 // We can remove the files once the SQLite transaction has |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
212 // been successfully committed. Some files might have to be |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
213 // deleted because of recycling. |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
214 CommitFilesToRemove(); |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
215 |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
216 // Send all the pending changes to the Orthanc plugins |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
217 CommitChanges(); |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
218 } |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
219 |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
220 virtual int64_t GetCompressedSizeDelta() ORTHANC_OVERRIDE |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
221 { |
4590
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
222 return (static_cast<int64_t>(sizeOfAddedAttachments_) - |
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
223 static_cast<int64_t>(sizeOfFilesToRemove_)); |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
224 } |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
225 }; |
0 | 226 |
227 | |
4585
f0bdd99f3d81
created a ITransactionContextFactory around ServerIndex::Listener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4584
diff
changeset
|
228 class ServerIndex::TransactionContextFactory : public ITransactionContextFactory |
f0bdd99f3d81
created a ITransactionContextFactory around ServerIndex::Listener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4584
diff
changeset
|
229 { |
f0bdd99f3d81
created a ITransactionContextFactory around ServerIndex::Listener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4584
diff
changeset
|
230 private: |
4590
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
231 ServerContext& context_; |
4585
f0bdd99f3d81
created a ITransactionContextFactory around ServerIndex::Listener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4584
diff
changeset
|
232 |
f0bdd99f3d81
created a ITransactionContextFactory around ServerIndex::Listener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4584
diff
changeset
|
233 public: |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4590
diff
changeset
|
234 explicit TransactionContextFactory(ServerContext& context) : |
4590
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
235 context_(context) |
4585
f0bdd99f3d81
created a ITransactionContextFactory around ServerIndex::Listener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4584
diff
changeset
|
236 { |
f0bdd99f3d81
created a ITransactionContextFactory around ServerIndex::Listener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4584
diff
changeset
|
237 } |
f0bdd99f3d81
created a ITransactionContextFactory around ServerIndex::Listener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4584
diff
changeset
|
238 |
f0bdd99f3d81
created a ITransactionContextFactory around ServerIndex::Listener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4584
diff
changeset
|
239 virtual ITransactionContext* Create() |
f0bdd99f3d81
created a ITransactionContextFactory around ServerIndex::Listener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4584
diff
changeset
|
240 { |
4594
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
241 // There can be concurrent calls to this method, which is not an |
d494b4f1103e
removed the global database mutex from ServerIndex and StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4591
diff
changeset
|
242 // issue because we simply create an object |
4590
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
243 return new TransactionContext(context_); |
4585
f0bdd99f3d81
created a ITransactionContextFactory around ServerIndex::Listener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4584
diff
changeset
|
244 } |
f0bdd99f3d81
created a ITransactionContextFactory around ServerIndex::Listener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4584
diff
changeset
|
245 }; |
f0bdd99f3d81
created a ITransactionContextFactory around ServerIndex::Listener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4584
diff
changeset
|
246 |
f0bdd99f3d81
created a ITransactionContextFactory around ServerIndex::Listener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4584
diff
changeset
|
247 |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
248 class ServerIndex::UnstableResourcePayload |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
249 { |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
250 private: |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
251 std::string publicId_; |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
252 boost::posix_time::ptime time_; |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
253 |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
254 public: |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
255 UnstableResourcePayload() |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
256 { |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
257 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
258 |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
259 explicit UnstableResourcePayload(const std::string& publicId) : |
4205 | 260 publicId_(publicId), |
261 time_(boost::posix_time::second_clock::local_time()) | |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
262 { |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
263 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
264 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
265 unsigned int GetAge() const |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
266 { |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
267 return (boost::posix_time::second_clock::local_time() - time_).total_seconds(); |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
268 } |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
269 |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
270 const std::string& GetPublicId() const |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
271 { |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
272 return publicId_; |
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
273 } |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
274 }; |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
275 |
5661 | 276 void ServerIndex::UpdateStatisticsThread(ServerIndex* that, |
277 unsigned int threadSleepGranularityMilliseconds) | |
278 { | |
279 Logging::SetCurrentThreadName("DB-STATS"); | |
280 | |
5819 | 281 static const unsigned int SLEEP_SECONDS = 10; |
5661 | 282 |
283 if (threadSleepGranularityMilliseconds > 1000) | |
284 { | |
285 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
286 } | |
287 | |
288 LOG(INFO) << "Starting the update statistics thread (sleep = " << SLEEP_SECONDS << " seconds)"; | |
289 | |
290 unsigned int count = 0; | |
291 unsigned int countThreshold = (1000 * SLEEP_SECONDS) / threadSleepGranularityMilliseconds; | |
292 | |
293 while (!that->done_) | |
294 { | |
295 boost::this_thread::sleep(boost::posix_time::milliseconds(threadSleepGranularityMilliseconds)); | |
296 count++; | |
297 | |
298 if (count >= countThreshold) | |
299 { | |
300 uint64_t diskSize, uncompressedSize, countPatients, countStudies, countSeries, countInstances; | |
301 that->GetGlobalStatistics(diskSize, uncompressedSize, countPatients, countStudies, countSeries, countInstances); | |
302 | |
303 count = 0; | |
304 } | |
305 } | |
306 | |
307 LOG(INFO) << "Stopping the update statistics thread"; | |
308 } | |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
309 |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
310 void ServerIndex::FlushThread(ServerIndex* that, |
4580
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
311 unsigned int threadSleepGranularityMilliseconds) |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
312 { |
5450
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5430
diff
changeset
|
313 Logging::SetCurrentThreadName("DB-FLUSH"); |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5430
diff
changeset
|
314 |
1102
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1006
diff
changeset
|
315 // By default, wait for 10 seconds before flushing |
4580
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
316 static const unsigned int SLEEP_SECONDS = 10; |
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
317 |
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
318 if (threadSleepGranularityMilliseconds > 1000) |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
319 { |
4580
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
320 throw OrthancException(ErrorCode_ParameterOutOfRange); |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
321 } |
4580
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
322 |
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
323 LOG(INFO) << "Starting the database flushing thread (sleep = " << SLEEP_SECONDS << " seconds)"; |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
324 |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
325 unsigned int count = 0; |
4580
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
326 unsigned int countThreshold = (1000 * SLEEP_SECONDS) / threadSleepGranularityMilliseconds; |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
327 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
328 while (!that->done_) |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
329 { |
4580
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
330 boost::this_thread::sleep(boost::posix_time::milliseconds(threadSleepGranularityMilliseconds)); |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
331 count++; |
4580
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
332 |
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
333 if (count >= countThreshold) |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
334 { |
4580
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
335 Logging::Flush(); |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
336 that->FlushToDisk(); |
4580
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
337 |
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
338 count = 0; |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
339 } |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
340 } |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
341 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
342 LOG(INFO) << "Stopping the database flushing thread"; |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
343 } |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
344 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
345 |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
346 bool ServerIndex::IsUnstableResource(ResourceType type, |
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
347 int64_t id) |
4554 | 348 { |
4584
b25941dcdbbe
ITransactionContext to uncouple ServerIndex from database wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4583
diff
changeset
|
349 boost::mutex::scoped_lock lock(monitoringMutex_); |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
350 return unstableResources_.Contains(std::make_pair(type, id)); |
4554 | 351 } |
352 | |
1237 | 353 |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
354 ServerIndex::ServerIndex(ServerContext& context, |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
355 IDatabaseWrapper& db, |
5785 | 356 unsigned int threadSleepGranularityMilliseconds, |
357 bool readOnly) : | |
358 StatelessDatabaseOperations(db, readOnly), | |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
359 done_(false), |
5061
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
360 maximumStorageMode_(MaxStorageMode_Recycle), |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
361 maximumStorageSize_(0), |
5817 | 362 maximumPatients_(0), |
363 readOnly_(readOnly) | |
186
f68c039b0571
preparing refactoring of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
364 { |
4590
4a0bf1019335
simplification of ServerIndex::Listener as ServerIndex::TransactionContext
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4589
diff
changeset
|
365 SetTransactionContextFactory(new TransactionContextFactory(context)); |
4585
f0bdd99f3d81
created a ITransactionContextFactory around ServerIndex::Listener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4584
diff
changeset
|
366 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
367 // Initial recycling if the parameters have changed since the last |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
368 // execution of Orthanc |
5785 | 369 if (!readOnly) |
5783
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
370 { |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
371 StandaloneRecycling(maximumStorageMode_, maximumStorageSize_, maximumPatients_); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
372 } |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
373 |
5661 | 374 // For some DB engines (like SQLite), make sure we flush the DB to disk at regular interval |
5455
176bc05f85f4
DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
Alain Mazy <am@osimis.io>
parents:
5450
diff
changeset
|
375 if (GetDatabaseCapabilities().HasFlushToDisk()) |
1306
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1305
diff
changeset
|
376 { |
5786 | 377 if (readOnly) |
5783
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
378 { |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
379 LOG(WARNING) << "READ-ONLY SYSTEM: not starting the flush disk thread"; |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
380 } |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
381 else |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
382 { |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
383 flushThread_ = boost::thread(FlushThread, this, threadSleepGranularityMilliseconds); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
384 } |
1306
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1305
diff
changeset
|
385 } |
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1305
diff
changeset
|
386 |
5661 | 387 // For some DB plugins that implements the UpdateAndGetStatistics function, updating |
388 // the statistics can take quite some time if you have not done it for a long time | |
389 // -> make sure they are updated at regular interval | |
390 if (GetDatabaseCapabilities().HasUpdateAndGetStatistics()) | |
391 { | |
5786 | 392 if (readOnly) |
5783
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
393 { |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
394 LOG(WARNING) << "READ-ONLY SYSTEM: not starting the UpdateStatisticsThread"; |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
395 } |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
396 else |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
397 { |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
398 updateStatisticsThread_ = boost::thread(UpdateStatisticsThread, this, threadSleepGranularityMilliseconds); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
399 } |
5661 | 400 } |
401 | |
5786 | 402 if (readOnly) |
5783
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
403 { |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
404 LOG(WARNING) << "READ-ONLY SYSTEM: not starting the unstable resources monitor thread"; |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
405 } |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
406 else |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
407 { |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
408 unstableResourcesMonitorThread_ = boost::thread |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
409 (UnstableResourcesMonitorThread, this, threadSleepGranularityMilliseconds); |
56352ae88120
wip: new ReadOnly configuration
Alain Mazy <am@orthanc.team>
parents:
5661
diff
changeset
|
410 } |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
411 } |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
412 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
413 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
414 ServerIndex::~ServerIndex() |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
415 { |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
416 if (!done_) |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
417 { |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
418 LOG(ERROR) << "INTERNAL ERROR: ServerIndex::Stop() should be invoked manually to avoid mess in the destruction order!"; |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
419 Stop(); |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
420 } |
0 | 421 } |
422 | |
423 | |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
424 void ServerIndex::Stop() |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
425 { |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
426 if (!done_) |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
427 { |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
428 done_ = true; |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
429 |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
430 if (flushThread_.joinable()) |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
431 { |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
432 flushThread_.join(); |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
433 } |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
434 |
5661 | 435 if (updateStatisticsThread_.joinable()) |
436 { | |
437 updateStatisticsThread_.join(); | |
438 } | |
439 | |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
440 if (unstableResourcesMonitorThread_.joinable()) |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
441 { |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
442 unstableResourcesMonitorThread_.join(); |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
443 } |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
444 } |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
445 } |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
446 |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
447 |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
448 void ServerIndex::SetMaximumPatientCount(unsigned int count) |
268
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
449 { |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
450 { |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
451 boost::mutex::scoped_lock lock(monitoringMutex_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
452 maximumPatients_ = count; |
3020
d207f6ac1f86
tracking disk size by the database engine to ensure consistency across transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3019
diff
changeset
|
453 |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
454 if (count == 0) |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
455 { |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
456 LOG(WARNING) << "No limit on the number of stored patients"; |
4575
e23bacd4fffc
clarifications in ServerIndex::Recycle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4574
diff
changeset
|
457 } |
e23bacd4fffc
clarifications in ServerIndex::Recycle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4574
diff
changeset
|
458 else |
e23bacd4fffc
clarifications in ServerIndex::Recycle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4574
diff
changeset
|
459 { |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
460 LOG(WARNING) << "At most " << count << " patients will be stored"; |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
461 } |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
462 } |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
463 |
5061
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
464 StandaloneRecycling(maximumStorageMode_, maximumStorageSize_, maximumPatients_); |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
465 } |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
466 |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
467 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
468 void ServerIndex::SetMaximumStorageSize(uint64_t size) |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
469 { |
270
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
470 { |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
471 boost::mutex::scoped_lock lock(monitoringMutex_); |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
472 maximumStorageSize_ = size; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
473 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
474 if (size == 0) |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
475 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
476 LOG(WARNING) << "No limit on the size of the storage area"; |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
477 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
478 else |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
479 { |
5430
b83192e7ad10
Now displaying timings when reading from/writing to disk in the verbose logs
Alain Mazy <am@osimis.io>
parents:
5316
diff
changeset
|
480 LOG(WARNING) << "At most " << Toolbox::GetHumanFileSize(size) << " will be used for the storage area"; |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
481 } |
270
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
482 } |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
483 |
5061
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
484 StandaloneRecycling(maximumStorageMode_, maximumStorageSize_, maximumPatients_); |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
485 } |
272
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
486 |
5061
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
487 void ServerIndex::SetMaximumStorageMode(MaxStorageMode mode) |
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
488 { |
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
489 { |
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
490 boost::mutex::scoped_lock lock(monitoringMutex_); |
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
491 maximumStorageMode_ = mode; |
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
492 |
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
493 if (mode == MaxStorageMode_Recycle) |
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
494 { |
5467
68e9f7815fb8
Clarified recycle/reject + protection
Alain Mazy <am@osimis.io>
parents:
5450
diff
changeset
|
495 if (maximumStorageSize_ > 0 || maximumPatients_ > 0) |
68e9f7815fb8
Clarified recycle/reject + protection
Alain Mazy <am@osimis.io>
parents:
5450
diff
changeset
|
496 { |
68e9f7815fb8
Clarified recycle/reject + protection
Alain Mazy <am@osimis.io>
parents:
5450
diff
changeset
|
497 LOG(WARNING) << "Maximum Storage mode: Recycle"; |
68e9f7815fb8
Clarified recycle/reject + protection
Alain Mazy <am@osimis.io>
parents:
5450
diff
changeset
|
498 } |
5061
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
499 } |
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
500 else |
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
501 { |
5467
68e9f7815fb8
Clarified recycle/reject + protection
Alain Mazy <am@osimis.io>
parents:
5450
diff
changeset
|
502 if (maximumStorageSize_ > 0 || maximumPatients_ > 0) |
68e9f7815fb8
Clarified recycle/reject + protection
Alain Mazy <am@osimis.io>
parents:
5450
diff
changeset
|
503 { |
68e9f7815fb8
Clarified recycle/reject + protection
Alain Mazy <am@osimis.io>
parents:
5450
diff
changeset
|
504 LOG(WARNING) << "Maximum Storage mode: Reject"; |
68e9f7815fb8
Clarified recycle/reject + protection
Alain Mazy <am@osimis.io>
parents:
5450
diff
changeset
|
505 } |
5061
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
506 } |
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
507 } |
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
508 |
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
509 StandaloneRecycling(maximumStorageMode_, maximumStorageSize_, maximumPatients_); |
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
510 } |
272
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
511 |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
512 void ServerIndex::UnstableResourcesMonitorThread(ServerIndex* that, |
4580
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
513 unsigned int threadSleepGranularityMilliseconds) |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
514 { |
5450
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5430
diff
changeset
|
515 Logging::SetCurrentThreadName("UNSTABLE-MON"); |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5430
diff
changeset
|
516 |
2940
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
517 int stableAge; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
518 |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
519 { |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
520 OrthancConfiguration::ReaderLock lock; |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
521 stableAge = lock.GetConfiguration().GetUnsignedIntegerParameter("StableAge", 60); |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
522 } |
4767d36679ed
refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2898
diff
changeset
|
523 |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
524 if (stableAge <= 0) |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
525 { |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
526 stableAge = 60; |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
527 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
528 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
529 LOG(INFO) << "Starting the monitor for stable resources (stable age = " << stableAge << ")"; |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
530 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
531 while (!that->done_) |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
532 { |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
533 // Check for stable resources each few seconds |
4580
49f6b9a2b9f5
remove the only use of GlobalProperty_FlushSleep
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4579
diff
changeset
|
534 boost::this_thread::sleep(boost::posix_time::milliseconds(threadSleepGranularityMilliseconds)); |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
535 |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
536 for (;;) |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
537 { |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
538 UnstableResourcePayload stablePayload; |
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
539 ResourceType stableLevel; |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
540 int64_t stableId; |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
541 |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
542 { |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
543 boost::mutex::scoped_lock lock(that->monitoringMutex_); |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
544 |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
545 if (!that->unstableResources_.IsEmpty() && |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
546 that->unstableResources_.GetOldestPayload().GetAge() > static_cast<unsigned int>(stableAge)) |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
547 { |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
548 // This DICOM resource has not received any new instance for |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
549 // some time. It can be considered as stable. |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
550 std::pair<ResourceType, int64_t> stableResource = that->unstableResources_.RemoveOldest(stablePayload); |
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
551 stableLevel = stableResource.first; |
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
552 stableId = stableResource.second; |
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
553 //LOG(TRACE) << "Stable resource: " << EnumerationToString(stablePayload.GetResourceType()) << " " << stableId; |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
554 } |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
555 else |
513 | 556 { |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
557 // No more stable DICOM resource, leave the internal loop |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
558 break; |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
559 } |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
560 } |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
561 |
4614
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
562 try |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
563 { |
4614
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
564 /** |
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
565 * WARNING: Don't protect the calls to "LogChange()" using |
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
566 * "monitoringMutex_", as this could lead to deadlocks in |
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
567 * other threads (typically, if "Store()" is being running in |
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
568 * another thread, which leads to calls to "MarkAsUnstable()", |
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
569 * which leads to two lockings of "monitoringMutex_"). |
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
570 **/ |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
571 switch (stableLevel) |
4614
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
572 { |
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
573 case ResourceType_Patient: |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
574 that->LogChange(stableId, ChangeType_StablePatient, stablePayload.GetPublicId(), ResourceType_Patient); |
4614
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
575 break; |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
576 |
4614
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
577 case ResourceType_Study: |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
578 that->LogChange(stableId, ChangeType_StableStudy, stablePayload.GetPublicId(), ResourceType_Study); |
4614
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
579 break; |
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
580 |
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
581 case ResourceType_Series: |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
582 that->LogChange(stableId, ChangeType_StableSeries, stablePayload.GetPublicId(), ResourceType_Series); |
4614
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
583 break; |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
584 |
4614
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
585 default: |
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
586 throw OrthancException(ErrorCode_InternalError); |
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
587 } |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
588 } |
4614
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
589 catch (OrthancException& e) |
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
590 { |
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
591 LOG(ERROR) << "Cannot log a change about a stable resource into the database"; |
67d112ef680f
added missing try/catch
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4594
diff
changeset
|
592 } |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
593 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
594 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
595 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
596 LOG(INFO) << "Closing the monitor thread for stable resources"; |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
597 } |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
598 |
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
599 |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
600 void ServerIndex::MarkAsUnstable(ResourceType type, |
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
601 int64_t id, |
1177
5b2d8c280ac2
Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
602 const std::string& publicId) |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
603 { |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
604 assert(type == ResourceType_Patient || |
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
605 type == ResourceType_Study || |
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
606 type == ResourceType_Series); |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
607 |
4581
bb3c82b8f373
transient introduction of ServerIndex::databaseMutex_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4580
diff
changeset
|
608 { |
bb3c82b8f373
transient introduction of ServerIndex::databaseMutex_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4580
diff
changeset
|
609 boost::mutex::scoped_lock lock(monitoringMutex_); |
5603
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
610 UnstableResourcePayload payload(publicId); |
b2a97dfd719f
monitoring of stable resources now also considers the resource type
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5497
diff
changeset
|
611 unstableResources_.AddOrMakeMostRecent(std::make_pair(type, id), payload); |
4581
bb3c82b8f373
transient introduction of ServerIndex::databaseMutex_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4580
diff
changeset
|
612 //LOG(INFO) << "Unstable resource: " << EnumerationToString(type) << " " << id; |
bb3c82b8f373
transient introduction of ServerIndex::databaseMutex_
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4580
diff
changeset
|
613 } |
511
3b735fdf320b
monitoring of stable patients/studies/series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
440
diff
changeset
|
614 } |
521 | 615 |
616 | |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
617 StoreStatus ServerIndex::Store(std::map<MetadataType, std::string>& instanceMetadata, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
618 const DicomMap& dicomSummary, |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
619 const ServerIndex::Attachments& attachments, |
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
620 const ServerIndex::MetadataMap& metadata, |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
621 const DicomInstanceOrigin& origin, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
622 bool overwrite, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
623 bool hasTransferSyntax, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
624 DicomTransferSyntax transferSyntax, |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
625 bool hasPixelDataOffset, |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
626 uint64_t pixelDataOffset, |
5316
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
627 ValueRepresentation pixelDataVR, |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4892
diff
changeset
|
628 bool isReconstruct) |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
629 { |
4579 | 630 uint64_t maximumStorageSize; |
631 unsigned int maximumPatients; | |
5061
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
632 MaxStorageMode maximumStorageMode; |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
633 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
634 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
635 boost::mutex::scoped_lock lock(monitoringMutex_); |
4579 | 636 maximumStorageSize = maximumStorageSize_; |
637 maximumPatients = maximumPatients_; | |
5061
e95fadefeb72
new MaximumStorageMode configuration
Alain Mazy <am@osimis.io>
parents:
5044
diff
changeset
|
638 maximumStorageMode = maximumStorageMode_; |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
639 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
640 |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
641 return StatelessDatabaseOperations::Store( |
5044
6fed78e13233
Refactored DicomMap to handle sequences when needed
Alain Mazy <am@osimis.io>
parents:
5039
diff
changeset
|
642 instanceMetadata, dicomSummary, attachments, metadata, origin, overwrite, hasTransferSyntax, |
5316
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
643 transferSyntax, hasPixelDataOffset, pixelDataOffset, pixelDataVR, maximumStorageMode, |
03501a258d9e
added instance metadata "PixelDataVR"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
644 maximumStorageSize, maximumPatients, isReconstruct); |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
645 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
646 |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
647 |
4627
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4614
diff
changeset
|
648 StoreStatus ServerIndex::AddAttachment(int64_t& newRevision, |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4614
diff
changeset
|
649 const FileInfo& attachment, |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4614
diff
changeset
|
650 const std::string& publicId, |
f7d5372b59b3
handling revisions of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4614
diff
changeset
|
651 bool hasOldRevision, |
4640
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
652 int64_t oldRevision, |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
653 const std::string& oldMD5) |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
654 { |
4579 | 655 uint64_t maximumStorageSize; |
656 unsigned int maximumPatients; | |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
657 |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
658 { |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
659 boost::mutex::scoped_lock lock(monitoringMutex_); |
4579 | 660 maximumStorageSize = maximumStorageSize_; |
661 maximumPatients = maximumPatients_; | |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
662 } |
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
663 |
4587
888868a5dc4e
ServerIndex now uses StatelessDatabaseOperations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4586
diff
changeset
|
664 return StatelessDatabaseOperations::AddAttachment( |
4640
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
665 newRevision, attachment, publicId, maximumStorageSize, maximumPatients, |
66109d24d26e
"ETag" headers for metadata and attachments now allow strong comparison (MD5 is included)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4627
diff
changeset
|
666 hasOldRevision, oldRevision, oldMD5); |
4577
a114a5db2afe
end of refactoring read-write transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4576
diff
changeset
|
667 } |
0 | 668 } |