You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by je...@apache.org on 2015/12/08 23:23:58 UTC
[1/2] incubator-geode git commit: GEODE-390: removing
PartitionManager and related tests
Repository: incubator-geode
Updated Branches:
refs/heads/develop 80b59bfa3 -> 386d1ac8c
GEODE-390: removing PartitionManager and related tests
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/4a07f458
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/4a07f458
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/4a07f458
Branch: refs/heads/develop
Commit: 4a07f458283a493563cbbc9caedade18774a0fae
Parents: b2e0142
Author: Jinmei Liao <ji...@pivotal.io>
Authored: Wed Nov 18 09:33:28 2015 -0800
Committer: Jinmei Liao <ji...@pivotal.io>
Committed: Wed Nov 18 09:57:43 2015 -0800
----------------------------------------------------------------------
.../cache/partition/PartitionManager.java | 377 ----------------
.../partition/PartitionManagerDUnitTest.java | 443 -------------------
.../fixed/FixedPartitioningTestBase.java | 83 ----
...ngWithColocationAndPersistenceDUnitTest.java | 106 -----
4 files changed, 1009 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4a07f458/gemfire-core/src/main/java/com/gemstone/gemfire/cache/partition/PartitionManager.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/partition/PartitionManager.java b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/partition/PartitionManager.java
deleted file mode 100644
index 8454d2c..0000000
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/partition/PartitionManager.java
+++ /dev/null
@@ -1,377 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gemstone.gemfire.cache.partition;
-
-import java.util.List;
-import java.util.Set;
-
-import org.apache.logging.log4j.Logger;
-
-import com.gemstone.gemfire.cache.DataPolicy;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.control.RebalanceFactory;
-import com.gemstone.gemfire.distributed.DistributedMember;
-import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
-import com.gemstone.gemfire.internal.cache.FixedPartitionAttributesImpl;
-import com.gemstone.gemfire.internal.cache.PartitionedRegion;
-import com.gemstone.gemfire.internal.cache.PartitionedRegion.RecoveryLock;
-import com.gemstone.gemfire.internal.cache.PartitionedRegionDataStore;
-import com.gemstone.gemfire.internal.cache.partitioned.RemoveBucketMessage;
-import com.gemstone.gemfire.internal.cache.partitioned.RemoveBucketMessage.RemoveBucketResponse;
-import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
-import com.gemstone.gemfire.internal.logging.LogService;
-
-/**
- * An utility class to manage partitions (aka buckets) on a Partitioned Region
- * without requiring data (e.g. keys).
- *
- * Note : Please contact support@gemstone.com before using these APIs.
- *
- * <br>
- * This is an example of how this API can be used to create a view
- * region with redundancy 0, which is colocated with another region of
- * redundancy 1, without using the standard gemfire colocated-with attribute,
- * which only supports colocated regions with the same redundancy level.
- *
- * Note that when using this API, the data in the view region is discarded every
- * time a primary moves.
- *
- * <pre>
- * public class ColocatingPartitionListener implements PartitionListener,
- * Declarable {
- * private Cache cache;
- *
- * private List<String> viewRegionNames = new ArrayList<String>();
- *
- * public ColocatingPartitionListener() {
- * }
- *
- * public void afterPrimary(int bucketId) {
- *
- * for (String viewRegionName : viewRegionNames) {
- * Region viewRegion = cache.getRegion(viewRegionName);
- * PartitionManager.createPrimaryBucket(viewRegion, bucketId, true, true);
- * }
- * }
- *
- * public void init(Properties props) {
- * String viewRegions = props.getProperty("viewRegions");
- * StringTokenizer tokenizer = new StringTokenizer(viewRegions, ",");
- * while (tokenizer.hasMoreTokens()) {
- * viewRegionNames.add(tokenizer.nextToken());
- * }
- * }
- *
- * public void afterRegionCreate(Region<?, ?> region) {
- * cache = region.getCache();
- * }
- * }
- * </pre>
- *
- * In the declaration of the parent region in cache.xml, install
- * the ColocatedPartitionListener as follows :<br>
- *
- * <pre>
- * <partition-attributes redundant-copies="1">
- * <partition-listener>
- * <class-name>com.myCompany.ColocatingPartitionListener</class-name>
- * <parameter name="viewRegions">
- * <string>/customer/ViewA,/customer/ViewB</string>
- * </parameter>
- * </partition-listener>
- * </partition-attributes>
- * </pre>
- *
- * If the regions needs to be rebalanced, use the {@link RebalanceFactory#excludeRegions(Set)}
- * method to exclude the view regions.
- *
- *
- * @author Yogesh Mahajan
- *
- * @since 6.5
- */
-public final class PartitionManager {
- private static final Logger logger = LogService.getLogger();
-
- private PartitionManager() {
- }
-
- /**
- * This method creates a copy of the bucket on the current node, if no
- * copy already exists. Depending on the values of destroyExistingLocal
- * and destroyExistingRemote, it will first destroy the existing primary
- * copy of the bucket.
- *
- * This behavior of this method is undefined on partitioned regions with
- * redundancy greater than 0. The behavior is also undefined for partitioned
- * regions colocated with the colocated-with attribute.
- *
- * This method creates primary bucket in the following way:
- *
- * <p>
- * If the partitioned region does not have a primary bucket for the bucketId,
- * it creates a primary bucket on the member and returns true.
- *
- * <p>
- * If the partitioned region does have a primary bucket for the bucketId on
- * the member :<br>
- * a) If destroyExistingLocal passed is true, it destroys the existing bucket,
- * and then creates a new primary bucket and returns true. <br>
- * b) If destroyExistingLocal passed is false, it does nothing and returns
- * false.
- *
- * <p>
- * If the partitioned region does have a primary bucket for the bucketId on
- * remote members :<br>
- * a) If destroyExistingRemote passed is true, it destroys the existing bucket
- * on remote member, and then creates a new primary bucket on this member and
- * returns true. <br>
- * b) If destroyExistingRemote passed is false, it throws
- * IllegalStateException.
- *
- *
- * @param region
- * the partitioned region on which to create the bucket
- * @param bucketId
- * the identifier of the bucket to create
- * @param destroyExistingRemote
- * whether to destroy the remote bucket if it exists
- * @param destroyExistingLocal
- * whether to destroy the local bucket if it exists
- * @return true when the bucket has been created otherwise false
- * @throws IllegalArgumentException
- * if the provided region is not a partitioned region
- * @throws IllegalArgumentException
- * if the provided bucketId is less than zero or greater than or
- * equal to the partitioned region's total number of buckets
- * @throws IllegalStateException
- * if the partitioned region has the primary bucket for the bucket
- * id on a remote member and the destroyExistingRemote parameter
- * provided is false
- */
- public static boolean createPrimaryBucket(final Region<?, ?> region,
- final int bucketId, final boolean destroyExistingRemote,
- final boolean destroyExistingLocal) {
- final PartitionedRegion pr = prCheck(region, bucketId);
- boolean createdBucket = false;
-
- //Getting this lock prevents rebalancing while this bucket is created.
- //It will also prevent conflicts with other members in createPrimaryBucket
- final RecoveryLock recovLock = pr.getRecoveryLock();
- recovLock.lock();
- try {
- DistributedMember primary = PartitionManager.getPrimaryMemberForBucket(pr,
- bucketId);
- InternalDistributedMember self = (InternalDistributedMember)pr.getCache()
- .getDistributedSystem().getDistributedMember();
-
- if (primary == null) {
- if (logger.isDebugEnabled()) {
- logger.debug("createPrimaryBucket: {} bucket {} no existing primary, creating primary", pr, bucketId);
- }
- createdBucket = createBucket(self, pr, bucketId, destroyExistingRemote);
- }
- else if (self.equals(primary)) {
- if (destroyExistingLocal) {
- if (logger.isDebugEnabled()) {
- logger.debug("createPrimaryBucket: {} bucket {} already primary, destroying local primary", pr, bucketId);
- }
- if (dumpBucket(self, region, bucketId)) {
- createdBucket = createBucket(self, region, bucketId, destroyExistingLocal);
- }
- } else {
- if (logger.isDebugEnabled()) {
- logger.debug("createPrimaryBucket: {} bucket {} already primary, no action needed", pr, bucketId);
- }
- }
- }
- else {
- if (destroyExistingRemote) {
- if (logger.isDebugEnabled()) {
- logger.debug("createPrimaryBucket: {} bucket {},{} is primary, destroying it", pr, bucketId, primary);
- }
- if (dumpBucket(primary, region, bucketId)) {
- createdBucket = createBucket(self, region, bucketId, destroyExistingRemote);
- }
- }
- else {
- Object[] params = new Object[] { self, primary };
- throw new IllegalStateException(
- LocalizedStrings.PartitionManager_BUCKET_CANNOT_BE_MOVED_AS_DESTROYEXISTING_IS_FALSE
- .toLocalizedString(params));
- }
- }
- }
- finally {
- recovLock.unlock();
- }
- return createdBucket;
- }
-
- /**
- * Get the current primary owner for a bucket. If the bucket is not yet
- * created it returns null immediately
- *
- * @throws IllegalStateException
- * if the provided region is something other than a
- * {@linkplain DataPolicy#PARTITION partitioned Region}
- * @return the primary member for the bucket, possibly null if a primary is
- * not yet determined
- * @since 6.5
- * @param region
- * @param bucketId
- */
- private static DistributedMember getPrimaryMemberForBucket(
- final Region<?, ?> region, final int bucketId) {
- PartitionedRegion pr = prCheck(region, bucketId);
- if (pr.getRegionAdvisor().isStorageAssignedForBucket(bucketId)) {
- return pr.getBucketPrimary(bucketId);
- }
- else {
- return null;
- }
- }
-
- private static boolean createBucket(final DistributedMember target,
- final Region<?, ?> region, final int bucketId, final boolean destroyExistingRemote) {
- final PartitionedRegion pr = prCheck(region, bucketId);
- InternalDistributedMember createTarget = dataStoreCheck(target, pr);
-
- //This is a bit of a hack. If we don't have a source for a bucket move,
- //createBackupBucketOnMember isn't going to let us exceed redundancy.
- InternalDistributedMember moveSource = createTarget;
- boolean createdBucket = pr.getRedundancyProvider().createBackupBucketOnMember(
- bucketId, createTarget, false, false, moveSource, true);
-
- Set<InternalDistributedMember> currentBucketOwners = pr.getRegionAdvisor()
- .getBucketOwners(bucketId);
-
- boolean includesTarget = currentBucketOwners.remove(target);
-
- //Race condition. Someone else may have created the bucket while we were
- //trying to create it. If they got in first, we could have exceeded redundancy
- //Based on the flags, we need to get back down to redundancy.
- //Note that nobody else is going to create the bucket now, because
- //redundancy is already satisfied.
- if(currentBucketOwners.size() > pr.getRedundantCopies() && includesTarget) {
- InternalDistributedMember remoteBucket = currentBucketOwners.iterator().next();
- if(destroyExistingRemote) {
- if (logger.isDebugEnabled()) {
- logger.debug("createPrimaryBucket: {}, bucket {} Redundancy is exceeded due to concurrent bucket create, destroying remote bucket: {}", pr, bucketId, remoteBucket);
- }
- dumpBucket(remoteBucket, region, bucketId);
- }
- else {
- if (logger.isDebugEnabled()) {
- logger.debug("createPrimaryBucket: {}, bucket {} Redundancy is exceeded due to concurrent bucket create, destroying my bucket", pr, bucketId);
- }
- dumpBucket(target, region, bucketId);
- Object[] params = new Object[] { target, remoteBucket };
- throw new IllegalStateException(
- LocalizedStrings.PartitionManager_BUCKET_CANNOT_BE_MOVED_AS_DESTROYEXISTING_IS_FALSE
- .toLocalizedString(params));
- }
- }
- return createdBucket;
- }
-
- private static boolean dumpBucket(final DistributedMember source,
- final Region<?, ?> region, final int bucketId) {
- final PartitionedRegion pr = prCheck(region, bucketId);
- InternalDistributedMember bucketSource = dataStoreCheck(source, pr);
- Set<InternalDistributedMember> currentBucketOwners = pr.getRegionAdvisor()
- .getBucketOwners(bucketId);
- if (!currentBucketOwners.contains(bucketSource)) {
- Object[] params = new Object[] { bucketSource, Integer.valueOf(bucketId) };
- throw new IllegalArgumentException(
- LocalizedStrings.PartitionManager_SOURCE_MEMBER_0_BUCKETID_1_DOES_NOT_HAVE_THE_BUCKET
- .toLocalizedString(params));
- }
- InternalDistributedMember self = (InternalDistributedMember)pr.getCache()
- .getDistributedSystem().getDistributedMember();
-
- if (bucketSource.equals(self)) {
- PartitionedRegionDataStore dataStore = pr.getDataStore();
- return dataStore.removeBucket(bucketId, true);
- }
- else {
- RemoveBucketResponse response = RemoveBucketMessage.send(bucketSource,
- pr, bucketId, true);
- if (response != null) {
- return response.waitForResponse();
- }
- }
- return false;
- }
-
- private static PartitionedRegion prCheck(final Region<?, ?> region,
- final int bucketId) {
- if (region == null) {
- throw new IllegalArgumentException(
- LocalizedStrings.PartitionRegionHelper_ARGUMENT_REGION_IS_NULL
- .toString());
- }
- if (!(region instanceof PartitionedRegion)) {
- throw new IllegalArgumentException(
- LocalizedStrings.PartitionManager_REGION_0_IS_NOT_A_PARTITIONED_REGION
- .toLocalizedString(region.getFullPath()));
- }
- final PartitionedRegion pr = (PartitionedRegion)region;
- if (bucketId < 0 || bucketId >= pr.getTotalNumberOfBuckets()) {
- throw new IllegalArgumentException(
- LocalizedStrings.PartitionManager_BUCKETID_ARG0_RANGE_0_TO_ARG1_PR_ARG2
- .toLocalizedString(new Object[] { Integer.valueOf(bucketId),
- Integer.valueOf((pr.getTotalNumberOfBuckets() - 1)),
- pr.getFullPath() }));
- }
-
- if (pr.isFixedPartitionedRegion()) {
- boolean containsBucket = false;
- List<FixedPartitionAttributesImpl> fpas = pr
- .getFixedPartitionAttributesImpl();
- for (FixedPartitionAttributesImpl fpa : fpas) {
- if (fpa.isPrimary() && (fpa.hasBucket(bucketId))) {
- containsBucket = true;
- break;
- }
- }
- if (!containsBucket)
- throw new IllegalArgumentException(
- LocalizedStrings.FixedPartitionManager_BUCKETID_ARG_PR_ARG2
- .toLocalizedString(new Object[] { Integer.valueOf(bucketId),
- pr.getFullPath() }));
-
- }
- return pr;
- }
-
- private static InternalDistributedMember dataStoreCheck(
- final DistributedMember target, final PartitionedRegion pr) {
- final InternalDistributedMember idmTarget = (InternalDistributedMember)target;
- final boolean localIsDatastore = pr.isDataStore()
- && pr.getCache().getDistributedSystem().getDistributedMember().equals(
- target);
- if (!(localIsDatastore || pr.getRegionAdvisor().adviseDataStore().contains(
- idmTarget))) {
- throw new IllegalArgumentException(
- LocalizedStrings.PartitionManager_PROVIDED_MEMBER_0_NO_PR_OR_NO_DATASTORE
- .toLocalizedString(target));
- }
- return idmTarget;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4a07f458/gemfire-core/src/test/java/com/gemstone/gemfire/cache/partition/PartitionManagerDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/partition/PartitionManagerDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/partition/PartitionManagerDUnitTest.java
deleted file mode 100644
index a7696c3..0000000
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/partition/PartitionManagerDUnitTest.java
+++ /dev/null
@@ -1,443 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gemstone.gemfire.cache.partition;
-
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-import com.gemstone.gemfire.InternalGemFireError;
-import com.gemstone.gemfire.cache.AttributesFactory;
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.PartitionAttributes;
-import com.gemstone.gemfire.cache.PartitionAttributesFactory;
-import com.gemstone.gemfire.cache30.CacheTestCase;
-import com.gemstone.gemfire.internal.cache.ForceReattemptException;
-import com.gemstone.gemfire.internal.cache.PartitionedRegion;
-
-import dunit.AsyncInvocation;
-import dunit.Host;
-import dunit.RMIException;
-import dunit.SerializableRunnable;
-import dunit.VM;
-
-/**
- * Test of the PartitionManager.createPrimaryBucket method.
- * @author dsmith
- *
- */
-public class PartitionManagerDUnitTest extends CacheTestCase {
-
- private static final int BUCKET_ID = 5;
- protected static final long CONCURRENT_TIME = 10;
- protected static final long MAX_WAIT = 60 * 1000;
-
-
- public PartitionManagerDUnitTest(String name) {
- super(name);
- }
-
- public void testDestroyExistingRemote() {
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
-
- SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {
- public void run()
- {
- Cache cache = getCache();
- AttributesFactory attr = new AttributesFactory();
- PartitionAttributesFactory paf = new PartitionAttributesFactory();
- paf.setRedundantCopies(0);
- paf.setRecoveryDelay(-1);
- paf.setStartupRecoveryDelay(-1);
- PartitionAttributes prAttr = paf.create();
- attr.setPartitionAttributes(prAttr);
- cache.createRegion("region1", attr.create());
- }
- };
-
- //create the PR
- vm0.invoke(createPrRegion);
- vm1.invoke(createPrRegion);
-
-
- //Move the bucket around a couple times. Make sure it moves
- createPrimaryBucket(vm0, true, false);
- assertNotPrimary(vm1);
- createPrimaryBucket(vm1, true, false);
- assertNotPrimary(vm0);
-
- //Put something in the bucket
- vm1.invoke(new SerializableRunnable() {
-
- public void run() {
- Cache cache = getCache();
- PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
- region.put(BUCKET_ID, "B");
- }
- });
-
- //Make sure we don't mess with the if it's already local
- createPrimaryBucket(vm1, true, false);
- vm1.invoke(new SerializableRunnable() {
-
- public void run() {
- Cache cache = getCache();
- PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
- assertEquals("B", region.get(BUCKET_ID));
- }
- });
-
- //Make sure we drop the data when we move the bucket
- createPrimaryBucket(vm0, true, false);
- vm1.invoke(new SerializableRunnable() {
-
- public void run() {
- Cache cache = getCache();
- PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
- assertEquals(null, region.get(BUCKET_ID));
- }
- });
- }
-
- public void testDestroyExistingBoth() {
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
-
- SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {
- public void run()
- {
- Cache cache = getCache();
- AttributesFactory attr = new AttributesFactory();
- PartitionAttributesFactory paf = new PartitionAttributesFactory();
- paf.setRedundantCopies(0);
- paf.setRecoveryDelay(-1);
- paf.setStartupRecoveryDelay(-1);
- PartitionAttributes prAttr = paf.create();
- attr.setPartitionAttributes(prAttr);
- cache.createRegion("region1", attr.create());
- }
- };
-
- //create the PR
- vm0.invoke(createPrRegion);
- vm1.invoke(createPrRegion);
-
-
- //Move the bucket around a couple times. Make sure it moves
- createPrimaryBucket(vm0, true, true);
- createPrimaryBucket(vm1, true, true);
-
- //Put something in the bucket
- vm1.invoke(new SerializableRunnable() {
-
- public void run() {
- Cache cache = getCache();
- PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
- region.put(BUCKET_ID, "B");
- }
- });
-
- //Make sure we do drop the data even if the bucket is already local
- createPrimaryBucket(vm1, true, true);
- vm1.invoke(new SerializableRunnable() {
-
- public void run() {
- Cache cache = getCache();
- PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
- assertEquals(null, region.get(BUCKET_ID));
- }
- });
- }
-
- public void testDestroyExistingLocal() {
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
-
- SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {
- public void run()
- {
- Cache cache = getCache();
- AttributesFactory attr = new AttributesFactory();
- PartitionAttributesFactory paf = new PartitionAttributesFactory();
- paf.setRedundantCopies(0);
- paf.setRecoveryDelay(-1);
- paf.setStartupRecoveryDelay(-1);
- PartitionAttributes prAttr = paf.create();
- attr.setPartitionAttributes(prAttr);
- cache.createRegion("region1", attr.create());
- }
- };
-
- //create the PR
- vm0.invoke(createPrRegion);
- vm1.invoke(createPrRegion);
-
-
- createPrimaryBucket(vm0, false, true);
-
- //This should throw an exception
- try {
- createPrimaryBucket(vm1, false, false);
- } catch(RMIException e) {
- if(!(e.getCause() instanceof IllegalStateException)) {
- throw e;
- }
- }
-
- //Put something in the bucket
- vm0.invoke(new SerializableRunnable() {
-
- public void run() {
- Cache cache = getCache();
- PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
- region.put(BUCKET_ID, "B");
- }
- });
-
- //Make sure we do drop the data even if the bucket is already local
- createPrimaryBucket(vm0, false, true);
- vm1.invoke(new SerializableRunnable() {
-
- public void run() {
- Cache cache = getCache();
- PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
- assertEquals(null, region.get(BUCKET_ID));
- }
- });
- }
-
- public void testDestroyExistingNeither() {
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
-
- SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {
- public void run()
- {
- Cache cache = getCache();
- AttributesFactory attr = new AttributesFactory();
- PartitionAttributesFactory paf = new PartitionAttributesFactory();
- paf.setRedundantCopies(0);
- paf.setRecoveryDelay(-1);
- paf.setStartupRecoveryDelay(-1);
- PartitionAttributes prAttr = paf.create();
- attr.setPartitionAttributes(prAttr);
- cache.createRegion("region1", attr.create());
- }
- };
-
- //create the PR
- vm0.invoke(createPrRegion);
- vm1.invoke(createPrRegion);
- //Move the bucket around a couple times. Make sure it moves
- createPrimaryBucket(vm0, false, false);
-
- //This should throw an exception
- try {
- createPrimaryBucket(vm1, false, false);
- } catch(RMIException e) {
- if(!(e.getCause() instanceof IllegalStateException)) {
- throw e;
- }
- }
-
- //So should this
- try {
- createPrimaryBucket(vm0, false, false);
- } catch(RMIException e) {
- if(!(e.getCause() instanceof IllegalStateException)) {
- throw e;
- }
- }
-
- //Put something in the bucket
- vm0.invoke(new SerializableRunnable() {
-
- public void run() {
- Cache cache = getCache();
- PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
- region.put(BUCKET_ID, "B");
- }
- });
-
- //Make sure we do drop the data even if the bucket is already local
- createPrimaryBucket(vm0, false, true);
- vm1.invoke(new SerializableRunnable() {
-
- public void run() {
- Cache cache = getCache();
- PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
- assertEquals(null, region.get(BUCKET_ID));
- }
- });
- }
-
- private void createPrimaryBucket(VM vm0, final boolean destroyRemote, final boolean destroyLocal) {
- vm0.invoke(new SerializableRunnable("Move PR") {
-
- public void run() {
- Cache cache = getCache();
- final PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
- PartitionManager.createPrimaryBucket(region, BUCKET_ID, destroyRemote, destroyLocal);
-
- //There is a race here that someone else on this same node could
- //trigger the bucket creation. If that happens, we won't create the bucket,
- //but getPrimary may not wait for the bucket either.
- //if we were doing a put, it would reattempt the put until the bucket was
- //created. In this case, we just want to wait for the bucket to have a primary
- waitForCriterion(new WaitCriterion() {
-
- public boolean done() {
- return region.getBucketPrimary(BUCKET_ID) != null;
- }
-
- public String description() {
- return null;
- }
- }, 10000, 100, false);
-
- //Make sure we really are the primary now
- assertEquals(cache.getDistributedSystem().getDistributedMember(), region.getBucketPrimary(BUCKET_ID));
-
- //Make sure there is only 1 bucket owner
- Set owners = region.getDataStore().getLocalBucketById(BUCKET_ID).getBucketOwners();
- assertEquals(1, owners.size());
- }
- });
- }
-
- private void assertNotPrimary(VM vm0) {
- vm0.invoke(new SerializableRunnable("Move PR") {
-
- public void run() {
- Cache cache = getCache();
- PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
- //Make sure we're not the primary
- assertFalse(region.getBucketPrimary(BUCKET_ID).equals(cache.getDistributedSystem().getDistributedMember()));
- }
- });
- }
-
-// public void testLoop() throws Throwable {
-// for(int i=0 ;i < 50; i++) {
-// getLogWriter().info("test iteration #" + i);
-// doTestConcurrent();
-// tearDown();
-// setUp();
-// }
-// }
-
- public void testConcurrent() throws Throwable {
-
- Host host = Host.getHost(0);
- VM vm0 = host.getVM(0);
- VM vm1 = host.getVM(1);
-
- SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {
- public void run()
- {
- Cache cache = getCache();
- AttributesFactory attr = new AttributesFactory();
- PartitionAttributesFactory paf = new PartitionAttributesFactory();
- paf.setRedundantCopies(0);
- paf.setRecoveryDelay(-1);
- paf.setStartupRecoveryDelay(-1);
- PartitionAttributes prAttr = paf.create();
- attr.setPartitionAttributes(prAttr);
- cache.createRegion("region1", attr.create());
- }
- };
-
- vm0.invoke(createPrRegion);
- vm1.invoke(createPrRegion);
-
- SerializableRunnable hungryHungryPrimary = new SerializableRunnable("Try to grab the primary a lot") {
- public void run()
- {
- Cache cache = getCache();
- PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
-
- long start = System.nanoTime();
-
- while(TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start) < CONCURRENT_TIME) {
- PartitionManager.createPrimaryBucket(region, BUCKET_ID, true, false);
- }
- }
- };
-
- SerializableRunnable lotsOfPuts= new SerializableRunnable("A bunch of puts") {
- public void run()
- {
- Cache cache = getCache();
- PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
-
- long start = System.nanoTime();
-
- while(TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start) < CONCURRENT_TIME) {
- //Do a put which might trigger bucket creation
- try {
- region.put(BUCKET_ID, "B");
- } catch (InternalGemFireError e) {
- if (e.getMessage().contains("recordVersion invoked for a local version tag that is higher")) {
- // bug #50566 encountered. This can happen in this test that aggressively moves
- // buckets around w/o persistence, causing a node to create, destroy and recreate
- // the same bucket while the operation is in progress. Not something likely
- // to happen to a customer.
- }
- }
- try {
- Thread.sleep(10);
- } catch (InterruptedException e) {
- fail("", e);
- }
- }
- }
- };
-
- AsyncInvocation async0 = vm0.invokeAsync(hungryHungryPrimary);
- AsyncInvocation async1 = vm1.invokeAsync(hungryHungryPrimary);
-
- AsyncInvocation async0_2 = vm0.invokeAsync(lotsOfPuts);
- AsyncInvocation async1_2 = vm1.invokeAsync(lotsOfPuts);
-
-
- async0.getResult(MAX_WAIT);
- async1.getResult(MAX_WAIT);
- async0_2.getResult(MAX_WAIT);
- async1_2.getResult(MAX_WAIT);
-
- vm0.invoke(new SerializableRunnable("Check the number of owners") {
- public void run()
- {
- Cache cache = getCache();
- PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
- List owners;
- try {
- owners = region.getBucketOwnersForValidation(BUCKET_ID);
- assertEquals(1, owners.size());
- } catch (ForceReattemptException e) {
- fail("shouldn't have seen force reattempt", e);
- }
- }
- });
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4a07f458/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/fixed/FixedPartitioningTestBase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/fixed/FixedPartitioningTestBase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/fixed/FixedPartitioningTestBase.java
index f0f3295..ddc83ea 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/fixed/FixedPartitioningTestBase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/fixed/FixedPartitioningTestBase.java
@@ -42,7 +42,6 @@ import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.control.RebalanceOperation;
import com.gemstone.gemfire.cache.control.RebalanceResults;
import com.gemstone.gemfire.cache.control.ResourceManager;
-import com.gemstone.gemfire.cache.partition.PartitionManager;
import com.gemstone.gemfire.cache.partition.PartitionRegionHelper;
import com.gemstone.gemfire.cache30.CacheTestCase;
import com.gemstone.gemfire.distributed.DistributedSystem;
@@ -1275,89 +1274,7 @@ public class FixedPartitioningTestBase extends DistributedTestCase {
assertEquals(
region_FPR.getDataStore().getAllLocalPrimaryBucketIds().size() % 3, 0);
}
-
- public static void createPrimaryBucketsBelongingToThisPartition(
- String regionName, Boolean destroyExistingRemote,
- Boolean destroyExistingLocal) {
- region_FPR = (PartitionedRegion)cache.getRegion(regionName);
- assertNotNull(region_FPR);
- int startingBucketId=0;
- List<FixedPartitionAttributesImpl> fpas = region_FPR
- .getFixedPartitionAttributesImpl();
- for (FixedPartitionAttributesImpl fpa : fpas) {
- if (fpa.isPrimary()) {
- startingBucketId = fpa.getStartingBucketID();
- break;
- }else{
- startingBucketId = 0;
- }
- }
- final int bucketId = startingBucketId;
- try {
- PartitionManager.createPrimaryBucket(region_FPR, startingBucketId,
- destroyExistingRemote, destroyExistingLocal);
- waitForCriterion(new WaitCriterion() {
-
- public boolean done() {
- return region_FPR.getBucketPrimary(bucketId) != null;
- }
-
- public String description() {
- return null;
- }
- }, 10000, 100, false);
- } catch (Exception e) {
- fail(
- "Caught exception while creating primary bucket using PartitionManager for FPR",
- e);
- }
- }
-
- public static void createPrimaryBucketsBelongingToOtherPartition(
- String regionName, Boolean destroyExistingRemote,
- Boolean destroyExistingLocal) {
- region_FPR = (PartitionedRegion)cache.getRegion(regionName);
- assertNotNull(region_FPR);
- int bucketId = 13;
- List<FixedPartitionAttributesImpl> fpas = region_FPR.getRegionAdvisor()
- .adviseRemotePrimaryFPAs();
- for (FixedPartitionAttributesImpl fpa : fpas) {
- if (fpa.isPrimary()) {
- bucketId = fpa.getStartingBucketID();
- }
- }
-
- try {
- PartitionManager.createPrimaryBucket(region_FPR, bucketId,
- destroyExistingRemote, destroyExistingLocal);
- fail("PartitionManager created primary bucket not belonging to the node.");
- } catch (Exception expected) {
- if (!((expected instanceof IllegalArgumentException) && (expected
- .getMessage()
- .contains(
- "not part of any primary partition on this node for the FixedPartitionRegion")))) {
- fail("Expected IllegalArgumentException ", expected);
- }
- }
- }
-
- public static void createOutOfRangePrimaryBucketUsingPartitionManager(
- String regionName, Integer bucketId, Boolean destroyExistingRemote,
- Boolean destroyExistingLocal) {
- region_FPR = (PartitionedRegion)cache.getRegion(regionName);
- assertNotNull(region_FPR);
- try {
- PartitionManager.createPrimaryBucket(region_FPR, bucketId,
- destroyExistingRemote, destroyExistingLocal);
- fail("PartitionManager created out of range primary bucket .");
- } catch (Exception expected) {
- if (!((expected instanceof IllegalArgumentException) && (expected
- .getMessage().contains("must be in the range")))) {
- fail("Expected IllegalArgumentException ", expected);
- }
- }
- }
public static void setPRObserverBeforeCalculateStartingBucketId() {
PartitionedRegion.BEFORE_CALCULATE_STARTING_BUCKET_FLAG = true;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4a07f458/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/fixed/FixedPartitioningWithColocationAndPersistenceDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/fixed/FixedPartitioningWithColocationAndPersistenceDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/fixed/FixedPartitioningWithColocationAndPersistenceDUnitTest.java
index dbd819a..741495d 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/fixed/FixedPartitioningWithColocationAndPersistenceDUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/fixed/FixedPartitioningWithColocationAndPersistenceDUnitTest.java
@@ -774,112 +774,6 @@ public class FixedPartitioningWithColocationAndPersistenceDUnitTest extends
}
/**
- * Create bucket on an empty FPR and see if and check if it gets created or
- * exceptions are thrown. IllegalArguementException is expected for bucketId
- * which is out of range or doesn't belong to the FPR node.
- *
- */
- public void testPartitionManagerWithFPR_NoBucketsCreatedYet() {
- member1.invoke(FixedPartitioningTestBase.class, "createCacheOnMember");
- FixedPartitionAttributes fpa1 = FixedPartitionAttributes
- .createFixedPartition(Quarter1, true, 3);
- FixedPartitionAttributes fpa2 = FixedPartitionAttributes
- .createFixedPartition(Quarter2, false, 3);
- List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
-
- fpaList.add(fpa1);
- fpaList.add(fpa2);
- member1.invoke(FixedPartitioningTestBase.class,
- "createRegionWithPartitionAttributes", new Object[] { "Quarter",
- fpaList, 1, 40, 6, new QuarterPartitionResolver(), null, false });
-
- member2.invoke(FixedPartitioningTestBase.class, "createCacheOnMember");
- fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter2, true, 3);
- fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter1, false, 3);
- fpaList = new ArrayList<FixedPartitionAttributes>();
- fpaList.add(fpa1);
- fpaList.add(fpa2);
- member2.invoke(FixedPartitioningTestBase.class,
- "createRegionWithPartitionAttributes", new Object[] { "Quarter",
- fpaList, 1, 40, 6, new QuarterPartitionResolver(), null, false });
-
- // create primary buckets belonging to this partition
- member1.invoke(FixedPartitioningTestBase.class,
- "createPrimaryBucketsBelongingToThisPartition", new Object[] {
- "Quarter", Boolean.FALSE, Boolean.FALSE });
-
- // create primary buckets not belonging to this partition
- member1.invoke(FixedPartitioningTestBase.class,
- "createPrimaryBucketsBelongingToOtherPartition", new Object[] {
- "Quarter", Boolean.FALSE, Boolean.FALSE });
-
- // try creating out of range primary buckets
- final int outOfRangeBucketId = 13;
- member1.invoke(FixedPartitioningTestBase.class,
- "createOutOfRangePrimaryBucketUsingPartitionManager", new Object[] {
- "Quarter", outOfRangeBucketId, Boolean.FALSE, Boolean.FALSE });
- }
-
- /**
- * Create bucket on FPR for which buckets are created and see if it gets
- * created
- */
-
- public void testPartitionManagerWithFPR_BucketsAlreadyCreated() {
- member1.invoke(FixedPartitioningTestBase.class, "createCacheOnMember");
- FixedPartitionAttributes fpa1 = FixedPartitionAttributes
- .createFixedPartition(Quarter1, true, 3);
- List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
-
- fpaList.add(fpa1);
- member1.invoke(FixedPartitioningTestBase.class,
- "createRegionWithPartitionAttributes", new Object[] { "Quarter",
- fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, false });
-
- member2.invoke(FixedPartitioningTestBase.class, "createCacheOnMember");
- fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter2, true, 3);
- fpaList = new ArrayList<FixedPartitionAttributes>();
- fpaList.add(fpa1);
- member2.invoke(FixedPartitioningTestBase.class,
- "createRegionWithPartitionAttributes", new Object[] { "Quarter",
- fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, false });
-
- member3.invoke(FixedPartitioningTestBase.class, "createCacheOnMember");
- fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter3, true, 3);
- fpaList = new ArrayList<FixedPartitionAttributes>();
- fpaList.add(fpa1);
- member3.invoke(FixedPartitioningTestBase.class,
- "createRegionWithPartitionAttributes", new Object[] { "Quarter",
- fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, false });
-
- member4.invoke(FixedPartitioningTestBase.class, "createCacheOnMember");
- fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter4, true, 3);
- fpaList = new ArrayList<FixedPartitionAttributes>();
- fpaList.add(fpa1);
- member4.invoke(FixedPartitioningTestBase.class,
- "createRegionWithPartitionAttributes", new Object[] { "Quarter",
- fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, false });
-
- member1.invoke(FixedPartitioningTestBase.class, "putThroughDataStore",
- new Object[] { "Quarter" });
-
- // create primary buckets belonging to this partition
- member1.invoke(FixedPartitioningTestBase.class,
- "createPrimaryBucketsBelongingToThisPartition", new Object[] {
- "Quarter", Boolean.FALSE, Boolean.TRUE });
-
- member1.invoke(FixedPartitioningTestBase.class,
- "checkPrimaryBucketsForQuarter", new Object[] { 3, 3 });
- member2.invoke(FixedPartitioningTestBase.class,
- "checkPrimaryBucketsForQuarter", new Object[] { 3, 3 });
- member3.invoke(FixedPartitioningTestBase.class,
- "checkPrimaryBucketsForQuarter", new Object[] { 3, 3 });
- member4.invoke(FixedPartitioningTestBase.class,
- "checkPrimaryBucketsForQuarter", new Object[] { 3, 3 });
-
- }
-
- /**
* Tests validate the behavior of FPR with persistence when one member is kept
* alive and other members goes down and come up
*/
[2/2] incubator-geode git commit: Merge branch 'feature/GEODE-390'
into develop
Posted by je...@apache.org.
Merge branch 'feature/GEODE-390' into develop
Closes #37
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/386d1ac8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/386d1ac8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/386d1ac8
Branch: refs/heads/develop
Commit: 386d1ac8c9ed486d7c9415ac3d14bcc78dc15c97
Parents: 80b59bf 4a07f45
Author: Jens Deppe <jd...@pivotal.io>
Authored: Tue Dec 8 14:22:29 2015 -0800
Committer: Jens Deppe <jd...@pivotal.io>
Committed: Tue Dec 8 14:22:29 2015 -0800
----------------------------------------------------------------------
.../cache/partition/PartitionManager.java | 377 ----------------
.../partition/PartitionManagerDUnitTest.java | 443 -------------------
.../fixed/FixedPartitioningTestBase.java | 83 ----
...ngWithColocationAndPersistenceDUnitTest.java | 106 -----
4 files changed, 1009 deletions(-)
----------------------------------------------------------------------