Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,10 @@ public final void sync(Collection<String> 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();
}
}
13 changes: 13 additions & 0 deletions lucene/core/src/java/org/apache/lucene/store/BaseDirectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 2 additions & 11 deletions lucene/core/src/java/org/apache/lucene/store/Directory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,10 @@ public Set<String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Method> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading