-
Notifications
You must be signed in to change notification settings - Fork 24.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dedup translog operations by reading in reverse (#27268)
Currently, translog operations are read and processed one by one. This may be a problem as stale operations in translogs may suddenly reappear in recoveries. To make sure that stale operations won't be processed, we read the translog files in a reverse order (eg. from the most recent file to the oldest file) and only process an operation if its sequence number was not seen before. Relates to #10708
- Loading branch information
Showing
7 changed files
with
454 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
core/src/test/java/org/elasticsearch/index/translog/MultiSnapshotTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.index.translog; | ||
|
||
import com.carrotsearch.hppc.LongHashSet; | ||
import com.carrotsearch.hppc.LongSet; | ||
import org.elasticsearch.common.Randomness; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
import java.util.stream.LongStream; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.Matchers.lessThanOrEqualTo; | ||
|
||
public class MultiSnapshotTests extends ESTestCase { | ||
|
||
public void testTrackSeqNoSimpleRange() throws Exception { | ||
final MultiSnapshot.SeqNoSet bitSet = new MultiSnapshot.SeqNoSet(); | ||
final List<Long> values = LongStream.range(0, 1024).boxed().collect(Collectors.toList()); | ||
Randomness.shuffle(values); | ||
for (int i = 0; i < 1023; i++) { | ||
assertThat(bitSet.getAndSet(values.get(i)), equalTo(false)); | ||
assertThat(bitSet.ongoingSetsSize(), equalTo(1L)); | ||
assertThat(bitSet.completeSetsSize(), equalTo(0L)); | ||
} | ||
|
||
assertThat(bitSet.getAndSet(values.get(1023)), equalTo(false)); | ||
assertThat(bitSet.ongoingSetsSize(), equalTo(0L)); | ||
assertThat(bitSet.completeSetsSize(), equalTo(1L)); | ||
|
||
assertThat(bitSet.getAndSet(between(0, 1023)), equalTo(true)); | ||
assertThat(bitSet.getAndSet(between(1024, Integer.MAX_VALUE)), equalTo(false)); | ||
} | ||
|
||
public void testTrackSeqNoDenseRanges() throws Exception { | ||
final MultiSnapshot.SeqNoSet bitSet = new MultiSnapshot.SeqNoSet(); | ||
final LongSet normalSet = new LongHashSet(); | ||
IntStream.range(0, scaledRandomIntBetween(5_000, 10_000)).forEach(i -> { | ||
long seq = between(0, 5000); | ||
boolean existed = normalSet.add(seq) == false; | ||
assertThat("SeqNoSet != Set" + seq, bitSet.getAndSet(seq), equalTo(existed)); | ||
assertThat(bitSet.ongoingSetsSize() + bitSet.completeSetsSize(), lessThanOrEqualTo(5L)); | ||
}); | ||
} | ||
|
||
public void testTrackSeqNoSparseRanges() throws Exception { | ||
final MultiSnapshot.SeqNoSet bitSet = new MultiSnapshot.SeqNoSet(); | ||
final LongSet normalSet = new LongHashSet(); | ||
IntStream.range(0, scaledRandomIntBetween(5_000, 10_000)).forEach(i -> { | ||
long seq = between(i * 10_000, i * 30_000); | ||
boolean existed = normalSet.add(seq) == false; | ||
assertThat("SeqNoSet != Set", bitSet.getAndSet(seq), equalTo(existed)); | ||
}); | ||
} | ||
|
||
public void testTrackSeqNoMimicTranslogRanges() throws Exception { | ||
final MultiSnapshot.SeqNoSet bitSet = new MultiSnapshot.SeqNoSet(); | ||
final LongSet normalSet = new LongHashSet(); | ||
long currentSeq = between(10_000_000, 1_000_000_000); | ||
final int iterations = scaledRandomIntBetween(100, 2000); | ||
assertThat(bitSet.completeSetsSize(), equalTo(0L)); | ||
assertThat(bitSet.ongoingSetsSize(), equalTo(0L)); | ||
long totalDocs = 0; | ||
for (long i = 0; i < iterations; i++) { | ||
int batchSize = between(1, 1500); | ||
totalDocs += batchSize; | ||
currentSeq -= batchSize; | ||
List<Long> batch = LongStream.range(currentSeq, currentSeq + batchSize) | ||
.boxed() | ||
.collect(Collectors.toList()); | ||
Randomness.shuffle(batch); | ||
batch.forEach(seq -> { | ||
boolean existed = normalSet.add(seq) == false; | ||
assertThat("SeqNoSet != Set", bitSet.getAndSet(seq), equalTo(existed)); | ||
assertThat(bitSet.ongoingSetsSize(), lessThanOrEqualTo(4L)); | ||
}); | ||
assertThat(bitSet.ongoingSetsSize(), lessThanOrEqualTo(2L)); | ||
} | ||
assertThat(bitSet.completeSetsSize(), lessThanOrEqualTo(totalDocs / 1024)); | ||
assertThat(bitSet.ongoingSetsSize(), lessThanOrEqualTo(2L)); | ||
} | ||
} |
Oops, something went wrong.