diff --git a/solr/core/src/java/org/apache/solr/update/UpdateLog.java b/solr/core/src/java/org/apache/solr/update/UpdateLog.java index 46d84353440..1abf23c2f77 100644 --- a/solr/core/src/java/org/apache/solr/update/UpdateLog.java +++ b/solr/core/src/java/org/apache/solr/update/UpdateLog.java @@ -188,6 +188,7 @@ public class UpdateLog implements PluginInfoInitialized, SolrMetricProducer { protected TransactionLog bufferTlog; protected TransactionLog tlog; protected TransactionLog prevTlog; + protected TransactionLog prevTlogOnPrecommit; protected final Deque logs = new LinkedList<>(); // list of recent logs, newest first protected LinkedList newestLogsOnStartup = new LinkedList<>(); protected int numOldRecords; // number of records in the recent logs @@ -810,6 +811,11 @@ public class UpdateLog implements PluginInfoInitialized, SolrMetricProducer { // since document additions can happen concurrently with commit, create // a new transaction log first so that we know the old one is definitely // in the index. + if (prevTlog != null) { + // postCommit for prevTlog is not called, may be the index is corrupted + // if we override prevTlog value, the correspond tlog will be leaked, close it first + postCommit(cmd); + } prevTlog = tlog; tlog = null; id++; diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java index e43249330a0..83bd3c303f5 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderTragicEventTest.java @@ -38,6 +38,7 @@ import org.apache.solr.common.cloud.ClusterStateUtil; import org.apache.solr.common.cloud.DocCollection; import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Slice; +import org.apache.solr.common.util.ObjectReleaseTracker; import org.apache.solr.core.CoreContainer; import org.apache.solr.core.DirectoryFactory; import org.apache.solr.core.MockDirectoryFactory; @@ -181,15 +182,13 @@ public class LeaderTragicEventTest extends SolrCloudTestCase { Replica oldLeader = corruptLeader(collection, new ArrayList<>()); - //TODO better way to test this - Thread.sleep(5000); - Replica leader = getCollectionState(collection).getSlice("shard1").getLeader(); - assertEquals(leader.getName(), oldLeader.getName()); - if (otherReplicaJetty != null) { - // won't be able to do anything here, since this replica can't recovery from the leader otherReplicaJetty.start(); } + //TODO better way to test this + Thread.sleep(2000); + Replica leader = getCollectionState(collection).getSlice("shard1").getLeader(); + assertEquals(leader.getName(), oldLeader.getName()); } finally { CollectionAdminRequest.deleteCollection(collection).process(cluster.getSolrClient()); }