comparison OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp @ 5466:dceed5e3d6a9 pg-transactions

new DB plugin primitive: UpdateAndGetStatistics
author Alain Mazy <am@osimis.io>
date Fri, 15 Dec 2023 17:15:43 +0100
parents 38f1d06875ad
children 26877f4b306f
comparison
equal deleted inserted replaced
5465:2829889bfa57 5466:dceed5e3d6a9
1100 /* out */ uint64_t& countPatients, 1100 /* out */ uint64_t& countPatients,
1101 /* out */ uint64_t& countStudies, 1101 /* out */ uint64_t& countStudies,
1102 /* out */ uint64_t& countSeries, 1102 /* out */ uint64_t& countSeries,
1103 /* out */ uint64_t& countInstances) 1103 /* out */ uint64_t& countInstances)
1104 { 1104 {
1105 class Operations : public ReadOnlyOperationsT6<uint64_t&, uint64_t&, uint64_t&, uint64_t&, uint64_t&, uint64_t&> 1105 // new code that updates and gets all statistics.
1106 // I.e, PostgreSQL now store "changes" to apply to the statistics to prevent row locking
1107 // of the GlobalIntegers table while multiple clients are inserting/deleting new resources.
1108 // Then, the statistics are updated when requested to make sure they are correct.
1109 class Operations : public IReadWriteOperations
1110 {
1111 private:
1112 int64_t diskSize_;
1113 int64_t uncompressedSize_;
1114 int64_t countPatients_;
1115 int64_t countStudies_;
1116 int64_t countSeries_;
1117 int64_t countInstances_;
1118
1119 public:
1120 Operations() :
1121 diskSize_(0),
1122 uncompressedSize_(0),
1123 countPatients_(0),
1124 countStudies_(0),
1125 countSeries_(0),
1126 countInstances_(0)
1127 {
1128 }
1129
1130 void GetValues(uint64_t& diskSize,
1131 uint64_t& uncompressedSize,
1132 uint64_t& countPatients,
1133 uint64_t& countStudies,
1134 uint64_t& countSeries,
1135 uint64_t& countInstances) const
1136 {
1137 diskSize = static_cast<uint64_t>(diskSize_);
1138 uncompressedSize = static_cast<uint64_t>(uncompressedSize_);
1139 countPatients = static_cast<uint64_t>(countPatients_);
1140 countStudies = static_cast<uint64_t>(countStudies_);
1141 countSeries = static_cast<uint64_t>(countSeries_);
1142 countInstances = static_cast<uint64_t>(countInstances_);
1143 }
1144
1145 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
1146 {
1147 transaction.UpdateAndGetStatistics(countPatients_, countStudies_, countSeries_, countInstances_, diskSize_, uncompressedSize_);
1148 }
1149 };
1150
1151 // legacy oprations that reads each entry individualy
1152 class LegacyOperations : public ReadOnlyOperationsT6<uint64_t&, uint64_t&, uint64_t&, uint64_t&, uint64_t&, uint64_t&>
1106 { 1153 {
1107 public: 1154 public:
1108 virtual void ApplyTuple(ReadOnlyTransaction& transaction, 1155 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1109 const Tuple& tuple) ORTHANC_OVERRIDE 1156 const Tuple& tuple) ORTHANC_OVERRIDE
1110 { 1157 {
1114 tuple.get<3>() = transaction.GetResourcesCount(ResourceType_Study); 1161 tuple.get<3>() = transaction.GetResourcesCount(ResourceType_Study);
1115 tuple.get<4>() = transaction.GetResourcesCount(ResourceType_Series); 1162 tuple.get<4>() = transaction.GetResourcesCount(ResourceType_Series);
1116 tuple.get<5>() = transaction.GetResourcesCount(ResourceType_Instance); 1163 tuple.get<5>() = transaction.GetResourcesCount(ResourceType_Instance);
1117 } 1164 }
1118 }; 1165 };
1119 1166
1120 Operations operations; 1167 if (GetDatabaseCapabilities().HasUpdateAndGetStatistics())
1121 operations.Apply(*this, diskSize, uncompressedSize, countPatients, 1168 {
1122 countStudies, countSeries, countInstances); 1169 Operations operations;
1170 Apply(operations);
1171
1172 operations.GetValues(diskSize, uncompressedSize, countPatients, countStudies, countSeries, countInstances);
1173 }
1174 else
1175 {
1176 LegacyOperations operations;
1177 operations.Apply(*this, diskSize, uncompressedSize, countPatients,
1178 countStudies, countSeries, countInstances);
1179 }
1123 } 1180 }
1124 1181
1125 1182
1126 void StatelessDatabaseOperations::GetChanges(Json::Value& target, 1183 void StatelessDatabaseOperations::GetChanges(Json::Value& target,
1127 int64_t since, 1184 int64_t since,