comparison OrthancServer/Sources/ServerIndex.cpp @ 5061:e95fadefeb72

new MaximumStorageMode configuration
author Alain Mazy <am@osimis.io>
date Tue, 09 Aug 2022 17:57:38 +0200
parents 6fed78e13233
children d7274e43ea7c 0ea402b4d901
comparison
equal deleted inserted replaced
5060:e69a3ff39bc5 5061:e95fadefeb72
319 ServerIndex::ServerIndex(ServerContext& context, 319 ServerIndex::ServerIndex(ServerContext& context,
320 IDatabaseWrapper& db, 320 IDatabaseWrapper& db,
321 unsigned int threadSleepGranularityMilliseconds) : 321 unsigned int threadSleepGranularityMilliseconds) :
322 StatelessDatabaseOperations(db), 322 StatelessDatabaseOperations(db),
323 done_(false), 323 done_(false),
324 maximumStorageMode_(MaxStorageMode_Recycle),
324 maximumStorageSize_(0), 325 maximumStorageSize_(0),
325 maximumPatients_(0) 326 maximumPatients_(0)
326 { 327 {
327 SetTransactionContextFactory(new TransactionContextFactory(context)); 328 SetTransactionContextFactory(new TransactionContextFactory(context));
328 329
329 // Initial recycling if the parameters have changed since the last 330 // Initial recycling if the parameters have changed since the last
330 // execution of Orthanc 331 // execution of Orthanc
331 StandaloneRecycling(maximumStorageSize_, maximumPatients_); 332 StandaloneRecycling(maximumStorageMode_, maximumStorageSize_, maximumPatients_);
332 333
333 if (HasFlushToDisk()) 334 if (HasFlushToDisk())
334 { 335 {
335 flushThread_ = boost::thread(FlushThread, this, threadSleepGranularityMilliseconds); 336 flushThread_ = boost::thread(FlushThread, this, threadSleepGranularityMilliseconds);
336 } 337 }
383 { 384 {
384 LOG(WARNING) << "At most " << count << " patients will be stored"; 385 LOG(WARNING) << "At most " << count << " patients will be stored";
385 } 386 }
386 } 387 }
387 388
388 StandaloneRecycling(maximumStorageSize_, maximumPatients_); 389 StandaloneRecycling(maximumStorageMode_, maximumStorageSize_, maximumPatients_);
389 } 390 }
390 391
391 392
392 void ServerIndex::SetMaximumStorageSize(uint64_t size) 393 void ServerIndex::SetMaximumStorageSize(uint64_t size)
393 { 394 {
403 { 404 {
404 LOG(WARNING) << "At most " << (size / MEGA_BYTES) << "MB will be used for the storage area"; 405 LOG(WARNING) << "At most " << (size / MEGA_BYTES) << "MB will be used for the storage area";
405 } 406 }
406 } 407 }
407 408
408 StandaloneRecycling(maximumStorageSize_, maximumPatients_); 409 StandaloneRecycling(maximumStorageMode_, maximumStorageSize_, maximumPatients_);
409 } 410 }
410 411
412 void ServerIndex::SetMaximumStorageMode(MaxStorageMode mode)
413 {
414 {
415 boost::mutex::scoped_lock lock(monitoringMutex_);
416 maximumStorageMode_ = mode;
417
418 if (mode == MaxStorageMode_Recycle)
419 {
420 LOG(WARNING) << "Maximum Storage mode: Recycle";
421 }
422 else
423 {
424 LOG(WARNING) << "Maximum Storage mode: Reject";
425 }
426 }
427
428 StandaloneRecycling(maximumStorageMode_, maximumStorageSize_, maximumPatients_);
429 }
411 430
412 void ServerIndex::UnstableResourcesMonitorThread(ServerIndex* that, 431 void ServerIndex::UnstableResourcesMonitorThread(ServerIndex* that,
413 unsigned int threadSleepGranularityMilliseconds) 432 unsigned int threadSleepGranularityMilliseconds)
414 { 433 {
415 int stableAge; 434 int stableAge;
521 uint64_t pixelDataOffset, 540 uint64_t pixelDataOffset,
522 bool isReconstruct) 541 bool isReconstruct)
523 { 542 {
524 uint64_t maximumStorageSize; 543 uint64_t maximumStorageSize;
525 unsigned int maximumPatients; 544 unsigned int maximumPatients;
545 MaxStorageMode maximumStorageMode;
526 546
527 { 547 {
528 boost::mutex::scoped_lock lock(monitoringMutex_); 548 boost::mutex::scoped_lock lock(monitoringMutex_);
529 maximumStorageSize = maximumStorageSize_; 549 maximumStorageSize = maximumStorageSize_;
530 maximumPatients = maximumPatients_; 550 maximumPatients = maximumPatients_;
551 maximumStorageMode = maximumStorageMode_;
531 } 552 }
532 553
533 return StatelessDatabaseOperations::Store( 554 return StatelessDatabaseOperations::Store(
534 instanceMetadata, dicomSummary, attachments, metadata, origin, overwrite, hasTransferSyntax, 555 instanceMetadata, dicomSummary, attachments, metadata, origin, overwrite, hasTransferSyntax,
535 transferSyntax, hasPixelDataOffset, pixelDataOffset, maximumStorageSize, maximumPatients, isReconstruct); 556 transferSyntax, hasPixelDataOffset, pixelDataOffset, maximumStorageMode, maximumStorageSize, maximumPatients, isReconstruct);
536 } 557 }
537 558
538 559
539 StoreStatus ServerIndex::AddAttachment(int64_t& newRevision, 560 StoreStatus ServerIndex::AddAttachment(int64_t& newRevision,
540 const FileInfo& attachment, 561 const FileInfo& attachment,