Skip to content

Commit 9bbca7e

Browse files
committed
Force normal niofs for fdt tmp file read access when flushing stored fields and
force direct io for checksuming fdt tmp file.
1 parent 9c3f586 commit 9bbca7e

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

server/src/main/java/org/elasticsearch/index/store/FsDirectoryFactory.java

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.apache.lucene.store.FSDirectory;
1515
import org.apache.lucene.store.FileSwitchDirectory;
1616
import org.apache.lucene.store.FilterDirectory;
17+
import org.apache.lucene.store.FilterIndexInput;
1718
import org.apache.lucene.store.IOContext;
1819
import org.apache.lucene.store.IndexInput;
1920
import org.apache.lucene.store.LockFactory;
@@ -35,6 +36,7 @@
3536
import org.elasticsearch.plugins.IndexStorePlugin;
3637

3738
import java.io.IOException;
39+
import java.io.UncheckedIOException;
3840
import java.nio.file.Files;
3941
import java.nio.file.Path;
4042
import java.util.HashSet;
@@ -171,6 +173,40 @@ protected boolean useDirectIO(String name, IOContext context, OptionalLong fileL
171173

172174
@Override
173175
public IndexInput openInput(String name, IOContext context) throws IOException {
176+
// Force normal read advice for stored field temp fdt files:
177+
// (tmp fdt files should only exist when index sorting is enabled)
178+
if (LuceneFilesExtensions.TMP.getExtension().equals(getExtension(name)) && name.contains("fdt")) {
179+
ensureOpen();
180+
ensureCanRead(name);
181+
var niofsDelegate = super.openInput(name, context);
182+
var ioContext = context;
183+
return new FilterIndexInput(niofsDelegate.toString(), niofsDelegate) {
184+
185+
IndexInput directIOInput;
186+
187+
@Override
188+
public IndexInput clone() {
189+
// HACK: only StoredFieldsWriter#checkIntegrity() will invoking this clone method for fdt tmp file.
190+
if (directIOInput == null) {
191+
try {
192+
directIOInput = directIODelegate.openInput(name, ioContext);
193+
} catch (IOException e) {
194+
throw new UncheckedIOException(e);
195+
}
196+
}
197+
return directIOInput.clone();
198+
}
199+
200+
@Override
201+
public void close() throws IOException {
202+
super.close();
203+
if (directIOInput != null) {
204+
directIOInput.close();
205+
}
206+
}
207+
};
208+
}
209+
174210
if (useDelegate(name, context)) {
175211
// we need to do these checks on the outer directory since the inner doesn't know about pending deletes
176212
ensureOpen();
@@ -181,13 +217,6 @@ public IndexInput openInput(String name, IOContext context) throws IOException {
181217
// we might run into trouble with files that are pendingDelete in one directory but still
182218
// listed in listAll() from the other. We on the other hand don't want to list files from both dirs
183219
// and intersect for perf reasons.
184-
185-
// Force normal read advice for stored field temp fdt files:
186-
// (tmp fdt files should only exist when index sorting is enabled)
187-
if (LuceneFilesExtensions.TMP.getExtension().equals(getExtension(name)) && name.contains("fdt")) {
188-
context = context.withReadAdvice(ReadAdvice.NORMAL);
189-
}
190-
191220
return delegate.openInput(name, context);
192221
} else {
193222
return super.openInput(name, context);

0 commit comments

Comments
 (0)