Search in sources :

Example 26 with RegionDestroyedException

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

the class PRQueryDUnitHelper method getCacheSerializableRunnableForPROrderByQueryAndCompareResults.

public CacheSerializableRunnable getCacheSerializableRunnableForPROrderByQueryAndCompareResults(final String regionName, final String localRegion) {
    SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") {

        public void run2() throws CacheException {
            Cache cache = getCache();
            // Querying the localRegion and the PR region
            String[] queries = new String[] { "p.status from /REGION_NAME p order by p.status", "* from /REGION_NAME order by status, ID desc", "status, ID from /REGION_NAME order by status", "p.status, p.ID from /REGION_NAME p order by p.status", "p.position1.secId, p.ID from /REGION_NAME p order by p.position1.secId", "key from /REGION_NAME.keys key order by key.status", "key.ID from /REGION_NAME.keys key order by key.ID", "key.ID, key.status from /REGION_NAME.keys key order by key.status", "key.ID, key.status from /REGION_NAME.keys key order by key.status, key.ID", "key.ID, key.status from /REGION_NAME.keys key order by key.status desc, key.ID", "key.ID, key.status from /REGION_NAME.keys key order by key.status, key.ID desc", "p.status, p.ID from /REGION_NAME p order by p.status asc, p.ID", "* from /REGION_NAME p order by p.status, p.ID", "p.ID from /REGION_NAME p, p.positions.values order by p.ID", "* from /REGION_NAME p, p.positions.values order by p.ID", "p.ID, p.status from /REGION_NAME p, p.positions.values order by p.status", "pos.secId from /REGION_NAME p, p.positions.values pos order by pos.secId", "p.ID, pos.secId from /REGION_NAME p, p.positions.values pos order by pos.secId", "* from /REGION_NAME p order by p.iD", "p.iD from /REGION_NAME p order by p.iD", "p.iD, p.status from /REGION_NAME p order by p.iD", "iD, status from /REGION_NAME order by iD", "* from /REGION_NAME p order by p.getID()", "p.getID() from /REGION_NAME p order by p.getID()", "* from /REGION_NAME p order by p.names[1]", "* from /REGION_NAME p order by p.getP1().secId", "* from /REGION_NAME p order by p.getP1().getSecId()", "* from /REGION_NAME p order by p.position1.secId", "p.ID, p.position1.secId from /REGION_NAME p order by p.position1.secId", "p.position1.secId, p.ID from /REGION_NAME p order by p.position1.secId", "e.key.ID from /REGION_NAME.entries e order by e.key.ID", "e.key.ID, e.value.status from /REGION_NAME.entries e order by e.key.ID", "e.key.ID, e.value.status from /REGION_NAME.entrySet e order by e.key.ID, e.value.status desc", "e.key, e.value from /REGION_NAME.entrySet e order by e.key.ID, e.value.status desc", "e.key from /REGION_NAME.entrySet e order by e.key.ID, e.key.pkid desc", "p, pos from /REGION_NAME p, p.positions.values pos order by p.ID", "p, pos from /REGION_NAME p, p.positions.values pos order by pos.secId", "p, pos from /REGION_NAME p, p.positions.values pos order by p.ID, pos.secId" };
            Object[][] r = new Object[queries.length][2];
            Region local = cache.getRegion(localRegion);
            Region region = cache.getRegion(regionName);
            assertNotNull(region);
            final String[] expectedExceptions = new String[] { RegionDestroyedException.class.getName(), ReplyException.class.getName(), CacheClosedException.class.getName(), ForceReattemptException.class.getName(), QueryInvocationTargetException.class.getName() };
            for (final String expectedException : expectedExceptions) {
                getCache().getLogger().info("<ExpectedException action=add>" + expectedException + "</ExpectedException>");
            }
            String distinct = "SELECT DISTINCT ";
            QueryService qs = getCache().getQueryService();
            Object[] params;
            try {
                for (int j = 0; j < queries.length; j++) {
                    String qStr = null;
                    synchronized (region) {
                        // Execute on local region.
                        qStr = (distinct + queries[j].replace("REGION_NAME", localRegion));
                        r[j][0] = qs.newQuery(qStr).execute();
                        // Execute on remote region.
                        qStr = (distinct + queries[j].replace("REGION_NAME", regionName));
                        r[j][1] = qs.newQuery(qStr).execute();
                    }
                }
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Queries Executed successfully on Local region & PR Region");
                StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
                ssORrs.CompareQueryResultsWithoutAndWithIndexes(r, queries.length, queries);
            } catch (QueryInvocationTargetException e) {
                // not it's okay
                throw new TestException("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught unexpected query exception", e);
            } catch (QueryException e) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().error("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught QueryException while querying" + e, e);
                throw new TestException("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught unexpected query exception", e);
            } catch (RegionDestroyedException rde) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught a RegionDestroyedException while querying as expected ", rde);
            } catch (CancelException cce) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught a CancelException while querying as expected ", cce);
            } finally {
                for (final String expectedException : expectedExceptions) {
                    getCache().getLogger().info("<ExpectedException action=remove>" + expectedException + "</ExpectedException>");
                }
            }
        }
    };
    return (CacheSerializableRunnable) PrRegion;
}
Also used : StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) TestException(util.TestException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) QueryException(org.apache.geode.cache.query.QueryException) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException) Cache(org.apache.geode.cache.Cache)

Example 27 with RegionDestroyedException

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

the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRAndRRQueryWithCompactAndRangeIndexAndCompareResults.

public SerializableRunnableIF getCacheSerializableRunnableForPRAndRRQueryWithCompactAndRangeIndexAndCompareResults(final String name, final String coloName, final String localName, final String coloLocalName) {
    SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            // Querying the PR region
            String[] queries = new String[] { "r1.ID = pos2.id", "r1.ID = pos2.id AND r1.ID > 5", "r1.ID = pos2.id AND r1.status = 'active'", "r1.ID = pos2.id ORDER BY r1.ID", "r1.ID = pos2.id ORDER BY pos2.id", "r1.ID = pos2.id ORDER BY r2.status", "r1.ID = pos2.id AND r1.status != r2.status", "r1.ID = pos2.id AND r1.status = r2.status", "r1.ID = pos2.id AND r1.positions.size = r2.positions.size", "r1.ID = pos2.id AND r1.positions.size > r2.positions.size", "r1.ID = pos2.id AND r1.positions.size < r2.positions.size", "r1.ID = pos2.id AND r1.positions.size = r2.positions.size AND r2.positions.size > 0", "r1.ID = pos2.id AND (r1.positions.size > r2.positions.size OR r2.positions.size > 0)", "r1.ID = pos2.id AND (r1.positions.size < r2.positions.size OR r1.positions.size > 0)" };
            Object[][] r = new Object[queries.length][2];
            Region region = null;
            region = cache.getRegion(name);
            assertNotNull(region);
            region = cache.getRegion(coloName);
            assertNotNull(region);
            region = cache.getRegion(localName);
            assertNotNull(region);
            region = cache.getRegion(coloLocalName);
            assertNotNull(region);
            final String[] expectedExceptions = new String[] { RegionDestroyedException.class.getName(), ReplyException.class.getName(), CacheClosedException.class.getName(), ForceReattemptException.class.getName(), QueryInvocationTargetException.class.getName() };
            for (final String expectedException : expectedExceptions) {
                getCache().getLogger().info("<ExpectedException action=add>" + expectedException + "</ExpectedException>");
            }
            QueryService qs = getCache().getQueryService();
            try {
                for (int j = 0; j < queries.length; j++) {
                    getCache().getLogger().info("About to execute local query: " + queries[j]);
                    Function func = new TestQueryFunction("testfunction");
                    Object funcResult = FunctionService.onRegion((getCache().getRegion(name) instanceof PartitionedRegion) ? getCache().getRegion(name) : getCache().getRegion(coloName)).setArguments("<trace> Select " + (queries[j].contains("ORDER BY") ? "DISTINCT" : "") + " * from /" + name + " r1, /" + coloName + " r2, r2.positions.values pos2 where " + queries[j]).execute(func).getResult();
                    r[j][0] = ((ArrayList) funcResult).get(0);
                    getCache().getLogger().info("About to execute local query: " + queries[j]);
                    SelectResults r2 = (SelectResults) qs.newQuery("Select " + (queries[j].contains("ORDER BY") ? "DISTINCT" : "") + " * from /" + localName + " r1, /" + coloLocalName + " r2, r2.positions.values pos2 where " + queries[j]).execute();
                    r[j][1] = r2.asList();
                }
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Queries Executed successfully on Local region & PR Region");
                StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
                ssORrs.CompareQueryResultsAsListWithoutAndWithIndexes(r, queries.length, false, false, queries);
            } catch (QueryInvocationTargetException e) {
                // cause and see whether or not it's okay
                throw new TestException("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught unexpected query exception", e);
            } catch (QueryException e) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().error("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught QueryException while querying" + e, e);
                throw new TestException("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught unexpected query exception", e);
            } catch (RegionDestroyedException rde) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught a RegionDestroyedException while querying as expected ", rde);
            } catch (CancelException cce) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught a CancelException while querying as expected ", cce);
            } finally {
                for (final String expectedException : expectedExceptions) {
                    getCache().getLogger().info("<ExpectedException action=remove>" + expectedException + "</ExpectedException>");
                }
            }
        }
    };
    return (CacheSerializableRunnable) PrRegion;
}
Also used : StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) TestException(util.TestException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) Function(org.apache.geode.cache.execute.Function) QueryException(org.apache.geode.cache.query.QueryException) SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException) Cache(org.apache.geode.cache.Cache)

Example 28 with RegionDestroyedException

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

the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRColocatedDataSetQueryAndCompareResults.

public SerializableRunnableIF getCacheSerializableRunnableForPRColocatedDataSetQueryAndCompareResults(final String name, final String coloName, final String localName, final String coloLocalName) {
    SerializableRunnable PrRegion = new CacheSerializableRunnable("PRQuery") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            // Querying the PR region
            String[] queries = new String[] { "r1.ID = r2.id", "r1.ID = r2.id AND r1.ID > 5", "r1.ID = r2.id AND r1.status = 'active'", // "r1.ID = r2.id LIMIT 10",
            "r1.ID = r2.id ORDER BY r1.ID", "r1.ID = r2.id ORDER BY r2.id", "r1.ID = r2.id ORDER BY r2.status", "r1.ID = r2.id AND r1.status != r2.status", "r1.ID = r2.id AND r1.status = r2.status", "r1.ID = r2.id AND r1.positions.size = r2.positions.size", "r1.ID = r2.id AND r1.positions.size > r2.positions.size", "r1.ID = r2.id AND r1.positions.size < r2.positions.size", "r1.ID = r2.id AND r1.positions.size = r2.positions.size AND r2.positions.size > 0", "r1.ID = r2.id AND (r1.positions.size > r2.positions.size OR r2.positions.size > 0)", "r1.ID = r2.id AND (r1.positions.size < r2.positions.size OR r1.positions.size > 0)" };
            Object[][] r = new Object[queries.length][2];
            Region region = null;
            region = cache.getRegion(name);
            assertNotNull(region);
            region = cache.getRegion(coloName);
            assertNotNull(region);
            region = cache.getRegion(localName);
            assertNotNull(region);
            region = cache.getRegion(coloLocalName);
            assertNotNull(region);
            final String[] expectedExceptions = new String[] { RegionDestroyedException.class.getName(), ReplyException.class.getName(), CacheClosedException.class.getName(), ForceReattemptException.class.getName(), QueryInvocationTargetException.class.getName() };
            for (final String expectedException : expectedExceptions) {
                getCache().getLogger().info("<ExpectedException action=add>" + expectedException + "</ExpectedException>");
            }
            QueryService qs = getCache().getQueryService();
            Object[] params;
            try {
                for (int j = 0; j < queries.length; j++) {
                    getCache().getLogger().info("About to execute local query: " + queries[j]);
                    Function func = new TestQueryFunction("testfunction");
                    Object funcResult = FunctionService.onRegion((getCache().getRegion(name) instanceof PartitionedRegion) ? getCache().getRegion(name) : getCache().getRegion(coloName)).setArguments("<trace> Select " + (queries[j].contains("ORDER BY") ? "DISTINCT" : "") + " * from /" + name + " r1, /" + coloName + " r2 where " + queries[j]).execute(func).getResult();
                    r[j][0] = ((ArrayList) funcResult).get(0);
                    getCache().getLogger().info("About to execute local query: " + queries[j]);
                    SelectResults r2 = (SelectResults) qs.newQuery("Select " + (queries[j].contains("ORDER BY") ? "DISTINCT" : "") + " * from /" + localName + " r1, /" + coloLocalName + " r2 where " + queries[j]).execute();
                    r[j][1] = r2.asList();
                }
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Queries Executed successfully on Local region & PR Region");
                // compareTwoQueryResults(r, queries.length);
                StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
                ssORrs.CompareQueryResultsAsListWithoutAndWithIndexes(r, queries.length, false, false, queries);
            } catch (QueryInvocationTargetException e) {
                // cause and see whether or not it's okay
                throw new TestException("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught unexpected query exception", e);
            } catch (QueryException e) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().error("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught QueryException while querying" + e, e);
                throw new TestException("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught unexpected query exception", e);
            } catch (RegionDestroyedException rde) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught a RegionDestroyedException while querying as expected ", rde);
            } catch (CancelException cce) {
                org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PRQueryDUnitHelper#getCacheSerializableRunnableForPRQueryAndCompareResults: Caught a CancelException while querying as expected ", cce);
            } finally {
                for (final String expectedException : expectedExceptions) {
                    getCache().getLogger().info("<ExpectedException action=remove>" + expectedException + "</ExpectedException>");
                }
            }
        }
    };
    return (CacheSerializableRunnable) PrRegion;
}
Also used : StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) TestException(util.TestException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) Function(org.apache.geode.cache.execute.Function) QueryException(org.apache.geode.cache.query.QueryException) SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException) Cache(org.apache.geode.cache.Cache)

Example 29 with RegionDestroyedException

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

the class AbstractRegion method getLastModifiedTime.

/**
   * The logical lastModifiedTime of a region is the most recent lastModifiedTime of the region and
   * all its subregions. This implementation trades performance of stat retrieval for performance of
   * get/put, which is more critical.
   */
@Override
public synchronized long getLastModifiedTime() {
    checkReadiness();
    long mostRecent = basicGetLastModifiedTime();
    // don't need to wait on getInitialImage for this operation in subregions
    int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.ANY_INIT);
    try {
        for (Object region : subregions(false)) {
            try {
                LocalRegion localRegion = (LocalRegion) region;
                if (localRegion.isInitialized()) {
                    mostRecent = Math.max(mostRecent, localRegion.getLastModifiedTime());
                }
            } catch (RegionDestroyedException ignore) {
            // pass over destroyed region
            }
        }
    } finally {
        LocalRegion.setThreadInitLevelRequirement(oldLevel);
    }
    return mostRecent;
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ExtensionPoint(org.apache.geode.internal.cache.extension.ExtensionPoint) SimpleExtensionPoint(org.apache.geode.internal.cache.extension.SimpleExtensionPoint)

Example 30 with RegionDestroyedException

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

the class Oplog method recoverDrf.

/**
   * Return bytes read.
   */
long recoverDrf(OplogEntryIdSet deletedIds, boolean alreadyRecoveredOnce, boolean latestOplog) {
    File drfFile = this.drf.f;
    if (drfFile == null) {
        this.haveRecoveredDrf = true;
        return 0L;
    }
    lockCompactor();
    try {
        if (this.haveRecoveredDrf && !getHasDeletes())
            // do this while holding lock
            return 0L;
        if (!this.haveRecoveredDrf) {
            this.haveRecoveredDrf = true;
        }
        logger.info(LocalizedMessage.create(LocalizedStrings.DiskRegion_RECOVERING_OPLOG_0_1_2, new Object[] { toString(), drfFile.getAbsolutePath(), getParent().getName() }));
        this.recoverDelEntryId = DiskStoreImpl.INVALID_ID;
        boolean readLastRecord = true;
        CountingDataInputStream dis = null;
        try {
            int recordCount = 0;
            boolean foundDiskStoreRecord = false;
            FileInputStream fis = null;
            try {
                fis = new FileInputStream(drfFile);
                dis = new CountingDataInputStream(new BufferedInputStream(fis, 32 * 1024), drfFile.length());
                boolean endOfLog = false;
                while (!endOfLog) {
                    if (dis.atEndOfFile()) {
                        endOfLog = true;
                        break;
                    }
                    readLastRecord = false;
                    byte opCode = dis.readByte();
                    if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY)) {
                        logger.trace(LogMarker.PERSIST_RECOVERY, "drf byte={} location={}", opCode, Long.toHexString(dis.getCount()));
                    }
                    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_DEL_ENTRY_1ID:
                        case OPLOG_DEL_ENTRY_2ID:
                        case OPLOG_DEL_ENTRY_3ID:
                        case OPLOG_DEL_ENTRY_4ID:
                        case OPLOG_DEL_ENTRY_5ID:
                        case OPLOG_DEL_ENTRY_6ID:
                        case OPLOG_DEL_ENTRY_7ID:
                        case OPLOG_DEL_ENTRY_8ID:
                            readDelEntry(dis, opCode, deletedIds, parent);
                            recordCount++;
                            break;
                        case OPLOG_DISK_STORE_ID:
                            readDiskStoreRecord(dis, this.drf.f);
                            foundDiskStoreRecord = true;
                            recordCount++;
                            break;
                        case OPLOG_MAGIC_SEQ_ID:
                            readOplogMagicSeqRecord(dis, this.drf.f, OPLOG_TYPE.DRF);
                            break;
                        case OPLOG_GEMFIRE_VERSION:
                            readGemfireVersionRecord(dis, this.drf.f);
                            recordCount++;
                            break;
                        case OPLOG_RVV:
                            long idx = dis.getCount();
                            readRVVRecord(dis, this.drf.f, true, 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.drf.f + "\" does not belong to the init file \"" + getParent().getInitFile() + "\". Drf 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(drfFile.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();
            }
        }
        if (!alreadyRecoveredOnce) {
            setRecoveredDrfSize(byteCount);
            this.dirHolder.incrementTotalOplogSize(byteCount);
        }
        return byteCount;
    } finally {
        unlockCompactor();
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) DiskAccessException(org.apache.geode.cache.DiskAccessException) EOFException(java.io.EOFException) StoredObject(org.apache.geode.internal.offheap.StoredObject) CancelException(org.apache.geode.CancelException) File(java.io.File) UninterruptibleRandomAccessFile(org.apache.geode.internal.cache.persistence.UninterruptibleRandomAccessFile)

Aggregations

RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)124 CancelException (org.apache.geode.CancelException)41 LocalRegion (org.apache.geode.internal.cache.LocalRegion)37 Region (org.apache.geode.cache.Region)35 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)28 IOException (java.io.IOException)25 Cache (org.apache.geode.cache.Cache)20 CacheException (org.apache.geode.cache.CacheException)19 QueryException (org.apache.geode.cache.query.QueryException)16 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)16 ReplyException (org.apache.geode.distributed.internal.ReplyException)16 CacheClosedException (org.apache.geode.cache.CacheClosedException)14 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)14 SelectResults (org.apache.geode.cache.query.SelectResults)13 EventID (org.apache.geode.internal.cache.EventID)13 Test (org.junit.Test)13 Iterator (java.util.Iterator)12 TransactionDataNotColocatedException (org.apache.geode.cache.TransactionDataNotColocatedException)12 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)12 QueryService (org.apache.geode.cache.query.QueryService)11