Mercurial > hg > orthanc
changeset 5785:b4e7a85cde80 find-refactoring
fix readonly init
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 17 Sep 2024 11:09:06 +0200 |
parents | b0d778f1e66d |
children | 09e337d45d22 |
files | OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerContext.h OrthancServer/Sources/ServerIndex.cpp OrthancServer/Sources/ServerIndex.h OrthancServer/Sources/main.cpp OrthancServer/UnitTestsSources/ServerIndexTests.cpp OrthancServer/UnitTestsSources/ServerJobsTests.cpp |
diffstat | 7 files changed, 28 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerContext.cpp Mon Sep 16 18:57:15 2024 +0200 +++ b/OrthancServer/Sources/ServerContext.cpp Tue Sep 17 11:09:06 2024 +0200 @@ -361,8 +361,9 @@ ServerContext::ServerContext(IDatabaseWrapper& database, IStorageArea& area, bool unitTesting, - size_t maxCompletedJobs) : - index_(*this, database, (unitTesting ? 20 : 500)), + size_t maxCompletedJobs, + bool readOnly) : + index_(*this, database, (unitTesting ? 20 : 500), readOnly), area_(area), compressionEnabled_(false), storeMD5_(true), @@ -388,9 +389,9 @@ ingestTranscodingOfUncompressed_(true), ingestTranscodingOfCompressed_(true), preferredTransferSyntax_(DicomTransferSyntax_LittleEndianExplicit), + readOnly_(readOnly), deidentifyLogs_(false), - serverStartTimeUtc_(boost::posix_time::second_clock::universal_time()), - readOnly_(false) + serverStartTimeUtc_(boost::posix_time::second_clock::universal_time()) { try {
--- a/OrthancServer/Sources/ServerContext.h Mon Sep 16 18:57:15 2024 +0200 +++ b/OrthancServer/Sources/ServerContext.h Tue Sep 17 11:09:06 2024 +0200 @@ -322,7 +322,8 @@ ServerContext(IDatabaseWrapper& database, IStorageArea& area, bool unitTesting, - size_t maxCompletedJobs); + size_t maxCompletedJobs, + bool readOnly); ~ServerContext(); @@ -345,12 +346,6 @@ { return compressionEnabled_; } - - void SetReadOnly(bool readOnly) - { - readOnly_ = readOnly; - } - bool IsReadOnly() const { return readOnly_;
--- a/OrthancServer/Sources/ServerIndex.cpp Mon Sep 16 18:57:15 2024 +0200 +++ b/OrthancServer/Sources/ServerIndex.cpp Tue Sep 17 11:09:06 2024 +0200 @@ -346,8 +346,9 @@ ServerIndex::ServerIndex(ServerContext& context, IDatabaseWrapper& db, - unsigned int threadSleepGranularityMilliseconds) : - StatelessDatabaseOperations(db, context.IsReadOnly()), + unsigned int threadSleepGranularityMilliseconds, + bool readOnly) : + StatelessDatabaseOperations(db, readOnly), done_(false), maximumStorageMode_(MaxStorageMode_Recycle), maximumStorageSize_(0), @@ -357,7 +358,7 @@ // Initial recycling if the parameters have changed since the last // execution of Orthanc - if (!context.IsReadOnly()) + if (!readOnly) { StandaloneRecycling(maximumStorageMode_, maximumStorageSize_, maximumPatients_); } @@ -365,7 +366,7 @@ // For some DB engines (like SQLite), make sure we flush the DB to disk at regular interval if (GetDatabaseCapabilities().HasFlushToDisk()) { - if (context.IsReadOnly()) + if (!readOnly) { LOG(WARNING) << "READ-ONLY SYSTEM: not starting the flush disk thread"; } @@ -380,7 +381,7 @@ // -> make sure they are updated at regular interval if (GetDatabaseCapabilities().HasUpdateAndGetStatistics()) { - if (context.IsReadOnly()) + if (!readOnly) { LOG(WARNING) << "READ-ONLY SYSTEM: not starting the UpdateStatisticsThread"; } @@ -390,7 +391,7 @@ } } - if (context.IsReadOnly()) + if (!readOnly) { LOG(WARNING) << "READ-ONLY SYSTEM: not starting the unstable resources monitor thread"; }
--- a/OrthancServer/Sources/ServerIndex.h Mon Sep 16 18:57:15 2024 +0200 +++ b/OrthancServer/Sources/ServerIndex.h Tue Sep 17 11:09:06 2024 +0200 @@ -67,7 +67,8 @@ public: ServerIndex(ServerContext& context, IDatabaseWrapper& database, - unsigned int threadSleepGranularityMilliseconds); + unsigned int threadSleepGranularityMilliseconds, + bool readOnly); ~ServerIndex();
--- a/OrthancServer/Sources/main.cpp Mon Sep 16 18:57:15 2024 +0200 +++ b/OrthancServer/Sources/main.cpp Tue Sep 17 11:09:06 2024 +0200 @@ -1518,6 +1518,7 @@ bool loadJobsFromDatabase) { size_t maxCompletedJobs; + bool readOnly; { OrthancConfiguration::ReaderLock lock; @@ -1545,6 +1546,9 @@ LOG(WARNING) << "Setting option \"JobsHistorySize\" to zero is not recommended"; } + // New option in Orthanc 1.12.5 + readOnly = lock.GetConfiguration().GetBooleanParameter("ReadOnly", false); + // Configuration of DICOM TLS for Orthanc SCU (since Orthanc 1.9.0) DicomAssociationParameters::SetDefaultOwnCertificatePath( lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_PRIVATE_KEY, ""), @@ -1559,14 +1563,11 @@ lock.GetConfiguration().GetBooleanParameter(KEY_DICOM_TLS_REMOTE_CERTIFICATE_REQUIRED, true)); } - ServerContext context(database, storageArea, false /* not running unit tests */, maxCompletedJobs); + ServerContext context(database, storageArea, false /* not running unit tests */, maxCompletedJobs, readOnly); { OrthancConfiguration::ReaderLock lock; - // New option in Orthanc 1.12.5 - context.SetReadOnly(lock.GetConfiguration().GetBooleanParameter("ReadOnly", false)); - if (context.IsReadOnly()) { LOG(WARNING) << "READ-ONLY SYSTEM: ignoring these configurations: StorageCompression, StoreMD5ForAttachments, OverwriteInstances, MaximumPatientCount, MaximumStorageSize, MaximumStorageMode"; @@ -1972,7 +1973,7 @@ SQLiteDatabaseWrapper inMemoryDatabase; inMemoryDatabase.Open(); MemoryStorageArea inMemoryStorage; - ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */); + ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */, false /* readonly */); OrthancRestApi restApi(context, false /* no Orthanc Explorer */); restApi.GenerateOpenApiDocumentation(openapi); context.Stop(); @@ -2023,7 +2024,7 @@ SQLiteDatabaseWrapper inMemoryDatabase; inMemoryDatabase.Open(); MemoryStorageArea inMemoryStorage; - ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */); + ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */, false /* readonly */); OrthancRestApi restApi(context, false /* no Orthanc Explorer */); restApi.GenerateReStructuredTextCheatSheet(cheatsheet, "https://orthanc.uclouvain.be/api/index.html"); context.Stop();
--- a/OrthancServer/UnitTestsSources/ServerIndexTests.cpp Mon Sep 16 18:57:15 2024 +0200 +++ b/OrthancServer/UnitTestsSources/ServerIndexTests.cpp Tue Sep 17 11:09:06 2024 +0200 @@ -621,7 +621,7 @@ FilesystemStorage storage(path); SQLiteDatabaseWrapper db; // The SQLite DB is in memory db.Open(); - ServerContext context(db, storage, true /* running unit tests */, 10); + ServerContext context(db, storage, true /* running unit tests */, 10, false /* readonly */); context.SetupJobsEngine(true, false); ServerIndex& index = context.GetIndex(); @@ -703,7 +703,7 @@ FilesystemStorage storage(path); SQLiteDatabaseWrapper db; // The SQLite DB is in memory db.Open(); - ServerContext context(db, storage, true /* running unit tests */, 10); + ServerContext context(db, storage, true /* running unit tests */, 10, false /* readonly */); context.SetupJobsEngine(true, false); ServerIndex& index = context.GetIndex(); @@ -820,7 +820,7 @@ MemoryStorageArea storage; SQLiteDatabaseWrapper db; // The SQLite DB is in memory db.Open(); - ServerContext context(db, storage, true /* running unit tests */, 10); + ServerContext context(db, storage, true /* running unit tests */, 10, false /* readonly */); context.SetupJobsEngine(true, false); context.SetCompressionEnabled(true); @@ -985,7 +985,7 @@ MemoryStorageArea storage; SQLiteDatabaseWrapper db; // The SQLite DB is in memory db.Open(); - ServerContext context(db, storage, true /* running unit tests */, 10); + ServerContext context(db, storage, true /* running unit tests */, 10, false /* readonly */); context.SetupJobsEngine(true, false); context.SetCompressionEnabled(compression);
--- a/OrthancServer/UnitTestsSources/ServerJobsTests.cpp Mon Sep 16 18:57:15 2024 +0200 +++ b/OrthancServer/UnitTestsSources/ServerJobsTests.cpp Tue Sep 17 11:09:06 2024 +0200 @@ -536,7 +536,7 @@ OrthancJobsSerialization() { db_.Open(); - context_.reset(new ServerContext(db_, storage_, true /* running unit tests */, 10)); + context_.reset(new ServerContext(db_, storage_, true /* running unit tests */, 10, false /* readonly */)); context_->SetupJobsEngine(true, false); }