Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 3020:d207f6ac1f86 db-changes
tracking disk size by the database engine to ensure consistency across transactions
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 15 Dec 2018 10:57:18 +0100 |
parents | 8336204d95dc |
children | 039a9d262d64 |
comparison
equal
deleted
inserted
replaced
3019:8336204d95dc | 3020:d207f6ac1f86 |
---|---|
224 isCommitted_(false) | 224 isCommitted_(false) |
225 { | 225 { |
226 transaction_.reset(index_.db_.StartTransaction()); | 226 transaction_.reset(index_.db_.StartTransaction()); |
227 transaction_->Begin(); | 227 transaction_->Begin(); |
228 | 228 |
229 assert(index_.currentStorageSize_ == index_.db_.GetTotalCompressedSize()); | |
230 | |
231 index_.listener_->StartTransaction(); | 229 index_.listener_->StartTransaction(); |
232 } | 230 } |
233 | 231 |
234 ~Transaction() | 232 ~Transaction() |
235 { | 233 { |
252 | 250 |
253 // We can remove the files once the SQLite transaction has | 251 // We can remove the files once the SQLite transaction has |
254 // been successfully committed. Some files might have to be | 252 // been successfully committed. Some files might have to be |
255 // deleted because of recycling. | 253 // deleted because of recycling. |
256 index_.listener_->CommitFilesToRemove(); | 254 index_.listener_->CommitFilesToRemove(); |
257 | |
258 index_.currentStorageSize_ += sizeOfAddedFiles; | |
259 | |
260 assert(index_.currentStorageSize_ >= index_.listener_->GetSizeOfFilesToRemove()); | |
261 index_.currentStorageSize_ -= index_.listener_->GetSizeOfFilesToRemove(); | |
262 | 255 |
263 // Send all the pending changes to the Orthanc plugins | 256 // Send all the pending changes to the Orthanc plugins |
264 index_.listener_->CommitChanges(); | 257 index_.listener_->CommitChanges(); |
265 | 258 |
266 isCommitted_ = true; | 259 isCommitted_ = true; |
550 maximumPatients_(0), | 543 maximumPatients_(0), |
551 overwrite_(false) | 544 overwrite_(false) |
552 { | 545 { |
553 listener_.reset(new Listener(context)); | 546 listener_.reset(new Listener(context)); |
554 db_.SetListener(*listener_); | 547 db_.SetListener(*listener_); |
555 | |
556 currentStorageSize_ = db_.GetTotalCompressedSize(); | |
557 | 548 |
558 // Initial recycling if the parameters have changed since the last | 549 // Initial recycling if the parameters have changed since the last |
559 // execution of Orthanc | 550 // execution of Orthanc |
560 StandaloneRecycling(); | 551 StandaloneRecycling(); |
561 | 552 |
878 void ServerIndex::ComputeStatistics(Json::Value& target) | 869 void ServerIndex::ComputeStatistics(Json::Value& target) |
879 { | 870 { |
880 boost::mutex::scoped_lock lock(mutex_); | 871 boost::mutex::scoped_lock lock(mutex_); |
881 target = Json::objectValue; | 872 target = Json::objectValue; |
882 | 873 |
883 uint64_t cs = currentStorageSize_; | 874 uint64_t cs = db_.GetTotalCompressedSize(); |
884 assert(cs == db_.GetTotalCompressedSize()); | |
885 uint64_t us = db_.GetTotalUncompressedSize(); | 875 uint64_t us = db_.GetTotalUncompressedSize(); |
886 target["TotalDiskSize"] = boost::lexical_cast<std::string>(cs); | 876 target["TotalDiskSize"] = boost::lexical_cast<std::string>(cs); |
887 target["TotalUncompressedSize"] = boost::lexical_cast<std::string>(us); | 877 target["TotalUncompressedSize"] = boost::lexical_cast<std::string>(us); |
888 target["TotalDiskSizeMB"] = static_cast<unsigned int>(cs / MEGA_BYTES); | 878 target["TotalDiskSizeMB"] = static_cast<unsigned int>(cs / MEGA_BYTES); |
889 target["TotalUncompressedSizeMB"] = static_cast<unsigned int>(us / MEGA_BYTES); | 879 target["TotalUncompressedSizeMB"] = static_cast<unsigned int>(us / MEGA_BYTES); |
1370 | 1360 |
1371 bool ServerIndex::IsRecyclingNeeded(uint64_t instanceSize) | 1361 bool ServerIndex::IsRecyclingNeeded(uint64_t instanceSize) |
1372 { | 1362 { |
1373 if (maximumStorageSize_ != 0) | 1363 if (maximumStorageSize_ != 0) |
1374 { | 1364 { |
1375 uint64_t currentSize = currentStorageSize_ - listener_->GetSizeOfFilesToRemove(); | 1365 assert(maximumStorageSize_ >= instanceSize); |
1376 assert(db_.GetTotalCompressedSize() == currentSize); | 1366 |
1377 | 1367 if (db_.IsDiskSizeAbove(maximumStorageSize_ - instanceSize)) |
1378 if (currentSize + instanceSize > maximumStorageSize_) | |
1379 { | 1368 { |
1380 return true; | 1369 return true; |
1381 } | 1370 } |
1382 } | 1371 } |
1383 | 1372 |