@@ -64,16 +64,22 @@ public IndexInput fetchBlob(BlobFetchRequest blobFetchRequest) throws IOExceptio
64
64
final Path key = blobFetchRequest .getFilePath ();
65
65
logger .trace ("fetchBlob called for {}" , key .toString ());
66
66
67
- final CachedIndexInput cacheEntry = fileCache .compute (key , (path , cachedIndexInput ) -> {
68
- if (cachedIndexInput == null || cachedIndexInput .isClosed ()) {
69
- logger .trace ("Transfer Manager - IndexInput closed or not in cache" );
70
- // Doesn't exist or is closed, either way create a new one
71
- return new DelayedCreationCachedIndexInput (fileCache , streamReader , blobFetchRequest );
72
- } else {
73
- logger .trace ("Transfer Manager - Already in cache" );
74
- // already in the cache and ready to be used (open)
75
- return cachedIndexInput ;
76
- }
67
+ // We need to do a privileged action here in order to fetch from remote
68
+ // and write/evict from local file cache in case this is invoked as a side
69
+ // effect of a plugin (such as a scripted search) that doesn't have the
70
+ // necessary permissions.
71
+ final CachedIndexInput cacheEntry = AccessController .doPrivileged ((PrivilegedAction <CachedIndexInput >) () -> {
72
+ return fileCache .compute (key , (path , cachedIndexInput ) -> {
73
+ if (cachedIndexInput == null || cachedIndexInput .isClosed ()) {
74
+ logger .trace ("Transfer Manager - IndexInput closed or not in cache" );
75
+ // Doesn't exist or is closed, either way create a new one
76
+ return new DelayedCreationCachedIndexInput (fileCache , streamReader , blobFetchRequest );
77
+ } else {
78
+ logger .trace ("Transfer Manager - Already in cache" );
79
+ // already in the cache and ready to be used (open)
80
+ return cachedIndexInput ;
81
+ }
82
+ });
77
83
});
78
84
79
85
// Cache entry was either retrieved from the cache or newly added, either
@@ -88,37 +94,31 @@ public IndexInput fetchBlob(BlobFetchRequest blobFetchRequest) throws IOExceptio
88
94
89
95
@ SuppressWarnings ("removal" )
90
96
private static FileCachedIndexInput createIndexInput (FileCache fileCache , StreamReader streamReader , BlobFetchRequest request ) {
91
- // We need to do a privileged action here in order to fetch from remote
92
- // and write to the local file cache in case this is invoked as a side
93
- // effect of a plugin (such as a scripted search) that doesn't have the
94
- // necessary permissions.
95
- return AccessController .doPrivileged ((PrivilegedAction <FileCachedIndexInput >) () -> {
96
- try {
97
- if (Files .exists (request .getFilePath ()) == false ) {
98
- logger .trace ("Fetching from Remote in createIndexInput of Transfer Manager" );
99
- try (
100
- OutputStream fileOutputStream = Files .newOutputStream (request .getFilePath ());
101
- OutputStream localFileOutputStream = new BufferedOutputStream (fileOutputStream )
102
- ) {
103
- for (BlobFetchRequest .BlobPart blobPart : request .blobParts ()) {
104
- try (
105
- InputStream snapshotFileInputStream = streamReader .read (
106
- blobPart .getBlobName (),
107
- blobPart .getPosition (),
108
- blobPart .getLength ()
109
- );
110
- ) {
111
- snapshotFileInputStream .transferTo (localFileOutputStream );
112
- }
97
+ try {
98
+ if (Files .exists (request .getFilePath ()) == false ) {
99
+ logger .trace ("Fetching from Remote in createIndexInput of Transfer Manager" );
100
+ try (
101
+ OutputStream fileOutputStream = Files .newOutputStream (request .getFilePath ());
102
+ OutputStream localFileOutputStream = new BufferedOutputStream (fileOutputStream )
103
+ ) {
104
+ for (BlobFetchRequest .BlobPart blobPart : request .blobParts ()) {
105
+ try (
106
+ InputStream snapshotFileInputStream = streamReader .read (
107
+ blobPart .getBlobName (),
108
+ blobPart .getPosition (),
109
+ blobPart .getLength ()
110
+ );
111
+ ) {
112
+ snapshotFileInputStream .transferTo (localFileOutputStream );
113
113
}
114
114
}
115
115
}
116
- final IndexInput luceneIndexInput = request .getDirectory ().openInput (request .getFileName (), IOContext .READ );
117
- return new FileCachedIndexInput (fileCache , request .getFilePath (), luceneIndexInput );
118
- } catch (IOException e ) {
119
- throw new UncheckedIOException (e );
120
116
}
121
- });
117
+ final IndexInput luceneIndexInput = request .getDirectory ().openInput (request .getFileName (), IOContext .READ );
118
+ return new FileCachedIndexInput (fileCache , request .getFilePath (), luceneIndexInput );
119
+ } catch (IOException e ) {
120
+ throw new UncheckedIOException (e );
121
+ }
122
122
}
123
123
124
124
/**
0 commit comments