Skip to content

Commit 5e59730

Browse files
committed
extract common IndexInputFileReader
1 parent f4d47bc commit 5e59730

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

server/src/main/java/org/elasticsearch/repositories/LocalPrimarySnapshotShardContext.java

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.apache.lucene.util.BytesRef;
1616
import org.elasticsearch.action.ActionListener;
1717
import org.elasticsearch.common.lucene.Lucene;
18-
import org.elasticsearch.common.lucene.store.InputStreamIndexInput;
1918
import org.elasticsearch.core.IOUtils;
2019
import org.elasticsearch.core.Nullable;
2120
import org.elasticsearch.core.Releasable;
@@ -34,7 +33,6 @@
3433
import org.elasticsearch.snapshots.SnapshotId;
3534

3635
import java.io.IOException;
37-
import java.io.InputStream;
3836
import java.util.Collection;
3937

4038
/**
@@ -191,37 +189,10 @@ public SnapshotShardContext.FileReader fileReader(String file, StoreFileMetadata
191189
try {
192190
commitRefReleasable = withCommitRef();
193191
indexInput = store.openVerifyingInput(file, IOContext.DEFAULT, metadata);
194-
return new FileReader(commitRefReleasable, indexInput);
192+
return new IndexInputFileReader(commitRefReleasable, indexInput);
195193
} catch (Exception e) {
196194
IOUtils.close(e, indexInput, commitRefReleasable);
197195
throw e;
198196
}
199197
}
200-
201-
static class FileReader implements SnapshotShardContext.FileReader {
202-
203-
private final Releasable commitRefReleasable;
204-
private final IndexInput indexInput;
205-
206-
FileReader(Releasable commitRefReleasable, IndexInput indexInput) {
207-
this.commitRefReleasable = commitRefReleasable;
208-
this.indexInput = indexInput;
209-
}
210-
211-
@Override
212-
public InputStream openInput(long limit) throws IOException {
213-
return new InputStreamIndexInput(indexInput, limit);
214-
}
215-
216-
@Override
217-
public void close() throws IOException {
218-
IOUtils.close(indexInput, commitRefReleasable);
219-
}
220-
221-
@Override
222-
public void verify() throws IOException {
223-
Store.verify(indexInput);
224-
}
225-
}
226-
227198
}

server/src/main/java/org/elasticsearch/repositories/SnapshotShardContext.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
package org.elasticsearch.repositories;
1111

1212
import org.apache.lucene.index.IndexCommit;
13+
import org.apache.lucene.store.IndexInput;
1314
import org.elasticsearch.action.ActionListener;
1415
import org.elasticsearch.action.DelegatingActionListener;
16+
import org.elasticsearch.common.lucene.store.InputStreamIndexInput;
17+
import org.elasticsearch.core.IOUtils;
1518
import org.elasticsearch.core.Nullable;
1619
import org.elasticsearch.core.Releasable;
1720
import org.elasticsearch.index.IndexVersion;
@@ -115,4 +118,29 @@ public interface FileReader extends Closeable {
115118
void verify() throws IOException;
116119
}
117120

121+
public static class IndexInputFileReader implements FileReader {
122+
123+
private final Releasable commitRefReleasable;
124+
private final IndexInput indexInput;
125+
126+
public IndexInputFileReader(Releasable commitRefReleasable, IndexInput indexInput) {
127+
this.commitRefReleasable = commitRefReleasable;
128+
this.indexInput = indexInput;
129+
}
130+
131+
@Override
132+
public InputStream openInput(long limit) throws IOException {
133+
return new InputStreamIndexInput(indexInput, limit);
134+
}
135+
136+
@Override
137+
public void close() throws IOException {
138+
IOUtils.close(indexInput, commitRefReleasable);
139+
}
140+
141+
@Override
142+
public void verify() throws IOException {
143+
Store.verify(indexInput);
144+
}
145+
}
118146
}

0 commit comments

Comments
 (0)