Search in sources :

Example 1 with FixedPartitionAttributes

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

the class PartitionRegionConfigValidator method validateFixedPartitionAttributesAgainstRedundantCopies.

/**
   * Validate that for the given partition, number if secondaries are never exceed redundant copies
   * defined Validate that the num-buckets defined for a partition are same across all datastores
   */
private void validateFixedPartitionAttributesAgainstRedundantCopies() {
    for (FixedPartitionAttributesImpl fpa : this.pr.getFixedPartitionAttributesImpl()) {
        List<FixedPartitionAttributesImpl> allSameFPAs = this.pr.getRegionAdvisor().adviseSameFPAs(fpa);
        allSameFPAs.add(fpa);
        if (!allSameFPAs.isEmpty()) {
            int numSecondaries = 0;
            for (FixedPartitionAttributes otherfpa : allSameFPAs) {
                if (fpa.getNumBuckets() != otherfpa.getNumBuckets()) {
                    Object[] prms = new Object[] { this.pr.getName(), fpa.getPartitionName(), fpa.getNumBuckets(), otherfpa.getNumBuckets() };
                    throw new IllegalStateException(LocalizedStrings.PartitionedRegionConfigValidator_FOR_REGION_0_FOR_PARTITION_1_NUM_BUCKETS_ARE_NOT_SAME_ACROSS_NODES.toString(prms));
                }
                if (!otherfpa.isPrimary()) {
                    if (++numSecondaries > (this.pr.getRedundantCopies())) {
                        Object[] prms = new Object[] { this.pr.getName(), numSecondaries, fpa.getPartitionName(), this.pr.getRedundantCopies() };
                        throw new IllegalStateException(LocalizedStrings.PartitionedRegionConfigValidator_FOR_REGION_0_NUMBER_OF_SECONDARY_PARTITIONS_1_OF_A_PARTITION_2_SHOULD_NEVER_EXCEED_NUMBER_OF_REDUNDANT_COPIES_3.toString(prms));
                    }
                }
            }
        }
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes)

Example 2 with FixedPartitionAttributes

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

the class RegionMBeanCompositeDataFactory method getFixedPartitionAttributesData.

public static FixedPartitionAttributesData[] getFixedPartitionAttributesData(PartitionAttributes partAttrs) {
    FixedPartitionAttributesData[] fixedPartitionAttributesTable = new FixedPartitionAttributesData[partAttrs.getFixedPartitionAttributes().size()];
    Iterator<FixedPartitionAttributes> it = partAttrs.getFixedPartitionAttributes().iterator();
    int j = 0;
    while (it.hasNext()) {
        FixedPartitionAttributes fa = it.next();
        FixedPartitionAttributesData data = new FixedPartitionAttributesData(fa.getPartitionName(), fa.isPrimary(), fa.getNumBuckets());
        fixedPartitionAttributesTable[j] = data;
        j++;
    }
    return fixedPartitionAttributesTable;
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) FixedPartitionAttributesData(org.apache.geode.management.FixedPartitionAttributesData)

Example 3 with FixedPartitionAttributes

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

the class CacheXml66DUnitTest method validateAttributes.

private void validateAttributes(Region region, List<FixedPartitionAttributes> fpattrsList, QuarterPartitionResolver resolver, boolean isColocated) {
    RegionAttributes regionAttrs = region.getAttributes();
    PartitionAttributes pa = regionAttrs.getPartitionAttributes();
    assertEquals(pa.getRedundantCopies(), 1);
    assertNotNull(pa.getPartitionResolver().getClass());
    assertEquals(pa.getPartitionResolver(), resolver);
    List<FixedPartitionAttributesImpl> fixedPartitionsList = pa.getFixedPartitionAttributes();
    if (isColocated) {
        assertNull(fixedPartitionsList);
        assertNotNull(pa.getColocatedWith());
    } else {
        assertNull(pa.getColocatedWith());
        assertEquals(fixedPartitionsList.size(), 4);
        assertEquals(fixedPartitionsList.containsAll(fpattrsList), true);
        for (FixedPartitionAttributes fpa : fixedPartitionsList) {
            if (fpa.getPartitionName().equals("Q1")) {
                assertEquals(fpa.getNumBuckets(), 1);
                assertEquals(fpa.isPrimary(), false);
            }
            if (fpa.getPartitionName().equals("Q2")) {
                assertEquals(fpa.getNumBuckets(), 1);
                assertEquals(fpa.isPrimary(), true);
            }
            if (fpa.getPartitionName().equals("Q3")) {
                assertEquals(fpa.getNumBuckets(), 3);
                assertEquals(fpa.isPrimary(), false);
            }
            if (fpa.getPartitionName().equals("Q4")) {
                assertEquals(fpa.getNumBuckets(), 3);
                assertEquals(fpa.isPrimary(), false);
            }
        }
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) RegionAttributes(org.apache.geode.cache.RegionAttributes) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) FixedPartitionAttributesImpl(org.apache.geode.internal.cache.FixedPartitionAttributesImpl)

Example 4 with FixedPartitionAttributes

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

the class CacheXmlGenerator method generateFixedPartitionAttributes.

/**
   * Generate XML for FixedPartitionAttribute element in PartitionedRegion Attributes
   */
private void generateFixedPartitionAttributes(String kind, List<FixedPartitionAttributes> allStaticAttrs) throws SAXException {
    for (FixedPartitionAttributes attr : allStaticAttrs) {
        AttributesImpl sAtts = new AttributesImpl();
        sAtts.addAttribute("", "", PARTITION_NAME, "", attr.getPartitionName());
        sAtts.addAttribute("", "", IS_PRIMARY, "", String.valueOf(attr.isPrimary()));
        sAtts.addAttribute("", "", NUM_BUCKETS, "", String.valueOf(attr.getNumBuckets()));
        handler.startElement("", kind, kind, sAtts);
        handler.endElement("", kind, kind);
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) DiskWriteAttributesImpl(org.apache.geode.internal.cache.DiskWriteAttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) AttributesImpl(org.xml.sax.helpers.AttributesImpl)

Example 5 with FixedPartitionAttributes

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

the class PartitionedRegionHelper method getAllAvailablePartitions.

private static Set<String> getAllAvailablePartitions(PartitionedRegion region) {
    Set<String> partitionSet = new HashSet<String>();
    List<FixedPartitionAttributesImpl> localFPAs = region.getFixedPartitionAttributesImpl();
    if (localFPAs != null) {
        for (FixedPartitionAttributesImpl fpa : localFPAs) {
            partitionSet.add(fpa.getPartitionName());
        }
    }
    List<FixedPartitionAttributesImpl> remoteFPAs = region.getRegionAdvisor().adviseAllFixedPartitionAttributes();
    for (FixedPartitionAttributes fpa : remoteFPAs) {
        partitionSet.add(fpa.getPartitionName());
    }
    return Collections.unmodifiableSet(partitionSet);
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) HashSet(java.util.HashSet)

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