mirror of https://github.com/apache/lucene.git
SOLR-4459: The Replication 'index move' rather than copy optimization doesn't kick in when using NRTCachingDirectory or the rate limiting feature.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1446833 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1a12ff7b5c
commit
3a4103d19b
|
@ -107,7 +107,7 @@ Bug Fixes
|
|||
* SOLR-3926: Solr should support better way of finding active sorts (Eirik Lygre via
|
||||
Erick Erickson)
|
||||
|
||||
* SOLR-4342: Fix DataImportHandler stats to be a prper Map (hossman)
|
||||
* SOLR-4342: Fix DataImportHandler stats to be a proper Map (hossman)
|
||||
|
||||
* SOLR-3967: langid.enforceSchema option checks source field instead of target field (janhoy)
|
||||
|
||||
|
@ -125,6 +125,10 @@ Bug Fixes
|
|||
|
||||
* SOLR-4463: Fix SolrCoreState reference counting. (Mark Miller)
|
||||
|
||||
* SOLR-4459: The Replication 'index move' rather than copy optimization doesn't
|
||||
kick in when using NRTCachingDirectory or the rate limiting feature.
|
||||
(Mark Miller)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -103,6 +103,10 @@ public abstract class DirectoryFactory implements NamedListInitializedPlugin,
|
|||
/**
|
||||
* Override for more efficient moves.
|
||||
*
|
||||
* Intended for use with replication - use
|
||||
* carefully - some Directory wrappers will
|
||||
* cache files for example.
|
||||
*
|
||||
* @throws IOException If there is a low-level I/O error.
|
||||
*/
|
||||
public void move(Directory fromDir, Directory toDir, String fileName, IOContext ioContext) throws IOException {
|
||||
|
|
|
@ -23,6 +23,8 @@ import org.apache.commons.io.FileUtils;
|
|||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.apache.lucene.store.IOContext;
|
||||
import org.apache.lucene.store.NRTCachingDirectory;
|
||||
import org.apache.lucene.store.RateLimitedDirectoryWrapper;
|
||||
|
||||
/**
|
||||
* Directory provider which mimics original Solr
|
||||
|
@ -69,15 +71,29 @@ public class StandardDirectoryFactory extends CachingDirectoryFactory {
|
|||
/**
|
||||
* Override for more efficient moves.
|
||||
*
|
||||
* Intended for use with replication - use
|
||||
* carefully - some Directory wrappers will
|
||||
* cache files for example.
|
||||
*
|
||||
* This implementation works with two wrappers:
|
||||
* NRTCachingDirectory and RateLimitedDirectoryWrapper.
|
||||
*
|
||||
* You should first {@link Directory#sync(java.util.Collection)} any file that will be
|
||||
* moved or avoid cached files through settings.
|
||||
*
|
||||
* @throws IOException
|
||||
* If there is a low-level I/O error.
|
||||
*/
|
||||
@Override
|
||||
public void move(Directory fromDir, Directory toDir, String fileName, IOContext ioContext)
|
||||
throws IOException {
|
||||
if (fromDir instanceof FSDirectory && toDir instanceof FSDirectory) {
|
||||
File dir1 = ((FSDirectory) fromDir).getDirectory();
|
||||
File dir2 = ((FSDirectory) toDir).getDirectory();
|
||||
|
||||
Directory baseFromDir = getBaseDir(fromDir);
|
||||
Directory baseToDir = getBaseDir(fromDir);
|
||||
|
||||
if (baseFromDir instanceof FSDirectory && baseToDir instanceof FSDirectory) {
|
||||
File dir1 = ((FSDirectory) baseFromDir).getDirectory();
|
||||
File dir2 = ((FSDirectory) baseToDir).getDirectory();
|
||||
File indexFileInTmpDir = new File(dir1, fileName);
|
||||
File indexFileInIndex = new File(dir2, fileName);
|
||||
boolean success = indexFileInTmpDir.renameTo(indexFileInIndex);
|
||||
|
@ -89,4 +105,18 @@ public class StandardDirectoryFactory extends CachingDirectoryFactory {
|
|||
super.move(fromDir, toDir, fileName, ioContext);
|
||||
}
|
||||
|
||||
// special hack to work with NRTCachingDirectory and RateLimitedDirectoryWrapper
|
||||
private Directory getBaseDir(Directory dir) {
|
||||
Directory baseDir;
|
||||
if (dir instanceof NRTCachingDirectory) {
|
||||
baseDir = ((NRTCachingDirectory)dir).getDelegate();
|
||||
} else if (dir instanceof RateLimitedDirectoryWrapper) {
|
||||
baseDir = ((RateLimitedDirectoryWrapper)dir).getDelegate();
|
||||
} else {
|
||||
baseDir = dir;
|
||||
}
|
||||
|
||||
return baseDir;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue