fine = e.toString(); e.add(missingVersion); if (e.isFilled()) { if (fine != null) { logger.trace(LogMarker.RVV_VERBOSE, "Filled exception {}", fine); } else if (e.shouldChangeForm()) { this.exceptions.set(i, e.changeForm());
if (exception.isEmpty()) { canon.add(exception); } else { exception.receivedVersionsReverseIterator(); it.hasNext();) { long received = it.next(); canon.add(RVVException.createException(received, previous)); canon.add(RVVException.createException(exception.previousVersion, previous));
@Override public synchronized RegionVersionHolder<T> clone() { RegionVersionHolder<T> clone = new RegionVersionHolder<T>(this.version); clone.id = this.id; clone.isDepartedMember = this.isDepartedMember; if (this.exceptions != null) { clone.exceptions = new LinkedList<RVVException>(); for (RVVException e : this.exceptions) { clone.exceptions.add(e.clone()); } } if (this.bitSet != null) { clone.bitSet = (BitSet) this.bitSet.clone(); clone.bitSetVersion = this.bitSetVersion; clone.mergeBitSet(); } return clone; }
@Test public void testCanonicalExceptions() { List<RVVException> exceptionList = new ArrayList<>(); for (int i = NUM_TEST_EXCEPTIONS; i > 0; --i) { long start = i * TEST_EXCEPTION_SIZE; long end = start + TEST_EXCEPTION_SIZE; RVVException testException = RVVException.createException(start, end); for (long j = start + 2; j < end; j += 2) { testException.add(j); } exceptionList.add(testException); } List<RVVException> canonicalExceptions = RegionVersionHolder.canonicalExceptions(exceptionList); long expectedStart = NUM_TEST_EXCEPTIONS * TEST_EXCEPTION_SIZE + TEST_EXCEPTION_SIZE - 2; for (RVVException exception : canonicalExceptions) { assertEquals(expectedStart, exception.previousVersion); assertEquals(expectedStart + 2, exception.nextVersion); assertTrue(exception.isEmpty()); expectedStart -= 2; } }
RVVException e = RVVException.createException(this.version, myVersion + 1); if (e.compareTo(exception) >= 0) { break;
/** * RegionVersionHolder.fromData() calls this to create an exception */ static RVVException createException(DataInput in) throws IOException { long previousVersion = InternalDataSerializer.readUnsignedVL(in); int size = (int) InternalDataSerializer.readUnsignedVL(in); long last = previousVersion; long[] versions = new long[(int) size]; for (int i = 0; i < size; i++) { long delta = InternalDataSerializer.readUnsignedVL(in); long value = delta + last; versions[i] = value; last = value; } long delta = InternalDataSerializer.readUnsignedVL(in); long nextVersion = last + delta; RVVException result = createException(previousVersion, nextVersion, size); for (int i = 0; i < size; i++) { result.addReceived(versions[i]); } return result; }
private void testExceptionOutput(RVVException ex) throws Exception { ex.add(60); ex.add(85); ex.add(70); ex.add(72); ex.add(74); ex.add(73); DataOutput mockOutput = mock(DataOutput.class); InOrder inOrder = Mockito.inOrder(mockOutput); ex.toData(mockOutput); inOrder.verify(mockOutput).writeByte(50); // prev = 50 inOrder.verify(mockOutput).writeByte(6); // 6 received versions inOrder.verify(mockOutput, times(2)).writeByte(10); // 60, 70 inOrder.verify(mockOutput).writeByte(2); // 72 inOrder.verify(mockOutput, times(2)).writeByte(1); // 73, 74 inOrder.verify(mockOutput).writeByte(11); // 85 inOrder.verify(mockOutput).writeByte(15); // 100 inOrder.verifyNoMoreInteractions(); } }
/** * Add an exception that is older than this.bitSetVersion. */ protected synchronized void addException(long previousVersion, long nextVersion) { if (this.exceptions == null) { this.exceptions = new LinkedList<RVVException>(); } int i = 0; for (Iterator<RVVException> it = this.exceptions.iterator(); it.hasNext(); i++) { RVVException e = it.next(); if (previousVersion >= e.nextVersion) { RVVException except = RVVException.createException(previousVersion, nextVersion); this.exceptions.add(i, except); return; } } this.exceptions.add(RVVException.createException(previousVersion, nextVersion)); }
ex.receivedVersionsReverseIterator(); it.hasNext();) { Long received = it.next(); if (received >= ex.nextVersion) {
/** * Returns true if this version hold has an exception in the exception list for the given version * number. * * This differs from contains because it returns true if v is greater than the last seen version * for this holder. */ synchronized boolean hasExceptionFor(long v) { if (this.bitSet != null && v >= this.bitSetVersion) { if (v > this.bitSetVersion + this.bitSet.length()) { return false; } return this.bitSet.get((int) (v - this.bitSetVersion)); } if (this.exceptions == null) { return false; } for (Iterator<RVVException> it = this.exceptions.iterator(); it.hasNext();) { RVVException e = it.next(); if (e.nextVersion <= v) { return false; // there is no RVVException for this version } if (e.previousVersion < v) { return !e.contains(v); } } return false; }
public synchronized long getVersion() { RVVException e = null; List<RVVException> exs = getExceptions(); if (!exs.isEmpty()) { e = exs.get(0); } if (isSpecialException(e, this)) { return e.getHighestReceivedVersion(); } else { return this.version; } }
@Override public void fromData(DataInput in) throws IOException { this.version = InternalDataSerializer.readUnsignedVL(in); int size = (int) InternalDataSerializer.readUnsignedVL(in); this.isDepartedMember = in.readBoolean(); if (size > 0) { this.exceptions = new LinkedList<RVVException>(); for (int i = 0; i < size; i++) { RVVException e = RVVException.createException(in); this.exceptions.add(e); } } }
/** * returns true if this version holder has seen the given version number */ synchronized boolean contains(long v) { if (v > getVersion()) { return false; } else { if (this.bitSet != null && v >= this.bitSetVersion) { return this.bitSet.get((int) (v - this.bitSetVersion)); } if (this.exceptions == null) { return true; } for (Iterator<RVVException> it = this.exceptions.iterator(); it.hasNext();) { RVVException e = it.next(); if (e.nextVersion <= v) { return true; // there is no RVVException for this version } if (e.previousVersion < v) { return e.contains(v); } } return true; } }
/** Use this method to create a new RVVException */ static RVVException createException(long previousVersion, long nextVersion, long initialExceptionCount) { // arbitrary cutoff of 100 bytes to use a treeSet instead of bitSet // But if we are deserializing an exception too many received versions use a // bitset anyway. long delta = nextVersion - previousVersion; if (UseTreeSetsForTesting || (delta > RVV_MAX_BITSET_SPAN && initialExceptionCount * 512 < delta)) { return new RVVExceptionT(previousVersion, nextVersion); } return new RVVExceptionB(previousVersion, nextVersion); }