From 59350092ea20dc6e7221409fe50633177e94f12b Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Wed, 8 Nov 2017 14:07:53 -0500 Subject: [PATCH] remove tier in name and comment --- .../index/translog/MultiSnapshot.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/translog/MultiSnapshot.java b/core/src/main/java/org/elasticsearch/index/translog/MultiSnapshot.java index 11e78540b029d..0983bfdb32c83 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/MultiSnapshot.java +++ b/core/src/main/java/org/elasticsearch/index/translog/MultiSnapshot.java @@ -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++; } } @@ -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 bottomTier = new LongObjectHashMap<>(); + private final LongSet completedSets = new LongHashSet(); + private final LongObjectHashMap ongoingSets = new LongObjectHashMap<>(); /** * Marks this sequence number and returns true if it is seen before. @@ -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(); + } } }