comparison OrthancServer/Sources/ServerIndex.cpp @ 4576:f6cd49af7526 db-changes

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 08 Mar 2021 18:42:13 +0100
parents e23bacd4fffc
children a114a5db2afe
comparison
equal deleted inserted replaced
4575:e23bacd4fffc 4576:f6cd49af7526
249 { 249 {
250 private: 250 private:
251 ServerIndex& index_; 251 ServerIndex& index_;
252 std::unique_ptr<IDatabaseWrapper::ITransaction> transaction_; 252 std::unique_ptr<IDatabaseWrapper::ITransaction> transaction_;
253 bool isCommitted_; 253 bool isCommitted_;
254 uint64_t sizeOfAddedAttachments_;
254 255
255 public: 256 public:
256 explicit Transaction(ServerIndex& index, 257 explicit Transaction(ServerIndex& index,
257 TransactionType type) : 258 TransactionType type) :
258 index_(index), 259 index_(index),
259 isCommitted_(false) 260 isCommitted_(false),
261 sizeOfAddedAttachments_(0)
260 { 262 {
261 transaction_.reset(index_.db_.StartTransaction(type)); 263 transaction_.reset(index_.db_.StartTransaction(type));
262 index_.listener_->StartTransaction(); 264 index_.listener_->StartTransaction();
263 } 265 }
264 266
270 { 272 {
271 transaction_->Rollback(); 273 transaction_->Rollback();
272 } 274 }
273 } 275 }
274 276
275 void Commit(uint64_t sizeOfAddedFiles) 277 void SignalAttachmentsAdded(uint64_t compressedSize)
278 {
279 sizeOfAddedAttachments_ += compressedSize;
280 }
281
282 void Commit()
276 { 283 {
277 if (!isCommitted_) 284 if (!isCommitted_)
278 { 285 {
279 int64_t delta = (static_cast<int64_t>(sizeOfAddedFiles) - 286 int64_t delta = (static_cast<int64_t>(sizeOfAddedAttachments_) -
280 static_cast<int64_t>(index_.listener_->GetSizeOfFilesToRemove())); 287 static_cast<int64_t>(index_.listener_->GetSizeOfFilesToRemove()));
281 288
282 transaction_->Commit(delta); 289 transaction_->Commit(delta);
283 290
284 // We can remove the files once the SQLite transaction has 291 // We can remove the files once the SQLite transaction has
953 // Mark the parent resources of this instance as unstable 960 // Mark the parent resources of this instance as unstable
954 MarkAsUnstable(status.seriesId_, ResourceType_Series, hashSeries); 961 MarkAsUnstable(status.seriesId_, ResourceType_Series, hashSeries);
955 MarkAsUnstable(status.studyId_, ResourceType_Study, hashStudy); 962 MarkAsUnstable(status.studyId_, ResourceType_Study, hashStudy);
956 MarkAsUnstable(status.patientId_, ResourceType_Patient, hashPatient); 963 MarkAsUnstable(status.patientId_, ResourceType_Patient, hashPatient);
957 964
958 t.Commit(instanceSize); 965 t.SignalAttachmentsAdded(instanceSize);
966 t.Commit();
959 967
960 return StoreStatus_Success; 968 return StoreStatus_Success;
961 } 969 }
962 catch (OrthancException& e) 970 catch (OrthancException& e)
963 { 971 {
1200 void ServerIndex::StandaloneRecycling() 1208 void ServerIndex::StandaloneRecycling()
1201 { 1209 {
1202 // WARNING: No mutex here, do not include this as a public method 1210 // WARNING: No mutex here, do not include this as a public method
1203 Transaction t(*this, TransactionType_ReadWrite); 1211 Transaction t(*this, TransactionType_ReadWrite);
1204 Recycle(0, ""); 1212 Recycle(0, "");
1205 t.Commit(0); 1213 t.Commit();
1206 } 1214 }
1207 1215
1208 1216
1209 void ServerIndex::UnstableResourcesMonitorThread(ServerIndex* that, 1217 void ServerIndex::UnstableResourcesMonitorThread(ServerIndex* that,
1210 unsigned int threadSleep) 1218 unsigned int threadSleep)
1331 if (IsUserContentType(attachment.GetContentType())) 1339 if (IsUserContentType(attachment.GetContentType()))
1332 { 1340 {
1333 LogChange(resourceId, ChangeType_UpdatedAttachment, resourceType, publicId); 1341 LogChange(resourceId, ChangeType_UpdatedAttachment, resourceType, publicId);
1334 } 1342 }
1335 1343
1336 t.Commit(attachment.GetCompressedSize()); 1344 t.SignalAttachmentsAdded(attachment.GetCompressedSize());
1345 t.Commit();
1337 1346
1338 return StoreStatus_Success; 1347 return StoreStatus_Success;
1339 } 1348 }
1340 1349
1341 1350
1605 Transaction transaction(*this, TransactionType_ReadOnly); // TODO - Only if not "TransactionType_Implicit" 1614 Transaction transaction(*this, TransactionType_ReadOnly); // TODO - Only if not "TransactionType_Implicit"
1606 { 1615 {
1607 ReadOnlyTransaction t(db_); 1616 ReadOnlyTransaction t(db_);
1608 readOperations->Apply(t); 1617 readOperations->Apply(t);
1609 } 1618 }
1610 transaction.Commit(0); 1619 transaction.Commit();
1611 } 1620 }
1612 else 1621 else
1613 { 1622 {
1614 assert(writeOperations != NULL); 1623 assert(writeOperations != NULL);
1615 1624
1617 { 1626 {
1618 assert(listener_.get() != NULL); 1627 assert(listener_.get() != NULL);
1619 ReadWriteTransaction t(db_, *listener_, *this); 1628 ReadWriteTransaction t(db_, *listener_, *this);
1620 writeOperations->Apply(t); 1629 writeOperations->Apply(t);
1621 } 1630 }
1622 transaction.Commit(0); 1631 transaction.Commit();
1623 } 1632 }
1624 1633
1625 return; // Success 1634 return; // Success
1626 } 1635 }
1627 catch (OrthancException& e) 1636 catch (OrthancException& e)