Search in sources :

Example 51 with FixedPartitionAttributes

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

the class CacheXmlGenerator method generate.

/**
   * Generates XML for a <code>PartitionAttributes</code>
   */
private void generate(PartitionAttributes pa) throws SAXException {
    AttributesImpl atts = new AttributesImpl();
    if (generateDefaults() || pa.getRedundantCopies() != 0)
        atts.addAttribute("", "", PARTITION_REDUNDANT_COPIES, "", String.valueOf(pa.getRedundantCopies()));
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) {
        if (generateDefaults() || pa.getLocalMaxMemory() != ((PartitionAttributesImpl) pa).getLocalMaxMemoryDefault())
            atts.addAttribute("", "", LOCAL_MAX_MEMORY, "", String.valueOf(pa.getLocalMaxMemory()));
        if (generateDefaults() || pa.getTotalMaxMemory() != PartitionAttributesFactory.GLOBAL_MAX_MEMORY_DEFAULT)
            atts.addAttribute("", "", TOTAL_MAX_MEMORY, "", String.valueOf(pa.getTotalMaxMemory()));
        if (generateDefaults() || pa.getTotalNumBuckets() != PartitionAttributesFactory.GLOBAL_MAX_BUCKETS_DEFAULT)
            atts.addAttribute("", "", TOTAL_NUM_BUCKETS, "", String.valueOf(pa.getTotalNumBuckets()));
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
        if (pa.getColocatedWith() != null)
            atts.addAttribute("", "", PARTITION_COLOCATED_WITH, "", pa.getColocatedWith());
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
        if (generateDefaults() || pa.getRecoveryDelay() != PartitionAttributesFactory.RECOVERY_DELAY_DEFAULT)
            atts.addAttribute("", "", RECOVERY_DELAY, "", String.valueOf(pa.getRecoveryDelay()));
        if (generateDefaults() || pa.getStartupRecoveryDelay() != PartitionAttributesFactory.STARTUP_RECOVERY_DELAY_DEFAULT)
            atts.addAttribute("", "", STARTUP_RECOVERY_DELAY, "", String.valueOf(pa.getStartupRecoveryDelay()));
    }
    if (!generateDefaults() && atts.getLength() == 0 && pa.getPartitionResolver() == null && pa.getPartitionListeners().length == 0 && (pa.getFixedPartitionAttributes() == null || pa.getFixedPartitionAttributes().isEmpty())) {
        return;
    }
    handler.startElement("", PARTITION_ATTRIBUTES, PARTITION_ATTRIBUTES, atts);
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
        PartitionResolver rr = pa.getPartitionResolver();
        if (rr != null) {
            generate(PARTITION_RESOLVER, rr);
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_1) >= 0) {
        PartitionListener[] listeners = pa.getPartitionListeners();
        for (int i = 0; i < listeners.length; i++) {
            PartitionListener listener = listeners[i];
            if (listener != null) {
                generate(PARTITION_LISTENER, listener);
            }
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
        List<FixedPartitionAttributes> staticAttrs = pa.getFixedPartitionAttributes();
        if (staticAttrs != null) {
            generateFixedPartitionAttributes(FIXED_PARTITION_ATTRIBUTES, staticAttrs);
        }
    }
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) < 0) {
        Properties p = pa.getLocalProperties();
        generate(p, LOCAL_PROPERTIES);
        p = pa.getGlobalProperties();
        generate(p, GLOBAL_PROPERTIES);
    }
    handler.endElement("", PARTITION_ATTRIBUTES, PARTITION_ATTRIBUTES);
}
Also used : PartitionListener(org.apache.geode.cache.partition.PartitionListener) DiskWriteAttributesImpl(org.apache.geode.internal.cache.DiskWriteAttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) AttributesImpl(org.xml.sax.helpers.AttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) PartitionResolver(org.apache.geode.cache.PartitionResolver) Properties(java.util.Properties)

Example 52 with FixedPartitionAttributes

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

the class PartitionAttributesImpl method validateAttributes.

/**
   * Validates that the attributes are consistent with each other. The following rules are checked
   * and enforced:
   * <ul>
   * <li>Redundancy should be between 1 and 4</li>
   * <li>Scope should be either DIST_ACK or DIST_NO_ACK</li>
   * </ul>
   * NOTE: validation that depends on more than one attribute can not be done in this method. That
   * validation needs to be done in validateWhenAllAttributesAreSet
   * 
   * @throws IllegalStateException if the attributes are not consistent with each other.
   */
public void validateAttributes() {
    if ((this.totalNumBuckets <= 0)) {
        throw new IllegalStateException(LocalizedStrings.PartitionAttributesImpl_TOTALNUMBICKETS_0_IS_AN_ILLEGAL_VALUE_PLEASE_CHOOSE_A_VALUE_GREATER_THAN_0.toLocalizedString(this.totalNumBuckets));
    }
    if ((this.redundancy < 0) || (this.redundancy >= 4)) {
        throw new IllegalStateException(LocalizedStrings.PartitionAttributesImpl_REDUNDANTCOPIES_0_IS_AN_ILLEGAL_VALUE_PLEASE_CHOOSE_A_VALUE_BETWEEN_0_AND_3.toLocalizedString(this.redundancy));
    }
    for (Iterator it = this.getLocalProperties().keySet().iterator(); it.hasNext(); ) {
        String propName = (String) it.next();
        if (!PartitionAttributesFactory.LOCAL_MAX_MEMORY_PROPERTY.equals(propName)) {
            throw new IllegalStateException(LocalizedStrings.PartitionAttributesImpl_UNKNOWN_LOCAL_PROPERTY_0.toLocalizedString(propName));
        }
    }
    for (Iterator it = this.getGlobalProperties().keySet().iterator(); it.hasNext(); ) {
        String propName = (String) it.next();
        if (!PartitionAttributesFactory.GLOBAL_MAX_BUCKETS_PROPERTY.equals(propName) && !PartitionAttributesFactory.GLOBAL_MAX_MEMORY_PROPERTY.equals(propName)) {
            throw new IllegalStateException(LocalizedStrings.PartitionAttributesImpl_UNKNOWN_GLOBAL_PROPERTY_0.toLocalizedString(propName));
        }
    }
    if (this.recoveryDelay < -1) {
        throw new IllegalStateException("RecoveryDelay " + this.recoveryDelay + " is an illegal value, please choose a value that is greater than or equal to -1");
    }
    if (this.startupRecoveryDelay < -1) {
        throw new IllegalStateException("StartupRecoveryDelay " + this.startupRecoveryDelay + " is an illegal value, please choose a value that is greater than or equal to -1");
    }
    if (this.fixedPAttrs != null) {
        List<FixedPartitionAttributesImpl> duplicateFPAattrsList = new ArrayList<FixedPartitionAttributesImpl>();
        Set<FixedPartitionAttributes> fpAttrsSet = new HashSet<FixedPartitionAttributes>();
        for (FixedPartitionAttributesImpl fpa : this.fixedPAttrs) {
            if (fpa == null || fpa.getPartitionName() == null) {
                throw new IllegalStateException(LocalizedStrings.PartitionAttributesImpl_FIXED_PARTITION_NAME_CANNOT_BE_NULL.toString());
            }
            if (fpAttrsSet.contains(fpa)) {
                duplicateFPAattrsList.add(fpa);
            } else {
                fpAttrsSet.add(fpa);
            }
        }
        if (duplicateFPAattrsList.size() != 0) {
            throw new IllegalStateException(LocalizedStrings.PartitionAttributesImpl_PARTITION_NAME_0_CAN_BE_ADDED_ONLY_ONCE_IN_FIXED_PARTITION_ATTRIBUTES.toString(duplicateFPAattrsList.toString()));
        }
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 53 with FixedPartitionAttributes

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

the class PartitionRegionConfigValidator method validateFixedPartitionAttributesAgainstTotalNumberBuckets.

/**
   * validate that for all partitions defined across all datastores, sum of num-buckets is not more
   * than total-num-buckets defined
   */
private void validateFixedPartitionAttributesAgainstTotalNumberBuckets() {
    for (FixedPartitionAttributesImpl fpa : this.pr.getFixedPartitionAttributesImpl()) {
        int numBuckets = 0;
        Set<FixedPartitionAttributesImpl> allFPAs = new HashSet<FixedPartitionAttributesImpl>(this.pr.getRegionAdvisor().adviseAllFixedPartitionAttributes());
        allFPAs.add(fpa);
        for (FixedPartitionAttributes samefpa : allFPAs) {
            numBuckets = numBuckets + samefpa.getNumBuckets();
        }
        if (numBuckets > this.pr.getTotalNumberOfBuckets()) {
            Object[] prms = new Object[] { this.pr.getName(), numBuckets, this.pr.getTotalNumberOfBuckets() };
            throw new IllegalStateException(LocalizedStrings.PartitionedRegionConfigValidator_FOR_REGION_0_SUM_OF_NUM_BUCKETS_1_FOR_DIFFERENT_PRIMARY_PARTITIONS_SHOULD_NOT_BE_GREATER_THAN_TOTAL_NUM_BUCKETS_2.toString(prms));
        }
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) HashSet(java.util.HashSet)

Example 54 with FixedPartitionAttributes

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

the class PartitionRegionHelperDUnitTest method testAssignBucketsToPartitions_FPR.

@Test
public void testAssignBucketsToPartitions_FPR() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    SerializableRunnable createPrRegion1 = new SerializableRunnable("createRegion") {

        public void run() {
            Cache cache = getCache();
            FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("Q1", true, 3);
            FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition("Q2", false, 3);
            AttributesFactory attr = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.addFixedPartitionAttributes(fpa1);
            paf.addFixedPartitionAttributes(fpa2);
            paf.setPartitionResolver(new QuarterPartitionResolver());
            paf.setRedundantCopies(1);
            paf.setTotalNumBuckets(12);
            PartitionAttributes prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            cache.createRegion("region1", attr.create());
        }
    };
    vm0.invoke(createPrRegion1);
    SerializableRunnable createPrRegion2 = new SerializableRunnable("createRegion") {

        public void run() {
            Cache cache = getCache();
            FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("Q2", true, 3);
            FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition("Q3", false, 3);
            AttributesFactory attr = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.addFixedPartitionAttributes(fpa1);
            paf.addFixedPartitionAttributes(fpa2);
            paf.setPartitionResolver(new QuarterPartitionResolver());
            paf.setRedundantCopies(1);
            paf.setTotalNumBuckets(12);
            PartitionAttributes prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            cache.createRegion("region1", attr.create());
        }
    };
    vm1.invoke(createPrRegion2);
    SerializableRunnable createPrRegion3 = new SerializableRunnable("createRegion") {

        public void run() {
            Cache cache = getCache();
            FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("Q3", true, 3);
            FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition("Q1", false, 3);
            AttributesFactory attr = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.addFixedPartitionAttributes(fpa1);
            paf.addFixedPartitionAttributes(fpa2);
            paf.setPartitionResolver(new QuarterPartitionResolver());
            paf.setRedundantCopies(1);
            paf.setTotalNumBuckets(12);
            PartitionAttributes prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            cache.createRegion("region1", attr.create());
        }
    };
    vm2.invoke(createPrRegion3);
    SerializableRunnable assignBuckets = new SerializableRunnable("assign partitions") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("region1");
            PartitionRegionHelper.assignBucketsToPartitions(region);
        }
    };
    AsyncInvocation future1 = vm0.invokeAsync(assignBuckets);
    AsyncInvocation future2 = vm1.invokeAsync(assignBuckets);
    AsyncInvocation future3 = vm2.invokeAsync(assignBuckets);
    future1.join();
    future2.join();
    future3.join();
    if (future1.exceptionOccurred())
        throw future1.getException();
    if (future2.exceptionOccurred())
        throw future2.getException();
    if (future3.exceptionOccurred())
        throw future3.getException();
    SerializableRunnable checkAssignment = new SerializableRunnable("check assignment") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("region1");
            PartitionRegionInfo info = PartitionRegionHelper.getPartitionRegionInfo(region);
            assertEquals(9, info.getCreatedBucketCount());
            assertEquals(0, info.getLowRedundancyBucketCount());
            for (PartitionMemberInfo member : info.getPartitionMemberInfo()) {
                assertEquals(6, member.getBucketCount());
            }
        }
    };
    vm0.invoke(checkAssignment);
    SerializableRunnable createPrRegion4 = new SerializableRunnable("createRegion") {

        public void run() {
            Cache cache = getCache();
            AttributesFactory attr = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setPartitionResolver(new QuarterPartitionResolver());
            paf.setLocalMaxMemory(0);
            paf.setRedundantCopies(1);
            paf.setTotalNumBuckets(12);
            PartitionAttributes prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            Region region = cache.createRegion("region1", attr.create());
            for (Months_Accessor month : Months_Accessor.values()) {
                String dateString = 10 + "-" + month + "-" + "2009";
                String DATE_FORMAT = "dd-MMM-yyyy";
                SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
                Date date = null;
                try {
                    date = sdf.parse(dateString);
                } catch (ParseException e) {
                    Assert.fail("Exception Occurred while parseing date", e);
                }
                String value = month.toString() + 10;
                region.put(date, value);
            }
        }
    };
    vm3.invoke(createPrRegion4);
    SerializableRunnable checkMembers = new SerializableRunnable("createRegion") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("region1");
            for (Months_Accessor month : Months_Accessor.values()) {
                String dateString = 10 + "-" + month + "-" + "2009";
                String DATE_FORMAT = "dd-MMM-yyyy";
                SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, Locale.US);
                Date date = null;
                try {
                    date = sdf.parse(dateString);
                } catch (ParseException e) {
                    Assert.fail("Exception Occurred while parseing date", e);
                }
                DistributedMember key1Pri = PartitionRegionHelper.getPrimaryMemberForKey(region, date);
                assertNotNull(key1Pri);
                Set<DistributedMember> buk0AllMems = PartitionRegionHelper.getAllMembersForKey(region, date);
                assertEquals(2, buk0AllMems.size());
                Set<DistributedMember> buk0RedundantMems = PartitionRegionHelper.getRedundantMembersForKey(region, date);
                assertEquals(1, buk0RedundantMems.size());
            }
        }
    };
    vm3.invoke(checkMembers);
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Date(java.util.Date) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) QuarterPartitionResolver(org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver) VM(org.apache.geode.test.dunit.VM) Months_Accessor(org.apache.geode.internal.cache.partitioned.fixed.FixedPartitioningTestBase.Months_Accessor) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 55 with FixedPartitionAttributes

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

the class FixedPRSinglehopDUnitTest method createServerWithLocator.

public static int createServerWithLocator(String locator, boolean isAccessor, List<FixedPartitionAttributes> fpaList, boolean simpleFPR) {
    FixedPRSinglehopDUnitTest test = new FixedPRSinglehopDUnitTest();
    Properties props = new Properties();
    props = new Properties();
    props.setProperty(LOCATORS, locator);
    DistributedSystem ds = test.getSystem(props);
    cache = new CacheFactory(props).create(ds);
    CacheServer server = cache.addCacheServer();
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    server.setPort(port);
    server.setHostnameForClients("localhost");
    try {
        server.start();
    } catch (IOException e) {
        Assert.fail("Failed to start server ", e);
    }
    if (!fpaList.isEmpty() || isAccessor) {
        PartitionAttributesFactory paf = new PartitionAttributesFactory();
        paf.setRedundantCopies(1).setTotalNumBuckets(12);
        if (isAccessor) {
            paf.setLocalMaxMemory(0);
        }
        for (FixedPartitionAttributes fpa : fpaList) {
            paf.addFixedPartitionAttributes(fpa);
        }
        // paf.setPartitionResolver(new SingleHopQuarterPartitionResolver());
        paf.setPartitionResolver(new QuarterPartitionResolver());
        AttributesFactory attr = new AttributesFactory();
        attr.setPartitionAttributes(paf.create());
        region = cache.createRegion(PR_NAME, attr.create());
        assertNotNull(region);
        LogWriterUtils.getLogWriter().info("Partitioned Region " + PR_NAME + " created Successfully :" + region.toString());
    }
    return port;
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SingleHopQuarterPartitionResolver(org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver) QuarterPartitionResolver(org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver) CacheServer(org.apache.geode.cache.server.CacheServer) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory) DistributedSystem(org.apache.geode.distributed.DistributedSystem)

Aggregations

FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)63 Test (org.junit.Test)46 ArrayList (java.util.ArrayList)45 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)43 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)30 IgnoredException (org.apache.geode.test.dunit.IgnoredException)16 DuplicatePrimaryPartitionException (org.apache.geode.cache.DuplicatePrimaryPartitionException)15 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)15 PartitionNotAvailableException (org.apache.geode.cache.partition.PartitionNotAvailableException)15 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)12 AttributesFactory (org.apache.geode.cache.AttributesFactory)7 Region (org.apache.geode.cache.Region)6 VM (org.apache.geode.test.dunit.VM)6 Cache (org.apache.geode.cache.Cache)5 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)5 SingleHopQuarterPartitionResolver (org.apache.geode.internal.cache.partitioned.fixed.SingleHopQuarterPartitionResolver)5 Host (org.apache.geode.test.dunit.Host)5 IOException (java.io.IOException)4 QuarterPartitionResolver (org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver)4 HashSet (java.util.HashSet)3