changeset 6913:a66b5e2dfb6e streaming

deprecating class StorageAccessor
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 02 Jun 2026 18:06:22 +0200
parents 89677acd8f8d
children 689d73b259f1
files OrthancFramework/Sources/FileStorage/StorageAccessor.h OrthancFramework/UnitTestsSources/FileStorageTests.cpp OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerContext.h OrthancServer/Sources/ServerToolbox.cpp
diffstat 5 files changed, 135 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/FileStorage/StorageAccessor.h	Tue Jun 02 16:13:19 2026 +0200
+++ b/OrthancFramework/Sources/FileStorage/StorageAccessor.h	Tue Jun 02 18:06:22 2026 +0200
@@ -61,7 +61,7 @@
    * contained in the storage area, and monitors timing metrics (if
    * enabled).
    **/
-  class ORTHANC_PUBLIC StorageAccessor : boost::noncopyable
+  class ORTHANC_PUBLIC ORTHANC_DEPRECATED_CLASS(StorageAccessor) : boost::noncopyable
   {
   private:
     class MetricsTimer;
--- a/OrthancFramework/UnitTestsSources/FileStorageTests.cpp	Tue Jun 02 16:13:19 2026 +0200
+++ b/OrthancFramework/UnitTestsSources/FileStorageTests.cpp	Tue Jun 02 18:06:22 2026 +0200
@@ -29,6 +29,10 @@
 
 #include <gtest/gtest.h>
 
+#if defined(__GNUC__) || defined(__clang__)
+#  pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
 #include "../Sources/FileStorage/FilesystemStorage.h"
 #include "../Sources/FileStorage/PluginStorageAreaAdapter.h"
 #include "../Sources/FileStorage/StorageAccessor.h"
--- a/OrthancServer/Sources/ServerContext.cpp	Tue Jun 02 16:13:19 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.cpp	Tue Jun 02 18:06:22 2026 +0200
@@ -35,7 +35,6 @@
 #include "../../OrthancFramework/Sources/DicomNetworking/DicomStoreUserConnection.h"
 #include "../../OrthancFramework/Sources/DicomParsing/DicomModification.h"
 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
-#include "../../OrthancFramework/Sources/FileStorage/StorageAccessor.h"
 #include "../../OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h"
 #include "../../OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h"
 #include "../../OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.h"
@@ -71,8 +70,10 @@
 
 
 // Those metrics correspond to those found in StorageAccessor in Orthanc <= 1.12.11
+static const char* const METRICS_STORAGE_AREA_CREATE_DURATION = "orthanc_storage_create_duration_ms";
 static const char* const METRICS_STORAGE_AREA_READ_BYTES = "orthanc_storage_read_bytes";
 static const char* const METRICS_STORAGE_AREA_READ_DURATION = "orthanc_storage_read_duration_ms";
+static const char* const METRICS_STORAGE_AREA_REMOVE_DURATION = "orthanc_storage_remove_duration_ms";
 static const char* const METRICS_STORAGE_AREA_WRITTEN_BYTES = "orthanc_storage_written_bytes";
 
 
@@ -133,6 +134,84 @@
   }
 
 
+  void ServerContext::CreateFile(FileInfo& info,
+                                 const void* data,
+                                 size_t size,
+                                 FileContentType type,
+                                 CompressionType compression,
+                                 const std::string& precomputedMd5,
+                                 const DicomInstanceToStore* instance)
+  {
+    assert(metricsRegistry_.get() != NULL);
+    const std::string uuid = Toolbox::GenerateUuid();
+
+    std::string md5 = precomputedMd5;
+
+    if (storeMD5_ &&
+        md5.empty()) // if it has not been precomputed, compute it now
+    {
+      Toolbox::ComputeMD5(md5, data, size);
+    }
+
+    std::string customData;
+
+    switch (compression)
+    {
+      case CompressionType_None:
+      {
+        {
+          MetricsRegistry::Timer timer(*metricsRegistry_, METRICS_STORAGE_AREA_CREATE_DURATION);
+          area_.Create(customData, uuid, data, size, type, compression, instance);
+        }
+
+        metricsRegistry_->IncrementIntegerValue(METRICS_STORAGE_AREA_WRITTEN_BYTES, static_cast<int64_t>(size));
+
+        info = FileInfo(uuid, type, size, md5);
+        info.SetCustomData(customData);
+        return;
+      }
+
+      case CompressionType_ZlibWithSize:
+      {
+        ZlibCompressor zlib;
+
+        std::string compressed;
+        zlib.Compress(compressed, data, size);
+
+        std::string compressedMD5;
+
+        if (storeMD5_)
+        {
+          Toolbox::ComputeMD5(compressedMD5, compressed);
+        }
+
+        {
+          MetricsRegistry::Timer timer(*metricsRegistry_, METRICS_STORAGE_AREA_CREATE_DURATION);
+
+          if (compressed.size() > 0)
+          {
+            area_.Create(customData, uuid, &compressed[0], compressed.size(), type, compression, instance);
+          }
+          else
+          {
+            area_.Create(customData, uuid, NULL, 0, type, compression, instance);
+          }
+        }
+
+        metricsRegistry_->IncrementIntegerValue(METRICS_STORAGE_AREA_WRITTEN_BYTES, static_cast<int64_t>(compressed.size()));
+
+        info = FileInfo(uuid, type, size, md5,
+                        CompressionType_ZlibWithSize, compressed.size(), compressedMD5);
+        info.SetCustomData(customData);
+        return;
+      }
+
+      default:
+        throw OrthancException(ErrorCode_NotImplemented);
+    }
+  }
+
+
   ServerContext::StoreResult::StoreResult() :
     status_(StoreStatus_Failure),
     cstoreStatusCode_(0)
@@ -751,8 +830,8 @@
                                  FileContentType type,
                                  const std::string& customData)
   {
-    StorageAccessor accessor(area_, *metricsRegistry_);
-    accessor.Remove(fileUuid, type, customData);
+    MetricsRegistry::Timer timer(*metricsRegistry_, METRICS_STORAGE_AREA_REMOVE_DURATION);
+    area_.Remove(fileUuid, type, customData);
   }
 
 
@@ -917,9 +996,8 @@
 
       if (!isAdoption)
       {
-        StorageAccessor accessor(area_, *metricsRegistry_);
-        accessor.Write(dicomInfo, dicom.GetBufferData(), dicom.GetBufferSize(),
-                       FileContentType_Dicom, compression, dicomMd5, storeMD5_, &dicom);
+        CreateFile(dicomInfo, dicom.GetBufferData(), dicom.GetBufferSize(),
+                   FileContentType_Dicom, compression, dicomMd5, &dicom);
 
         attachments.push_back(dicomInfo);
       }
@@ -933,9 +1011,8 @@
           (!area_.HasEfficientReadRange() ||
            compressionEnabled_))
       {
-        StorageAccessor accessor(area_, *metricsRegistry_);
-        accessor.Write(dicomUntilPixelData, dicom.GetBufferData(), pixelDataOffset,
-                       FileContentType_DicomUntilPixelData, compression, storeMD5_, NULL);
+        CreateFile(dicomUntilPixelData, dicom.GetBufferData(), pixelDataOffset, FileContentType_DicomUntilPixelData,
+                   compression, "" /* MD5 will be computed if needed */, NULL);
 
         attachments.push_back(dicomUntilPixelData);
       }
@@ -1269,8 +1346,8 @@
     {
       std::unique_ptr<StorageAreaDataSource::Range> range(ReadAttachment(attachment, true /* uncompress */));
 
-      StorageAccessor accessor(area_, *metricsRegistry_);
-      accessor.Write(modified, range->GetData(), range->GetSize(), attachmentType, compression, storeMD5_, NULL);
+      CreateFile(modified, range->GetData(), range->GetSize(), attachmentType, compression,
+                 "" /* MD5 will be computed if needed */, NULL);
     }
 
     try
@@ -1660,11 +1737,7 @@
     assert(attachmentType != FileContentType_Dicom && attachmentType != FileContentType_DicomUntilPixelData); // this method can not be used to store instances
 
     FileInfo attachment;
-
-    {
-      StorageAccessor accessor(area_, *metricsRegistry_);
-      accessor.Write(attachment, data, size, attachmentType, compression, storeMD5_, NULL);
-    }
+    CreateFile(attachment, data, size, attachmentType, compression, "" /* MD5 will be computed if needed */, NULL);
 
     try
     {
--- a/OrthancServer/Sources/ServerContext.h	Tue Jun 02 16:13:19 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.h	Tue Jun 02 18:06:22 2026 +0200
@@ -281,6 +281,15 @@
 
     void RemoveFile(const FileInfo& attachment);
 
+    // This method corresponds to StorageAccessor::Write() in Orthanc <= 1.12.11
+    void CreateFile(FileInfo& info,
+                    const void* data,
+                    size_t size,
+                    FileContentType type,
+                    CompressionType compression,
+                    const std::string& precomputedMd5,
+                    const DicomInstanceToStore* instance);
+
     // This DicomModification object is intended to be used as a
     // "rules engine" when de-identifying logs for C-Find, C-Get, and
     // C-Move queries (new in Orthanc 1.8.2)
--- a/OrthancServer/Sources/ServerToolbox.cpp	Tue Jun 02 16:13:19 2026 +0200
+++ b/OrthancServer/Sources/ServerToolbox.cpp	Tue Jun 02 18:06:22 2026 +0200
@@ -24,8 +24,8 @@
 #include "PrecompiledHeadersServer.h"
 #include "ServerToolbox.h"
 
+#include "../../OrthancFramework/Sources/Compression/ZlibCompressor.h"
 #include "../../OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h"
-#include "../../OrthancFramework/Sources/FileStorage/StorageAccessor.h"
 #include "../../OrthancFramework/Sources/Logging.h"
 #include "../../OrthancFramework/Sources/OrthancException.h"
 #include "Database/IDatabaseWrapper.h"
@@ -95,6 +95,36 @@
     }
 
 
+    // This corresponds to StorageAccessor::Read() in Orthanc <= 1.12.11
+    static void ReadFile(std::string& content,
+                         IPluginStorageArea& storageArea,
+                         const FileInfo& info)
+    {
+      switch (info.GetCompressionType())
+      {
+        case CompressionType_None:
+        {
+          std::unique_ptr<IMemoryBuffer> buffer;
+          buffer.reset(storageArea.ReadRange(info.GetUuid(), info.GetContentType(), 0, info.GetCompressedSize(), info.GetCustomData()));
+          buffer->MoveToString(content);
+          break;
+        }
+
+        case CompressionType_ZlibWithSize:
+        {
+          ZlibCompressor zlib;
+          std::unique_ptr<IMemoryBuffer> compressed;
+          compressed.reset(storageArea.ReadRange(info.GetUuid(), info.GetContentType(), 0, info.GetCompressedSize(), info.GetCustomData()));
+          zlib.Uncompress(content, compressed->GetData(), compressed->GetSize());
+          break;
+        }
+
+        default:
+          throw OrthancException(ErrorCode_NotImplemented);
+      }
+    }
+
+
     void ReconstructMainDicomTags(IDatabaseWrapper::ITransaction& transaction,
                                   IPluginStorageArea& storageArea,
                                   ResourceType level)
@@ -145,10 +175,8 @@
         try
         {
           // Read and parse the content of the DICOM file
-          StorageAccessor accessor(storageArea);  // no cache
-
           std::string content;
-          accessor.Read(content, attachment);
+          ReadFile(content, storageArea, attachment);
 
           ParsedDicomFile dicom(content);