Search in sources :

Example 61 with DiskAccessException

use of org.apache.geode.cache.DiskAccessException in project geode by apache.

the class Oplog method getBytesAndBits.

/**
   * Returns the unserialized bytes and bits for the given Entry. If Oplog is destroyed while
   * querying, then the DiskRegion is queried again to obatin the value This method should never get
   * invoked for an entry which has been destroyed
   * 
   * @since GemFire 3.2.1
   * @param id The DiskId for the entry @param offset The offset in this OpLog where the entry is
   *        present. @param faultingIn @param bitOnly boolean indicating whether to extract just the
   *        UserBit or UserBit with value @return BytesAndBits object wrapping the value & user bit
   */
public BytesAndBits getBytesAndBits(DiskRegionView dr, DiskId id, boolean faultingIn, boolean bitOnly) {
    Oplog retryOplog = null;
    long offset = 0;
    synchronized (id) {
        long opId = id.getOplogId();
        if (opId != getOplogId()) {
            // the oplog changed on us so we need to do a recursive
            // call after unsyncing
            retryOplog = getOplogSet().getChild(opId);
        } else {
            // fetch this while synced so it will be consistent with oplogId
            offset = id.getOffsetInOplog();
        }
    }
    if (retryOplog != null) {
        return retryOplog.getBytesAndBits(dr, id, faultingIn, bitOnly);
    }
    BytesAndBits bb = null;
    long start = this.stats.startRead();
    // the data is present in the current oplog file.
    if (offset == -1) {
        // Since it is given that a get operation has alreadty
        // taken a
        // lock on an entry , no put operation could have modified the
        // oplog ID
        // there fore synchronization is not needed
        offset = id.getOffsetInOplog();
    }
    // is still open) we can retrieve the value from this oplog.
    try {
        bb = basicGet(dr, offset, bitOnly, id.getValueLength(), id.getUserBits());
    } catch (DiskAccessException dae) {
        logger.error(LocalizedMessage.create(LocalizedStrings.Oplog_OPLOGBASICGET_ERROR_IN_READING_THE_DATA_FROM_DISK_FOR_DISK_ID_HAVING_DATA_AS_0, id), dae);
        throw dae;
    }
    if (bb == null) {
        throw new EntryDestroyedException(LocalizedStrings.Oplog_NO_VALUE_WAS_FOUND_FOR_ENTRY_WITH_DISK_ID_0_ON_A_REGION_WITH_SYNCHRONOUS_WRITING_SET_TO_1.toLocalizedString(new Object[] { id, dr.isSync() }));
    }
    if (bitOnly) {
        dr.endRead(start, this.stats.endRead(start, 1), 1);
    } else {
        dr.endRead(start, this.stats.endRead(start, bb.getBytes().length), bb.getBytes().length);
    }
    return bb;
}
Also used : EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) DiskAccessException(org.apache.geode.cache.DiskAccessException) StoredObject(org.apache.geode.internal.offheap.StoredObject) BytesAndBits(org.apache.geode.internal.cache.persistence.BytesAndBits)

Example 62 with DiskAccessException

use of org.apache.geode.cache.DiskAccessException 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 63 with DiskAccessException

use of org.apache.geode.cache.DiskAccessException in project geode by apache.

the class Oplog method create.

/**
   * Modified the code so as to reuse the already created ByteBuffer during transition. Creates a
   * key/value pair from a region entry on disk. Updates all of the necessary
   * {@linkplain DiskStoreStats statistics} and invokes basicCreate
   * 
   * @param entry The DiskEntry object for this key/value pair.
   * @param value byte array representing the value
   */
public void create(LocalRegion region, DiskEntry entry, ValueWrapper value, boolean async) {
    if (this != getOplogSet().getChild()) {
        getOplogSet().getChild().create(region, entry, value, async);
    } else {
        DiskId did = entry.getDiskId();
        boolean exceptionOccurred = false;
        byte prevUsrBit = did.getUserBits();
        int len = did.getValueLength();
        try {
            // It is ok to do this outside of "lock" because
            // create records do not need to change.
            byte userBits = calcUserBits(value);
            // 7.0
            if (entry.getVersionStamp() != null) {
                if (entry.getVersionStamp().getMemberID() == null) {
                    throw new AssertionError("Version stamp should have a member at this point for entry " + entry);
                }
                // pdx and tx will not use version
                userBits = EntryBits.setWithVersions(userBits, true);
            }
            basicCreate(region.getDiskRegion(), entry, value, userBits, async);
        } catch (IOException ex) {
            exceptionOccurred = true;
            region.getCancelCriterion().checkCancelInProgress(ex);
            throw new DiskAccessException(LocalizedStrings.Oplog_FAILED_WRITING_KEY_TO_0.toLocalizedString(this.diskFile.getPath()), ex, region.getFullPath());
        } catch (InterruptedException ie) {
            Thread.currentThread().interrupt();
            exceptionOccurred = true;
            region.getCancelCriterion().checkCancelInProgress(ie);
            throw new DiskAccessException(LocalizedStrings.Oplog_FAILED_WRITING_KEY_TO_0_DUE_TO_FAILURE_IN_ACQUIRING_READ_LOCK_FOR_ASYNCH_WRITING.toLocalizedString(this.diskFile.getPath()), ie, region.getFullPath());
        } finally {
            if (exceptionOccurred) {
                did.setValueLength(len);
                did.setUserBits(prevUsrBit);
            }
        }
    }
}
Also used : DiskAccessException(org.apache.geode.cache.DiskAccessException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 64 with DiskAccessException

use of org.apache.geode.cache.DiskAccessException 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 65 with DiskAccessException

use of org.apache.geode.cache.DiskAccessException in project geode by apache.

the class Oplog method flushAll.

public void flushAll(boolean skipDrf, boolean doSync) {
    try {
        // TODO: if skipDrf then only need to do drf if crf has flushable data
        flush(this.drf, doSync);
        flush(this.crf, doSync);
    } catch (IOException ex) {
        getParent().getCancelCriterion().checkCancelInProgress(ex);
        throw new DiskAccessException(LocalizedStrings.Oplog_FAILED_WRITING_KEY_TO_0.toLocalizedString(this.diskFile.getPath()), ex, getParent());
    }
}
Also used : DiskAccessException(org.apache.geode.cache.DiskAccessException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Aggregations

DiskAccessException (org.apache.geode.cache.DiskAccessException)76 IOException (java.io.IOException)44 InterruptedIOException (java.io.InterruptedIOException)17 StoredObject (org.apache.geode.internal.offheap.StoredObject)13 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)11 ByteBuffer (java.nio.ByteBuffer)9 Test (org.junit.Test)8 Version (org.apache.geode.internal.Version)6 File (java.io.File)5 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)5 IndexManager (org.apache.geode.cache.query.internal.index.IndexManager)5 UninterruptibleFileChannel (org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel)5 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)5 Released (org.apache.geode.internal.offheap.annotations.Released)5 BufferedInputStream (java.io.BufferedInputStream)4 FileInputStream (java.io.FileInputStream)4 CancelException (org.apache.geode.CancelException)4 BytesAndBits (org.apache.geode.internal.cache.persistence.BytesAndBits)4 UninterruptibleRandomAccessFile (org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile)4 EOFException (java.io.EOFException)3