From 5eea489e447be1bbc291d1465fca8b40c1f46d11 Mon Sep 17 00:00:00 2001 From: Andrzej Bialecki Date: Mon, 4 May 2020 14:43:43 +0200 Subject: [PATCH] SOLR-14431: SegmentsInfoRequestHandler does not release IndexWriter. --- solr/CHANGES.txt | 2 ++ .../admin/SegmentsInfoRequestHandler.java | 2 +- .../admin/SegmentsInfoRequestHandlerTest.java | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 50f2614aec1..584ebaf258a 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -150,6 +150,8 @@ Bug Fixes * SOLR-14421: New examples in solr.in.cmd in Solr 8.5 don't work as provided (Colvin Cowie via janhoy) +* SOLR-14431: SegmentsInfoRequestHandler does not release IndexWriter (Tiziano Degaetano, ab) + Other Changes --------------------- * SOLR-14197: SolrResourceLoader: marked many methods as deprecated, and in some cases rerouted exiting logic to avoid diff --git a/solr/core/src/java/org/apache/solr/handler/admin/SegmentsInfoRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/SegmentsInfoRequestHandler.java index 19d9d8148a2..9183dcf08b2 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/SegmentsInfoRequestHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/SegmentsInfoRequestHandler.java @@ -127,7 +127,6 @@ public class SegmentsInfoRequestHandler extends RequestHandlerBase { SimpleOrderedMap segmentInfos = new SimpleOrderedMap<>(); SolrCore core = req.getCore(); - RefCounted iwRef = core.getSolrCoreState().getIndexWriter(core); SimpleOrderedMap infosInfo = new SimpleOrderedMap<>(); Version minVersion = infos.getMinSegmentLuceneVersion(); if (minVersion != null) { @@ -149,6 +148,7 @@ public class SegmentsInfoRequestHandler extends RequestHandlerBase { coreInfo.add("indexDir", core.getIndexDir()); coreInfo.add("sizeInGB", (double)core.getIndexSize() / GB); + RefCounted iwRef = core.getSolrCoreState().getIndexWriter(core); if (iwRef != null) { try { IndexWriter iw = iwRef.get(); diff --git a/solr/core/src/test/org/apache/solr/handler/admin/SegmentsInfoRequestHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/SegmentsInfoRequestHandlerTest.java index 06d3da50686..23c0df52683 100644 --- a/solr/core/src/test/org/apache/solr/handler/admin/SegmentsInfoRequestHandlerTest.java +++ b/solr/core/src/test/org/apache/solr/handler/admin/SegmentsInfoRequestHandlerTest.java @@ -17,11 +17,14 @@ package org.apache.solr.handler.admin; import java.io.IOException; + +import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.SegmentCommitInfo; import org.apache.lucene.index.SegmentInfos; import org.apache.lucene.util.Version; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.index.NoMergePolicyFactory; +import org.apache.solr.util.RefCounted; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -35,6 +38,8 @@ public class SegmentsInfoRequestHandlerTest extends SolrTestCaseJ4 { private static final int DEL_COUNT = 1; private static final int NUM_SEGMENTS = 2; + + private static int initialRefCount; @BeforeClass public static void beforeClass() throws Exception { @@ -69,11 +74,18 @@ public class SegmentsInfoRequestHandlerTest extends SolrTestCaseJ4 { NUM_SEGMENTS, numSegments); return null; }); - + // see SOLR-14431 + RefCounted iwRef = h.getCore().getSolrCoreState().getIndexWriter(h.getCore()); + initialRefCount = iwRef.getRefcount(); + iwRef.decref(); } @AfterClass - public static void afterClass() { + public static void afterClass() throws Exception { + RefCounted iwRef = h.getCore().getSolrCoreState().getIndexWriter(h.getCore()); + int finalRefCount = iwRef.getRefcount(); + iwRef.decref(); + assertEquals("IW refcount mismatch", initialRefCount, finalRefCount); systemClearPropertySolrTestsMergePolicyFactory(); System.clearProperty("solr.tests.maxBufferedDocs"); System.clearProperty("solr.tests.ramBufferSizeMB");