This is an automated email from the ASF dual-hosted git repository.

ishan pushed a commit to branch branch_10_0
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_10_0 by this push:
     new 331aa1e5ffe SOLR-17942: Raising configurable RAM per thread hard limit 
using VarHandle (#3741)
331aa1e5ffe is described below

commit 331aa1e5ffe317678c04c3252b16639ca458e5b7
Author: Puneet Ahuja <[email protected]>
AuthorDate: Thu Dec 18 20:34:26 2025 +0530

    SOLR-17942: Raising configurable RAM per thread hard limit using VarHandle 
(#3741)
---
 .../SOLR-17942-raising-ramPerThreadHardLimit.yml   |  8 +++++
 .../org/apache/solr/update/SolrIndexConfig.java    | 37 +++++++++++++++++++++-
 .../pages/index-segments-merging.adoc              |  4 ++-
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git 
a/changelog/unreleased/puneet/SOLR-17942-raising-ramPerThreadHardLimit.yml 
b/changelog/unreleased/puneet/SOLR-17942-raising-ramPerThreadHardLimit.yml
new file mode 100644
index 00000000000..e503e37c697
--- /dev/null
+++ b/changelog/unreleased/puneet/SOLR-17942-raising-ramPerThreadHardLimit.yml
@@ -0,0 +1,8 @@
+# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
+title: Raising the per ramPerThreadHardLimit to be configurable >2GB
+type: other # added, changed, fixed, deprecated, removed, dependency_update, 
security, other
+authors:
+  - name: Puneet Ahuja
+links:
+  - name: SOLR-17942
+    url: https://issues.apache.org/jira/browse/SOLR-17942
diff --git a/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java 
b/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java
index 236c9eb72bf..19a8e0135b9 100644
--- a/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java
+++ b/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java
@@ -20,6 +20,7 @@ import static 
org.apache.solr.core.XmlConfigFile.assertWarnOrFail;
 
 import java.io.IOException;
 import java.lang.invoke.MethodHandles;
+import java.lang.invoke.VarHandle;
 import java.util.Collections;
 import java.util.Map;
 import org.apache.lucene.analysis.Analyzer;
@@ -34,6 +35,7 @@ import org.apache.lucene.util.InfoStream;
 import org.apache.solr.common.ConfigNode;
 import org.apache.solr.common.MapSerializable;
 import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.SuppressForbidden;
 import org.apache.solr.core.DirectoryFactory;
 import org.apache.solr.core.PluginInfo;
 import org.apache.solr.core.SolrConfig;
@@ -246,7 +248,11 @@ public class SolrIndexConfig implements MapSerializable {
     if (ramBufferSizeMB != -1) iwc.setRAMBufferSizeMB(ramBufferSizeMB);
 
     if (ramPerThreadHardLimitMB != -1) {
-      iwc.setRAMPerThreadHardLimitMB(ramPerThreadHardLimitMB);
+      if (ramPerThreadHardLimitMB > 2048) {
+        setPerThreadRAMLimitViaVarHandle(iwc, ramPerThreadHardLimitMB);
+      } else {
+        iwc.setRAMPerThreadHardLimitMB(ramPerThreadHardLimitMB);
+      }
     }
 
     if (maxCommitMergeWaitMillis > 0) {
@@ -346,4 +352,33 @@ public class SolrIndexConfig implements MapSerializable {
 
     return scheduler;
   }
+
+  @SuppressForbidden(reason = "Need to override Lucene's 2GB per-thread limit 
for large datasets")
+  private static void setPerThreadRAMLimitViaVarHandle(IndexWriterConfig 
config, int limitMB) {
+    MethodHandles.Lookup lookup = MethodHandles.lookup();
+    VarHandle fieldHandle = null;
+    Class<?> currentClass = config.getClass();
+
+    // Traverse the hierarchy to find the field
+    while (currentClass != null && fieldHandle == null) {
+      try {
+        MethodHandles.Lookup privateLookup = 
MethodHandles.privateLookupIn(currentClass, lookup);
+        fieldHandle = privateLookup.findVarHandle(currentClass, 
"perThreadHardLimitMB", int.class);
+      } catch (IllegalAccessException | NoSuchFieldException e) {
+        currentClass = currentClass.getSuperclass();
+      }
+    }
+
+    if (fieldHandle == null) {
+      log.error("Could not find VarHandle for perThreadHardLimitMB field");
+      return;
+    }
+
+    try {
+      fieldHandle.set(config, limitMB);
+      log.info("Set perThreadHardLimitMB to {} MB via VarHandle", limitMB);
+    } catch (RuntimeException | Error e) {
+      log.error("Failed to set per-thread RAM limit via VarHandle", e);
+    }
+  }
 }
diff --git 
a/solr/solr-ref-guide/modules/configuration-guide/pages/index-segments-merging.adoc
 
b/solr/solr-ref-guide/modules/configuration-guide/pages/index-segments-merging.adoc
index 3ffa49ef435..aa6a4985323 100644
--- 
a/solr/solr-ref-guide/modules/configuration-guide/pages/index-segments-merging.adoc
+++ 
b/solr/solr-ref-guide/modules/configuration-guide/pages/index-segments-merging.adoc
@@ -77,7 +77,7 @@ The default is `false`.
 === ramPerThreadHardLimitMB
 
 Sets the maximum memory (defined in megabytes) consumption per thread 
triggering a forced flush if exceeded.
-The given value must be greater than `0` and less than `2048` MB (2GB).
+The given value must be greater than `0`.
 
 [source,xml]
 ----
@@ -86,6 +86,8 @@ The given value must be greater than `0` and less than `2048` 
MB (2GB).
 
 NOTE: This is an expert level parameter as it triggers forced flush even if 
`ramBufferSizeMB` has not been exceeded.
 
+WARNING: Values greater than 2048 MB (2GB) will bypass Lucene's built-in limit 
using reflection. This is an advanced feature that should only be used by 
experienced administrators who understand the memory implications.
+
 == Merging Index Segments
 
 The following settings define when segments are merged.

Reply via email to