Skip to content

Ensure FrozenEngine always applies engine-level wrapper #76100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class ReadOnlyEngine extends Engine {

protected volatile TranslogStats translogStats;
private final String commitId;
private final Function<DirectoryReader, DirectoryReader> readerWrapperFunction;

/**
* Creates a new ReadOnlyEngine. This ctor can also be used to open a read-only engine on top of an already opened
Expand Down Expand Up @@ -116,7 +117,8 @@ public ReadOnlyEngine(EngineConfig config, SeqNoStats seqNoStats, TranslogStats
this.seqNoStats = seqNoStats;
this.indexCommit = Lucene.getIndexCommit(lastCommittedSegmentInfos, directory);
this.lazilyLoadSoftDeletes = lazilyLoadSoftDeletes;
reader = wrapReader(open(indexCommit), readerWrapperFunction);
this.readerWrapperFunction = readerWrapperFunction;
reader = wrapReader(open(indexCommit));
readerManager = new ElasticsearchReaderManager(reader);
assert translogStats != null || obtainLock : "mutiple translogs instances should not be opened at the same time";
this.translogStats = translogStats != null ? translogStats : translogStats(config, lastCommittedSegmentInfos);
Expand Down Expand Up @@ -192,8 +194,7 @@ public void verifyEngineBeforeIndexClosing() throws IllegalStateException {
// reopened as an internal engine, which would be the path to fix the issue.
}

protected final ElasticsearchDirectoryReader wrapReader(DirectoryReader reader,
Function<DirectoryReader, DirectoryReader> readerWrapperFunction) throws IOException {
protected final ElasticsearchDirectoryReader wrapReader(DirectoryReader reader) throws IOException {
reader = readerWrapperFunction.apply(reader);
return ElasticsearchDirectoryReader.wrap(reader, engineConfig.getShardId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private synchronized ElasticsearchDirectoryReader getOrOpenReader() throws IOExc
listeners.beforeRefresh();
}
final DirectoryReader dirReader = openDirectory(engineConfig.getStore().directory());
reader = lastOpenedReader = wrapReader(dirReader, Function.identity());
reader = lastOpenedReader = wrapReader(dirReader);
reader.getReaderCacheHelper().addClosedListener(this::onReaderClosed);
for (ReferenceManager.RefreshListener listeners : config().getInternalRefreshListener()) {
listeners.afterRefresh(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.mapper.SeqNoFieldMapper;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.test.rest.ESRestTestCase;

import java.io.IOException;
Expand Down Expand Up @@ -468,7 +470,12 @@ protected static Number count(String index) throws IOException {

protected static Map<String, Object> search(String index, QueryBuilder query, Boolean ignoreThrottled) throws IOException {
final Request request = new Request(HttpPost.METHOD_NAME, '/' + index + "/_search");
request.setJsonEntity(new SearchSourceBuilder().trackTotalHits(true).query(query).toString());
final SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().trackTotalHits(true).query(query);
if (randomBoolean()) {
// ensures we can always access sequence numbers, even on source-only mounted snapshots
searchSourceBuilder.sort(SeqNoFieldMapper.NAME, SortOrder.ASC);
}
request.setJsonEntity(searchSourceBuilder.toString());
if (ignoreThrottled != null) {
request.addParameter("ignore_throttled", ignoreThrottled.toString());
}
Expand Down