Search in sources :

Example 1 with PRPersistentConfig

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

the class DiskStoreImpl method destroyRegion.

/**
   * Destroy a region which has not been created.
   * 
   * @param regName the name of the region to destroy
   */
public void destroyRegion(String regName) {
    DiskRegionView drv = getDiskInitFile().getDiskRegionByName(regName);
    if (drv == null) {
        drv = getDiskInitFile().getDiskRegionByPrName(regName);
        PRPersistentConfig prConfig = getDiskInitFile().getPersistentPR(regName);
        if (drv == null && prConfig == null) {
            throw new IllegalArgumentException("The disk store does not contain a region named: " + regName);
        } else {
            getDiskInitFile().destroyPRRegion(regName);
        }
    } else {
        getDiskInitFile().endDestroyRegion(drv);
    }
}
Also used : PRPersistentConfig(org.apache.geode.internal.cache.persistence.PRPersistentConfig) DiskRegionView(org.apache.geode.internal.cache.persistence.DiskRegionView)

Example 2 with PRPersistentConfig

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

the class DiskIFJUnitTest method testPRConfig.

@Test
public void testPRConfig() throws Exception {
    DiskStoreImpl store = (DiskStoreImpl) cache.createDiskStoreFactory().create("testStore");
    PRPersistentConfig config = new PRPersistentConfig(5, "j");
    store.addPersistentPR("pr1", config);
    store.addPersistentPR("pr2", config);
    store.removePersistentPR("pr1");
    assertEquals(config, store.getPersistentPRConfig("pr2"));
    assertEquals(null, store.getPersistentPRConfig("pr1"));
    // recover the store
    cache.close();
    cache = createCache();
    store = (DiskStoreImpl) cache.createDiskStoreFactory().create("testStore");
    // Make sure the config is still the same.
    assertEquals(config, store.getPersistentPRConfig("pr2"));
    assertEquals(null, store.getPersistentPRConfig("pr1"));
    store.forceIFCompaction();
    assertEquals(config, store.getPersistentPRConfig("pr2"));
    assertEquals(null, store.getPersistentPRConfig("pr1"));
    // recover the store again
    cache.close();
    cache = createCache();
    store = (DiskStoreImpl) cache.createDiskStoreFactory().create("testStore");
    assertEquals(config, store.getPersistentPRConfig("pr2"));
    assertEquals(null, store.getPersistentPRConfig("pr1"));
}
Also used : PRPersistentConfig(org.apache.geode.internal.cache.persistence.PRPersistentConfig) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with PRPersistentConfig

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

the class PartitionedRegion method createAndValidatePersistentConfig.

private void createAndValidatePersistentConfig() {
    DiskStoreImpl dsi = this.getDiskStore();
    if (this.dataPolicy.withPersistence() && !this.concurrencyChecksEnabled && supportsConcurrencyChecks()) {
        logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_ENABLING_CONCURRENCY_CHECKS_FOR_PERSISTENT_PR, this.getFullPath()));
        this.concurrencyChecksEnabled = true;
    }
    if (dsi != null && this.getDataPolicy().withPersistence()) {
        String colocatedWith = colocatedWithRegion == null ? "" : colocatedWithRegion.getFullPath();
        PRPersistentConfig config = dsi.getPersistentPRConfig(this.getFullPath());
        if (config != null) {
            if (config.getTotalNumBuckets() != this.getTotalNumberOfBuckets()) {
                Object[] prms = new Object[] { this.getFullPath(), this.getTotalNumberOfBuckets(), config.getTotalNumBuckets() };
                throw new IllegalStateException(LocalizedStrings.PartitionedRegion_FOR_REGION_0_TotalBucketNum_1_SHOULD_NOT_BE_CHANGED_Previous_Configured_2.toString(prms));
            }
            // a record to disk, so we won't allow that right now either.
            if (!colocatedWith.equals(config.getColocatedWith())) {
                Object[] prms = new Object[] { this.getFullPath(), colocatedWith, config.getColocatedWith() };
                DiskAccessException dae = new DiskAccessException(LocalizedStrings.LocalRegion_A_DISKACCESSEXCEPTION_HAS_OCCURRED_WHILE_WRITING_TO_THE_DISK_FOR_REGION_0_THE_REGION_WILL_BE_CLOSED.toLocalizedString(this.getFullPath()), null, dsi);
                dsi.handleDiskAccessException(dae);
                throw new IllegalStateException(LocalizedStrings.PartitionedRegion_FOR_REGION_0_ColocatedWith_1_SHOULD_NOT_BE_CHANGED_Previous_Configured_2.toString(prms));
            }
        } else {
            config = new PRPersistentConfig(this.getTotalNumberOfBuckets(), colocatedWith);
            dsi.addPersistentPR(this.getFullPath(), config);
            // as well.
            if (colocatedWithRegion != null && colocatedWithRegion.getDiskStore() != null && colocatedWithRegion.getDiskStore() != dsi) {
                colocatedWithRegion.getDiskStore().addPersistentPR(this.getFullPath(), config);
            }
        }
    }
}
Also used : PRPersistentConfig(org.apache.geode.internal.cache.persistence.PRPersistentConfig) DiskAccessException(org.apache.geode.cache.DiskAccessException)

Example 4 with PRPersistentConfig

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

the class ColocationHelper method hasOfflineColocatedChildRegions.

/**
   * Returns true if there are regions that are persisted on this member and were previously
   * colocated with the given region, but have not yet been created.
   * 
   * @param region The parent region
   * @return true if there are any child regions that are persisted on this member, but have not yet
   *         been created.
   */
private static boolean hasOfflineColocatedChildRegions(PartitionedRegion region) {
    boolean hasOfflineChildren = false;
    int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.ANY_INIT);
    try {
        InternalCache cache = region.getCache();
        Collection<DiskStore> stores = cache.listDiskStores();
        // Look through all of the disk stores for offline colocated child regions
        for (DiskStore diskStore : stores) {
            // Look at all of the partitioned regions.
            for (Map.Entry<String, PRPersistentConfig> entry : ((DiskStoreImpl) diskStore).getAllPRs().entrySet()) {
                PRPersistentConfig config = entry.getValue();
                String childName = entry.getKey();
                // Check to see if they're colocated with this region.
                if (region.getFullPath().equals(config.getColocatedWith())) {
                    PartitionedRegion childRegion = (PartitionedRegion) cache.getRegion(childName);
                    if (childRegion == null) {
                        // unless it is a parallel queue that the user has removed.
                        if (!ignoreUnrecoveredQueue(region, childName)) {
                            region.addMissingColocatedRegionLogger(childName);
                            hasOfflineChildren = true;
                        }
                    } else {
                        // Otherwise, look for offline children of that region.
                        if (hasOfflineColocatedChildRegions(childRegion)) {
                            hasOfflineChildren = true;
                            // Add the offline children of this child to the region's missingChildren list
                            region.addMissingColocatedRegionLogger(childRegion);
                        }
                    }
                }
            }
        }
    } finally {
        LocalRegion.setThreadInitLevelRequirement(oldLevel);
    }
    return hasOfflineChildren;
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) PRPersistentConfig(org.apache.geode.internal.cache.persistence.PRPersistentConfig) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

PRPersistentConfig (org.apache.geode.internal.cache.persistence.PRPersistentConfig)4 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DiskAccessException (org.apache.geode.cache.DiskAccessException)1 DiskStore (org.apache.geode.cache.DiskStore)1 DiskRegionView (org.apache.geode.internal.cache.persistence.DiskRegionView)1 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)1 Test (org.junit.Test)1