Skip to content

Commit

Permalink
SeqNum -> SeqNo
Browse files Browse the repository at this point in the history
  • Loading branch information
dnhatn committed Nov 22, 2017
1 parent 7d3482b commit a3994f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class MultiSnapshot implements Translog.Snapshot {
private int overriddenOperations;
private final Closeable onClose;
private int index;
private final SeqNumSet seenSeqNo;
private final SeqNoSet seenSeqNo;

/**
* Creates a new point in time snapshot of the given snapshots. Those snapshots are always iterated in-order.
Expand All @@ -49,7 +49,7 @@ final class MultiSnapshot implements Translog.Snapshot {
this.totalOperations = Arrays.stream(translogs).mapToInt(TranslogSnapshot::totalOperations).sum();
this.overriddenOperations = 0;
this.onClose = onClose;
this.seenSeqNo = new SeqNumSet();
this.seenSeqNo = new SeqNoSet();
this.index = translogs.length - 1;
}

Expand Down Expand Up @@ -115,7 +115,7 @@ boolean hasAllBitsOn() {
* Sequence numbers from translog are likely to form contiguous ranges,
* thus collapsing a completed bitset into a single entry will reduce memory usage.
*/
static final class SeqNumSet {
static final class SeqNoSet {
static final short BIT_SET_SIZE = 1024;
private final LongSet completedSets = new LongHashSet();
private final LongObjectHashMap<CountedBitSet> ongoingSets = new LongObjectHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

public class MultiSnapshotTests extends ESTestCase {

public void testTrackSimpleSeqNoRanges() throws Exception {
final MultiSnapshot.SeqNumSet bitSet = new MultiSnapshot.SeqNumSet();
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++) {
Expand All @@ -52,29 +52,29 @@ public void testTrackSimpleSeqNoRanges() throws Exception {
assertThat(bitSet.getAndSet(between(1024, Integer.MAX_VALUE)), equalTo(false));
}

public void testTrackSeqNumDenseRanges() throws Exception {
final MultiSnapshot.SeqNumSet bitSet = new MultiSnapshot.SeqNumSet();
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("SeqNumSet != Set" + seq, bitSet.getAndSet(seq), equalTo(existed));
assertThat("SeqNoSet != Set" + seq, bitSet.getAndSet(seq), equalTo(existed));
assertThat(bitSet.ongoingSetsSize() + bitSet.completeSetsSize(), lessThanOrEqualTo(5L));
});
}

public void testTrackSeqNumSparseRanges() throws Exception {
final MultiSnapshot.SeqNumSet bitSet = new MultiSnapshot.SeqNumSet();
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("SeqNumSet != Set", bitSet.getAndSet(seq), equalTo(existed));
assertThat("SeqNoSet != Set", bitSet.getAndSet(seq), equalTo(existed));
});
}

public void testSequenceNumMimicTranslog() throws Exception {
final MultiSnapshot.SeqNumSet bitSet = new MultiSnapshot.SeqNumSet();
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);
Expand All @@ -91,7 +91,7 @@ public void testSequenceNumMimicTranslog() throws Exception {
Randomness.shuffle(batch);
batch.forEach(seq -> {
boolean existed = normalSet.add(seq) == false;
assertThat("SeqNumSet != Set", bitSet.getAndSet(seq), equalTo(existed));
assertThat("SeqNoSet != Set", bitSet.getAndSet(seq), equalTo(existed));
assertThat(bitSet.ongoingSetsSize(), lessThanOrEqualTo(4L));
});
assertThat(bitSet.ongoingSetsSize(), lessThanOrEqualTo(2L));
Expand Down

0 comments on commit a3994f8

Please sign in to comment.