SOLR-12412: Leak transaction log on tragic event

This commit is contained in:
Cao Manh Dat 2018-08-01 07:13:41 +07:00
parent c9e3c456e3
commit eada799f57
2 changed files with 11 additions and 6 deletions

View File

@ -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<TransactionLog> logs = new LinkedList<>(); // list of recent logs, newest first
protected LinkedList<TransactionLog> 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++;

View File

@ -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());
}