Search in sources :

Example 1 with PartitionNotAvailableException

use of org.apache.geode.cache.partition.PartitionNotAvailableException in project geode by apache.

the class PartitionedRegion method createBucket.

/**
   * Create a bucket for the provided bucket identifier in an atomic fashion.
   * 
   * @param bucketId the bucket identifier for the bucket that needs creation
   * @param snoozer tracking object used to determine length of time t for bucket creation
   * @return a selected Node on which to perform bucket operations
   */
public InternalDistributedMember createBucket(int bucketId, int size, final RetryTimeKeeper snoozer) {
    InternalDistributedMember ret = getNodeForBucketWrite(bucketId, snoozer);
    if (ret != null) {
        return ret;
    }
    // In the current co-location scheme, we have to create the bucket for the
    // colocatedWith region, before we create bucket for this region
    final PartitionedRegion colocatedWith = ColocationHelper.getColocatedRegion(this);
    if (colocatedWith != null) {
        colocatedWith.createBucket(bucketId, size, snoozer);
    }
    // THis is for FPR.if the given bucket id is not starting bucket id then
    // create bucket for starting bucket id
    String partitionName = null;
    if (this.isFixedPartitionedRegion()) {
        FixedPartitionAttributesImpl fpa = PartitionedRegionHelper.getFixedPartitionAttributesForBucket(this, bucketId);
        partitionName = fpa.getPartitionName();
        int startBucketId = fpa.getStartingBucketID();
        if (startBucketId == -1) {
            throw new PartitionNotAvailableException(LocalizedStrings.FOR_FIXED_PARTITION_REGION_0_PARTITION_1_IS_NOT_YET_INITIALIZED_ON_DATASTORE.toString(new Object[] { getName(), partitionName }));
        }
        if (startBucketId != bucketId) {
            createBucket(startBucketId, size, snoozer);
        }
    }
    // Potentially no storage assigned, start bucket creation, be careful of race
    // conditions
    final long startTime = PartitionedRegionStats.startTime();
    if (isDataStore()) {
        ret = this.redundancyProvider.createBucketAtomically(bucketId, size, startTime, false, partitionName);
    } else {
        ret = this.redundancyProvider.createBucketOnDataStore(bucketId, size, startTime, snoozer);
    }
    return ret;
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionNotAvailableException(org.apache.geode.cache.partition.PartitionNotAvailableException)

Example 2 with PartitionNotAvailableException

use of org.apache.geode.cache.partition.PartitionNotAvailableException in project geode by apache.

the class FixedPartitioningDUnitTest method testPut_PartitionNotAvailableException.

/**
   * This test validates that if the required partition is not available at the time of entry
   * operation then PartitionNotAvailabelException is thrown
   */
@Test
public void testPut_PartitionNotAvailableException() {
    try {
        member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", null, 1, 0, 12, new QuarterPartitionResolver(), null, false));
        member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter1, true, 3);
        List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
        fpaList.add(fpa1);
        member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, false));
        member3.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
        fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter2, true, 3);
        fpaList.clear();
        fpaList.add(fpa1);
        member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, false));
        member1.invoke(() -> FixedPartitioningTestBase.putThorughAccessor("Quarter"));
        fail("PartitionNotAvailableException Expected");
    } catch (Exception ex) {
        if (!((ex.getCause() instanceof PartitionNotAvailableException))) {
            Assert.fail("Expected PartitionNotAvailableException ", ex);
        }
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ArrayList(java.util.ArrayList) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PartitionNotAvailableException(org.apache.geode.cache.partition.PartitionNotAvailableException) DuplicatePrimaryPartitionException(org.apache.geode.cache.DuplicatePrimaryPartitionException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) PartitionNotAvailableException(org.apache.geode.cache.partition.PartitionNotAvailableException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 3 with PartitionNotAvailableException

use of org.apache.geode.cache.partition.PartitionNotAvailableException in project geode by apache.

the class PartitionedRegionHelper method getHashKey.

/**
   * Runs hashCode() on given key/routing object producing a long value and then finds absolute
   * value of the modulus with bucketSize. For better key distribution, possibly use MD5 or SHA or
   * any unique ID generator for the hash function.
   * 
   * @param event entry event created for this entry operation; can be null
   * @param pr the partitioned region on which to operate
   * @param operation operation
   * @param key the key on which to determine the hash key
   * @param callbackArgument the callbackArgument is passed to <code>PartitionResolver</code> to get
   *        Routing object
   * @return the bucket id the key/routing object hashes to
   */
private static int getHashKey(EntryOperation event, PartitionedRegion pr, Operation operation, Object key, Object value, Object callbackArgument) {
    // avoid creating EntryOperation if there is no resolver
    if (event != null) {
        pr = (PartitionedRegion) event.getRegion();
        key = event.getKey();
        callbackArgument = event.getCallbackArgument();
    }
    PartitionResolver resolver = getResolver(pr, key, callbackArgument);
    Object resolveKey = null;
    if (pr.isFixedPartitionedRegion()) {
        String partition = null;
        if (resolver instanceof FixedPartitionResolver) {
            Map<String, Integer[]> partitionMap = pr.getPartitionsMap();
            if (event == null) {
                event = new EntryOperationImpl(pr, operation, key, value, callbackArgument);
            }
            partition = ((FixedPartitionResolver) resolver).getPartitionName(event, partitionMap.keySet());
            if (partition == null) {
                Object[] prms = new Object[] { pr.getName(), resolver };
                throw new IllegalStateException(LocalizedStrings.PartitionedRegionHelper_FOR_REGION_0_PARTITIONRESOLVER_1_RETURNED_PARTITION_NAME_NULL.toLocalizedString(prms));
            }
            Integer[] bucketArray = partitionMap.get(partition);
            if (bucketArray == null) {
                Object[] prms = new Object[] { pr.getName(), partition };
                throw new PartitionNotAvailableException(LocalizedStrings.PartitionedRegionHelper_FOR_FIXED_PARTITIONED_REGION_0_FIXED_PARTITION_1_IS_NOT_AVAILABLE_ON_ANY_DATASTORE.toLocalizedString(prms));
            }
            int numBukets = bucketArray[1];
            resolveKey = (numBukets == 1) ? partition : resolver.getRoutingObject(event);
        } else if (resolver == null) {
            throw new IllegalStateException(LocalizedStrings.PartitionedRegionHelper_FOR_FIXED_PARTITIONED_REGION_0_FIXED_PARTITION_RESOLVER_IS_NOT_AVAILABLE.toString(pr.getName()));
        } else if (!(resolver instanceof FixedPartitionResolver)) {
            Object[] prms = new Object[] { pr.getName(), resolver };
            throw new IllegalStateException(LocalizedStrings.PartitionedRegionHelper_FOR_FIXED_PARTITIONED_REGION_0_RESOLVER_DEFINED_1_IS_NOT_AN_INSTANCE_OF_FIXEDPARTITIONRESOLVER.toLocalizedString(prms));
        }
        return assignFixedBucketId(pr, partition, resolveKey);
    } else {
        // Calculate resolveKey.
        if (resolver == null) {
            // no custom partitioning at all
            resolveKey = key;
            if (resolveKey == null) {
                throw new IllegalStateException("attempting to hash null");
            }
        } else {
            if (event == null) {
                event = new EntryOperationImpl(pr, operation, key, value, callbackArgument);
            }
            resolveKey = resolver.getRoutingObject(event);
            if (resolveKey == null) {
                throw new IllegalStateException(LocalizedStrings.PartitionedRegionHelper_THE_ROUTINGOBJECT_RETURNED_BY_PARTITIONRESOLVER_IS_NULL.toLocalizedString());
            }
        }
        // Finally, calculate the hash.
        return getHashKey(pr, resolveKey);
    }
}
Also used : FixedPartitionResolver(org.apache.geode.cache.FixedPartitionResolver) PartitionResolver(org.apache.geode.cache.PartitionResolver) FixedPartitionResolver(org.apache.geode.cache.FixedPartitionResolver) PartitionNotAvailableException(org.apache.geode.cache.partition.PartitionNotAvailableException)

Example 4 with PartitionNotAvailableException

use of org.apache.geode.cache.partition.PartitionNotAvailableException in project geode by apache.

the class FixedPartitioningDUnitTest method testBug43283.

// GEODE-567: async actions, waitForCriterion, time sensitive,
@Category(FlakyTest.class)
// non-thread-safe test hook, eats exceptions (partially fixed)
@Test
public void testBug43283() {
    member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
    member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
    member3.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
    member4.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
    member1.invoke(() -> FixedPartitioningTestBase.setPRObserverBeforeCalculateStartingBucketId());
    member2.invoke(() -> FixedPartitioningTestBase.setPRObserverBeforeCalculateStartingBucketId());
    member3.invoke(() -> FixedPartitioningTestBase.setPRObserverBeforeCalculateStartingBucketId());
    member4.invoke(() -> FixedPartitioningTestBase.setPRObserverBeforeCalculateStartingBucketId());
    try {
        FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter1, true, 3);
        List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
        fpaList.add(fpa1);
        AsyncInvocation inv1 = member1.invokeAsync(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 0, 40, 12, new QuarterPartitionResolver(), null, false));
        FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter2, true, 3);
        fpaList.clear();
        fpaList.add(fpa2);
        AsyncInvocation inv2 = member2.invokeAsync(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 0, 40, 12, new QuarterPartitionResolver(), null, false));
        FixedPartitionAttributes fpa3 = FixedPartitionAttributes.createFixedPartition(Quarter3, true, 3);
        fpaList.clear();
        fpaList.add(fpa3);
        AsyncInvocation inv3 = member3.invokeAsync(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 0, 40, 12, new QuarterPartitionResolver(), null, false));
        member4.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", null, 0, 0, 12, new QuarterPartitionResolver(), null, false));
        try {
            member4.invoke(() -> FixedPartitioningTestBase.putThorughAccessor_Immediate("Quarter"));
        } catch (Exception e) {
            e.printStackTrace();
            if (!(e.getCause() instanceof PartitionNotAvailableException)) {
                Assert.fail("exception thrown is not PartitionNotAvailableException", e);
            }
        }
        try {
            inv1.join();
            inv2.join();
            inv3.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
            Assert.fail("Unexpected Exception", e);
        }
    } finally {
        member1.invoke(() -> FixedPartitioningTestBase.resetPRObserverBeforeCalculateStartingBucketId());
        member2.invoke(() -> FixedPartitioningTestBase.resetPRObserverBeforeCalculateStartingBucketId());
        member3.invoke(() -> FixedPartitioningTestBase.resetPRObserverBeforeCalculateStartingBucketId());
        member4.invoke(() -> FixedPartitioningTestBase.resetPRObserverBeforeCalculateStartingBucketId());
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ArrayList(java.util.ArrayList) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PartitionNotAvailableException(org.apache.geode.cache.partition.PartitionNotAvailableException) DuplicatePrimaryPartitionException(org.apache.geode.cache.DuplicatePrimaryPartitionException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) PartitionNotAvailableException(org.apache.geode.cache.partition.PartitionNotAvailableException) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Aggregations

PartitionNotAvailableException (org.apache.geode.cache.partition.PartitionNotAvailableException)4 ArrayList (java.util.ArrayList)2 DuplicatePrimaryPartitionException (org.apache.geode.cache.DuplicatePrimaryPartitionException)2 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)2 FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)2 IgnoredException (org.apache.geode.test.dunit.IgnoredException)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)2 Test (org.junit.Test)2 FixedPartitionResolver (org.apache.geode.cache.FixedPartitionResolver)1 PartitionResolver (org.apache.geode.cache.PartitionResolver)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)1 Category (org.junit.experimental.categories.Category)1