diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 56974c03cd50..fbf39f818d03 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -69,6 +69,8 @@ Bug Fixes * GITHUB#14847: Allow Faiss vector format to index >2GB of vectors per-field per-segment by using MemorySegment APIs (instead of ByteBuffer) to copy bytes to native memory. (Kaival Parikh) +* GITHUB#14985: Add delegate method copyFrom for FilterDirectory. (Ve Lee) + Changes in Runtime Behavior --------------------- * GITHUB#14187: The query cache is now disabled by default. (Adrien Grand) diff --git a/lucene/core/src/java/org/apache/lucene/codecs/CompoundDirectory.java b/lucene/core/src/java/org/apache/lucene/codecs/CompoundDirectory.java index 362b5b3880f8..f0a4fb6a25e9 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/CompoundDirectory.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/CompoundDirectory.java @@ -85,4 +85,10 @@ public final void sync(Collection names) { public final Lock obtainLock(String name) { throw new UnsupportedOperationException(); } + + @Override + public void copyFrom(Directory from, String src, String dest, IOContext context) + throws IOException { + throw new UnsupportedOperationException(); + } } diff --git a/lucene/core/src/java/org/apache/lucene/store/BaseDirectory.java b/lucene/core/src/java/org/apache/lucene/store/BaseDirectory.java index 21e878352685..0534e911c9af 100644 --- a/lucene/core/src/java/org/apache/lucene/store/BaseDirectory.java +++ b/lucene/core/src/java/org/apache/lucene/store/BaseDirectory.java @@ -17,6 +17,7 @@ package org.apache.lucene.store; import java.io.IOException; +import org.apache.lucene.util.IOUtils; /** * Base implementation for a concrete {@link Directory} that uses a {@link LockFactory} for locking. @@ -51,6 +52,18 @@ protected final void ensureOpen() throws AlreadyClosedException { } } + @Override + public void copyFrom(Directory from, String src, String dest, IOContext context) + throws IOException { + try (IndexInput is = from.openInput(src, IOContext.READONCE); + IndexOutput os = createOutput(dest, context)) { + os.copyBytes(is, is.length()); + } catch (Throwable t) { + IOUtils.deleteFilesSuppressingExceptions(t, this, dest); + throw t; + } + } + @Override public String toString() { return super.toString() + " lockFactory=" + lockFactory; diff --git a/lucene/core/src/java/org/apache/lucene/store/Directory.java b/lucene/core/src/java/org/apache/lucene/store/Directory.java index 80236f5c1867..abfb8fa47901 100644 --- a/lucene/core/src/java/org/apache/lucene/store/Directory.java +++ b/lucene/core/src/java/org/apache/lucene/store/Directory.java @@ -23,7 +23,6 @@ import java.util.Collection; // for javadocs import java.util.Set; import org.apache.lucene.index.IndexFileNames; -import org.apache.lucene.util.IOUtils; /** * A {@code Directory} provides an abstraction layer for storing a list of files. A directory @@ -174,16 +173,8 @@ public ChecksumIndexInput openChecksumInput(String name) throws IOException { * Copies an existing {@code src} file from directory {@code from} to a non-existent file {@code * dest} in this directory. The given IOContext is only used for opening the destination file. */ - public void copyFrom(Directory from, String src, String dest, IOContext context) - throws IOException { - try (IndexInput is = from.openInput(src, IOContext.READONCE); - IndexOutput os = createOutput(dest, context)) { - os.copyBytes(is, is.length()); - } catch (Throwable t) { - IOUtils.deleteFilesSuppressingExceptions(t, this, dest); - throw t; - } - } + public abstract void copyFrom(Directory from, String src, String dest, IOContext context) + throws IOException; @Override public String toString() { diff --git a/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java index 36889486b5d5..e7d051861c46 100644 --- a/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java +++ b/lucene/core/src/java/org/apache/lucene/store/FileSwitchDirectory.java @@ -250,4 +250,10 @@ public Set getPendingDeletions() throws IOException { return Collections.unmodifiableSet(combined); } } + + @Override + public void copyFrom(Directory from, String src, String dest, IOContext context) + throws IOException { + getDirectory(dest).copyFrom(from, src, dest, context); + } } diff --git a/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java index 43185a54f451..439b56ac7d9d 100644 --- a/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java +++ b/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java @@ -111,6 +111,12 @@ public void close() throws IOException { in.close(); } + @Override + public void copyFrom(Directory from, String src, String dest, IOContext context) + throws IOException { + in.copyFrom(from, src, dest, context); + } + @Override public String toString() { return getClass().getSimpleName() + "(" + in.toString() + ")"; diff --git a/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java index 6109115c885a..2a2236433400 100644 --- a/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java +++ b/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java @@ -36,9 +36,6 @@ public void testOverrides() throws Exception { // verify that all methods of Directory are overridden by FilterDirectory, // except those under the 'exclude' list Set exclude = new HashSet<>(); - exclude.add( - Directory.class.getMethod( - "copyFrom", Directory.class, String.class, String.class, IOContext.class)); exclude.add(Directory.class.getMethod("openChecksumInput", String.class)); for (Method m : FilterDirectory.class.getMethods()) { if (m.getDeclaringClass() == Directory.class) { diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/index/BaseMergePolicyTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/tests/index/BaseMergePolicyTestCase.java index cc4180a2a079..32e62d33687a 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/tests/index/BaseMergePolicyTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/tests/index/BaseMergePolicyTestCase.java @@ -312,6 +312,12 @@ public Lock obtainLock(String name) throws IOException { throw new UnsupportedOperationException(); } + @Override + public void copyFrom(Directory from, String src, String dest, IOContext context) + throws IOException { + throw new UnsupportedOperationException(); + } + @Override public void close() throws IOException { throw new UnsupportedOperationException();