Search in sources :

Example 86 with VersionTag

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

the class Oplog method createDummyTag.

private synchronized VersionTag createDummyTag(DiskRecoveryStore drs) {
    DiskStoreID member = getParent().getDiskStoreID();
    int memberid = getParent().getDiskInitFile().getOrCreateCanonicalId(member);
    long regionVersion = drs.getVersionForMember(member);
    VersionTag vt = VersionTag.create(member);
    vt.setEntryVersion(1);
    vt.setRegionVersion(regionVersion + 1);
    vt.setMemberID(member);
    vt.setVersionTimeStamp(getParent().getCache().cacheTimeMillis());
    vt.setDistributedSystemId(-1);
    return vt;
}
Also used : VersionTag(org.apache.geode.internal.cache.versions.VersionTag) DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID)

Example 87 with VersionTag

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

the class Oplog method readModifyEntryWithKey.

/**
   * Reads an oplog entry of type ModifyWithKey
   * 
   * @param dis DataInputStream from which the oplog is being read
   * @param opcode byte whether the id is short/int/long
   */
private void readModifyEntryWithKey(CountingDataInputStream dis, byte opcode, OplogEntryIdSet deletedIds, boolean recoverValue, final LocalRegion currentRegion, Version version, ByteArrayDataInput in, HeapDataOutputStream hdos) throws IOException {
    long oplogOffset = -1;
    byte userBits = dis.readByte();
    int idByteCount = (opcode - OPLOG_MOD_ENTRY_WITH_KEY_1ID) + 1;
    // long debugRecoverModEntryId = this.recoverModEntryId;
    long oplogKeyId = getModEntryId(dis, idByteCount);
    // long debugOplogKeyId = dis.readLong();
    // //assert oplogKeyId == debugOplogKeyId
    // // : "expected=" + debugOplogKeyId + " actual=" + oplogKeyId
    // assert debugRecoverModEntryId == debugOplogKeyId
    // : "expected=" + debugOplogKeyId + " actual=" + debugRecoverModEntryId
    // + " idByteCount=" + idByteCount
    // + " delta=" + this.lastDelta;
    long drId = DiskInitFile.readDiskRegionID(dis);
    DiskRecoveryStore drs = getOplogSet().getCurrentlyRecovering(drId);
    // read version
    VersionTag tag = null;
    if (EntryBits.isWithVersions(userBits)) {
        tag = readVersionsFromOplog(dis);
    } else if (getParent().isUpgradeVersionOnly() && drs != null) {
        tag = this.createDummyTag(drs);
        userBits = EntryBits.setWithVersions(userBits, true);
    }
    if (drs != null && !drs.getDiskRegionView().getFlags().contains(DiskRegionFlag.IS_WITH_VERSIONING)) {
        // 50044 Remove version tag from entry if we don't want versioning for
        // this region
        tag = null;
        userBits = EntryBits.setWithVersions(userBits, false);
    }
    OkToSkipResult skipResult = okToSkipModifyRecord(deletedIds, drId, drs, oplogKeyId, true, tag);
    if (skipResult.skip()) {
        if (!isPhase2()) {
            incSkipped();
            this.stats.incRecoveryRecordsSkipped();
        }
    } else if (recoverValue && !getParent().isOfflineCompacting()) {
        recoverValue = recoverLruValue(drs);
    }
    byte[] objValue = null;
    int valueLength = 0;
    CompactionRecord p2cr = null;
    long crOffset;
    if (EntryBits.isAnyInvalid(userBits) || EntryBits.isTombstone(userBits)) {
        if (EntryBits.isInvalid(userBits)) {
            objValue = DiskEntry.INVALID_BYTES;
        } else if (EntryBits.isTombstone(userBits)) {
            objValue = DiskEntry.TOMBSTONE_BYTES;
        } else {
            objValue = DiskEntry.LOCAL_INVALID_BYTES;
        }
        crOffset = dis.getCount();
        if (!skipResult.skip()) {
            if (isPhase2()) {
                p2cr = (CompactionRecord) getRecoveryMap().get(oplogKeyId);
                if (p2cr != null && p2cr.getOffset() != crOffset) {
                    skipResult = OkToSkipResult.SKIP_RECORD;
                }
            }
        }
    } else {
        int len = dis.readInt();
        oplogOffset = dis.getCount();
        crOffset = oplogOffset;
        valueLength = len;
        if (!skipResult.skip()) {
            if (isPhase2()) {
                p2cr = (CompactionRecord) getRecoveryMap().get(oplogKeyId);
                if (p2cr != null && p2cr.getOffset() != crOffset) {
                    skipResult = OkToSkipResult.SKIP_RECORD;
                }
            }
        }
        if (!skipResult.skip() && recoverValue) {
            byte[] valueBytes = new byte[len];
            dis.readFully(valueBytes);
            objValue = valueBytes;
            validateValue(valueBytes, userBits, version, in);
        } else {
            forceSkipBytes(dis, len);
        }
    }
    int keyLen = dis.readInt();
    incTotalCount();
    if (skipResult.skip()) {
        if (skipResult.skipKey()) {
            forceSkipBytes(dis, keyLen);
        } else {
            byte[] keyBytes = new byte[keyLen];
            dis.readFully(keyBytes);
            skippedKeyBytes.put(oplogKeyId, keyBytes);
        }
        readEndOfRecord(dis);
        if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY)) {
            logger.trace(LogMarker.PERSIST_RECOVERY, "skipping readModEntryWK init oplogKeyId=<{}> drId={}", oplogKeyId, drId);
        }
    } else {
        // read the key
        byte[] keyBytes = null;
        if (isPhase2()) {
            forceSkipBytes(dis, keyLen);
        } else {
            keyBytes = new byte[keyLen];
            dis.readFully(keyBytes);
        }
        readEndOfRecord(dis);
        if (drs != null && tag != null) {
            // Update the RVV with the new entry
            // This must be done after reading the end of record to make sure
            // we don't have a corrupt record. See bug #45538
            drs.recordRecoveredVersionTag(tag);
        }
        assert oplogKeyId >= 0;
        if (getParent().isOfflineCompacting()) {
            if (isPhase1()) {
                CompactionRecord cr = new CompactionRecord(keyBytes, crOffset);
                getRecoveryMap().put(oplogKeyId, cr);
                drs.getDiskRegionView().incRecoveredEntryCount();
                this.stats.incRecoveredEntryCreates();
            } else {
                // phase2
                Assert.assertTrue(p2cr != null, "First pass did not find create a compaction record");
                getOplogSet().getChild().copyForwardForOfflineCompact(oplogKeyId, p2cr.getKeyBytes(), objValue, userBits, drId, tag);
                if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY)) {
                    logger.trace(LogMarker.PERSIST_RECOVERY, "readModifyEntryWithKey copyForward oplogKeyId=<{}>", oplogKeyId);
                }
                // add it to the deletedIds set so we will ignore it in earlier oplogs
                deletedIds.add(oplogKeyId);
            }
        } else {
            Object key = deserializeKey(keyBytes, version, in);
            Object oldValue = getRecoveryMap().put(oplogKeyId, key);
            if (oldValue != null) {
                throw new AssertionError(LocalizedStrings.Oplog_DUPLICATE_CREATE.toLocalizedString(oplogKeyId));
            }
            // Check the actual region to see if it has this key from
            // a previous recovered oplog.
            DiskEntry de = drs.getDiskEntry(key);
            if (de == null) {
                DiskRegionView drv = drs.getDiskRegionView();
                // and create an entry
                DiskEntry.RecoveredEntry re = createRecoveredEntry(objValue, valueLength, userBits, getOplogId(), oplogOffset, oplogKeyId, recoverValue, version, in);
                if (tag != null) {
                    re.setVersionTag(tag);
                }
                if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY)) {
                    logger.trace(LogMarker.PERSIST_RECOVERY, "readModEntryWK init oplogKeyId=<{}> drId={} key={} oplogOffset={} userBits={} valueLen={} tag={}", oplogKeyId, drId, key, oplogOffset, userBits, valueLength, tag);
                }
                initRecoveredEntry(drv, drs.initializeRecoveredEntry(key, re));
                drs.getDiskRegionView().incRecoveredEntryCount();
                this.stats.incRecoveredEntryCreates();
            } else {
                DiskId curdid = de.getDiskId();
                assert curdid.getOplogId() != getOplogId() : "Mutiple ModEntryWK in the same oplog for getOplogId()=" + getOplogId() + " , curdid.getOplogId()=" + curdid.getOplogId() + " , for drId=" + drId + " , key=" + key;
                if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY)) {
                    logger.trace(LogMarker.PERSIST_RECOVERY, "ignore readModEntryWK because getOplogId()={} != curdid.getOplogId()={} for drId={} key={}", getOplogId(), curdid.getOplogId(), drId, key);
                }
            // de = drs.updateRecoveredEntry(key, re);
            // updateRecoveredEntry(drv, de, re);
            // this.stats.incRecoveredEntryUpdates();
            }
        }
    }
}
Also used : DiskRegionView(org.apache.geode.internal.cache.persistence.DiskRegionView) DiskRecoveryStore(org.apache.geode.internal.cache.persistence.DiskRecoveryStore) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) StoredObject(org.apache.geode.internal.offheap.StoredObject)

Example 88 with VersionTag

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

the class Oplog method readNewEntry.

/**
   * Reads an oplog entry of type Create
   * 
   * @param dis DataInputStream from which the oplog is being read
   * @param opcode byte whether the id is short/int/long
   */
private void readNewEntry(CountingDataInputStream dis, byte opcode, OplogEntryIdSet deletedIds, boolean recoverValue, final LocalRegion currentRegion, Version version, ByteArrayDataInput in, HeapDataOutputStream hdos) throws IOException {
    final boolean isPersistRecoveryDebugEnabled = logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY);
    long oplogOffset = -1;
    byte userBits = dis.readByte();
    byte[] objValue = null;
    int valueLength = 0;
    long oplogKeyId = incRecoverNewEntryId();
    long drId = DiskInitFile.readDiskRegionID(dis);
    DiskRecoveryStore drs = getOplogSet().getCurrentlyRecovering(drId);
    // read versions
    VersionTag tag = null;
    boolean isDummy = false;
    if (EntryBits.isWithVersions(userBits)) {
        tag = readVersionsFromOplog(dis);
        isDummy = false;
    } else if (getParent().isUpgradeVersionOnly() && drs != null) {
        tag = this.createDummyTag(drs);
        userBits = EntryBits.setWithVersions(userBits, true);
        isDummy = true;
    }
    if (drs != null && !drs.getDiskRegionView().getFlags().contains(DiskRegionFlag.IS_WITH_VERSIONING)) {
        // 50044 Remove version tag from entry if we don't want versioning for
        // this region
        tag = null;
        userBits = EntryBits.setWithVersions(userBits, false);
    }
    OkToSkipResult skipResult = okToSkipModifyRecord(deletedIds, drId, drs, oplogKeyId, true, tag);
    if (skipResult.skip()) {
        if (!isPhase2()) {
            this.stats.incRecoveryRecordsSkipped();
            incSkipped();
        }
    } else if (recoverValue && !getParent().isOfflineCompacting()) {
        recoverValue = recoverLruValue(drs);
    }
    CompactionRecord p2cr = null;
    long crOffset;
    if (EntryBits.isAnyInvalid(userBits) || EntryBits.isTombstone(userBits)) {
        if (EntryBits.isInvalid(userBits)) {
            objValue = DiskEntry.INVALID_BYTES;
        } else if (EntryBits.isTombstone(userBits)) {
            objValue = DiskEntry.TOMBSTONE_BYTES;
        } else {
            objValue = DiskEntry.LOCAL_INVALID_BYTES;
        }
        crOffset = dis.getCount();
        if (!skipResult.skip()) {
            if (isPhase2()) {
                p2cr = (CompactionRecord) getRecoveryMap().get(oplogKeyId);
                if (p2cr != null && p2cr.getOffset() != crOffset) {
                    skipResult = OkToSkipResult.SKIP_RECORD;
                }
            }
        }
    } else {
        int len = dis.readInt();
        oplogOffset = dis.getCount();
        crOffset = oplogOffset;
        valueLength = len;
        if (!skipResult.skip()) {
            if (isPhase2()) {
                p2cr = (CompactionRecord) getRecoveryMap().get(oplogKeyId);
                if (p2cr != null && p2cr.getOffset() != crOffset) {
                    skipResult = OkToSkipResult.SKIP_RECORD;
                }
            }
        }
        if (recoverValue && !skipResult.skip()) {
            byte[] valueBytes = new byte[len];
            dis.readFully(valueBytes);
            objValue = valueBytes;
            validateValue(valueBytes, userBits, version, in);
        } else {
            forceSkipBytes(dis, len);
        }
    }
    {
        int len = dis.readInt();
        incTotalCount();
        if (skipResult.skip()) {
            if (skipResult.skipKey()) {
                forceSkipBytes(dis, len);
            } else {
                byte[] keyBytes = new byte[len];
                dis.readFully(keyBytes);
                skippedKeyBytes.put(oplogKeyId, keyBytes);
            }
            readEndOfRecord(dis);
            if (drs != null && tag != null) {
                // Update the RVV with the new entry
                // This must be done after reading the end of record to make sure
                // we don't have a corrupt record. See bug #45538
                drs.recordRecoveredVersionTag(tag);
            }
            if (isPersistRecoveryDebugEnabled) {
                logger.trace(LogMarker.PERSIST_RECOVERY, "readNewEntry SKIPPING oplogKeyId=<{}> drId={} userBits={} keyLen={} valueLen={} tag={}", oplogKeyId, drId, userBits, len, valueLength, tag);
            }
        } else {
            byte[] keyBytes = null;
            if (isPhase2()) {
                forceSkipBytes(dis, len);
            } else {
                keyBytes = new byte[len];
                dis.readFully(keyBytes);
            }
            readEndOfRecord(dis);
            if (drs != null && tag != null) {
                // Update the RVV with the new entry
                // This must be done after reading the end of record to make sure
                // we don't have a corrupt record. See bug #45538
                drs.recordRecoveredVersionTag(tag);
            }
            if (getParent().isOfflineCompacting()) {
                if (isPhase1()) {
                    CompactionRecord cr = new CompactionRecord(keyBytes, crOffset);
                    getRecoveryMap().put(oplogKeyId, cr);
                    drs.getDiskRegionView().incRecoveredEntryCount();
                    this.stats.incRecoveredEntryCreates();
                } else {
                    // phase2
                    Assert.assertTrue(p2cr != null, "First pass did not find create a compaction record");
                    getOplogSet().getChild().copyForwardForOfflineCompact(oplogKeyId, p2cr.getKeyBytes(), objValue, userBits, drId, tag);
                    if (isPersistRecoveryDebugEnabled) {
                        logger.trace(LogMarker.PERSIST_RECOVERY, "readNewEntry copyForward oplogKeyId=<{}>", oplogKeyId);
                    }
                    // add it to the deletedIds set so we will ignore it in earlier
                    // oplogs
                    deletedIds.add(oplogKeyId);
                }
            } else {
                Object key = deserializeKey(keyBytes, version, in);
                {
                    Object oldValue = getRecoveryMap().put(oplogKeyId, key);
                    if (oldValue != null) {
                        throw new AssertionError(LocalizedStrings.Oplog_DUPLICATE_CREATE.toLocalizedString(oplogKeyId));
                    }
                }
                DiskEntry de = drs.getDiskEntry(key);
                if (de == null) {
                    if (isPersistRecoveryDebugEnabled) {
                        logger.trace(LogMarker.PERSIST_RECOVERY, "readNewEntry oplogKeyId=<{}> drId={} key={} userBits={} oplogOffset={} valueLen={} tag={}", oplogKeyId, drId, key, userBits, oplogOffset, valueLength, tag);
                    }
                    DiskEntry.RecoveredEntry re = createRecoveredEntry(objValue, valueLength, userBits, getOplogId(), oplogOffset, oplogKeyId, recoverValue, version, in);
                    if (tag != null) {
                        re.setVersionTag(tag);
                    }
                    initRecoveredEntry(drs.getDiskRegionView(), drs.initializeRecoveredEntry(key, re));
                    drs.getDiskRegionView().incRecoveredEntryCount();
                    this.stats.incRecoveredEntryCreates();
                } else {
                    DiskId curdid = de.getDiskId();
                    assert curdid.getOplogId() != getOplogId();
                    if (isPersistRecoveryDebugEnabled) {
                        logger.trace(LogMarker.PERSIST_RECOVERY, "ignore readNewEntry because getOplogId()={} != curdid.getOplogId()={} for drId={} key={}", getOplogId(), curdid.getOplogId(), drId, key);
                    }
                }
            }
        }
    }
}
Also used : DiskRecoveryStore(org.apache.geode.internal.cache.persistence.DiskRecoveryStore) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) StoredObject(org.apache.geode.internal.offheap.StoredObject)

Example 89 with VersionTag

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

the class VersionedStatsDiskRegionEntryOffHeapObjectKey method asVersionTag.

// DO NOT modify this class. It was generated from LeafRegionEntry.cpp
public VersionTag asVersionTag() {
    VersionTag tag = VersionTag.create(memberID);
    tag.setEntryVersion(getEntryVersion());
    tag.setRegionVersion(this.regionVersionHighBytes, this.regionVersionLowBytes);
    tag.setVersionTimeStamp(getVersionTimeStamp());
    tag.setDistributedSystemId(this.distributedSystemId);
    return tag;
}
Also used : VersionTag(org.apache.geode.internal.cache.versions.VersionTag)

Example 90 with VersionTag

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

the class VersionedStatsDiskRegionEntryOffHeapStringKey2 method asVersionTag.

// DO NOT modify this class. It was generated from LeafRegionEntry.cpp
public VersionTag asVersionTag() {
    VersionTag tag = VersionTag.create(memberID);
    tag.setEntryVersion(getEntryVersion());
    tag.setRegionVersion(this.regionVersionHighBytes, this.regionVersionLowBytes);
    tag.setVersionTimeStamp(getVersionTimeStamp());
    tag.setDistributedSystemId(this.distributedSystemId);
    return tag;
}
Also used : VersionTag(org.apache.geode.internal.cache.versions.VersionTag)

Aggregations

VersionTag (org.apache.geode.internal.cache.versions.VersionTag)225 Test (org.junit.Test)43 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)31 VM (org.apache.geode.test.dunit.VM)24 CacheException (org.apache.geode.cache.CacheException)22 LocalRegion (org.apache.geode.internal.cache.LocalRegion)22 Region (org.apache.geode.cache.Region)21 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)19 VersionStamp (org.apache.geode.internal.cache.versions.VersionStamp)19 Host (org.apache.geode.test.dunit.Host)19 IOException (java.io.IOException)17 NonTXEntry (org.apache.geode.internal.cache.LocalRegion.NonTXEntry)16 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)16 VersionSource (org.apache.geode.internal.cache.versions.VersionSource)16 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)16 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)16 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)15 RegionVersionVector (org.apache.geode.internal.cache.versions.RegionVersionVector)15 ArrayList (java.util.ArrayList)14 CancelException (org.apache.geode.CancelException)14