Skip to content

Apache Lucene open-source search software

SOLR-9901: Implement move in HdfsDirectoryFactory.

markrmiller197590a928cf
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 06566e069e4..138385940ea 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -294,6 +294,8 @@ Bug Fixes
* SOLR-9859: replication.properties cannot be updated after being written and neither replication.properties or
index.properties are durable in the face of a crash. (Pushkar Raste, Chris de Kok, Cao Manh Dat, Mark Miller)
+* SOLR-9901: Implement move in HdfsDirectoryFactory. (Mark Miller)
+
Other Changes
----------------------
diff --git a/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java
index d481e0333e0..e1e3d6ed5ff 100644
--- a/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java
+++ b/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java
@@ -37,6 +37,7 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathFilter;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.LockFactory;
import org.apache.lucene.store.NRTCachingDirectory;
import org.apache.lucene.store.NoLockFactory;
@@ -577,4 +578,23 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Sol
FileContext fileContext = FileContext.getFileContext(getConf());
fileContext.rename(new Path(hdfsDirPath + "/" + fileName), new Path(hdfsDirPath + "/" + toName), Options.Rename.OVERWRITE);
}
+
+ @Override
+ public void move(Directory fromDir, Directory toDir, String fileName, IOContext ioContext) throws IOException {
+
+ Directory baseFromDir = getBaseDir(fromDir);
+ Directory baseToDir = getBaseDir(toDir);
+
+ if (baseFromDir instanceof HdfsDirectory && baseToDir instanceof HdfsDirectory) {
+ Path dir1 = ((HdfsDirectory) baseFromDir).getHdfsDirPath();
+ Path dir2 = ((HdfsDirectory) baseToDir).getHdfsDirPath();
+ Path file1 = new Path(dir1, fileName);
+ Path file2 = new Path(dir2, fileName);
+ FileContext fileContext = FileContext.getFileContext(getConf());
+ fileContext.rename(file1, file2);
+ return;
+ }
+
+ super.move(fromDir, toDir, fileName, ioContext);
+ }
}