Skip to content

Commit 6909e0e

Browse files
committed
Take only_expunge_deletes into account
1 parent 6bfbc0d commit 6909e0e

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/TransportForceMergeAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected void shardOperation(
108108
}).<EmptyResult>andThen((l, indexShard) -> {
109109
boolean forceMergeIsNoOp = indexShard.withEngineException(engine -> {
110110
engine.flush();
111-
return engine.forceMergeIsNoOp(request.maxNumSegments());
111+
return engine.forceMergeIsNoOp(request.maxNumSegments(), request.onlyExpungeDeletes());
112112
});
113113
if (forceMergeIsNoOp) {
114114
logger.info("---> skipping force merge for shard {} since it is a no-op", indexShard.shardId());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ public final void flush() throws EngineException {
15401540
public abstract void forceMerge(boolean flush, int maxNumSegments, boolean onlyExpungeDeletes, String forceMergeUUID)
15411541
throws EngineException, IOException;
15421542

1543-
public abstract boolean forceMergeIsNoOp(int maxNumSegments) throws IOException;
1543+
public abstract boolean forceMergeIsNoOp(int maxNumSegments, boolean onlyExpungeDeletes) throws IOException;
15441544

15451545
/**
15461546
* Snapshots the most recent index and returns a handle to it. If needed will try and "commit" the

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,7 +2545,10 @@ public void forceMerge(final boolean flush, int maxNumSegments, boolean onlyExpu
25452545
}
25462546

25472547
@Override
2548-
public boolean forceMergeIsNoOp(int maxNumSegments) throws IOException {
2548+
public boolean forceMergeIsNoOp(int maxNumSegments, boolean onlyExpungeDeletes) throws IOException {
2549+
if (onlyExpungeDeletes && maxNumSegments >= 0) {
2550+
throw new IllegalArgumentException("only_expunge_deletes and max_num_segments are mutually exclusive");
2551+
}
25492552
// TODO: is there a way for us to determine no-op with no max num segments?
25502553
if (maxNumSegments <= 0) {
25512554
return false;
@@ -2554,9 +2557,16 @@ public boolean forceMergeIsNoOp(int maxNumSegments) throws IOException {
25542557
final var segmentCommitInfos = SegmentInfos.readCommit(reader.directory(), reader.getIndexCommit().getSegmentsFileName());
25552558
final var segmentsToMerge = new HashMap<SegmentCommitInfo, Boolean>();
25562559
for (int i = 0; i < segmentCommitInfos.size(); i++) {
2557-
segmentsToMerge.put(segmentCommitInfos.info(i), Boolean.TRUE);
2560+
final var segmentInfo = segmentCommitInfos.info(i);
2561+
if (onlyExpungeDeletes && segmentInfo.hasDeletions()) {
2562+
return false;
2563+
}
2564+
segmentsToMerge.put(segmentInfo, Boolean.TRUE);
25582565
}
25592566

2567+
if (onlyExpungeDeletes) {
2568+
return true;
2569+
}
25602570
final var mergeSpecification = indexWriter.getConfig()
25612571
.getMergePolicy()
25622572
.findForcedMerges(segmentCommitInfos, maxNumSegments, segmentsToMerge, indexWriter);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ public void forceMerge(boolean flush, int maxNumSegments, boolean onlyExpungeDel
479479
}
480480

481481
@Override
482-
public boolean forceMergeIsNoOp(int maxNumSegments) throws IOException {
482+
public boolean forceMergeIsNoOp(int maxNumSegments, boolean onlyExpungeDeletes) throws IOException {
483483
throw new UnsupportedOperationException(
484484
"force merge is not supported on a read-only engine, "
485485
+ "target max number of segments["

0 commit comments

Comments
 (0)