com.gemstone.gemfire.internal.cache.versions.RVVException Maven / Gradle / Ivy
Show all versions of gemfire-core Show documentation
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.gemstone.gemfire.internal.cache.versions;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import com.gemstone.gemfire.internal.InternalDataSerializer;
import com.gemstone.gemfire.internal.VersionedDataSerializable;
import com.gemstone.gemfire.internal.shared.Version;
/**
* RVV exceptions are part of a RegionVersionVector. They are held by
* RegionVersionHolders.
*
* An RVV exception represents a missing range of versions from a member.
* This is represented as a pair of version numbers: the last version we've
* received from the member and the next version we've received from the member.
* The span of versions between (but not including) these two numbers are
* the versions that are missing.
*
* RVVException also tracks the scattering of versions we've received that fall
* within the range of the exception. As these missing versions are received
* the RVVException coalesces the range. If isFilled() returns true after
* adding a missing version to the RVVException, the hole has been filled
* and the RVVException is no longer needed.
*
* New exceptions are common to see as operations
* arrive from parallel threads operating on the same region. These exceptions
* are soon mended and disappear.
*
* Old exceptions indicate that we missed something that we are unlikely
* to receive without asking for it.
*
* RVVException currently depends on external synchronization. Typically the
* RegionVersionHolder that holds the exception is locked while accessing
* its RVVExceptions. This is what is done in RegionVersionVector.
*
* @author Bruce Schuchardt
*/
abstract class RVVException implements Comparable, Cloneable, VersionedDataSerializable {
protected static boolean UseTreeSetsForTesting = false;
/**
* The maximum version span that can be represented by a bitset
* RVVException. If the span is greater than this we use the
* version of RVVException that collects "received versions" in a
* regular collection.
*/
protected static final long RVV_MAX_BITSET_SPAN = 128 * 8; // 128 bytes gives a span of 1k versions
long previousVersion;
long nextVersion;
static RVVException createException(long previousVersion, long nextVersion) {
return createException(previousVersion, nextVersion, 0);
}
/** 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);
}
RVVException(long previousVersion, long nextVersion) {
this.previousVersion = previousVersion;
this.nextVersion = nextVersion;
}
/**
* 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= this.nextVersion;
}
public abstract RVVException clone();
/* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
public int compareTo(RVVException o) {
long thisVal = this.previousVersion;
long anotherVal = o.previousVersion;
return (thisVal