Search in sources :

Example 21 with DiskAccessException

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

the class DiskInitFile method saveInstantiator.

private void saveInstantiator(int id, String instantiatorClassName, String instantiatedClassName) {
    lock.lock();
    try {
        if (!this.compactInProgress && this.instIds.contains(id)) {
            // instantiator already written to disk so just return
            return;
        }
        final byte[] classNameBytes = classNameToBytes(instantiatorClassName);
        final byte[] instClassNameBytes = classNameToBytes(instantiatedClassName);
        ByteBuffer bb = getIFWriteBuffer(1 + 4 + 4 + classNameBytes.length + 4 + instClassNameBytes.length + 1);
        bb.put(IFREC_INSTANTIATOR_ID);
        bb.putInt(id);
        bb.putInt(classNameBytes.length);
        bb.put(classNameBytes);
        bb.putInt(instClassNameBytes.length);
        bb.put(instClassNameBytes);
        bb.put(END_OF_RECORD_ID);
        writeIFRecord(bb);
    } catch (IOException ex) {
        throw new DiskAccessException(LocalizedStrings.DiskInitFile_FAILED_SAVING_INSTANTIATOR_TO_DISK_BECAUSE_0.toLocalizedString(ex), this.parent);
    } finally {
        lock.unlock();
    }
}
Also used : DiskAccessException(org.apache.geode.cache.DiskAccessException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 22 with DiskAccessException

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

the class DiskInitFile method writeRegionConfig.

private void writeRegionConfig(DiskRegionView drv) {
    try {
        int len = estimateByteSize(drv.getPartitionName());
        int comprLen = estimateByteSize(drv.getCompressorClassName());
        HeapDataOutputStream bb = new HeapDataOutputStream(1 + DR_ID_MAX_BYTES + 1 + 1 + 4 + 4 + 4 + 1 + 1 + 4 + len + 4 + 1 + 1 + 1, Version.CURRENT);
        bb.write(IFREC_REGION_CONFIG_ID_90);
        writeDiskRegionID(bb, drv.getId());
        bb.write(drv.getLruAlgorithm());
        bb.write(drv.getLruAction());
        bb.writeInt(drv.getLruLimit());
        bb.writeInt(drv.getConcurrencyLevel());
        bb.writeInt(drv.getInitialCapacity());
        bb.writeFloat(drv.getLoadFactor());
        bb.write((byte) (drv.getStatisticsEnabled() ? 1 : 0));
        bb.write((byte) (drv.isBucket() ? 1 : 0));
        final EnumSet<DiskRegionFlag> flags = drv.getFlags();
        bb.writeUTF(drv.getPartitionName());
        bb.writeInt(drv.getStartingBucketId());
        bb.writeUTF(drv.getCompressorClassName() == null ? "" : drv.getCompressorClassName());
        bb.writeBoolean(flags.contains(DiskRegionFlag.IS_WITH_VERSIONING));
        // TODO the offheap flag needs to be in a new version
        bb.writeBoolean(drv.getOffHeap());
        bb.write(END_OF_RECORD_ID);
        // don't do stats for these small records
        writeIFRecord(bb, 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) IOException(java.io.IOException)

Example 23 with DiskAccessException

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

the class LocalRegion method initialize.

/**
   * Do any extra initialization required. Region is already visible in parent's subregion map. This
   * method releases the initialization Latches, so subclasses should call this super method last
   * after performing additional initialization.
   *
   * @param imageTarget ignored, used by subclass for get initial image
   * @see DistributedRegion#initialize(InputStream, InternalDistributedMember,
   *      InternalRegionArguments)
   */
protected void initialize(InputStream snapshotInputStream, InternalDistributedMember imageTarget, InternalRegionArguments internalRegionArgs) throws TimeoutException, IOException, ClassNotFoundException {
    if (!isInternalRegion()) {
        // acceptable because addResourceListener won't add it twice
        if (!this.isDestroyed) {
            this.cache.getInternalResourceManager().addResourceListener(ResourceType.MEMORY, this);
        }
    }
    // if we're versioning entries we need a region-level version vector
    if (this.concurrencyChecksEnabled && this.versionVector == null) {
        createVersionVector();
    }
    // if not local, then recovery happens in InitialImageOperation
    if (this.scope.isLocal()) {
        createOQLIndexes(internalRegionArgs);
        if (this.diskRegion != null) {
            try {
                this.diskRegion.initializeOwner(this);
                this.diskRegion.finishInitializeOwner(this, GIIStatus.NO_GII);
                // This block was added so that early recovery could figure out that
                // this data needs to be recovered from disk. Local regions used to
                // not bother assigning a memberId but that is what the early
                // recovery
                // code uses to figure out that a region needs to be recovered.
                PersistentMemberID oldId = this.diskRegion.getMyInitializingID();
                if (oldId == null) {
                    oldId = this.diskRegion.getMyPersistentID();
                }
                if (oldId == null) {
                    PersistentMemberID newId = this.diskRegion.generatePersistentID();
                    this.diskRegion.setInitializing(newId);
                    this.diskRegion.setInitialized();
                }
            } catch (DiskAccessException dae) {
                releaseAfterRegionCreateEventLatch();
                this.handleDiskAccessException(dae, true);
                throw dae;
            }
        }
    }
    // make sure latches are released if they haven't been by now already
    releaseBeforeGetInitialImageLatch();
    if (snapshotInputStream != null && this.scope.isLocal()) {
        try {
            loadSnapshotDuringInitialization(snapshotInputStream);
        } catch (DiskAccessException dae) {
            releaseAfterRegionCreateEventLatch();
            this.handleDiskAccessException(dae);
            throw dae;
        }
    }
    releaseAfterGetInitialImageLatch();
    if (logger.isDebugEnabled()) {
        logger.debug("Calling addExpiryTasks for {}", this);
    }
    // at this point
    try {
        addIdleExpiryTask();
        addTTLExpiryTask();
        if (isEntryExpiryPossible()) {
            // called after gii to fix bug 35214
            rescheduleEntryExpiryTasks();
        }
        initialized();
    } catch (RegionDestroyedException ignore) {
        // whether it is this region or a parent region that is destroyed,
        // then so must we be
        Assert.assertTrue(isDestroyed());
    // just proceed, a destroyed region will be returned to caller
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) DiskAccessException(org.apache.geode.cache.DiskAccessException) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID)

Example 24 with DiskAccessException

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

the class LocalRegion method getDeserialized.

/**
   * @param disableCopyOnRead if true then do not make a copy on read
   * @param preferCachedDeserializable true if the preferred result form is CachedDeserializable
   * @param retainResult if true then the result may be a retained off-heap reference
   * @return the value found, which can be
   *         <ul>
   *         <li>null if the value was removed from the region entry
   *         <li>Token.INVALID if the value of the region entry is invalid
   *         <li>Token.LOCAL_INVALID if the value of the region entry is local invalid
   *         </ul>
   */
@Retained
Object getDeserialized(RegionEntry regionEntry, boolean updateStats, boolean disableCopyOnRead, boolean preferCachedDeserializable, boolean retainResult) {
    assert !retainResult || preferCachedDeserializable;
    boolean disabledLRUCallback = this.entries.disableLruUpdateCallback();
    try {
        @Retained Object value;
        try {
            if (retainResult) {
                value = regionEntry.getValueRetain(this);
            } else {
                value = regionEntry.getValue(this);
            }
        } catch (DiskAccessException dae) {
            this.handleDiskAccessException(dae);
            throw dae;
        }
        // skip updating the stats if the value is null
        if (value == null) {
            return null;
        }
        if (value instanceof CachedDeserializable) {
            if (!preferCachedDeserializable) {
                if (isCopyOnRead()) {
                    if (disableCopyOnRead) {
                        value = ((CachedDeserializable) value).getDeserializedForReading();
                    } else {
                        value = ((CachedDeserializable) value).getDeserializedWritableCopy(this, regionEntry);
                    }
                } else {
                    value = ((CachedDeserializable) value).getDeserializedValue(this, regionEntry);
                }
            }
        } else if (!disableCopyOnRead) {
            value = conditionalCopy(value);
        }
        if (updateStats) {
            updateStatsForGet(regionEntry, value != null && !Token.isInvalid(value));
        }
        return value;
    } catch (IllegalArgumentException i) {
        throw new IllegalArgumentException(LocalizedStrings.DONT_RELEASE.toLocalizedString("Error while deserializing value for key=" + regionEntry.getKey()), i);
    } finally {
        if (disabledLRUCallback) {
            this.entries.enableLruUpdateCallback();
            this.entries.lruUpdateCallback();
        }
    }
}
Also used : Retained(org.apache.geode.internal.offheap.annotations.Retained) DiskAccessException(org.apache.geode.cache.DiskAccessException) StoredObject(org.apache.geode.internal.offheap.StoredObject) Retained(org.apache.geode.internal.offheap.annotations.Retained)

Example 25 with DiskAccessException

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

the class LocalRegion method getDeserializedValue.

/**
   * Fetch the de-serialized value from non-transactional state.
   * 
   * @param keyInfo to which the value is associated
   * @param updateStats true if the entry stats should be updated.
   * @param disableCopyOnRead if true then disable copy on read
   * @param preferCachedDeserializable true if the preferred result form is CachedDeserializable
   * @param clientEvent client's event, if any (for version tag retrieval)
   * @param returnTombstones whether destroyed entries should be returned
   * @param retainResult if true then the result may be a retained off-heap reference
   * @return the value for the given key
   */
public Object getDeserializedValue(RegionEntry regionEntry, final KeyInfo keyInfo, final boolean updateStats, boolean disableCopyOnRead, boolean preferCachedDeserializable, EntryEventImpl clientEvent, boolean returnTombstones, boolean retainResult) {
    if (this.diskRegion != null) {
        this.diskRegion.setClearCountReference();
    }
    try {
        if (regionEntry == null) {
            regionEntry = this.entries.getEntry(keyInfo.getKey());
        }
        // update the statistics here, where it would make more sense.
        if (regionEntry == null) {
            return null;
        }
        final Object value;
        if (clientEvent != null && regionEntry.getVersionStamp() != null) {
            // defer the lruUpdateCallback to prevent a deadlock (see bug 51121).
            final boolean disabled = this.entries.disableLruUpdateCallback();
            try {
                synchronized (regionEntry) {
                    // bug #51059 value & version must be obtained atomically
                    clientEvent.setVersionTag(regionEntry.getVersionStamp().asVersionTag());
                    value = getDeserialized(regionEntry, updateStats, disableCopyOnRead, preferCachedDeserializable, retainResult);
                }
            } finally {
                if (disabled) {
                    this.entries.enableLruUpdateCallback();
                }
                try {
                    this.entries.lruUpdateCallback();
                } catch (DiskAccessException dae) {
                    this.handleDiskAccessException(dae);
                    throw dae;
                }
            }
        } else {
            value = getDeserialized(regionEntry, updateStats, disableCopyOnRead, preferCachedDeserializable, retainResult);
        }
        if (logger.isTraceEnabled() && !(this instanceof HARegion)) {
            logger.trace("getDeserializedValue for {} returning version: {} returnTombstones: {} value: {}", keyInfo.getKey(), regionEntry.getVersionStamp() == null ? "null" : regionEntry.getVersionStamp().asVersionTag(), returnTombstones, value);
        }
        return value;
    } finally {
        if (this.diskRegion != null) {
            this.diskRegion.removeClearCountReference();
        }
    }
}
Also used : DiskAccessException(org.apache.geode.cache.DiskAccessException) StoredObject(org.apache.geode.internal.offheap.StoredObject)

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