annotate PostgreSQL/Plugins/IndexPlugin.cpp @ 493:0a8168522165

news
author Alain Mazy <am@osimis.io>
date Fri, 22 Mar 2024 15:27:59 +0100
parents af6998ed73dd
children 54d518dcd74a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
459
ecd0b719cff5 update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium
ecd0b719cff5 update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU Affero General Public License
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * Affero General Public License for more details.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU Affero General Public License
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "PostgreSQLIndex.h"
24
17f849b2af34 sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
24 #include "../../Framework/Plugins/PluginInitialization.h"
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
26 #include <Logging.h>
267
ece4663dedde Fix issue #193
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
27 #include <Toolbox.h>
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
381
9cde77ca9ad9 initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
29 #include <google/protobuf/any.h>
9cde77ca9ad9 initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
30
492
af6998ed73dd fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 459
diff changeset
31 #define ORTHANC_PLUGIN_NAME "postgresql-index"
af6998ed73dd fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 459
diff changeset
32
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 extern "C"
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
381
9cde77ca9ad9 initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
38 GOOGLE_PROTOBUF_VERIFY_VERSION;
9cde77ca9ad9 initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
39
492
af6998ed73dd fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 459
diff changeset
40 if (!OrthancDatabases::InitializePlugin(context, ORTHANC_PLUGIN_NAME, "PostgreSQL", true))
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 return -1;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
267
ece4663dedde Fix issue #193
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
45 Orthanc::Toolbox::InitializeOpenSsl();
ece4663dedde Fix issue #193
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
46
62
eedd082355f9 fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 28
diff changeset
47 OrthancPlugins::OrthancConfiguration configuration;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 if (!configuration.IsSection("PostgreSQL"))
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 LOG(WARNING) << "No available configuration for the PostgreSQL index plugin";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 return 0;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 OrthancPlugins::OrthancConfiguration postgresql;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 configuration.GetSection(postgresql, "PostgreSQL");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 bool enable;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 if (!postgresql.LookupBooleanValue(enable, "EnableIndex") ||
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 !enable)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 LOG(WARNING) << "The PostgreSQL index is currently disabled, set \"EnableIndex\" "
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 << "to \"true\" in the \"PostgreSQL\" section of the configuration file of Orthanc";
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 return 0;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 try
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
253
3bc442765b88 new configuration option: "IndexConnectionsCount"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
69 const size_t countConnections = postgresql.GetUnsignedIntegerValue("IndexConnectionsCount", 1);
3bc442765b88 new configuration option: "IndexConnectionsCount"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
70
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 OrthancDatabases::PostgreSQLParameters parameters(postgresql);
234
d1b124d116c1 PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 222
diff changeset
72 OrthancDatabases::IndexBackend::Register(
253
3bc442765b88 new configuration option: "IndexConnectionsCount"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
73 new OrthancDatabases::PostgreSQLIndex(context, parameters), countConnections,
3bc442765b88 new configuration option: "IndexConnectionsCount"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 234
diff changeset
74 parameters.GetMaxConnectionRetries());
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
2
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
76 catch (Orthanc::OrthancException& e)
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
2
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
78 LOG(ERROR) << e.What();
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
79 return -1;
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
80 }
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
81 catch (...)
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
82 {
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 0
diff changeset
83 LOG(ERROR) << "Native exception while initializing the plugin";
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 return -1;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 return 0;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 10
diff changeset
93 LOG(WARNING) << "PostgreSQL index is finalizing";
222
c8e06b41feec refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 213
diff changeset
94 OrthancDatabases::IndexBackend::Finalize();
267
ece4663dedde Fix issue #193
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 253
diff changeset
95 Orthanc::Toolbox::FinalizeOpenSsl();
381
9cde77ca9ad9 initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 359
diff changeset
96 google::protobuf::ShutdownProtobufLibrary();
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
492
af6998ed73dd fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 459
diff changeset
102 return ORTHANC_PLUGIN_NAME;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 return ORTHANC_PLUGIN_VERSION;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }