|
22 | 22 | import org.apache.lucene.store.NativeFSLockFactory; |
23 | 23 | import org.apache.lucene.store.ReadAdvice; |
24 | 24 | import org.apache.lucene.store.SimpleFSLockFactory; |
| 25 | +import org.elasticsearch.common.Strings; |
25 | 26 | import org.elasticsearch.common.settings.Setting; |
26 | 27 | import org.elasticsearch.common.settings.Setting.Property; |
27 | 28 | import org.elasticsearch.common.util.FeatureFlag; |
|
36 | 37 | import org.elasticsearch.plugins.IndexStorePlugin; |
37 | 38 |
|
38 | 39 | import java.io.IOException; |
| 40 | +import java.nio.file.FileSystemException; |
39 | 41 | import java.nio.file.Files; |
40 | 42 | import java.nio.file.Path; |
41 | 43 | import java.util.HashSet; |
@@ -157,22 +159,38 @@ protected boolean useDirectIO(String name, IOContext context, OptionalLong fileL |
157 | 159 |
|
158 | 160 | @Override |
159 | 161 | public IndexInput openInput(String name, IOContext context) throws IOException { |
| 162 | + Throwable directIOException = null; |
160 | 163 | if (directIODelegate != null && context.hints().contains(DirectIOHint.INSTANCE)) { |
161 | 164 | ensureOpen(); |
162 | 165 | ensureCanRead(name); |
163 | | - Log.debug("Opening {} with direct IO", name); |
164 | | - return directIODelegate.openInput(name, context); |
165 | | - } else if (useDelegate(name, context)) { |
166 | | - // we need to do these checks on the outer directory since the inner doesn't know about pending deletes |
167 | | - ensureOpen(); |
168 | | - ensureCanRead(name); |
169 | | - // we only use the mmap to open inputs. Everything else is managed by the NIOFSDirectory otherwise |
170 | | - // we might run into trouble with files that are pendingDelete in one directory but still |
171 | | - // listed in listAll() from the other. We on the other hand don't want to list files from both dirs |
172 | | - // and intersect for perf reasons. |
173 | | - return delegate.openInput(name, context); |
174 | | - } else { |
175 | | - return super.openInput(name, context); |
| 166 | + try { |
| 167 | + Log.debug("Opening {} with direct IO", name); |
| 168 | + return directIODelegate.openInput(name, context); |
| 169 | + } catch (FileSystemException e) { |
| 170 | + Log.debug(() -> Strings.format("Could not open %s with direct IO", name), e); |
| 171 | + directIOException = e; |
| 172 | + // and fallthrough to normal opening below |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + try { |
| 177 | + if (useDelegate(name, context)) { |
| 178 | + // we need to do these checks on the outer directory since the inner doesn't know about pending deletes |
| 179 | + ensureOpen(); |
| 180 | + ensureCanRead(name); |
| 181 | + // we only use the mmap to open inputs. Everything else is managed by the NIOFSDirectory otherwise |
| 182 | + // we might run into trouble with files that are pendingDelete in one directory but still |
| 183 | + // listed in listAll() from the other. We on the other hand don't want to list files from both dirs |
| 184 | + // and intersect for perf reasons. |
| 185 | + return delegate.openInput(name, context); |
| 186 | + } else { |
| 187 | + return super.openInput(name, context); |
| 188 | + } |
| 189 | + } catch (Throwable t) { |
| 190 | + if (directIOException != null) { |
| 191 | + t.addSuppressed(directIOException); |
| 192 | + } |
| 193 | + throw t; |
176 | 194 | } |
177 | 195 | } |
178 | 196 |
|
|
0 commit comments