use of org.apache.geode.internal.cache.versions.VersionStamp in project geode by apache.
the class AbstractRegionEntry method basicProcessVersionTag.
protected void basicProcessVersionTag(LocalRegion region, VersionTag tag, boolean isTombstoneFromGII, boolean deltaCheck, VersionSource dmId, InternalDistributedMember sender, boolean checkForConflict) {
if (tag != null) {
VersionStamp stamp = getVersionStamp();
StringBuilder verbose = null;
if (logger.isTraceEnabled(LogMarker.TOMBSTONE)) {
VersionTag stampTag = stamp.asVersionTag();
if (stampTag.hasValidVersion() && checkForConflict) {
// only be verbose here if there's a possibility we might reject the operation
verbose = new StringBuilder();
verbose.append("processing tag for key ").append(getKey()).append(", stamp=").append(stamp.asVersionTag()).append(", tag=").append(tag).append(", checkForConflict=").append(checkForConflict);
}
}
if (stamp == null) {
throw new IllegalStateException("message contained a version tag but this region has no version storage");
}
boolean apply = true;
try {
if (checkForConflict) {
apply = checkForConflict(region, stamp, tag, isTombstoneFromGII, deltaCheck, dmId, sender, verbose);
}
} catch (ConcurrentCacheModificationException e) {
// applied there
if (!tag.isGatewayTag() && stamp.getDistributedSystemId() == tag.getDistributedSystemId() && tag.getVersionTimeStamp() > stamp.getVersionTimeStamp()) {
stamp.setVersionTimeStamp(tag.getVersionTimeStamp());
tag.setTimeStampApplied(true);
if (verbose != null) {
verbose.append("\nThough in conflict the tag timestamp was more recent and was recorded.");
}
}
throw e;
} finally {
if (verbose != null) {
logger.trace(LogMarker.TOMBSTONE, verbose);
}
}
if (apply) {
applyVersionTag(region, stamp, tag, sender);
}
}
}
use of org.apache.geode.internal.cache.versions.VersionStamp in project geode by apache.
the class AbstractRegionEntry method appendFieldsToString.
protected StringBuilder appendFieldsToString(final StringBuilder sb) {
// OFFHEAP _getValue ok: the current toString on ObjectChunk is safe to use without incing
// refcount.
sb.append("key=").append(getKey()).append("; rawValue=").append(_getValue());
VersionStamp stamp = getVersionStamp();
if (stamp != null) {
sb.append("; version=").append(stamp.asVersionTag()).append(";member=").append(stamp.getMemberID());
}
return sb;
}
use of org.apache.geode.internal.cache.versions.VersionStamp in project geode by apache.
the class PartitionedRegion method getAllBucketEntries.
/**
* Test Method: Get all entries for all copies of a bucket
*
* This method will not work correctly if membership in the distributed system changes while the
* result is being calculated.
*
* @return a List of HashMaps, each map being a copy of the entries in a bucket
*/
public List<BucketDump> getAllBucketEntries(final int bucketId) throws ForceReattemptException {
if (bucketId >= getTotalNumberOfBuckets()) {
return Collections.emptyList();
}
ArrayList<BucketDump> ret = new ArrayList<BucketDump>();
HashSet<InternalDistributedMember> collected = new HashSet<InternalDistributedMember>();
for (; ; ) {
// Collect all the candidates by re-examining the advisor...
Set<InternalDistributedMember> owners = getRegionAdvisor().getBucketOwners(bucketId);
// Remove ones we've already polled...
owners.removeAll(collected);
// Terminate if no more entries
if (owners.isEmpty()) {
break;
}
// Get first entry
Iterator<InternalDistributedMember> ownersI = owners.iterator();
InternalDistributedMember owner = (InternalDistributedMember) ownersI.next();
// Remove it from our list
collected.add(owner);
// If it is ourself, answer directly
if (owner.equals(getMyId())) {
BucketRegion br = this.dataStore.handleRemoteGetEntries(bucketId);
Map<Object, Object> m = new HashMap<Object, Object>() {
// TODO: clean this up -- outer class is not serializable
private static final long serialVersionUID = 0L;
@Override
public String toString() {
return "Bucket id = " + bucketId + " from local member = " + getDistributionManager().getDistributionManagerId() + ": " + super.toString();
}
};
Map<Object, VersionTag> versions = new HashMap<Object, VersionTag>();
for (Iterator<Map.Entry> it = br.entrySet().iterator(); it.hasNext(); ) {
LocalRegion.NonTXEntry entry = (LocalRegion.NonTXEntry) it.next();
RegionEntry re = entry.getRegionEntry();
// OFFHEAP: incrc, deserialize, decrc
Object value = re.getValue(br);
VersionStamp versionStamp = re.getVersionStamp();
VersionTag versionTag = versionStamp != null ? versionStamp.asVersionTag() : null;
if (versionTag != null) {
versionTag.replaceNullIDs(br.getVersionMember());
}
if (Token.isRemoved(value)) {
continue;
} else if (Token.isInvalid(value)) {
value = null;
} else if (value instanceof CachedDeserializable) {
value = ((CachedDeserializable) value).getDeserializedForReading();
}
m.put(re.getKey(), value);
versions.put(re.getKey(), versionTag);
}
RegionVersionVector rvv = br.getVersionVector();
rvv = rvv != null ? rvv.getCloneForTransmission() : null;
ret.add(new BucketDump(bucketId, owner, rvv, m, versions));
continue;
}
// Send a message
try {
final FetchEntriesResponse r;
r = FetchEntriesMessage.send(owner, this, bucketId);
ret.add(r.waitForEntries());
} catch (ForceReattemptException ignore) {
// node has departed? Ignore.
}
}
return ret;
}
use of org.apache.geode.internal.cache.versions.VersionStamp in project geode by apache.
the class UpdateVersionJUnitTest method testUpdateVersionAfterUpdateOnPR.
@Test
public void testUpdateVersionAfterUpdateOnPR() {
Cache cache = new CacheFactory().set(MCAST_PORT, "0").create();
Region region = cache.createRegionFactory(RegionShortcut.PARTITION).create(regionName);
try {
region.create("key-1", "value-1");
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
region.put("key-1", "value-2");
Entry entry = region.getEntry("key-1");
assertTrue(entry instanceof EntrySnapshot);
RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
VersionStamp stamp = regionEntry.getVersionStamp();
// Create a duplicate entry version tag from stamp with newer time-stamp.
VersionTag tag = VersionTag.create(stamp.getMemberID());
int entryVersion = stamp.getEntryVersion();
VersionSource member = stamp.getMemberID();
int dsid = stamp.getDistributedSystemId();
long time = System.currentTimeMillis();
tag.setEntryVersion(entryVersion);
tag.setDistributedSystemId(dsid);
tag.setVersionTimeStamp(time);
tag.setIsGatewayTag(true);
assertTrue(region instanceof PartitionedRegion);
EntryEventImpl event = createNewEvent((PartitionedRegion) region, tag, entry.getKey());
((PartitionedRegion) region).basicUpdateEntryVersion(event);
// Verify the new stamp
entry = region.getEntry("key-1");
assertTrue(entry instanceof EntrySnapshot);
regionEntry = ((EntrySnapshot) entry).getRegionEntry();
stamp = regionEntry.getVersionStamp();
assertEquals("Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion", time, stamp.getVersionTimeStamp());
assertEquals(++entryVersion, stamp.getEntryVersion());
assertEquals(member, stamp.getMemberID());
assertEquals(dsid, stamp.getDistributedSystemId());
} finally {
region.destroyRegion();
cache.close();
}
}
use of org.apache.geode.internal.cache.versions.VersionStamp in project geode by apache.
the class UpdateVersionJUnitTest method testUpdateVersionAfterUpdate.
@Test
public void testUpdateVersionAfterUpdate() {
Cache cache = new CacheFactory().set(MCAST_PORT, "0").create();
Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
try {
region.create("key-1", "value-1");
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
region.put("key-1", "value-2");
Entry entry = region.getEntry("key-1");
assertTrue(entry instanceof NonTXEntry);
RegionEntry regionEntry = ((NonTXEntry) entry).getRegionEntry();
VersionStamp stamp = regionEntry.getVersionStamp();
// Create a duplicate entry version tag from stamp with newer time-stamp.
VersionTag tag = VersionTag.create(stamp.getMemberID());
int entryVersion = stamp.getEntryVersion();
VersionSource member = stamp.getMemberID();
int dsid = stamp.getDistributedSystemId();
// Just in case if clock hasn't ticked.
long time = System.currentTimeMillis() + 1;
tag.setEntryVersion(entryVersion);
tag.setDistributedSystemId(dsid);
tag.setVersionTimeStamp(time);
tag.setIsGatewayTag(true);
assertTrue(region instanceof LocalRegion);
EntryEventImpl event = createNewEvent((LocalRegion) region, tag, entry.getKey());
((LocalRegion) region).basicUpdateEntryVersion(event);
// Verify the new stamp
entry = region.getEntry("key-1");
assertTrue(entry instanceof NonTXEntry);
regionEntry = ((NonTXEntry) entry).getRegionEntry();
stamp = regionEntry.getVersionStamp();
assertEquals("Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion", time, stamp.getVersionTimeStamp());
assertEquals(++entryVersion, stamp.getEntryVersion());
assertEquals(member, stamp.getMemberID());
assertEquals(dsid, stamp.getDistributedSystemId());
} finally {
region.destroyRegion();
cache.close();
}
}
Aggregations