Search in sources :

Example 21 with RegionVersionVector

use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.

the class DiskStoreImpl method writeRVV.

public void writeRVV(DiskRegion dr, LocalRegion region, Boolean isRVVTrusted) {
    acquireReadLock(dr);
    try {
        if (dr.isRegionClosed()) {
            dr.getCancelCriterion().checkCancelInProgress(null);
            throw new RegionDestroyedException(LocalizedStrings.DiskRegion_THE_DISKREGION_HAS_BEEN_CLOSED_OR_DESTROYED.toLocalizedString(), dr.getName());
        }
        RegionVersionVector inMemoryRVV = (region == null) ? null : region.getVersionVector();
        // persist the new GC RVV information for this region to the CRF
        PersistentOplogSet oplogSet = getPersistentOplogSet(dr);
        // use current dr.rvvTrust
        oplogSet.getChild().writeRVV(dr, inMemoryRVV, isRVVTrusted);
    } finally {
        releaseReadLock(dr);
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector)

Example 22 with RegionVersionVector

use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.

the class DiskStoreImpl method writeRVVGC.

public void writeRVVGC(DiskRegion dr, LocalRegion region) {
    acquireReadLock(dr);
    try {
        if (dr.isRegionClosed()) {
            region.getCancelCriterion().checkCancelInProgress(null);
            throw new RegionDestroyedException(LocalizedStrings.DiskRegion_THE_DISKREGION_HAS_BEEN_CLOSED_OR_DESTROYED.toLocalizedString(), dr.getName());
        }
        // Update on the on disk region version vector.
        // TODO - RVV - For async regions, it's possible that
        // the on disk RVV is actually less than the GC RVV we're trying record
        // it might make sense to push the RVV through the async queue?
        // What we're doing here is only recording the GC RVV if it is dominated
        // by the RVV of what we have persisted.
        RegionVersionVector inMemoryRVV = region.getVersionVector();
        RegionVersionVector diskRVV = dr.getRegionVersionVector();
        // Update the GC version for each member in our on disk version map
        updateDiskGCRVV(diskRVV, inMemoryRVV, diskRVV.getOwnerId());
        for (VersionSource member : (Collection<VersionSource>) inMemoryRVV.getMemberToGCVersion().keySet()) {
            updateDiskGCRVV(diskRVV, inMemoryRVV, member);
        }
        // Remove any exceptions from the disk RVV that are are dominated
        // by the GC RVV.
        diskRVV.pruneOldExceptions();
        PersistentOplogSet oplogSet = getPersistentOplogSet(dr);
        // persist the new GC RVV information for this region to the DRF
        oplogSet.getChild().writeGCRVV(dr);
    } finally {
        releaseReadLock(dr);
    }
}
Also used : VersionSource(org.apache.geode.internal.cache.versions.VersionSource) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) Collection(java.util.Collection) RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector)

Example 23 with RegionVersionVector

use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.

the class LocalRegion method cmnClearRegion.

// TODO: what does cmn refer to?
void cmnClearRegion(RegionEventImpl regionEvent, boolean cacheWrite, boolean useRVV) {
    RegionVersionVector rvv = null;
    if (useRVV && this.dataPolicy.withReplication() && this.concurrencyChecksEnabled) {
        rvv = this.versionVector.getCloneForTransmission();
    }
    clearRegionLocally(regionEvent, cacheWrite, rvv);
}
Also used : RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector)

Example 24 with RegionVersionVector

use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.

the class Oplog method serializeRVVs.

private byte[] serializeRVVs(Map<Long, AbstractDiskRegion> drMap, boolean gcRVV) throws IOException {
    HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
    // Filter out any regions that do not have versioning enabled
    drMap = new HashMap<Long, AbstractDiskRegion>(drMap);
    for (Iterator<Map.Entry<Long, AbstractDiskRegion>> itr = drMap.entrySet().iterator(); itr.hasNext(); ) {
        Map.Entry<Long, AbstractDiskRegion> regionEntry = itr.next();
        AbstractDiskRegion dr = regionEntry.getValue();
        if (!dr.getFlags().contains(DiskRegionFlag.IS_WITH_VERSIONING)) {
            itr.remove();
        }
    }
    // Write the size first
    InternalDataSerializer.writeUnsignedVL(drMap.size(), out);
    // Now write regions RVV.
    for (Map.Entry<Long, AbstractDiskRegion> regionEntry : drMap.entrySet()) {
        // For each region, write the RVV for the region.
        Long diskRegionID = regionEntry.getKey();
        AbstractDiskRegion dr = regionEntry.getValue();
        RegionVersionVector rvv = dr.getRegionVersionVector();
        if (logger.isTraceEnabled(LogMarker.PERSIST_WRITES)) {
            logger.trace(LogMarker.PERSIST_WRITES, "serializeRVVs: isGCRVV={} drId={} rvv={} oplog#{}", gcRVV, diskRegionID, rvv.fullToString(), getOplogId());
        }
        // Write the disk region id
        InternalDataSerializer.writeUnsignedVL(diskRegionID, out);
        if (gcRVV) {
            // For the GC RVV, we will just write the GC versions
            Map<VersionSource, Long> memberToVersion = rvv.getMemberToGCVersion();
            InternalDataSerializer.writeUnsignedVL(memberToVersion.size(), out);
            for (Entry<VersionSource, Long> memberEntry : memberToVersion.entrySet()) {
                // For each member, write the canonicalized member id,
                // and the version number for that member
                VersionSource member = memberEntry.getKey();
                Long gcVersion = memberEntry.getValue();
                int id = getParent().getDiskInitFile().getOrCreateCanonicalId(member);
                InternalDataSerializer.writeUnsignedVL(id, out);
                InternalDataSerializer.writeUnsignedVL(gcVersion, out);
            }
        } else {
            DataSerializer.writeBoolean(dr.getRVVTrusted(), out);
            // Otherwise, we will write the version and exception list for each
            // member
            Map<VersionSource, RegionVersionHolder> memberToVersion = rvv.getMemberToVersion();
            InternalDataSerializer.writeUnsignedVL(memberToVersion.size(), out);
            for (Map.Entry<VersionSource, RegionVersionHolder> memberEntry : memberToVersion.entrySet()) {
                // For each member, right the canonicalized member id,
                // and the version number with exceptions for that member
                VersionSource member = memberEntry.getKey();
                RegionVersionHolder versionHolder = memberEntry.getValue();
                int id = getParent().getDiskInitFile().getOrCreateCanonicalId(member);
                InternalDataSerializer.writeUnsignedVL(id, out);
                synchronized (versionHolder) {
                    InternalDataSerializer.invokeToData(versionHolder, out);
                }
            }
        }
    }
    return out.toByteArray();
}
Also used : RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) RegionVersionHolder(org.apache.geode.internal.cache.versions.RegionVersionHolder) Entry(java.util.Map.Entry) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 25 with RegionVersionVector

use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.

the class LocalRegion method repairRVV.

/**
   * Fix up our RVV by iterating over the entries in the region and making sure they are applied to
   * the RVV.
   * 
   * If we failed to do a GII, we may have applied the RVV from a remote member. That RVV may not
   * have seen some of the events in our local RVV. Those entries were supposed to be replaced with
   * the results of the GII. However, if we failed the GII, those entries may still be in the cache,
   * but are no longer reflected in the local RVV. This method iterates over those keys and makes
   * sure their versions are applied to the local RVV.
   * 
   * TODO - this method should probably rebuild the RVV from scratch, instead of starting with the
   * existing RVV. By starting with the existing RVV, we may claim to have entries that we actually
   * don't have. Unfortunately, we can't really rebuild the RVV from scratch because we will end up
   * with huge exception lists.
   * 
   * However, if we are in the state of recovering from disk with an untrusted RVV, we must be newer
   * than any other surviving members. So they shouldn't have any entries in their cache that match
   * entries that we failed to receive through the GII but are reflected in our current RVV. So it
   * should be safe to start with the current RVV.
   * 
   */
void repairRVV() {
    RegionVersionVector rvv = this.getVersionVector();
    if (rvv == null) {
        // No need to do anything.
        return;
    }
    Iterator<RegionEntry> it = getBestIterator(false);
    VersionSource<?> myId = getVersionMember();
    // Iterate over the all of the entries
    while (it.hasNext()) {
        RegionEntry mapEntry = it.next();
        VersionStamp<?> stamp = mapEntry.getVersionStamp();
        VersionSource<?> id = stamp.getMemberID();
        if (id == null) {
            id = myId;
        }
        // Make sure the version is applied to the regions RVV
        rvv.recordVersion(id, stamp.getRegionVersion());
    }
}
Also used : RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector)

Aggregations

RegionVersionVector (org.apache.geode.internal.cache.versions.RegionVersionVector)52 DiskStoreID (org.apache.geode.internal.cache.persistence.DiskStoreID)19 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)17 Test (org.junit.Test)17 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)16 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)15 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DataInputStream (java.io.DataInputStream)6 VersionSource (org.apache.geode.internal.cache.versions.VersionSource)6 Cache (org.apache.geode.cache.Cache)5 LocalRegion (org.apache.geode.internal.cache.LocalRegion)5 Host (org.apache.geode.test.dunit.Host)4 VM (org.apache.geode.test.dunit.VM)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 CacheClosedException (org.apache.geode.cache.CacheClosedException)3 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)3 IOException (java.io.IOException)2