SOLR-4605: Rollback does not work correctly.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1457784 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-03-18 14:52:49 +00:00
parent edbad37b0c
commit d5bcb41586
7 changed files with 60 additions and 6 deletions

View File

@ -123,4 +123,8 @@ public final class TrackingDirectoryWrapper extends Directory implements Closeab
public Set<String> getCreatedFiles() {
return createdFileNames;
}
public Directory getDelegate() {
return other;
}
}

View File

@ -159,6 +159,8 @@ Bug Fixes
* SOLR-4604: UpdateLog#init is over called on SolrCore#reload. (Mark Miller)
* SOLR-4605: Rollback does not work correctly. (Mark S, Mark Miller)
Optimizations
----------------------

View File

@ -186,7 +186,7 @@ public final class DefaultSolrCoreState extends SolrCoreState implements Recover
@Override
public synchronized void rollbackIndexWriter(SolrCore core) throws IOException {
newIndexWriter(core, true, true);
newIndexWriter(core, true, false);
}
protected SolrIndexWriter createMainIndexWriter(SolrCore core, String name, boolean forceNewDirectory) throws IOException {

View File

@ -250,6 +250,9 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 {
assertQ(req("id:[100 TO 110]")
,"//*[@numFound='0']"
);
assertU(h.simpleTag("rollback"));
assertU(commit());
}

View File

@ -22,6 +22,9 @@ import java.io.IOException;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.NRTCachingDirectory;
import org.apache.lucene.store.RateLimitedDirectoryWrapper;
import org.apache.lucene.store.TrackingDirectoryWrapper;
import org.apache.lucene.util.LuceneTestCase;
/**
@ -32,8 +35,13 @@ public class MockDirectoryFactory extends EphemeralDirectoryFactory {
@Override
protected Directory create(String path, DirContext dirContext) throws IOException {
Directory dir = LuceneTestCase.newDirectory();
if (dir instanceof MockDirectoryWrapper) {
MockDirectoryWrapper mockDirWrapper = (MockDirectoryWrapper) dir;
Directory cdir = reduce(dir);
cdir = reduce(cdir);
cdir = reduce(cdir);
if (cdir instanceof MockDirectoryWrapper) {
MockDirectoryWrapper mockDirWrapper = (MockDirectoryWrapper) cdir;
// we can't currently do this check because of how
// Solr has to reboot a new Directory sometimes when replicating
@ -56,6 +64,20 @@ public class MockDirectoryFactory extends EphemeralDirectoryFactory {
return dir;
}
private Directory reduce(Directory dir) {
Directory cdir = dir;
if (dir instanceof NRTCachingDirectory) {
cdir = ((NRTCachingDirectory)dir).getDelegate();
}
if (cdir instanceof RateLimitedDirectoryWrapper) {
cdir = ((RateLimitedDirectoryWrapper)dir).getDelegate();
}
if (cdir instanceof TrackingDirectoryWrapper) {
cdir = ((TrackingDirectoryWrapper)dir).getDelegate();
}
return cdir;
}
@Override
public boolean isAbsolute(String path) {
// TODO: kind of a hack - we don't know what the delegate is, so

View File

@ -22,6 +22,9 @@ import java.io.IOException;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.NRTCachingDirectory;
import org.apache.lucene.store.RateLimitedDirectoryWrapper;
import org.apache.lucene.store.TrackingDirectoryWrapper;
import org.apache.lucene.util.LuceneTestCase;
/**
@ -38,8 +41,14 @@ public class MockFSDirectoryFactory extends StandardDirectoryFactory {
// test assumes it can open an IndexWriter when that happens - we
// have a new Directory for the same dir and still an open IW at
// this point
if (dir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)dir).setAssertNoUnrefencedFilesOnClose(false);
Directory cdir = reduce(dir);
cdir = reduce(cdir);
cdir = reduce(cdir);
if (cdir instanceof MockDirectoryWrapper) {
((MockDirectoryWrapper)cdir).setAssertNoUnrefencedFilesOnClose(false);
((MockDirectoryWrapper)cdir).setPreventDoubleWrite(false);
}
return dir;
}
@ -50,4 +59,18 @@ public class MockFSDirectoryFactory extends StandardDirectoryFactory {
// we treat it as file based since this works on most ephem impls
return new File(path).isAbsolute();
}
private Directory reduce(Directory dir) {
Directory cdir = dir;
if (dir instanceof NRTCachingDirectory) {
cdir = ((NRTCachingDirectory)dir).getDelegate();
}
if (cdir instanceof RateLimitedDirectoryWrapper) {
cdir = ((RateLimitedDirectoryWrapper)dir).getDelegate();
}
if (cdir instanceof TrackingDirectoryWrapper) {
cdir = ((TrackingDirectoryWrapper)dir).getDelegate();
}
return cdir;
}
}

View File

@ -178,7 +178,7 @@ abstract public class BaseTestHarness {
return simpleTag("optimize", args);
}
private static String simpleTag(String tag, String... args) {
public static String simpleTag(String tag, String... args) {
try {
StringWriter r = new StringWriter();