use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.
the class GetClientPartitionAttributesCommand66 method cmdExecute.
@SuppressWarnings("unchecked")
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException, InterruptedException {
String regionFullPath = null;
regionFullPath = clientMessage.getPart(0).getString();
String errMessage = "";
if (regionFullPath == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPartitionAttributes_THE_INPUT_REGION_PATH_IS_NULL));
errMessage = LocalizedStrings.GetClientPartitionAttributes_THE_INPUT_REGION_PATH_IS_NULL.toLocalizedString();
writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR, errMessage.toString(), serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
Region region = serverConnection.getCache().getRegion(regionFullPath);
if (region == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPartitionAttributes_REGION_NOT_FOUND_FOR_SPECIFIED_REGION_PATH, regionFullPath));
errMessage = LocalizedStrings.GetClientPartitionAttributes_REGION_NOT_FOUND.toLocalizedString() + regionFullPath;
writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR, errMessage.toString(), serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
try {
Message responseMsg = serverConnection.getResponseMessage();
responseMsg.setTransactionId(clientMessage.getTransactionId());
responseMsg.setMessageType(MessageType.RESPONSE_CLIENT_PARTITION_ATTRIBUTES);
if (!(region instanceof PartitionedRegion)) {
responseMsg.setNumberOfParts(2);
responseMsg.addObjPart(-1);
responseMsg.addObjPart(region.getFullPath());
} else {
PartitionedRegion prRgion = (PartitionedRegion) region;
PartitionResolver partitionResolver = prRgion.getPartitionResolver();
// MINUMUM PARTS
int numParts = 2;
if (partitionResolver != null) {
numParts++;
}
if (prRgion.isFixedPartitionedRegion()) {
numParts++;
}
responseMsg.setNumberOfParts(numParts);
// PART 1
responseMsg.addObjPart(prRgion.getTotalNumberOfBuckets());
// PART 2
String leaderRegionPath = null;
PartitionedRegion leaderRegion = null;
String leaderRegionName = prRgion.getColocatedWith();
if (leaderRegionName != null) {
Cache cache = prRgion.getCache();
while (leaderRegionName != null) {
leaderRegion = (PartitionedRegion) cache.getRegion(leaderRegionName);
if (leaderRegion.getColocatedWith() == null) {
leaderRegionPath = leaderRegion.getFullPath();
break;
} else {
leaderRegionName = leaderRegion.getColocatedWith();
}
}
}
responseMsg.addObjPart(leaderRegionPath);
// PART 3
if (partitionResolver != null) {
responseMsg.addObjPart(partitionResolver.getClass().toString().substring(6));
}
// PART 4
if (prRgion.isFixedPartitionedRegion()) {
Set<FixedPartitionAttributes> fpaSet = null;
if (leaderRegion != null) {
fpaSet = PartitionedRegionHelper.getAllFixedPartitionAttributes(leaderRegion);
} else {
fpaSet = PartitionedRegionHelper.getAllFixedPartitionAttributes(prRgion);
}
responseMsg.addObjPart(fpaSet);
}
}
responseMsg.send();
clientMessage.clearParts();
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
} finally {
serverConnection.setAsTrue(Command.RESPONDED);
}
}
use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.
the class CacheXml66DUnitTest method testFixedPartitioning.
/**
* Tests that a partitioned region is created with FixedPartitionAttributes set programatically
* and correct cache.xml is generated with the same FixedPartitionAttributes
*/
@Test
public void testFixedPartitioning() throws Exception {
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation();
FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("Q1");
FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition("Q2", true);
FixedPartitionAttributes fpa3 = FixedPartitionAttributes.createFixedPartition("Q3", 3);
FixedPartitionAttributes fpa4 = FixedPartitionAttributes.createFixedPartition("Q4", false, 3);
List<FixedPartitionAttributes> fpattrsList = new ArrayList<FixedPartitionAttributes>();
fpattrsList.add(fpa1);
fpattrsList.add(fpa2);
fpattrsList.add(fpa3);
fpattrsList.add(fpa4);
QuarterPartitionResolver resolver = new QuarterPartitionResolver();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1).setPartitionResolver(resolver).addFixedPartitionAttributes(fpa1).addFixedPartitionAttributes(fpa2).addFixedPartitionAttributes(fpa3).addFixedPartitionAttributes(fpa4);
attrs.setPartitionAttributes(paf.create());
cache.createRegion("Quarter", attrs);
Region r = cache.getRegion("Quarter");
validateAttributes(r, fpattrsList, resolver, false);
testXml(cache);
Cache c = getCache();
assertNotNull(c);
Region region = c.getRegion("Quarter");
assertNotNull(region);
validateAttributes(region, fpattrsList, resolver, false);
}
use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.
the class FixedPartitioningWithColocationAndPersistenceDUnitTest method testColocation_FPRs_ChildUsingAttributesOfParent_HA.
/**
* This tests validates that Customer-Order-shipment colocation with failover scenario,
*/
@Test
public void testColocation_FPRs_ChildUsingAttributesOfParent_HA() {
try {
member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
member3.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("10", true, 5);
FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition("30", false, 5);
FixedPartitionAttributes fpa3 = FixedPartitionAttributes.createFixedPartition("40", false, 5);
List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
fpaList.add(fpa1);
fpaList.add(fpa2);
fpaList.add(fpa3);
member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 2, 50, 20, new CustomerFixedPartitionResolver(), null, false));
fpa1 = FixedPartitionAttributes.createFixedPartition("20", true, 5);
fpa2 = FixedPartitionAttributes.createFixedPartition("30", false, 5);
fpa3 = FixedPartitionAttributes.createFixedPartition("40", false, 5);
fpaList.clear();
fpaList.add(fpa1);
fpaList.add(fpa2);
fpaList.add(fpa3);
member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 2, 50, 20, new CustomerFixedPartitionResolver(), null, false));
fpa1 = FixedPartitionAttributes.createFixedPartition("30", true, 5);
fpa2 = FixedPartitionAttributes.createFixedPartition("40", true, 5);
fpa3 = FixedPartitionAttributes.createFixedPartition("10", false, 5);
FixedPartitionAttributes fpa4 = FixedPartitionAttributes.createFixedPartition("20", false, 5);
fpaList.clear();
fpaList.add(fpa1);
fpaList.add(fpa2);
fpaList.add(fpa3);
fpaList.add(fpa4);
member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 2, 50, 20, new CustomerFixedPartitionResolver(), null, false));
member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
member1.invoke(() -> FixedPartitioningTestBase.checkFPR("Order"));
member1.invoke(() -> FixedPartitioningTestBase.checkFPR("Shipment"));
member2.invoke(() -> FixedPartitioningTestBase.checkFPR("Order"));
member2.invoke(() -> FixedPartitioningTestBase.checkFPR("Shipment"));
member3.invoke(() -> FixedPartitioningTestBase.checkFPR("Order"));
member3.invoke(() -> FixedPartitioningTestBase.checkFPR("Shipment"));
member1.invoke(() -> FixedPartitioningTestBase.putCustomerPartitionedRegion("Customer"));
member1.invoke(() -> FixedPartitioningTestBase.putOrderPartitionedRegion("Order"));
member1.invoke(() -> FixedPartitioningTestBase.putShipmentPartitionedRegion("Shipment"));
member1.invoke(() -> FixedPartitioningTestBase.validateAfterPutPartitionedRegion("Customer", "Order", "Shipment"));
member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
member3.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(20, 10, "Customer", "Order", "Shipment"));
member3.invoke(() -> FixedPartitioningTestBase.closeCache());
Wait.pause(4000);
member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocationAfterCacheClosed(15, 5, "Customer", "Order", "Shipment"));
member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocationAfterCacheClosed(15, 5, "Customer", "Order", "Shipment"));
member3.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
fpa1 = FixedPartitionAttributes.createFixedPartition("30", true, 5);
fpa2 = FixedPartitionAttributes.createFixedPartition("10", false, 5);
fpa3 = FixedPartitionAttributes.createFixedPartition("20", false, 5);
fpaList.clear();
fpaList.add(fpa1);
fpaList.add(fpa2);
fpaList.add(fpa3);
member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 2, 50, 20, new CustomerFixedPartitionResolver(), null, false));
member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
member3.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
Wait.pause(4000);
member1.invoke(() -> FixedPartitioningTestBase.validateAfterPutPartitionedRegion("Customer", "Order", "Shipment"));
member3.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
member4.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
fpa1 = FixedPartitionAttributes.createFixedPartition("40", true, 5);
fpa2 = FixedPartitionAttributes.createFixedPartition("10", false, 5);
fpa3 = FixedPartitionAttributes.createFixedPartition("20", false, 5);
fpaList.clear();
fpaList.add(fpa1);
fpaList.add(fpa2);
fpaList.add(fpa3);
member4.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 2, 50, 20, new CustomerFixedPartitionResolver(), null, false));
member4.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
member4.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 2, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
Wait.pause(4000);
member1.invoke(() -> FixedPartitioningTestBase.validateAfterPutPartitionedRegion("Customer", "Order", "Shipment"));
member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
member3.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
member4.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(15, 5, "Customer", "Order", "Shipment"));
} catch (Exception e) {
Assert.fail("Unexpected Exception ", e);
}
}
use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.
the class FixedPartitioningWithColocationAndPersistenceDUnitTest method testColocation_FPR_Persistence_Colocation_OneMemberAlive.
/**
* Tests validate the behavior of FPR with persistence and with colocation when one member is kept
* alive and other members goes down and come up
*/
@Test
public void testColocation_FPR_Persistence_Colocation_OneMemberAlive() {
try {
member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("10", true, 5);
FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition("20", false, 5);
List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
fpaList.add(fpa1);
fpaList.add(fpa2);
member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 1, 50, 20, new CustomerFixedPartitionResolver(), null, true));
fpa1 = FixedPartitionAttributes.createFixedPartition("20", true, 5);
fpa2 = FixedPartitionAttributes.createFixedPartition("10", false, 5);
fpaList.clear();
fpaList.add(fpa1);
fpaList.add(fpa2);
member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 1, 50, 20, new CustomerFixedPartitionResolver(), null, true));
member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 1, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 1, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 1, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 1, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
member1.invoke(() -> FixedPartitioningTestBase.checkFPR("Order"));
member1.invoke(() -> FixedPartitioningTestBase.checkFPR("Shipment"));
member2.invoke(() -> FixedPartitioningTestBase.checkFPR("Order"));
member2.invoke(() -> FixedPartitioningTestBase.checkFPR("Shipment"));
member1.invoke(() -> FixedPartitioningTestBase.putCustomerPartitionedRegion_Persistence1("Customer"));
member1.invoke(() -> FixedPartitioningTestBase.putOrderPartitionedRegion_Persistence1("Order"));
member1.invoke(() -> FixedPartitioningTestBase.putShipmentPartitionedRegion_Persistence1("Shipment"));
member1.invoke(() -> FixedPartitioningTestBase.validateAfterPutPartitionedRegion("Customer", "Order", "Shipment"));
member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(10, 5, "Customer", "Order", "Shipment"));
member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(10, 5, "Customer", "Order", "Shipment"));
member2.invoke(() -> FixedPartitioningTestBase.closeCache());
member1.invoke(() -> FixedPartitioningTestBase.putCustomerPartitionedRegion_Persistence2("Customer"));
member1.invoke(() -> FixedPartitioningTestBase.putOrderPartitionedRegion_Persistence2("Order"));
member1.invoke(() -> FixedPartitioningTestBase.putShipmentPartitionedRegion_Persistence2("Shipment"));
member1.invoke(() -> FixedPartitioningTestBase.validateAfterPutPartitionedRegion("Customer", "Order", "Shipment"));
member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(10, 10, "Customer", "Order", "Shipment"));
member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
fpa1 = FixedPartitionAttributes.createFixedPartition("20", true, 5);
fpa2 = FixedPartitionAttributes.createFixedPartition("10", false, 5);
fpaList.clear();
fpaList.add(fpa1);
fpaList.add(fpa2);
AsyncInvocation[] async = new AsyncInvocation[2];
member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 1, 50, 20, new CustomerFixedPartitionResolver(), null, true));
member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", null, 1, 50, 20, new CustomerFixedPartitionResolver(), "Customer", false));
member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Shipment", null, 1, 50, 20, new CustomerFixedPartitionResolver(), "Order", false));
Wait.pause(4000);
member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(10, 5, "Customer", "Order", "Shipment"));
member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForColocation(10, 5, "Customer", "Order", "Shipment"));
member1.invoke(() -> FixedPartitioningTestBase.validateAfterPutPartitionedRegion("Customer", "Order", "Shipment"));
member2.invoke(() -> FixedPartitioningTestBase.validateAfterPutPartitionedRegion("Customer", "Order", "Shipment"));
} catch (Exception e) {
Assert.fail("Unexpected Exception ", e);
}
}
use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.
the class FixedPartitioningWithColocationAndPersistenceDUnitTest method testColocation_WithFPROnChildRegion.
/**
* This tests validates that in colocation of FPRs child region cannot specify
* FixedPartitionAttributes
*
*/
@Test
public void testColocation_WithFPROnChildRegion() {
try {
member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("Customer100", true, 2);
List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
fpaList.add(fpa1);
member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Customer", fpaList, 0, 40, 8, null, null, false));
fpa1 = FixedPartitionAttributes.createFixedPartition("Order100", true, 2);
fpaList.clear();
fpaList.add(fpa1);
member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Order", fpaList, 0, 40, 8, null, "Customer", false));
fail("IllegalStateException expected");
} catch (Exception illegal) {
if (!((illegal.getCause() instanceof IllegalStateException) && (illegal.getCause().getMessage().contains("not be specified in PartitionAttributesFactory if colocated-with is specified")))) {
Assert.fail("Expected IllegalStateException ", illegal);
}
}
}
Aggregations