Search in sources :

Example 1 with DiskInitFileParser

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

the class DiskInitFile method recover.

DiskStoreID recover() {
    recoverFromFailedCompaction();
    if (!this.ifFile.exists()) {
        // create a UUID using the cheaper Random class.
        return new DiskStoreID(UUID.randomUUID());
    }
    DiskStoreID result = null;
    try {
        FileInputStream fis = null;
        CountingDataInputStream dis = null;
        try {
            fis = new FileInputStream(this.ifFile);
            dis = new CountingDataInputStream(new BufferedInputStream(fis, 8 * 1024), this.ifFile.length());
            DiskInitFileParser parser = new DiskInitFileParser(dis, this);
            result = parser.parse();
            this.gotEOF = parser.gotEOF();
            this.nextSeekPosition = dis.getCount();
            if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY)) {
                logger.trace(LogMarker.PERSIST_RECOVERY, "liveRecordCount={} totalRecordCount={}", this.ifLiveRecordCount, this.ifTotalRecordCount);
            }
        } finally {
            if (dis != null) {
                dis.close();
            }
            if (fis != null) {
                fis.close();
            }
        }
        for (PlaceHolderDiskRegion drv : this.drMap.values()) {
            if (drv.getMyPersistentID() != null || drv.getMyInitializingID() != null) {
                // Prepare each region we found in the init file for early recovery.
                if (drv.isBucket() || !getDiskStore().getOwnedByRegion()) {
                    if (drv.isBucket() && !drv.getActualLruAlgorithm().isNone()) {
                        drv.prlruStats = getDiskStore().getOrCreatePRLRUStats(drv);
                    }
                    getDiskStore().getStats().incUncreatedRecoveredRegions(1);
                    drv.setRecoveredEntryMap(RegionMapFactory.createVM(drv, getDiskStore(), getDiskStore().getInternalRegionArguments()));
                    if (!getDiskStore().isOffline()) {
                        // schedule it for recovery since we want to recovery region data early now
                        getDiskStore().scheduleForRecovery(drv);
                    }
                // else if we are validating or offlineCompacting
                // then the scheduleForRecovery is called later in DiskStoreImpl
                // this helps fix bug 42043
                }
            }
        }
    } catch (EOFException ex) {
    // ignore since a partial record write can be caused by a crash
    // throw new
    // DiskAccessException(LocalizedStrings.Oplog_FAILED_READING_FILE_DURING_RECOVERY_FROM_0
    // .toLocalizedString(this.ifFile.getPath()), ex, this.parent);
    } catch (ClassNotFoundException ex) {
        throw new DiskAccessException(LocalizedStrings.Oplog_FAILED_READING_FILE_DURING_RECOVERY_FROM_0.toLocalizedString(this.ifFile.getPath()), ex, this.parent);
    } catch (IOException ex) {
        throw new DiskAccessException(LocalizedStrings.Oplog_FAILED_READING_FILE_DURING_RECOVERY_FROM_0.toLocalizedString(this.ifFile.getPath()), ex, this.parent);
    } catch (CancelException ignore) {
        if (logger.isDebugEnabled()) {
            logger.debug("Oplog::readOplog:Error in recovery as Cache was closed", ignore);
        }
    } catch (RegionDestroyedException ignore) {
        if (logger.isDebugEnabled()) {
            logger.debug("Oplog::readOplog:Error in recovery as Region was destroyed", ignore);
        }
    } catch (IllegalStateException ex) {
        if (!this.parent.isClosing()) {
            throw ex;
        }
    }
    return result;
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) DiskInitFileParser(org.apache.geode.internal.cache.persistence.DiskInitFileParser) BufferedInputStream(java.io.BufferedInputStream) EOFException(java.io.EOFException) DiskAccessException(org.apache.geode.cache.DiskAccessException) CancelException(org.apache.geode.CancelException) DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 EOFException (java.io.EOFException)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 CancelException (org.apache.geode.CancelException)1 DiskAccessException (org.apache.geode.cache.DiskAccessException)1 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1 DiskInitFileParser (org.apache.geode.internal.cache.persistence.DiskInitFileParser)1 DiskStoreID (org.apache.geode.internal.cache.persistence.DiskStoreID)1