Mercurial > hg > orthanc
diff OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp @ 4587:888868a5dc4e db-changes
ServerIndex now uses StatelessDatabaseOperations
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 Mar 2021 15:59:03 +0100 |
parents | 1d96fe7e054e |
children | bec74e29f86b |
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Tue Mar 09 18:24:59 2021 +0100 +++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp Wed Mar 10 15:59:03 2021 +0100 @@ -668,8 +668,24 @@ StatelessDatabaseOperations::StatelessDatabaseOperations(IDatabaseWrapper& db) : db_(db), maxRetries_(10), - mainDicomTagsRegistry_(new MainDicomTagsRegistry) + mainDicomTagsRegistry_(new MainDicomTagsRegistry), + hasFlushToDisk_(db.HasFlushToDisk()) + { + } + + + void StatelessDatabaseOperations::FlushToDisk() { + boost::mutex::scoped_lock lock(databaseMutex_); + + try + { + db_.FlushToDisk(); + } + catch (OrthancException&) + { + LOG(ERROR) << "Cannot flush the SQLite database to the disk (is your filesystem full?)"; + } } @@ -2415,21 +2431,25 @@ } - void StatelessDatabaseOperations::LogChange(ChangeType changeType, + void StatelessDatabaseOperations::LogChange(int64_t internalId, + ChangeType changeType, const std::string& publicId, ResourceType level) { class Operations : public IReadWriteOperations { private: + int64_t internalId_; ChangeType changeType_; const std::string& publicId_; ResourceType level_; public: - Operations(ChangeType changeType, + Operations(int64_t internalId, + ChangeType changeType, const std::string& publicId, ResourceType level) : + internalId_(internalId), changeType_(changeType), publicId_(publicId), level_(level) @@ -2440,13 +2460,18 @@ { int64_t id; ResourceType type; - if (transaction.LookupResource(id, type, publicId_)) + if (transaction.LookupResource(id, type, publicId_) && + id == internalId_) { - // Make sure that the resource is still existing. Ignore if - // the resource has been deleted, because this function - // might e.g. be called from - // "StatelessDatabaseOperations::UnstableResourcesMonitorThread()" (for - // which a deleted resource not an error case) + /** + * Make sure that the resource is still existing, with the + * same internal ID, which indicates the absence of bouncing + * (if deleting then recreating the same resource). Don't + * throw an exception if the resource has been deleted, + * because this function might e.g. be called from + * "StatelessDatabaseOperations::UnstableResourcesMonitorThread()" + * (for which a deleted resource is *not* an error case). + **/ if (type == level_) { transaction.LogChange(id, changeType_, type, publicId_); @@ -2460,7 +2485,7 @@ } }; - Operations operations(changeType, publicId, level); + Operations operations(internalId, changeType, publicId, level); Apply(operations); }