Search in sources :

Example 56 with PartitionAttributes

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

the class PRColocationDUnitTest method createSubPR.

public static void createSubPR(String partitionedRegionName, Integer redundancy, Integer localMaxMemory, Integer totalNumBuckets, Object colocatedWith, Boolean isPartitionResolver) {
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(redundancy.intValue()).setLocalMaxMemory(localMaxMemory.intValue()).setTotalNumBuckets(totalNumBuckets.intValue()).setColocatedWith((String) colocatedWith);
    if (isPartitionResolver.booleanValue()) {
        paf.setPartitionResolver(new CustomerIDPartitionResolver("CustomerIDPartitionResolver"));
    }
    PartitionAttributes prAttr = paf.create();
    AttributesFactory attr = new AttributesFactory();
    assertNotNull(basicGetCache());
    Region root = basicGetCache().createRegion("root" + partitionedRegionName, attr.create());
    attr.setPartitionAttributes(prAttr);
    Region pr = root.createSubregion(partitionedRegionName, attr.create());
    assertNotNull(pr);
    LogWriterUtils.getLogWriter().info("Partitioned sub region " + pr.getName() + " created Successfully :" + pr.toString());
    if (localMaxMemory == 0) {
        putInPartitionedRegion(pr);
    }
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region)

Example 57 with PartitionAttributes

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

the class PersistentRVVRecoveryDUnitTest method testConflictChecksDuringConcurrentDeltaGIIAndOtherOp.

/**
   * This test creates 2 VMs in a distributed system with a persistent PartitionedRegion and one VM
   * (VM1) puts an entry in region. Second VM (VM2) starts later and does a delta GII. During Delta
   * GII in VM2 a DESTROY operation happens in VM1 and gets propagated to VM2 concurrently with GII.
   * At this point if entry version is greater than the once received from GII then it must not get
   * applied. Which is Bug #45921.
   *
   */
@Test
public void testConflictChecksDuringConcurrentDeltaGIIAndOtherOp() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    vm0.invoke(new CacheSerializableRunnable("Create PR and put an entry") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            PartitionAttributes attrs = new PartitionAttributesFactory().setRedundantCopies(1).setTotalNumBuckets(1).create();
            AttributesFactory factory = new AttributesFactory();
            factory.setPartitionAttributes(attrs);
            RegionAttributes rAttrs = factory.create();
            Region region = cache.createRegionFactory(rAttrs).create("prRegion");
            region.put("testKey", "testValue");
            assertEquals(1, region.size());
        }
    });
    // Create a cache and region, do an update to change the version no. and
    // restart the cache and region.
    vm1.invoke(new CacheSerializableRunnable("Create PR and put an entry") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            PartitionAttributes attrs = new PartitionAttributesFactory().setRedundantCopies(1).setTotalNumBuckets(1).create();
            AttributesFactory factory = new AttributesFactory();
            factory.setPartitionAttributes(attrs);
            RegionAttributes rAttrs = factory.create();
            Region region = cache.createRegionFactory(rAttrs).create("prRegion");
            region.put("testKey", "testValue2");
            cache.close();
            // Restart
            cache = getCache();
            region = cache.createRegionFactory(rAttrs).create("prRegion");
        }
    });
    // Do a DESTROY in vm0 when delta GII is in progress in vm1 (Hopefully, Not
    // guaranteed).
    AsyncInvocation async = vm0.invokeAsync(new CacheSerializableRunnable("Detroy entry in region") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            Region region = cache.getRegion("prRegion");
            while (!region.get("testKey").equals("testValue2")) {
                Wait.pause(100);
            }
            region.destroy("testKey");
        }
    });
    try {
        async.join(3000);
    } catch (InterruptedException e) {
        new AssertionError("VM1 entry destroy did not finish in 3000 ms");
    }
    vm1.invoke(new CacheSerializableRunnable("Verifying entry version in new node VM1") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            Region region = cache.getRegion("prRegion");
            Region.Entry entry = ((PartitionedRegion) region).getEntry("testKey", true);
            RegionEntry re = ((EntrySnapshot) entry).getRegionEntry();
            LogWriterUtils.getLogWriter().fine("RegionEntry for testKey: " + re.getKey() + " " + re.getValueInVM((LocalRegion) region));
            assertTrue(re.getValueInVM((LocalRegion) region) instanceof Tombstone);
            VersionTag tag = re.getVersionStamp().asVersionTag();
            assertEquals(3, /* Two puts and a Destroy */
            tag.getEntryVersion());
        }
    });
    closeCache(vm0);
    closeCache(vm1);
}
Also used : CacheException(org.apache.geode.cache.CacheException) RegionAttributes(org.apache.geode.cache.RegionAttributes) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Host(org.apache.geode.test.dunit.Host) LocalRegion(org.apache.geode.internal.cache.LocalRegion) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Tombstone(org.apache.geode.internal.cache.Token.Tombstone) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionEntry(org.apache.geode.internal.cache.RegionEntry) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) DiskRegion(org.apache.geode.internal.cache.DiskRegion) Region(org.apache.geode.cache.Region) RegionEntry(org.apache.geode.internal.cache.RegionEntry) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 58 with PartitionAttributes

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

the class PDXQueryTestBase method configAndStartBridgeServer.

protected void configAndStartBridgeServer(boolean isPr, boolean isAccessor, boolean asyncIndex, Compressor compressor) {
    AttributesFactory factory = new AttributesFactory();
    if (isPr) {
        PartitionAttributesFactory paf = new PartitionAttributesFactory();
        if (isAccessor) {
            paf.setLocalMaxMemory(0);
        }
        PartitionAttributes prAttr = paf.setTotalNumBuckets(20).setRedundantCopies(0).create();
        factory.setPartitionAttributes(prAttr);
    } else {
        factory.setScope(Scope.DISTRIBUTED_ACK);
        factory.setDataPolicy(DataPolicy.REPLICATE);
    }
    if (asyncIndex) {
        factory.setIndexMaintenanceSynchronous(!asyncIndex);
    }
    if (compressor != null) {
        factory.setCompressor(compressor);
    }
    createRegion(this.regionName, this.rootRegionName, factory.create());
    createRegion(this.regionName2, this.rootRegionName, factory.create());
    try {
        startBridgeServer(0, false);
    } catch (Exception ex) {
        Assert.fail("While starting CacheServer", ex);
    }
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 59 with PartitionAttributes

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

the class PartitionedRegion method registerPartitionedRegion.

/**
   * Register this PartitionedRegion by: 1) Create a PartitionRegionConfig and 2) Bind it into the
   * allPartitionedRegion system wide Region.
   * 
   * @param storesData which indicates whether the instance in this cache stores data, effecting the
   *        Nodes PRType
   * 
   * @see Node#setPRType(int)
   */
private void registerPartitionedRegion(boolean storesData) {
    // Register this ParitionedRegion. First check if the ParitionedRegion
    // entry already exists globally.
    PartitionRegionConfig prConfig = null;
    PartitionAttributes prAttribs = getAttributes().getPartitionAttributes();
    if (storesData) {
        if (this.fixedPAttrs != null) {
            this.node.setPRType(Node.FIXED_PR_DATASTORE);
        } else {
            this.node.setPRType(Node.ACCESSOR_DATASTORE);
        }
        this.node.setPersistence(getAttributes().getDataPolicy() == DataPolicy.PERSISTENT_PARTITION);
        byte loaderByte = (byte) (getAttributes().getCacheLoader() != null ? 0x01 : 0x00);
        byte writerByte = (byte) (getAttributes().getCacheWriter() != null ? 0x02 : 0x00);
        this.node.setLoaderWriterByte((byte) (loaderByte + writerByte));
    } else {
        if (this.fixedPAttrs != null) {
            this.node.setPRType(Node.FIXED_PR_ACCESSOR);
        } else {
            this.node.setPRType(Node.ACCESSOR);
        }
    }
    final RegionLock rl = getRegionLock();
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("registerPartitionedRegion: obtaining lock");
        }
        rl.lock();
        checkReadiness();
        prConfig = this.prRoot.get(getRegionIdentifier());
        if (prConfig == null) {
            validateParalleGatewaySenderIds();
            this.partitionedRegionId = generatePRId(getSystem());
            prConfig = new PartitionRegionConfig(this.partitionedRegionId, this.getFullPath(), prAttribs, this.getScope(), getAttributes().getEvictionAttributes(), getAttributes().getRegionIdleTimeout(), getAttributes().getRegionTimeToLive(), getAttributes().getEntryIdleTimeout(), getAttributes().getEntryTimeToLive(), this.getAllGatewaySenderIds());
            logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_PARTITIONED_REGION_0_IS_BORN_WITH_PRID_1_IDENT_2, new Object[] { getFullPath(), this.partitionedRegionId, getRegionIdentifier() }));
            PRSanityCheckMessage.schedule(this);
        } else {
            validator.validatePartitionAttrsFromPRConfig(prConfig);
            if (storesData) {
                validator.validatePersistentMatchBetweenDataStores(prConfig);
                validator.validateCacheLoaderWriterBetweenDataStores(prConfig);
                validator.validateFixedPABetweenDataStores(prConfig);
            }
            this.partitionedRegionId = prConfig.getPRId();
            logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_PARTITIONED_REGION_0_IS_CREATED_WITH_PRID_1, new Object[] { getFullPath(), this.partitionedRegionId }));
        }
        synchronized (prIdToPR) {
            // last
            prIdToPR.put(this.partitionedRegionId, this);
        }
        prConfig.addNode(this.node);
        if (this.getFixedPartitionAttributesImpl() != null) {
            calculateStartingBucketIDs(prConfig);
        }
        updatePRConfig(prConfig, false);
        /*
       * try { if (this.redundantCopies > 0) { if (storesData) {
       * this.dataStore.grabBackupBuckets(false); } } } catch (RegionDestroyedException rde) { if
       * (!this.isClosed) throw rde; }
       */
        this.cleanPRRegistration = true;
    } catch (LockServiceDestroyedException lsde) {
        if (logger.isDebugEnabled()) {
            logger.debug("registerPartitionedRegion: unable to obtain lock for {}", this);
        }
        cleanupFailedInitialization();
        throw new PartitionedRegionException(LocalizedStrings.PartitionedRegion_CAN_NOT_CREATE_PARTITIONEDREGION_FAILED_TO_ACQUIRE_REGIONLOCK.toLocalizedString(), lsde);
    } catch (IllegalStateException ill) {
        cleanupFailedInitialization();
        throw ill;
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // now, so don't let this thread continue.
        throw err;
    } catch (Throwable t) {
        // Whenever you catch Error or Throwable, you must also
        // catch VirtualMachineError (see above). However, there is
        // _still_ a possibility that you are dealing with a cascading
        // error condition, so you also need to check to see if the JVM
        // is still usable:
        SystemFailure.checkFailure();
        String registerErrMsg = LocalizedStrings.PartitionedRegion_AN_EXCEPTION_WAS_CAUGHT_WHILE_REGISTERING_PARTITIONEDREGION_0_DUMPPRID_1.toLocalizedString(getFullPath(), prIdToPR.dump());
        try {
            synchronized (prIdToPR) {
                if (prIdToPR.containsKey(this.partitionedRegionId)) {
                    prIdToPR.put(this.partitionedRegionId, PRIdMap.FAILED_REGISTRATION, false);
                    logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_FAILED_REGISTRATION_PRID_0_NAMED_1, new Object[] { this.partitionedRegionId, this.getName() }));
                }
            }
        } catch (VirtualMachineError err) {
            SystemFailure.initiateFailure(err);
            // now, so don't let this thread continue.
            throw err;
        } catch (Throwable e) {
            // Whenever you catch Error or Throwable, you must also
            // catch VirtualMachineError (see above). However, there is
            // _still_ a possibility that you are dealing with a cascading
            // error condition, so you also need to check to see if the JVM
            // is still usable:
            SystemFailure.checkFailure();
            if (logger.isDebugEnabled()) {
                logger.debug("Partitioned Region creation, could not clean up after caught exception", e);
            }
        }
        throw new PartitionedRegionException(registerErrMsg, t);
    } finally {
        try {
            rl.unlock();
            if (logger.isDebugEnabled()) {
                logger.debug("registerPartitionedRegion: released lock");
            }
        } catch (Exception es) {
            if (logger.isDebugEnabled()) {
                logger.debug(es.getMessage(), es);
            }
        }
    }
}
Also used : LockServiceDestroyedException(org.apache.geode.distributed.LockServiceDestroyedException) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) TimeoutException(org.apache.geode.cache.TimeoutException) IndexCreationException(org.apache.geode.cache.query.IndexCreationException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InternalGemFireException(org.apache.geode.InternalGemFireException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) LockServiceDestroyedException(org.apache.geode.distributed.LockServiceDestroyedException) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) GatewaySenderConfigurationException(org.apache.geode.internal.cache.wan.GatewaySenderConfigurationException) ExecutionException(java.util.concurrent.ExecutionException) ReplyException(org.apache.geode.distributed.internal.ReplyException) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) EntryExistsException(org.apache.geode.cache.EntryExistsException) PartitionedRegionDistributionException(org.apache.geode.cache.PartitionedRegionDistributionException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) NoSuchElementException(java.util.NoSuchElementException) QueryException(org.apache.geode.cache.query.QueryException) PartitionNotAvailableException(org.apache.geode.cache.partition.PartitionNotAvailableException) LowMemoryException(org.apache.geode.cache.LowMemoryException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) RegionExistsException(org.apache.geode.cache.RegionExistsException) CancelException(org.apache.geode.CancelException) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheWriterException(org.apache.geode.cache.CacheWriterException) TransactionException(org.apache.geode.cache.TransactionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) EmptyRegionFunctionException(org.apache.geode.cache.execute.EmptyRegionFunctionException)

Example 60 with PartitionAttributes

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

the class PRQueryDUnitHelper method getCacheSerializableRunnableForCacheClose.

/**
   * This function <br>
   * 1. calls the cache.close on the VM <br>
   * 2. creates the cache again & also the PR <br>
   * 
   * @return cacheSerializable object
   *
   *         NOTE: Closing of the cache must be done from the test case rather than in
   *         PRQueryDUintHelper
   *
   */
public CacheSerializableRunnable getCacheSerializableRunnableForCacheClose(final String regionName, final int redundancy, final Class constraint) {
    SerializableRunnable PrRegion = new CacheSerializableRunnable("cacheClose") {

        @Override
        public void run2() throws CacheException {
            final String expectedCacheClosedException = CacheClosedException.class.getName();
            final String expectedReplyException = ReplyException.class.getName();
            getCache().getLogger().info("<ExpectedException action=add>" + expectedCacheClosedException + "</ExpectedException>");
            getCache().getLogger().info("<ExpectedException action=add>" + expectedReplyException + "</ExpectedException>");
            Cache cache = getCache();
            org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PROperationWithQueryDUnitTest#getCacheSerializableRunnableForCacheClose: Recreating the cache ");
            AttributesFactory attr = new AttributesFactory();
            attr.setValueConstraint(constraint);
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            PartitionAttributes prAttr = paf.setRedundantCopies(redundancy).create();
            attr.setPartitionAttributes(prAttr);
            final CountDownLatch cdl = new CountDownLatch(1);
            ResourceObserverAdapter observer = new InternalResourceManager.ResourceObserverAdapter() {

                @Override
                public void recoveryFinished(Region region) {
                    cdl.countDown();
                }
            };
            InternalResourceManager.setResourceObserver(observer);
            try {
                cache.createRegion(regionName, attr.create());
                // Wait for recovery to finish
                cdl.await();
            } catch (InterruptedException e) {
                Assert.fail("interupted", e);
            } finally {
                InternalResourceManager.setResourceObserver(null);
            }
            org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("PROperationWithQueryDUnitTest#getCacheSerializableRunnableForCacheClose: cache Recreated on VM ");
            getCache().getLogger().info("<ExpectedException action=remove>" + expectedReplyException + "</ExpectedException>");
            getCache().getLogger().info("<ExpectedException action=remove>" + expectedCacheClosedException + "</ExpectedException>");
        }
    };
    return (CacheSerializableRunnable) PrRegion;
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CountDownLatch(java.util.concurrent.CountDownLatch) ResourceObserverAdapter(org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserverAdapter) Cache(org.apache.geode.cache.Cache)

Aggregations

PartitionAttributes (org.apache.geode.cache.PartitionAttributes)129 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)117 AttributesFactory (org.apache.geode.cache.AttributesFactory)107 Region (org.apache.geode.cache.Region)82 Test (org.junit.Test)67 Cache (org.apache.geode.cache.Cache)66 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)61 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)49 Host (org.apache.geode.test.dunit.Host)48 VM (org.apache.geode.test.dunit.VM)48 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)47 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)38 RegionAttributes (org.apache.geode.cache.RegionAttributes)28 CacheException (org.apache.geode.cache.CacheException)26 LocalRegion (org.apache.geode.internal.cache.LocalRegion)26 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)21 BucketRegion (org.apache.geode.internal.cache.BucketRegion)19 FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)18 RebalanceResults (org.apache.geode.cache.control.RebalanceResults)16 HashSet (java.util.HashSet)15