Skip to content

Commit acf2a3a

Browse files
committed
ES-10826
1 parent 79e776a commit acf2a3a

File tree

6 files changed

+176
-49
lines changed

6 files changed

+176
-49
lines changed

server/src/main/java/org/elasticsearch/index/engine/Engine.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ public void flush(boolean force, boolean waitIfOngoing) throws EngineException {
13001300
*/
13011301
public final void flush(boolean force, boolean waitIfOngoing, ActionListener<FlushResult> listener) throws EngineException {
13021302
try (var ignored = acquireEnsureOpenRef()) {
1303-
flushHoldingLock(force, waitIfOngoing, listener);
1303+
flushHoldingLock(force, waitIfOngoing, false, listener);
13041304
}
13051305
}
13061306

@@ -1309,7 +1309,7 @@ public final void flush(boolean force, boolean waitIfOngoing, ActionListener<Flu
13091309
* the engine remains open, or holding {@code IndexShard#engineMutex} while closing the engine.
13101310
*
13111311
*/
1312-
protected abstract void flushHoldingLock(boolean force, boolean waitIfOngoing, ActionListener<FlushResult> listener)
1312+
protected abstract void flushHoldingLock(boolean force, boolean waitIfOngoing, boolean closing, ActionListener<FlushResult> listener)
13131313
throws EngineException;
13141314

13151315
/**
@@ -2058,7 +2058,7 @@ public void flushAndClose() throws IOException {
20582058
logger.debug("flushing shard on close - this might take some time to sync files to disk");
20592059
try {
20602060
// TODO: We are not waiting for full durability here atm because we are on the cluster state update thread
2061-
flushHoldingLock(false, false, ActionListener.noop());
2061+
flushHoldingLock(false, false, true, ActionListener.noop());
20622062
} catch (AlreadyClosedException ex) {
20632063
logger.debug("engine already closed - skipping flushAndClose");
20642064
}
@@ -2347,7 +2347,7 @@ public record FlushResult(boolean flushPerformed, long generation) {
23472347
* in-progress operations and listeners (e.g., primary term and generation listeners).
23482348
* At the moment, this is implemented in serverless for a special case that ensures the engine is prepared for reset.
23492349
*/
2350-
public void prepareForEngineReset() throws IOException {
2350+
public void beforeReset() throws IOException {
23512351
throw new UnsupportedOperationException("does not support engine reset");
23522352
}
23532353

server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,8 @@ private boolean shouldPeriodicallyFlush(long flushThresholdSizeInBytes, long flu
21792179
}
21802180

21812181
@Override
2182-
protected void flushHoldingLock(boolean force, boolean waitIfOngoing, ActionListener<FlushResult> listener) throws EngineException {
2182+
protected void flushHoldingLock(boolean force, boolean waitIfOngoing, boolean closing, ActionListener<FlushResult> listener)
2183+
throws EngineException {
21832184
ensureOpen(); // best-effort, a concurrent failEngine() can still happen but that's ok
21842185
if (force && waitIfOngoing == false) {
21852186
final String message = "wait_if_ongoing must be true for a force flush: force=" + force + " wait_if_ongoing=" + waitIfOngoing;
@@ -2227,8 +2228,11 @@ protected void flushHoldingLock(boolean force, boolean waitIfOngoing, ActionList
22272228
preCommitSegmentGeneration.set(lastCommittedSegmentInfos.getGeneration() + 1);
22282229
commitIndexWriter(indexWriter, translog);
22292230
logger.trace("finished commit for flush");
2230-
// we need to refresh in order to clear older version values
2231-
refresh("version_table_flush", SearcherScope.INTERNAL, true);
2231+
// Only refresh if we are not closing
2232+
if (closing == false) {
2233+
// we need to refresh in order to clear older version values
2234+
refresh("version_table_flush", SearcherScope.INTERNAL, true);
2235+
}
22322236
translog.trimUnreferencedReaders();
22332237
// Update the translog location for flushListener if (1) the writeLocation has changed during the flush and
22342238
// (2) indexWriter has committed all the changes (checks must be done in this order).

server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ public boolean shouldPeriodicallyFlush() {
458458
}
459459

460460
@Override
461-
protected void flushHoldingLock(boolean force, boolean waitIfOngoing, ActionListener<FlushResult> listener) throws EngineException {
461+
protected void flushHoldingLock(boolean force, boolean waitIfOngoing, boolean closing, ActionListener<FlushResult> listener)
462+
throws EngineException {
462463
listener.onResponse(new FlushResult(true, lastCommittedSegmentInfos.getGeneration()));
463464
}
464465

0 commit comments

Comments
 (0)