-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Lazy initialize checkpoint tracker bit sets #27179
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
21299b8
Lazy initialize checkpoint tracker bit sets
jasontedor 91fbab3
Method
jasontedor b2cbfc5
Add assertion
jasontedor cabda87
Use index
jasontedor 68c4eab
Use index more
jasontedor 97bb3ca
Revert
jasontedor f4f0dae
Oh yeah
jasontedor 67a709d
Merge branch 'master' into lazy-seq-no-bit-sets
jasontedor 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -19,10 +19,14 @@ | |
|
|
||
| package org.elasticsearch.index.seqno; | ||
|
|
||
| import com.carrotsearch.hppc.LongObjectHashMap; | ||
| import org.apache.lucene.util.FixedBitSet; | ||
| import org.elasticsearch.ElasticsearchException; | ||
| import org.elasticsearch.common.Randomness; | ||
| import org.elasticsearch.common.util.concurrent.AbstractRunnable; | ||
| import org.elasticsearch.test.ESTestCase; | ||
| import org.hamcrest.BaseMatcher; | ||
| import org.hamcrest.Description; | ||
| import org.junit.Before; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
@@ -36,8 +40,7 @@ | |
| import java.util.stream.Collectors; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| import static org.elasticsearch.index.seqno.LocalCheckpointTracker.BIT_ARRAYS_SIZE; | ||
| import static org.hamcrest.Matchers.empty; | ||
| import static org.elasticsearch.index.seqno.LocalCheckpointTracker.BIT_SET_SIZE; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.isOneOf; | ||
|
|
||
|
|
@@ -83,10 +86,19 @@ public void testSimpleReplica() { | |
| assertThat(tracker.getCheckpoint(), equalTo(2L)); | ||
| } | ||
|
|
||
| public void testLazyInitialization() { | ||
| /* | ||
| * Previously this would allocate the entire chain of bit sets to the one for the sequence number being marked; for very large | ||
| * sequence numbers this could lead to excessive memory usage resulting in out of memory errors. | ||
| */ | ||
| tracker.markSeqNoAsCompleted(randomNonNegativeLong()); | ||
| assertThat(tracker.processedSeqNo.size(), equalTo(1)); | ||
| } | ||
|
|
||
| public void testSimpleOverFlow() { | ||
| List<Integer> seqNoList = new ArrayList<>(); | ||
| final boolean aligned = randomBoolean(); | ||
| final int maxOps = BIT_ARRAYS_SIZE * randomIntBetween(1, 5) + (aligned ? 0 : randomIntBetween(1, BIT_ARRAYS_SIZE - 1)); | ||
| final int maxOps = BIT_SET_SIZE * randomIntBetween(1, 5) + (aligned ? 0 : randomIntBetween(1, BIT_SET_SIZE - 1)); | ||
|
|
||
| for (int i = 0; i < maxOps; i++) { | ||
| seqNoList.add(i); | ||
|
|
@@ -97,7 +109,9 @@ public void testSimpleOverFlow() { | |
| } | ||
| assertThat(tracker.checkpoint, equalTo(maxOps - 1L)); | ||
| assertThat(tracker.processedSeqNo.size(), equalTo(aligned ? 0 : 1)); | ||
| assertThat(tracker.firstProcessedSeqNo, equalTo(((long) maxOps / BIT_ARRAYS_SIZE) * BIT_ARRAYS_SIZE)); | ||
| if (aligned == false) { | ||
| assertThat(tracker.processedSeqNo.keys().iterator().next().value, equalTo(tracker.checkpoint / BIT_SET_SIZE)); | ||
| } | ||
| } | ||
|
|
||
| public void testConcurrentPrimary() throws InterruptedException { | ||
|
|
@@ -138,7 +152,9 @@ protected void doRun() throws Exception { | |
| tracker.markSeqNoAsCompleted(unFinishedSeq); | ||
| assertThat(tracker.getCheckpoint(), equalTo(maxOps - 1L)); | ||
| assertThat(tracker.processedSeqNo.size(), isOneOf(0, 1)); | ||
| assertThat(tracker.firstProcessedSeqNo, equalTo(((long) maxOps / BIT_ARRAYS_SIZE) * BIT_ARRAYS_SIZE)); | ||
| if (tracker.processedSeqNo.size() == 1) { | ||
| assertThat(tracker.processedSeqNo.keys().iterator().next().value, equalTo(tracker.checkpoint / BIT_SET_SIZE)); | ||
| } | ||
| } | ||
|
|
||
| public void testConcurrentReplica() throws InterruptedException { | ||
|
|
@@ -186,7 +202,10 @@ protected void doRun() throws Exception { | |
| assertThat(tracker.getCheckpoint(), equalTo(unFinishedSeq - 1L)); | ||
| tracker.markSeqNoAsCompleted(unFinishedSeq); | ||
| assertThat(tracker.getCheckpoint(), equalTo(maxOps - 1L)); | ||
| assertThat(tracker.firstProcessedSeqNo, equalTo(((long) maxOps / BIT_ARRAYS_SIZE) * BIT_ARRAYS_SIZE)); | ||
| assertThat(tracker.processedSeqNo.size(), isOneOf(0, 1)); | ||
| if (tracker.processedSeqNo.size() == 1) { | ||
| assertThat(tracker.processedSeqNo.keys().iterator().next().value, equalTo(tracker.checkpoint / BIT_SET_SIZE)); | ||
| } | ||
| } | ||
|
|
||
| public void testWaitForOpsToComplete() throws BrokenBarrierException, InterruptedException { | ||
|
|
@@ -241,7 +260,17 @@ public void testResetCheckpoint() { | |
| tracker.resetCheckpoint(localCheckpoint); | ||
| assertThat(tracker.getCheckpoint(), equalTo((long) localCheckpoint)); | ||
| assertThat(tracker.getMaxSeqNo(), equalTo((long) maxSeqNo)); | ||
| assertThat(tracker.processedSeqNo, empty()); | ||
| assertThat(tracker.processedSeqNo, new BaseMatcher<LongObjectHashMap<FixedBitSet>>() { | ||
|
Contributor
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. :(
Member
Author
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 despise as opposed to |
||
| @Override | ||
| public boolean matches(Object item) { | ||
| return (item instanceof LongObjectHashMap && ((LongObjectHashMap) item).isEmpty()); | ||
| } | ||
|
|
||
| @Override | ||
| public void describeTo(Description description) { | ||
| description.appendText("empty"); | ||
| } | ||
| }); | ||
| assertThat(tracker.generateSeqNo(), equalTo((long) (maxSeqNo + 1))); | ||
| } | ||
| } | ||
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.
lol. can we assert we allocated just one array?
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 pushed b2cbfc5.