Search in sources :

Example 1 with RegionVersionHolder

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

the class DiskOfflineCompactionJUnitTest method getRVVSize.

static int getRVVSize(int drMapSize, int[] numOfMemberPerDR, boolean gcRVV) {
    // if there's one member in rvv, total size is 9 bytes:
    // 0: OPLOG_RVV. 1: drMap.size()==1, 2: disRegionId, 3: getRVVTrusted
    // 4: memberToVersion.size()==1, 5: memberid, 6-7: versionHolder 8: END_OF_RECORD_ID
    // but not every diskRegion has a member in RVV
    HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
    RegionVersionHolder dummyHolder = new RegionVersionHolder(1);
    try {
        dummyHolder.toData(out);
    } catch (IOException e) {
    }
    int holderSize = out.size();
    out.close();
    int size = 1;
    size++;
    /* drMap.size */
    for (int i = 0; i < drMapSize; i++) {
        size++;
        /* disRegionId */
        if (gcRVV) {
            size++;
            /* numOfMember, i.e. memberToVersion.size */
            if (numOfMemberPerDR != null && numOfMemberPerDR[i] > 0) {
                for (int j = 0; j < numOfMemberPerDR[i]; j++) {
                    size++;
                    /* memberid */
                    size++;
                /* gcversion */
                }
            }
        } else {
            size++;
            /* getRVVTrusted */
            size++;
            /* numOfMember, i.e. memberToVersion.size */
            if (numOfMemberPerDR != null && numOfMemberPerDR[i] > 0) {
                for (int j = 0; j < numOfMemberPerDR[i]; j++) {
                    size++;
                    /* memberid */
                    size += holderSize;
                }
            }
        }
    }
    size++;
    /* END_OF_RECORD_ID */
    return size;
}
Also used : HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) RegionVersionHolder(org.apache.geode.internal.cache.versions.RegionVersionHolder) IOException(java.io.IOException)

Example 2 with RegionVersionHolder

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

the class PersistentRecoveryOrderDUnitTest method getAllMemberToVersion.

HashMap<DiskStoreID, RegionVersionHolder<DiskStoreID>> getAllMemberToVersion(RegionVersionVector rvv) {
    HashMap<DiskStoreID, RegionVersionHolder<DiskStoreID>> allMemberToVersion = new HashMap(rvv.getMemberToVersion());
    RegionVersionHolder localHolder = rvv.getLocalExceptions().clone();
    localHolder.setVersion(rvv.getCurrentVersion());
    allMemberToVersion.put((DiskStoreID) rvv.getOwnerId(), localHolder);
    return allMemberToVersion;
}
Also used : HashMap(java.util.HashMap) RegionVersionHolder(org.apache.geode.internal.cache.versions.RegionVersionHolder)

Example 3 with RegionVersionHolder

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

the class DiskInitFile method writeClearRecord.

/**
   * Write a clear with an RVV record.
   */
private void writeClearRecord(DiskRegionView dr, RegionVersionVector rvv) {
    try {
        HeapDataOutputStream hdos = new HeapDataOutputStream(32, Version.CURRENT);
        hdos.write(IFREC_CLEAR_REGION_WITH_RVV_ID);
        writeDiskRegionID(hdos, dr.getId());
        // We only need the memberToVersionMap for clear purposes
        Map<DiskStoreID, RegionVersionHolder> memberToVersion = rvv.getMemberToVersion();
        hdos.writeInt(memberToVersion.size());
        for (Map.Entry<DiskStoreID, RegionVersionHolder> entry : memberToVersion.entrySet()) {
            InternalDataSerializer.invokeToData(entry.getKey(), hdos);
            synchronized (entry.getValue()) {
                InternalDataSerializer.invokeToData(entry.getValue(), hdos);
            }
        }
        hdos.write(END_OF_RECORD_ID);
        // don't do stats for these small records
        writeIFRecord(hdos, false);
    } catch (IOException ex) {
        DiskAccessException dae = new DiskAccessException(LocalizedStrings.DiskInitFile_FAILED_INIT_FILE_WRITE_BECAUSE_0.toLocalizedString(ex), this.parent);
        if (!this.compactInProgress) {
            this.parent.handleDiskAccessException(dae);
        }
        throw dae;
    }
}
Also used : HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) DiskAccessException(org.apache.geode.cache.DiskAccessException) RegionVersionHolder(org.apache.geode.internal.cache.versions.RegionVersionHolder) IOException(java.io.IOException) DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID) Map(java.util.Map) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap)

Example 4 with RegionVersionHolder

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

the class Oplog method readRVVRecord.

private void readRVVRecord(DataInput dis, File f, boolean gcRVV, boolean latestOplog) throws IOException {
    final boolean isPersistRecoveryDebugEnabled = logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY);
    long numRegions = InternalDataSerializer.readUnsignedVL(dis);
    if (isPersistRecoveryDebugEnabled) {
        logger.trace(LogMarker.PERSIST_RECOVERY, "readRVV entry numRegions={}", numRegions);
    }
    for (int region = 0; region < numRegions; region++) {
        long drId = InternalDataSerializer.readUnsignedVL(dis);
        // Get the drs. This may be null if this region is not currently
        // recovering
        DiskRecoveryStore drs = getOplogSet().getCurrentlyRecovering(drId);
        if (isPersistRecoveryDebugEnabled) {
            logger.trace(LogMarker.PERSIST_RECOVERY, "readRVV drId={} region={}", drId, drs);
        }
        if (gcRVV) {
            // Read the GCC RV
            long rvvSize = InternalDataSerializer.readUnsignedVL(dis);
            for (int memberNum = 0; memberNum < rvvSize; memberNum++) {
                // for each member, read the member id and version
                long memberId = InternalDataSerializer.readUnsignedVL(dis);
                long gcVersion = InternalDataSerializer.readUnsignedVL(dis);
                // if we have a recovery store, add the recovered regions
                if (drs != null) {
                    Object member = getParent().getDiskInitFile().getCanonicalObject((int) memberId);
                    drs.recordRecoveredGCVersion((VersionSource) member, gcVersion);
                    if (isPersistRecoveryDebugEnabled) {
                        logger.trace(LogMarker.PERSIST_RECOVERY, "adding gcRVV entry drId={}, member={}, version={}", drId, memberId, gcVersion);
                    }
                } else {
                    if (isPersistRecoveryDebugEnabled) {
                        logger.trace(LogMarker.PERSIST_RECOVERY, "skipping gcRVV entry drId={}, member={}, version={}", drId, memberId, gcVersion);
                    }
                }
            }
        } else {
            boolean rvvTrusted = DataSerializer.readBoolean(dis);
            if (drs != null) {
                if (latestOplog) {
                    // only set rvvtrust based on the newest oplog recovered
                    drs.setRVVTrusted(rvvTrusted);
                    if (isPersistRecoveryDebugEnabled) {
                        logger.trace(LogMarker.PERSIST_RECOVERY, "marking RVV trusted drId={},tvvTrusted={}", drId, rvvTrusted);
                    }
                }
            }
            // Read a regular RVV
            long rvvSize = InternalDataSerializer.readUnsignedVL(dis);
            for (int memberNum = 0; memberNum < rvvSize; memberNum++) {
                // for each member, read the member id and version
                long memberId = InternalDataSerializer.readUnsignedVL(dis);
                RegionVersionHolder versionHolder = new RegionVersionHolder(dis);
                if (drs != null) {
                    Object member = getParent().getDiskInitFile().getCanonicalObject((int) memberId);
                    drs.recordRecoveredVersonHolder((VersionSource) member, versionHolder, latestOplog);
                    if (isPersistRecoveryDebugEnabled) {
                        logger.trace(LogMarker.PERSIST_RECOVERY, "adding RVV entry drId={},member={},versionHolder={},latestOplog={},oplogId={}", drId, memberId, versionHolder, latestOplog, getOplogId());
                    }
                } else {
                    if (isPersistRecoveryDebugEnabled) {
                        logger.trace(LogMarker.PERSIST_RECOVERY, "skipping RVV entry drId={}, member={}, versionHolder={}", drId, memberId, versionHolder);
                    }
                }
            }
        }
    }
    readEndOfRecord(dis);
}
Also used : DiskRecoveryStore(org.apache.geode.internal.cache.persistence.DiskRecoveryStore) StoredObject(org.apache.geode.internal.offheap.StoredObject) RegionVersionHolder(org.apache.geode.internal.cache.versions.RegionVersionHolder)

Example 5 with RegionVersionHolder

use of org.apache.geode.internal.cache.versions.RegionVersionHolder 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)

Aggregations

RegionVersionHolder (org.apache.geode.internal.cache.versions.RegionVersionHolder)6 HashMap (java.util.HashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)3 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)2 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)2 IOException (java.io.IOException)2 Map (java.util.Map)2 DiskAccessException (org.apache.geode.cache.DiskAccessException)2 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)1 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)1 EnumSet (java.util.EnumSet)1 Entry (java.util.Map.Entry)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 UnsupportedVersionException (org.apache.geode.cache.UnsupportedVersionException)1 Version (org.apache.geode.internal.Version)1 DiskRegionFlag (org.apache.geode.internal.cache.DiskInitFile.DiskRegionFlag)1 DiskRecoveryStore (org.apache.geode.internal.cache.persistence.DiskRecoveryStore)1 DiskStoreID (org.apache.geode.internal.cache.persistence.DiskStoreID)1