-
Notifications
You must be signed in to change notification settings - Fork 24.6k
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
Dedup translog operations by reading in reverse #27268
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d6e64ea
Dedup translog operations by reading in reverse
dnhatn d006988
add the replication test
dnhatn 5935009
remove tier in name and comment
dnhatn ea11a2a
improve the SeqNumSet tests
dnhatn ebe92b6
add description for the matcher
dnhatn def1d39
Merge branch 'master' into dedup-translog-merge
dnhatn 5cc33bb
skippedOperations -> overriddenOperations
dnhatn aa21d87
check against unassigned
dnhatn 9bdb507
correct condition
dnhatn b3e0b6d
fix compilation
dnhatn 3bd5cd5
Merge branch 'master' into dedup-translog
dnhatn 7d3482b
simple test
dnhatn a3994f8
SeqNum -> SeqNo
dnhatn 48b0ff9
address feedback
dnhatn 97aa4d7
more restrict asserts
dnhatn c960f37
Merge branch 'master' into dedup-translog
dnhatn a3ff8c8
another address
dnhatn f79e3ef
add todo
dnhatn 29aa2f2
Merge branch 'master' into dedup-translog
dnhatn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd still like to see a deterministic (i.e. no randomness) test that exercises the corners of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added 7d3482b |
||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also assert that the contents of the shards are the same - see ReplicationGroup#assertAllEqual
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, we don't rollback replicas; replica2 has doc1 and doc2 while replica1 (eg. the promoted primary) does not have doc1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, but you can remove replica1 with a comment about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bleskes, This becomes more interesting to me :).
{doc1}
{doc1, doc2}
{doc2}
only if operation-based recovery from replica2, or{doc1, doc2}
if file-based recovery from replica2.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funny you say this as I have a similar thought this morning while thinking about another issue. That other issue caused me to add a todo on the #10708 ticket to deal with it (see replica recover with rollback). I'm fine with leaving the test as is for now (with a comment explaining the situation and a todo to fix this when possible)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a TODO for this.