@@ -70,7 +70,7 @@ public Translog.Operation next() throws IOException {
7070 while ((op = current .next ()) != null ) {
7171 if (op .seqNo () < 0 || seenSeqNo .getAndSet (op .seqNo ()) == false ) {
7272 return op ;
73- }else {
73+ } else {
7474 skippedOperations ++;
7575 }
7676 }
@@ -111,12 +111,13 @@ boolean hasAllBitsOn() {
111111 }
112112
113113 /**
114- * Sequence numbers from translog are likely to form contiguous ranges, thus using two tiers can reduce memory usage.
114+ * Sequence numbers from translog are likely to form contiguous ranges,
115+ * thus collapsing a completed bitset into a single entry will reduce memory usage.
115116 */
116117 static final class SeqNumSet {
117118 static final short BIT_SET_SIZE = 1024 ;
118- private final LongSet topTier = new LongHashSet ();
119- private final LongObjectHashMap <CountedBitSet > bottomTier = new LongObjectHashMap <>();
119+ private final LongSet completedSets = new LongHashSet ();
120+ private final LongObjectHashMap <CountedBitSet > ongoingSets = new LongObjectHashMap <>();
120121
121122 /**
122123 * Marks this sequence number and returns <tt>true</tt> if it is seen before.
@@ -125,22 +126,32 @@ boolean getAndSet(long value) {
125126 assert value >= 0 ;
126127 final long key = value / BIT_SET_SIZE ;
127128
128- if (topTier .contains (key )) {
129+ if (completedSets .contains (key )) {
129130 return true ;
130131 }
131132
132- CountedBitSet bitset = bottomTier .get (key );
133+ CountedBitSet bitset = ongoingSets .get (key );
133134 if (bitset == null ) {
134135 bitset = new CountedBitSet (BIT_SET_SIZE );
135- bottomTier .put (key , bitset );
136+ ongoingSets .put (key , bitset );
136137 }
137138
138139 final boolean wasOn = bitset .getAndSet (Math .toIntExact (value % BIT_SET_SIZE ));
139140 if (bitset .hasAllBitsOn ()) {
140- bottomTier .remove (key );
141- topTier .add (key );
141+ ongoingSets .remove (key );
142+ completedSets .add (key );
142143 }
143144 return wasOn ;
144145 }
146+
147+ // For testing
148+ long completeSetsSize () {
149+ return completedSets .size ();
150+ }
151+
152+ // For testing
153+ long ongoingSetsSize () {
154+ return ongoingSets .size ();
155+ }
145156 }
146157}
0 commit comments