Skip to content

Commit

Permalink
remove tier in name and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
dnhatn committed Nov 8, 2017
1 parent d006988 commit 5935009
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Translog.Operation next() throws IOException {
while ((op = current.next()) != null) {
if (op.seqNo() < 0 || seenSeqNo.getAndSet(op.seqNo()) == false) {
return op;
}else {
} else {
skippedOperations++;
}
}
Expand Down Expand Up @@ -111,12 +111,13 @@ boolean hasAllBitsOn() {
}

/**
* Sequence numbers from translog are likely to form contiguous ranges, thus using two tiers can reduce memory usage.
* 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 short BIT_SET_SIZE = 1024;
private final LongSet topTier = new LongHashSet();
private final LongObjectHashMap<CountedBitSet> bottomTier = new LongObjectHashMap<>();
private final LongSet completedSets = new LongHashSet();
private final LongObjectHashMap<CountedBitSet> ongoingSets = new LongObjectHashMap<>();

/**
* Marks this sequence number and returns <tt>true</tt> if it is seen before.
Expand All @@ -125,22 +126,32 @@ boolean getAndSet(long value) {
assert value >= 0;
final long key = value / BIT_SET_SIZE;

if (topTier.contains(key)) {
if (completedSets.contains(key)) {
return true;
}

CountedBitSet bitset = bottomTier.get(key);
CountedBitSet bitset = ongoingSets.get(key);
if (bitset == null) {
bitset = new CountedBitSet(BIT_SET_SIZE);
bottomTier.put(key, bitset);
ongoingSets.put(key, bitset);
}

final boolean wasOn = bitset.getAndSet(Math.toIntExact(value % BIT_SET_SIZE));
if (bitset.hasAllBitsOn()) {
bottomTier.remove(key);
topTier.add(key);
ongoingSets.remove(key);
completedSets.add(key);
}
return wasOn;
}

// For testing
long completeSetsSize() {
return completedSets.size();
}

// For testing
long ongoingSetsSize() {
return ongoingSets.size();
}
}
}

0 comments on commit 5935009

Please sign in to comment.