Search in sources :

Example 1 with UninterruptibleRandomAccessFile

use of org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile in project geode by apache.

the class Oplog method createCrf.

/**
   * Creates the crf oplog file
   */
private void createCrf(OplogFile prevOlf) throws IOException {
    File f = new File(this.diskFile.getPath() + CRF_FILE_EXT);
    if (logger.isDebugEnabled()) {
        logger.debug("Creating operation log file {}", f);
    }
    this.crf.f = f;
    preblow(this.crf, getMaxCrfSize());
    this.crf.raf = new UninterruptibleRandomAccessFile(f, SYNC_WRITES ? "rwd" : "rw");
    this.crf.RAFClosed = false;
    oplogSet.crfCreate(this.oplogId);
    this.crf.writeBuf = allocateWriteBuf(prevOlf);
    logger.info(LocalizedMessage.create(LocalizedStrings.Oplog_CREATE_0_1_2, new Object[] { toString(), getFileType(this.crf), getParent().getName() }));
    this.crf.channel = this.crf.raf.getChannel();
    this.stats.incOpenOplogs();
    writeDiskStoreRecord(this.crf, OPLOG_TYPE.CRF);
    writeGemfireVersionRecord(this.crf);
    writeRVVRecord(this.crf, false);
    // Fix for bug 41654 - don't count the header
    // size against the size of the oplog. This ensures that
    // even if we have a large RVV, we can still write up to
    // max-oplog-size bytes to this oplog.
    this.maxCrfSize += this.crf.currSize;
}
Also used : UninterruptibleRandomAccessFile(org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile) StoredObject(org.apache.geode.internal.offheap.StoredObject) File(java.io.File) UninterruptibleRandomAccessFile(org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile)

Example 2 with UninterruptibleRandomAccessFile

use of org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile in project geode by apache.

the class Oplog method initAfterRecovery.

void initAfterRecovery(boolean offline) {
    this.isRecovering = false;
    this.closed = false;
    this.deleted.set(false);
    String n = getParent().getName();
    // crf might not exist; but drf always will
    this.diskFile = new File(this.drf.f.getParentFile(), oplogSet.getPrefix() + n + "_" + this.oplogId);
    try {
        // This is a recovered oplog and we only read from its crf.
        // No need to open the drf.
        this.doneAppending = true;
        if (this.crf.f != null && !hasNoLiveValues()) {
            this.closed = false;
            // truncate crf/drf if their actual size is less than their pre-blow
            // size
            this.crf.raf = new UninterruptibleRandomAccessFile(this.crf.f, "rw");
            this.crf.RAFClosed = false;
            this.crf.channel = this.crf.raf.getChannel();
            unpreblow(this.crf, getMaxCrfSize());
            this.crf.raf.close();
            // make crf read only
            this.crf.raf = new UninterruptibleRandomAccessFile(this.crf.f, "r");
            this.crf.channel = this.crf.raf.getChannel();
            this.stats.incOpenOplogs();
            // existing behavior
            try {
                this.drf.raf = new UninterruptibleRandomAccessFile(this.drf.f, "rw");
                this.drf.RAFClosed = false;
                this.drf.channel = this.drf.raf.getChannel();
                unpreblow(this.drf, getMaxDrfSize());
            } finally {
                this.drf.raf.close();
                this.drf.raf = null;
                this.drf.RAFClosed = true;
            }
        // no need to seek to the end; we will not be writing to a recovered
        // oplog; only reading
        // this.crf.raf.seek(this.crf.currSize);
        } else if (!offline) {
            // drf exists but crf has been deleted (because it was empty).
            // I don't think the drf needs to be opened. It is only used during
            // recovery.
            // At some point the compacter my identify that it can be deleted.
            this.crf.RAFClosed = true;
            deleteCRF();
            this.closed = true;
            this.deleted.set(true);
        }
        // since we never open it on a recovered oplog
        this.drf.RAFClosed = true;
    } catch (IOException ex) {
        getParent().getCancelCriterion().checkCancelInProgress(ex);
        throw new DiskAccessException(LocalizedStrings.Oplog_FAILED_CREATING_OPERATION_LOG_BECAUSE_0.toLocalizedString(ex), getParent());
    }
    if (hasNoLiveValues() && !offline) {
        getOplogSet().removeOplog(getOplogId(), true, getHasDeletes() ? this : null);
        if (!getHasDeletes()) {
            getOplogSet().drfDelete(this.oplogId);
            deleteFile(this.drf);
        }
    } else if (needsCompaction()) {
    // just leave it in the list it is already in
    } else {
        // remove it from the compactable list
        getOplogSet().removeOplog(getOplogId(), true, /*
               * say we are deleting so that undeletedOplogSize is not inced
               */
        null);
        // add it to the inactive list
        getOplogSet().addInactive(this);
    }
}
Also used : UninterruptibleRandomAccessFile(org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile) DiskAccessException(org.apache.geode.cache.DiskAccessException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) File(java.io.File) UninterruptibleRandomAccessFile(org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile)

Example 3 with UninterruptibleRandomAccessFile

use of org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile in project geode by apache.

the class Oplog method reopenFileIfClosed.

/**
   * If crfRAF has been closed then attempt to reopen the oplog for this read. Verify that this only
   * happens when test methods are invoked.
   * 
   * @return true if oplog file is open and can be read from; false if not
   */
private boolean reopenFileIfClosed() throws IOException {
    synchronized (this.lock) /* crf */
    {
        boolean result = !this.crf.RAFClosed;
        if (!result && this.okToReopen) {
            result = true;
            this.crf.raf = new UninterruptibleRandomAccessFile(this.crf.f, "r");
            this.stats.incOpenOplogs();
            this.crf.RAFClosed = false;
            this.okToReopen = false;
        }
        return result;
    }
}
Also used : UninterruptibleRandomAccessFile(org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile)

Example 4 with UninterruptibleRandomAccessFile

use of org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile in project geode by apache.

the class Oplog method createDrf.

/**
   * Creates the drf oplog file
   */
private void createDrf(OplogFile prevOlf) throws IOException {
    File f = new File(this.diskFile.getPath() + DRF_FILE_EXT);
    this.drf.f = f;
    if (logger.isDebugEnabled()) {
        logger.debug("Creating operation log file {}", f);
    }
    preblow(this.drf, getMaxDrfSize());
    this.drf.raf = new UninterruptibleRandomAccessFile(f, SYNC_WRITES ? "rwd" : "rw");
    this.drf.RAFClosed = false;
    this.oplogSet.drfCreate(this.oplogId);
    this.drf.writeBuf = allocateWriteBuf(prevOlf);
    logger.info(LocalizedMessage.create(LocalizedStrings.Oplog_CREATE_0_1_2, new Object[] { toString(), getFileType(this.drf), getParent().getName() }));
    this.drf.channel = this.drf.raf.getChannel();
    writeDiskStoreRecord(this.drf, OPLOG_TYPE.DRF);
    writeGemfireVersionRecord(this.drf);
    writeRVVRecord(this.drf, true);
}
Also used : UninterruptibleRandomAccessFile(org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile) StoredObject(org.apache.geode.internal.offheap.StoredObject) File(java.io.File) UninterruptibleRandomAccessFile(org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile)

Example 5 with UninterruptibleRandomAccessFile

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

Aggregations

UninterruptibleRandomAccessFile (org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile)5 File (java.io.File)3 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 DiskAccessException (org.apache.geode.cache.DiskAccessException)2 StoredObject (org.apache.geode.internal.offheap.StoredObject)2 Version (org.apache.geode.internal.Version)1 BytesAndBits (org.apache.geode.internal.cache.persistence.BytesAndBits)1