From 3800973a69c23deb5c770e8032074244f50f5b9a Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Thu, 20 Aug 2026 09:02:47 +0000
Subject: [PATCH] Stamp JDBC backend tables with their tree name and refresh optimizer statistics after import (#866)

---
 opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/OnDiskMergeImporter.java |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/OnDiskMergeImporter.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/OnDiskMergeImporter.java
index 9adafb7..5b53791 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/OnDiskMergeImporter.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/OnDiskMergeImporter.java
@@ -1195,6 +1195,33 @@
 
   private void doImport(final Source source) throws InterruptedException, ExecutionException
   {
+    try
+    {
+      importAllEntries(source);
+    }
+    catch (Throwable t)
+    {
+      // Cancellation lands here as well (see the InterruptedException below). The trees hold an
+      // incomplete import: the storage must not treat what is in them as the final data. Errors
+      // are caught too - an import killed by an OutOfMemoryError leaves the trees just as partial
+      // as one killed by an exception.
+      try
+      {
+        importStrategy.aborted();
+      }
+      catch (Throwable notified)
+      {
+        // What went wrong here matters less than what brought the import down: the report of the
+        // failure is the point of this block. Concrete for the motivating case, an import killed
+        // by an OutOfMemoryError, where notifying the storage allocates.
+        t.addSuppressed(notified);
+      }
+      throw t;
+    }
+  }
+
+  private void importAllEntries(final Source source) throws InterruptedException, ExecutionException
+  {
     final long phaseOneStartTime = System.currentTimeMillis();
     final PhaseOneWriteableTransaction transaction = new PhaseOneWriteableTransaction(importStrategy);
     importedCount.set(0);
@@ -1327,6 +1354,12 @@
       closeSilently(bufferPool);
     }
 
+    /** Tells the storage that the import stopped before it was through, so that its data is not final. */
+    void aborted()
+    {
+      importer.aborted();
+    }
+
     abstract Callable<Void> newPhaseTwoTask(TreeName treeName, Chunk source, PhaseTwoProgressReporter progressReporter);
 
     void afterPhaseTwo(EntryContainer entryContainer)

--
Gitblit v1.10.0