Skip to content
Merged
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
34 changes: 19 additions & 15 deletions server/src/main/java/org/elasticsearch/index/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -1214,25 +1214,29 @@ private void fillSegmentInfo(
public abstract List<Segment> segments(boolean includeVectorFormatsInfo);

public boolean refreshNeeded() {
if (store.tryIncRef()) {
/*
we need to inc the store here since we acquire a searcher and that might keep a file open on the
store. this violates the assumption that all files are closed when
the store is closed so we need to make sure we increment it here
*/
if (store.tryIncRef() == false) {
return false;
}
/*
we need to inc the store here since we acquire a directory reader and that might open a file on the store.
This violates the assumption that all files are closed when the store is closed so we need to make
sure we increment it here.
*/
try {
var refManager = getReferenceManager(SearcherScope.EXTERNAL);
var reader = refManager.acquire();
try {
try (Searcher searcher = acquireSearcher("refresh_needed", SearcherScope.EXTERNAL)) {
return searcher.getDirectoryReader().isCurrent() == false;
}
} catch (IOException e) {
logger.error("failed to access searcher manager", e);
failEngine("failed to access searcher manager", e);
throw new EngineException(shardId, "failed to access searcher manager", e);
return reader.isCurrent() == false;
} finally {
store.decRef();
refManager.release(reader);
}
} catch (IOException e) {
logger.error("failed to access directory reader", e);
failEngine("failed to access directory reader", e);
throw new EngineException(shardId, "failed to access directory reader", e);
} finally {
store.decRef();
}
return false;
}

/**
Expand Down