Skip to content

Commit 90d6317

Browse files
authored
Remove checkpoint tracker bit sets setting
We added an index-level setting for controlling the size of the bit sets used to back the local checkpoint tracker. This setting is really only needed to control the memory footprint of the bit sets but we do not think this setting is going to be needed. This commit removes this setting before it is released to the wild after which we would have to worry about BWC implications. Relates elastic#27191
1 parent ac9addd commit 90d6317

File tree

5 files changed

+18
-39
lines changed

5 files changed

+18
-39
lines changed

core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java

-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
120120
IndexSettings.QUERY_STRING_LENIENT_SETTING,
121121
IndexSettings.ALLOW_UNMAPPED,
122122
IndexSettings.INDEX_CHECK_ON_STARTUP,
123-
LocalCheckpointTracker.SETTINGS_BIT_ARRAYS_SIZE,
124123
IndexSettings.MAX_REFRESH_LISTENERS_PER_SHARD,
125124
IndexSettings.MAX_SLICES_PER_SCROLL,
126125
ShardsLimitAllocationDecider.INDEX_TOTAL_SHARDS_PER_NODE_SETTING,

core/src/main/java/org/elasticsearch/index/seqno/LocalCheckpointTracker.java

+10-18
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,16 @@ public class LocalCheckpointTracker {
3434

3535
/**
3636
* We keep a bit for each sequence number that is still pending. To optimize allocation, we do so in multiple arrays allocating them on
37-
* demand and cleaning up while completed. This setting controls the size of the arrays.
37+
* demand and cleaning up while completed. This constant controls the size of the arrays.
3838
*/
39-
public static Setting<Integer> SETTINGS_BIT_ARRAYS_SIZE =
40-
Setting.intSetting("index.seq_no.checkpoint.bit_arrays_size", 1024, 4, Setting.Property.IndexScope);
39+
static final int BIT_ARRAYS_SIZE = 1024;
4140

4241
/**
4342
* An ordered list of bit arrays representing pending sequence numbers. The list is "anchored" in {@link #firstProcessedSeqNo} which
4443
* marks the sequence number the fist bit in the first array corresponds to.
4544
*/
4645
final LinkedList<FixedBitSet> processedSeqNo = new LinkedList<>();
4746

48-
/**
49-
* The size of each bit set representing processed sequence numbers.
50-
*/
51-
private final int bitArraysSize;
52-
5347
/**
5448
* The sequence number that the first bit in the first array corresponds to.
5549
*/
@@ -70,11 +64,10 @@ public class LocalCheckpointTracker {
7064
* {@link SequenceNumbers#NO_OPS_PERFORMED} and {@code localCheckpoint} should be set to the last known local checkpoint,
7165
* or {@link SequenceNumbers#NO_OPS_PERFORMED}.
7266
*
73-
* @param indexSettings the index settings
7467
* @param maxSeqNo the last sequence number assigned, or {@link SequenceNumbers#NO_OPS_PERFORMED}
7568
* @param localCheckpoint the last known local checkpoint, or {@link SequenceNumbers#NO_OPS_PERFORMED}
7669
*/
77-
public LocalCheckpointTracker(final IndexSettings indexSettings, final long maxSeqNo, final long localCheckpoint) {
70+
public LocalCheckpointTracker(final long maxSeqNo, final long localCheckpoint) {
7871
if (localCheckpoint < 0 && localCheckpoint != SequenceNumbers.NO_OPS_PERFORMED) {
7972
throw new IllegalArgumentException(
8073
"local checkpoint must be non-negative or [" + SequenceNumbers.NO_OPS_PERFORMED + "] "
@@ -84,7 +77,6 @@ public LocalCheckpointTracker(final IndexSettings indexSettings, final long maxS
8477
throw new IllegalArgumentException(
8578
"max seq. no. must be non-negative or [" + SequenceNumbers.NO_OPS_PERFORMED + "] but was [" + maxSeqNo + "]");
8679
}
87-
bitArraysSize = SETTINGS_BIT_ARRAYS_SIZE.get(indexSettings.getSettings());
8880
firstProcessedSeqNo = localCheckpoint == SequenceNumbers.NO_OPS_PERFORMED ? 0 : localCheckpoint + 1;
8981
nextSeqNo = maxSeqNo == SequenceNumbers.NO_OPS_PERFORMED ? 0 : maxSeqNo + 1;
9082
checkpoint = localCheckpoint;
@@ -183,7 +175,7 @@ synchronized void waitForOpsToComplete(final long seqNo) throws InterruptedExcep
183175
@SuppressForbidden(reason = "Object#notifyAll")
184176
private void updateCheckpoint() {
185177
assert Thread.holdsLock(this);
186-
assert checkpoint < firstProcessedSeqNo + bitArraysSize - 1 :
178+
assert checkpoint < firstProcessedSeqNo + BIT_ARRAYS_SIZE - 1 :
187179
"checkpoint should be below the end of the first bit set (o.w. current bit set is completed and shouldn't be there)";
188180
assert getBitSetForSeqNo(checkpoint + 1) == processedSeqNo.getFirst() :
189181
"checkpoint + 1 doesn't point to the first bit set (o.w. current bit set is completed and shouldn't be there)";
@@ -196,10 +188,10 @@ assert getBitSetForSeqNo(checkpoint + 1).get(seqNoToBitSetOffset(checkpoint + 1)
196188
checkpoint++;
197189
// the checkpoint always falls in the first bit set or just before. If it falls
198190
// on the last bit of the current bit set, we can clean it.
199-
if (checkpoint == firstProcessedSeqNo + bitArraysSize - 1) {
191+
if (checkpoint == firstProcessedSeqNo + BIT_ARRAYS_SIZE - 1) {
200192
processedSeqNo.removeFirst();
201-
firstProcessedSeqNo += bitArraysSize;
202-
assert checkpoint - firstProcessedSeqNo < bitArraysSize;
193+
firstProcessedSeqNo += BIT_ARRAYS_SIZE;
194+
assert checkpoint - firstProcessedSeqNo < BIT_ARRAYS_SIZE;
203195
current = processedSeqNo.peekFirst();
204196
}
205197
} while (current != null && current.get(seqNoToBitSetOffset(checkpoint + 1)));
@@ -218,13 +210,13 @@ assert getBitSetForSeqNo(checkpoint + 1).get(seqNoToBitSetOffset(checkpoint + 1)
218210
private FixedBitSet getBitSetForSeqNo(final long seqNo) {
219211
assert Thread.holdsLock(this);
220212
assert seqNo >= firstProcessedSeqNo : "seqNo: " + seqNo + " firstProcessedSeqNo: " + firstProcessedSeqNo;
221-
final long bitSetOffset = (seqNo - firstProcessedSeqNo) / bitArraysSize;
213+
final long bitSetOffset = (seqNo - firstProcessedSeqNo) / BIT_ARRAYS_SIZE;
222214
if (bitSetOffset > Integer.MAX_VALUE) {
223215
throw new IndexOutOfBoundsException(
224216
"sequence number too high; got [" + seqNo + "], firstProcessedSeqNo [" + firstProcessedSeqNo + "]");
225217
}
226218
while (bitSetOffset >= processedSeqNo.size()) {
227-
processedSeqNo.add(new FixedBitSet(bitArraysSize));
219+
processedSeqNo.add(new FixedBitSet(BIT_ARRAYS_SIZE));
228220
}
229221
return processedSeqNo.get((int) bitSetOffset);
230222
}
@@ -239,7 +231,7 @@ private FixedBitSet getBitSetForSeqNo(final long seqNo) {
239231
private int seqNoToBitSetOffset(final long seqNo) {
240232
assert Thread.holdsLock(this);
241233
assert seqNo >= firstProcessedSeqNo;
242-
return ((int) (seqNo - firstProcessedSeqNo)) % bitArraysSize;
234+
return ((int) (seqNo - firstProcessedSeqNo)) % BIT_ARRAYS_SIZE;
243235
}
244236

245237
}

core/src/main/java/org/elasticsearch/index/seqno/SequenceNumbersService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public SequenceNumbersService(
5656
final long localCheckpoint,
5757
final long globalCheckpoint) {
5858
super(shardId, indexSettings);
59-
localCheckpointTracker = new LocalCheckpointTracker(indexSettings, maxSeqNo, localCheckpoint);
59+
localCheckpointTracker = new LocalCheckpointTracker(maxSeqNo, localCheckpoint);
6060
globalCheckpointTracker = new GlobalCheckpointTracker(shardId, allocationId, indexSettings, globalCheckpoint);
6161
}
6262

core/src/main/java/org/elasticsearch/indices/recovery/RecoverySourceHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ boolean isTranslogReadyForSequenceNumberBasedRecovery() throws IOException {
243243

244244
logger.trace("all operations up to [{}] completed, checking translog content", endingSeqNo);
245245

246-
final LocalCheckpointTracker tracker = new LocalCheckpointTracker(shard.indexSettings(), startingSeqNo, startingSeqNo - 1);
246+
final LocalCheckpointTracker tracker = new LocalCheckpointTracker(startingSeqNo, startingSeqNo - 1);
247247
try (Translog.Snapshot snapshot = shard.getTranslog().newSnapshotFromMinSeqNo(startingSeqNo)) {
248248
Translog.Operation operation;
249249
while ((operation = snapshot.next()) != null) {

core/src/test/java/org/elasticsearch/index/seqno/LocalCheckpointTrackerTests.java

+6-18
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121

2222
import org.elasticsearch.ElasticsearchException;
2323
import org.elasticsearch.common.Randomness;
24-
import org.elasticsearch.common.settings.Settings;
2524
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
2625
import org.elasticsearch.test.ESTestCase;
27-
import org.elasticsearch.test.IndexSettingsModule;
2826
import org.junit.Before;
2927

3028
import java.util.ArrayList;
@@ -38,6 +36,7 @@
3836
import java.util.stream.Collectors;
3937
import java.util.stream.IntStream;
4038

39+
import static org.elasticsearch.index.seqno.LocalCheckpointTracker.BIT_ARRAYS_SIZE;
4140
import static org.hamcrest.Matchers.empty;
4241
import static org.hamcrest.Matchers.equalTo;
4342
import static org.hamcrest.Matchers.isOneOf;
@@ -46,19 +45,8 @@ public class LocalCheckpointTrackerTests extends ESTestCase {
4645

4746
private LocalCheckpointTracker tracker;
4847

49-
private static final int SMALL_CHUNK_SIZE = 4;
50-
5148
public static LocalCheckpointTracker createEmptyTracker() {
52-
return new LocalCheckpointTracker(
53-
IndexSettingsModule.newIndexSettings(
54-
"test",
55-
Settings
56-
.builder()
57-
.put(LocalCheckpointTracker.SETTINGS_BIT_ARRAYS_SIZE.getKey(), SMALL_CHUNK_SIZE)
58-
.build()),
59-
SequenceNumbers.NO_OPS_PERFORMED,
60-
SequenceNumbers.NO_OPS_PERFORMED
61-
);
49+
return new LocalCheckpointTracker(SequenceNumbers.NO_OPS_PERFORMED, SequenceNumbers.NO_OPS_PERFORMED);
6250
}
6351

6452
@Override
@@ -98,7 +86,7 @@ public void testSimpleReplica() {
9886
public void testSimpleOverFlow() {
9987
List<Integer> seqNoList = new ArrayList<>();
10088
final boolean aligned = randomBoolean();
101-
final int maxOps = SMALL_CHUNK_SIZE * randomIntBetween(1, 5) + (aligned ? 0 : randomIntBetween(1, SMALL_CHUNK_SIZE - 1));
89+
final int maxOps = BIT_ARRAYS_SIZE * randomIntBetween(1, 5) + (aligned ? 0 : randomIntBetween(1, BIT_ARRAYS_SIZE - 1));
10290

10391
for (int i = 0; i < maxOps; i++) {
10492
seqNoList.add(i);
@@ -109,7 +97,7 @@ public void testSimpleOverFlow() {
10997
}
11098
assertThat(tracker.checkpoint, equalTo(maxOps - 1L));
11199
assertThat(tracker.processedSeqNo.size(), equalTo(aligned ? 0 : 1));
112-
assertThat(tracker.firstProcessedSeqNo, equalTo(((long) maxOps / SMALL_CHUNK_SIZE) * SMALL_CHUNK_SIZE));
100+
assertThat(tracker.firstProcessedSeqNo, equalTo(((long) maxOps / BIT_ARRAYS_SIZE) * BIT_ARRAYS_SIZE));
113101
}
114102

115103
public void testConcurrentPrimary() throws InterruptedException {
@@ -150,7 +138,7 @@ protected void doRun() throws Exception {
150138
tracker.markSeqNoAsCompleted(unFinishedSeq);
151139
assertThat(tracker.getCheckpoint(), equalTo(maxOps - 1L));
152140
assertThat(tracker.processedSeqNo.size(), isOneOf(0, 1));
153-
assertThat(tracker.firstProcessedSeqNo, equalTo(((long) maxOps / SMALL_CHUNK_SIZE) * SMALL_CHUNK_SIZE));
141+
assertThat(tracker.firstProcessedSeqNo, equalTo(((long) maxOps / BIT_ARRAYS_SIZE) * BIT_ARRAYS_SIZE));
154142
}
155143

156144
public void testConcurrentReplica() throws InterruptedException {
@@ -198,7 +186,7 @@ protected void doRun() throws Exception {
198186
assertThat(tracker.getCheckpoint(), equalTo(unFinishedSeq - 1L));
199187
tracker.markSeqNoAsCompleted(unFinishedSeq);
200188
assertThat(tracker.getCheckpoint(), equalTo(maxOps - 1L));
201-
assertThat(tracker.firstProcessedSeqNo, equalTo(((long) maxOps / SMALL_CHUNK_SIZE) * SMALL_CHUNK_SIZE));
189+
assertThat(tracker.firstProcessedSeqNo, equalTo(((long) maxOps / BIT_ARRAYS_SIZE) * BIT_ARRAYS_SIZE));
202190
}
203191

204192
public void testWaitForOpsToComplete() throws BrokenBarrierException, InterruptedException {

0 commit comments

Comments
 (0)