Skip to content

Commit ddf3415

Browse files
opensearch-trigger-bot[bot]github-actions[bot]
authored andcommitted
Add perms for remote snapshot cache eviction on scripted query (opensearch-project#14411) (opensearch-project#14884)
(cherry picked from commit 90d5500) Signed-off-by: Finn Carroll <carrofin@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Signed-off-by: kkewwei <kkewwei@163.com>
1 parent 8f67cbb commit ddf3415

File tree

2 files changed

+38
-37
lines changed

2 files changed

+38
-37
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8686
- Fix bulk upsert ignores the default_pipeline and final_pipeline when auto-created index matches the index template ([#12891](https://github.com/opensearch-project/OpenSearch/pull/12891))
8787
- Fix NPE in ReplicaShardAllocator ([#14385](https://github.com/opensearch-project/OpenSearch/pull/14385))
8888
- Use circuit breaker in InternalHistogram when adding empty buckets ([#14754](https://github.com/opensearch-project/OpenSearch/pull/14754))
89+
- Fix searchable snapshot failure with scripted fields ([#14411](https://github.com/opensearch-project/OpenSearch/pull/14411))
8990

9091
### Security
9192

server/src/main/java/org/opensearch/index/store/remote/utils/TransferManager.java

+37-37
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,22 @@ public IndexInput fetchBlob(BlobFetchRequest blobFetchRequest) throws IOExceptio
6464
final Path key = blobFetchRequest.getFilePath();
6565
logger.trace("fetchBlob called for {}", key.toString());
6666

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+
});
7783
});
7884

7985
// Cache entry was either retrieved from the cache or newly added, either
@@ -88,37 +94,31 @@ public IndexInput fetchBlob(BlobFetchRequest blobFetchRequest) throws IOExceptio
8894

8995
@SuppressWarnings("removal")
9096
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);
113113
}
114114
}
115115
}
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);
120116
}
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+
}
122122
}
123123

124124
/**

0 commit comments

Comments
 (0)