Search in sources :

Example 31 with Version

use of org.apache.geode.internal.Version in project geode by apache.

the class Oplog method readGemfireVersionRecord.

/**
   * @throws DiskAccessException if this file does not belong to our parent
   */
private void readGemfireVersionRecord(DataInput dis, File f) throws IOException {
    Version recoveredGFVersion = readProductVersionRecord(dis, f);
    final boolean hasDataVersion;
    if ((hasDataVersion = (recoveredGFVersion == Version.TOKEN))) {
        // actual GFE version will be the next record in this case
        byte opCode = dis.readByte();
        if (opCode != OPLOG_GEMFIRE_VERSION) {
            throw new DiskAccessException(LocalizedStrings.Oplog_UNKNOWN_OPCODE_0_FOUND_IN_DISK_OPERATION_LOG.toLocalizedString(opCode), getParent());
        }
        recoveredGFVersion = readProductVersionRecord(dis, f);
    }
    if (this.gfversion == null) {
        this.gfversion = recoveredGFVersion;
    } else {
        assert this.gfversion == recoveredGFVersion;
    }
    if (hasDataVersion) {
        byte opCode = dis.readByte();
        if (opCode != OPLOG_GEMFIRE_VERSION) {
            throw new DiskAccessException(LocalizedStrings.Oplog_UNKNOWN_OPCODE_0_FOUND_IN_DISK_OPERATION_LOG.toLocalizedString(opCode), getParent());
        }
        recoveredGFVersion = readProductVersionRecord(dis, f);
        if (this.dataVersion == null) {
            this.dataVersion = recoveredGFVersion;
        } else {
            assert this.dataVersion == recoveredGFVersion;
        }
    }
}
Also used : Version(org.apache.geode.internal.Version) DiskAccessException(org.apache.geode.cache.DiskAccessException)

Example 32 with Version

use of org.apache.geode.internal.Version in project geode by apache.

the class Oplog method readCrf.

/**
   * Return number of bytes read
   */
private long readCrf(OplogEntryIdSet deletedIds, boolean recoverValues, boolean latestOplog) {
    this.recoverNewEntryId = DiskStoreImpl.INVALID_ID;
    this.recoverModEntryId = DiskStoreImpl.INVALID_ID;
    this.recoverModEntryIdHWM = DiskStoreImpl.INVALID_ID;
    boolean readLastRecord = true;
    CountingDataInputStream dis = null;
    try {
        final LocalRegion currentRegion = LocalRegion.getInitializingRegion();
        final Version version = getProductVersionIfOld();
        final ByteArrayDataInput in = new ByteArrayDataInput();
        final HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
        int recordCount = 0;
        boolean foundDiskStoreRecord = false;
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(this.crf.f);
            dis = new CountingDataInputStream(new BufferedInputStream(fis, 1024 * 1024), this.crf.f.length());
            boolean endOfLog = false;
            while (!endOfLog) {
                // long startPosition = byteCount;
                if (dis.atEndOfFile()) {
                    endOfLog = true;
                    break;
                }
                readLastRecord = false;
                byte opCode = dis.readByte();
                if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY)) {
                    logger.trace(LogMarker.PERSIST_RECOVERY, "Oplog opCode={}", opCode);
                }
                switch(opCode) {
                    case OPLOG_EOF_ID:
                        // we are at the end of the oplog. So we need to back up one byte
                        dis.decrementCount();
                        endOfLog = true;
                        break;
                    case OPLOG_CONFLICT_VERSION:
                        this.readVersionTagOnlyEntry(dis, opCode);
                        break;
                    case OPLOG_NEW_ENTRY_BASE_ID:
                        {
                            long newEntryBase = dis.readLong();
                            if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY)) {
                                logger.trace(LogMarker.PERSIST_RECOVERY, "newEntryBase={}", newEntryBase);
                            }
                            readEndOfRecord(dis);
                            setRecoverNewEntryId(newEntryBase);
                            recordCount++;
                        }
                        break;
                    case OPLOG_NEW_ENTRY_0ID:
                        readNewEntry(dis, opCode, deletedIds, recoverValues, currentRegion, version, in, hdos);
                        recordCount++;
                        break;
                    case OPLOG_MOD_ENTRY_1ID:
                    case OPLOG_MOD_ENTRY_2ID:
                    case OPLOG_MOD_ENTRY_3ID:
                    case OPLOG_MOD_ENTRY_4ID:
                    case OPLOG_MOD_ENTRY_5ID:
                    case OPLOG_MOD_ENTRY_6ID:
                    case OPLOG_MOD_ENTRY_7ID:
                    case OPLOG_MOD_ENTRY_8ID:
                        readModifyEntry(dis, opCode, deletedIds, recoverValues, currentRegion, version, in, hdos);
                        recordCount++;
                        break;
                    case OPLOG_MOD_ENTRY_WITH_KEY_1ID:
                    case OPLOG_MOD_ENTRY_WITH_KEY_2ID:
                    case OPLOG_MOD_ENTRY_WITH_KEY_3ID:
                    case OPLOG_MOD_ENTRY_WITH_KEY_4ID:
                    case OPLOG_MOD_ENTRY_WITH_KEY_5ID:
                    case OPLOG_MOD_ENTRY_WITH_KEY_6ID:
                    case OPLOG_MOD_ENTRY_WITH_KEY_7ID:
                    case OPLOG_MOD_ENTRY_WITH_KEY_8ID:
                        readModifyEntryWithKey(dis, opCode, deletedIds, recoverValues, currentRegion, version, in, hdos);
                        recordCount++;
                        break;
                    case OPLOG_DISK_STORE_ID:
                        readDiskStoreRecord(dis, this.crf.f);
                        foundDiskStoreRecord = true;
                        recordCount++;
                        break;
                    case OPLOG_MAGIC_SEQ_ID:
                        readOplogMagicSeqRecord(dis, this.crf.f, OPLOG_TYPE.CRF);
                        break;
                    case OPLOG_GEMFIRE_VERSION:
                        readGemfireVersionRecord(dis, this.crf.f);
                        recordCount++;
                        break;
                    case OPLOG_RVV:
                        readRVVRecord(dis, this.drf.f, false, latestOplog);
                        recordCount++;
                        break;
                    default:
                        throw new DiskAccessException(LocalizedStrings.Oplog_UNKNOWN_OPCODE_0_FOUND_IN_DISK_OPERATION_LOG.toLocalizedString(opCode), getParent());
                }
                readLastRecord = true;
            // @todo
            // if (rgn.isDestroyed()) {
            // break;
            // }
            }
        // while
        } finally {
            if (dis != null) {
                dis.close();
            }
            if (fis != null) {
                fis.close();
            }
        }
        if (!foundDiskStoreRecord && recordCount > 0) {
            throw new DiskAccessException("The oplog file \"" + this.crf.f + "\" does not belong to the init file \"" + getParent().getInitFile() + "\". Crf did not contain a disk store id.", getParent());
        }
    } catch (EOFException ignore) {
    // ignore since a partial record write can be caused by a crash
    } catch (IOException ex) {
        getParent().getCancelCriterion().checkCancelInProgress(ex);
        throw new DiskAccessException(LocalizedStrings.Oplog_FAILED_READING_FILE_DURING_RECOVERY_FROM_0.toLocalizedString(this.crf.f.getPath()), ex, getParent());
    } catch (CancelException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Oplog::readOplog:Error in recovery as Cache was closed", e);
        }
    } catch (RegionDestroyedException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Oplog::readOplog:Error in recovery as Region was destroyed", e);
        }
    } catch (IllegalStateException e) {
        throw e;
    }
    // Add the Oplog size to the Directory Holder which owns this oplog,
    // so that available space is correctly calculated & stats updated.
    long byteCount = 0;
    if (!readLastRecord) {
        // this means that there was a crash
        // and hence we should not continue to read
        // the next oplog
        this.crashed = true;
        if (dis != null) {
            byteCount = dis.getFileLength();
        }
    } else {
        if (dis != null) {
            byteCount = dis.getCount();
        }
    }
    return byteCount;
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ByteArrayDataInput(org.apache.geode.internal.ByteArrayDataInput) FileInputStream(java.io.FileInputStream) Version(org.apache.geode.internal.Version) BufferedInputStream(java.io.BufferedInputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) DiskAccessException(org.apache.geode.cache.DiskAccessException) EOFException(java.io.EOFException) CancelException(org.apache.geode.CancelException)

Example 33 with Version

use of org.apache.geode.internal.Version in project geode by apache.

the class Oplog method attemptGet.

private BytesAndBits attemptGet(DiskRegionView dr, long offsetInOplog, boolean bitOnly, int valueLength, byte userBits) throws IOException {
    boolean didReopen = false;
    boolean accessedInactive = false;
    try {
        synchronized (this.lock) /* crf */
        {
            // if (this.closed || this.deleted.get()) {
            // throw new DiskAccessException("attempting get on "
            // + (this.deleted.get() ? "destroyed" : "closed")
            // + " oplog #" + getOplogId(), this.owner);
            // }
            this.beingRead = true;
            if (/*
             * !getParent().isSync() since compactor groups writes &&
             */
            (offsetInOplog + valueLength) > this.crf.bytesFlushed && !this.closed) {
                // fix for bug 41205
                flushAllNoSync(true);
            }
            try {
                UninterruptibleRandomAccessFile myRAF = null;
                if (this.crf.RAFClosed) {
                    myRAF = new UninterruptibleRandomAccessFile(this.crf.f, "r");
                    this.stats.incOpenOplogs();
                    if (this.okToReopen) {
                        this.crf.RAFClosed = false;
                        this.okToReopen = false;
                        this.crf.raf = myRAF;
                        didReopen = true;
                    }
                } else {
                    myRAF = this.crf.raf;
                    accessedInactive = true;
                }
                BytesAndBits bb = null;
                try {
                    final long writePosition = (this.doneAppending) ? this.crf.bytesFlushed : myRAF.getFilePointer();
                    if ((offsetInOplog + valueLength) > writePosition) {
                        throw new DiskAccessException(LocalizedStrings.Oplog_TRIED_TO_SEEK_TO_0_BUT_THE_FILE_LENGTH_IS_1_OPLOG_FILE_OBJECT_USED_FOR_READING_2.toLocalizedString(offsetInOplog + valueLength, writePosition, this.crf.raf), dr.getName());
                    } else if (offsetInOplog < 0) {
                        throw new DiskAccessException(LocalizedStrings.Oplog_CANNOT_FIND_RECORD_0_WHEN_READING_FROM_1.toLocalizedString(offsetInOplog, this.diskFile.getPath()), dr.getName());
                    }
                    try {
                        myRAF.seek(offsetInOplog);
                        this.stats.incOplogSeeks();
                        byte[] valueBytes = new byte[valueLength];
                        myRAF.readFully(valueBytes);
                        this.stats.incOplogReads();
                        bb = new BytesAndBits(valueBytes, userBits);
                        // also set the product version for an older product
                        final Version version = getProductVersionIfOld();
                        if (version != null) {
                            bb.setVersion(version);
                        }
                    } finally {
                        // disk io
                        if (!this.doneAppending) {
                            // by seeking back to writePosition
                            myRAF.seek(writePosition);
                            this.stats.incOplogSeeks();
                        }
                    }
                    return bb;
                } finally {
                    if (myRAF != this.crf.raf) {
                        try {
                            myRAF.close();
                        } catch (IOException ignore) {
                        }
                    }
                }
            } finally {
                this.beingRead = false;
            // if (this.closed || this.deleted.get()) {
            // throw new DiskAccessException("attempting get on "
            // + (this.deleted.get() ? "destroyed" : "closed")
            // + " oplog #" + getOplogId(), this.owner);
            // }
            }
        }
    // sync
    } finally {
        if (accessedInactive) {
            getOplogSet().inactiveAccessed(this);
        } else if (didReopen) {
            getOplogSet().inactiveReopened(this);
        }
    }
}
Also used : UninterruptibleRandomAccessFile(org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile) Version(org.apache.geode.internal.Version) DiskAccessException(org.apache.geode.cache.DiskAccessException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) BytesAndBits(org.apache.geode.internal.cache.persistence.BytesAndBits)

Example 34 with Version

use of org.apache.geode.internal.Version in project geode by apache.

the class Oplog method readProductVersionRecord.

private Version readProductVersionRecord(DataInput dis, File f) throws IOException {
    Version recoveredGFVersion;
    short ver = Version.readOrdinal(dis);
    try {
        recoveredGFVersion = Version.fromOrdinal(ver, false);
    } catch (UnsupportedVersionException e) {
        throw new DiskAccessException(LocalizedStrings.Oplog_UNEXPECTED_PRODUCT_VERSION_0.toLocalizedString(ver), e, getParent());
    }
    logger.trace(LogMarker.PERSIST_RECOVERY, "version={}", recoveredGFVersion);
    readEndOfRecord(dis);
    return recoveredGFVersion;
}
Also used : Version(org.apache.geode.internal.Version) DiskAccessException(org.apache.geode.cache.DiskAccessException) UnsupportedVersionException(org.apache.geode.cache.UnsupportedVersionException)

Example 35 with Version

use of org.apache.geode.internal.Version in project geode by apache.

the class EventID method toData.

public void toData(DataOutput dop) throws IOException {
    Version version = InternalDataSerializer.getVersionForDataStream(dop);
    if (version.compareTo(Version.GFE_90) <= 0) {
        InternalDistributedMember member = getDistributedMember();
        HeapDataOutputStream hdos = new HeapDataOutputStream(version);
        member.writeEssentialData(hdos);
        DataSerializer.writeByteArray(hdos.toByteArray(), dop);
    } else {
        DataSerializer.writeByteArray(this.membershipID, dop);
    }
    DataSerializer.writeByteArray(getOptimizedByteArrayForEventID(this.threadID, this.sequenceID), dop);
    dop.writeInt(this.bucketID);
    dop.writeByte(this.breadcrumbCounter);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Version(org.apache.geode.internal.Version) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream)

Aggregations

Version (org.apache.geode.internal.Version)40 IOException (java.io.IOException)16 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)10 ByteArrayDataInput (org.apache.geode.internal.ByteArrayDataInput)8 UnsupportedVersionException (org.apache.geode.cache.UnsupportedVersionException)6 EntryVersionsList (org.apache.geode.internal.cache.DistributedPutAllOperation.EntryVersionsList)6 DiskAccessException (org.apache.geode.cache.DiskAccessException)5 DataInputStream (java.io.DataInputStream)4 EOFException (java.io.EOFException)4 InterruptedIOException (java.io.InterruptedIOException)4 DataOutputStream (java.io.DataOutputStream)3 FileInputStream (java.io.FileInputStream)3 CancelException (org.apache.geode.CancelException)3 VersionedDataInputStream (org.apache.geode.internal.VersionedDataInputStream)3 VersionedDataOutputStream (org.apache.geode.internal.VersionedDataOutputStream)3 PutAllEntryData (org.apache.geode.internal.cache.DistributedPutAllOperation.PutAllEntryData)3 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 SocketAddress (java.net.SocketAddress)2