use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.
the class FixedPartitioningWithColocationAndPersistenceDUnitTest method testFPR_Persistence.
/**
* Tests validate the behavior of FPR with persistence when all members goes down and comes up.
*
*/
@Test
public void testFPR_Persistence() {
member1.invoke(() -> FixedPartitioningTestBase.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.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, true));
member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter2, true, 3);
fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter1, false, 3);
fpaList.clear();
fpaList.add(fpa1);
fpaList.add(fpa2);
member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, true));
member1.invoke(() -> FixedPartitioningTestBase.putForQuarter("Quarter", "Q1"));
member1.invoke(() -> FixedPartitioningTestBase.putForQuarter("Quarter", "Q2"));
member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryDataPersistence(Quarter1));
member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryDataPersistence(Quarter2));
member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(6, 3));
member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(6, 3));
member1.invoke(() -> FixedPartitioningTestBase.closeCache());
member2.invoke(() -> FixedPartitioningTestBase.closeCache());
member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter2, true, 3);
fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter1, false, 3);
fpaList.clear();
fpaList.add(fpa1);
fpaList.add(fpa2);
member2.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, true));
Wait.pause(4000);
member2.invoke(() -> FixedPartitioningTestBase.getForQuarter("Quarter", Quarter1));
member2.invoke(() -> FixedPartitioningTestBase.getForQuarter("Quarter", Quarter2));
member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryDataPersistence(Quarter2));
Wait.pause(2000);
member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(6, 6));
member1.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
fpa1 = FixedPartitionAttributes.createFixedPartition(Quarter1, true, 3);
fpa2 = FixedPartitionAttributes.createFixedPartition(Quarter2, false, 3);
fpaList.clear();
fpaList.add(fpa1);
fpaList.add(fpa2);
member1.invoke(() -> FixedPartitioningTestBase.createRegionWithPartitionAttributes("Quarter", fpaList, 1, 40, 12, new QuarterPartitionResolver(), null, true));
Wait.pause(4000);
member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryDataPersistence(Quarter1));
member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryDataPersistence(Quarter2));
member1.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(6, 3));
member2.invoke(() -> FixedPartitioningTestBase.checkPrimaryBucketsForQuarter(6, 3));
member1.invoke(() -> FixedPartitioningTestBase.getForQuarter("Quarter", Quarter1));
member2.invoke(() -> FixedPartitioningTestBase.getForQuarter("Quarter", Quarter2));
}
use of org.apache.geode.cache.FixedPartitionAttributes in project geode by apache.
the class FixedPartitioningWithColocationAndPersistenceDUnitTest method testColocation_FPR_Persistence_Colocation.
/**
* Tests validate the behavior of FPR with persistence and with colocation when all members goes
* down and comes up.
*
*/
@Test
public void testColocation_FPR_Persistence_Colocation() {
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_Persistence("Customer"));
member1.invoke(() -> FixedPartitioningTestBase.putOrderPartitionedRegion_Persistence("Order"));
member1.invoke(() -> FixedPartitioningTestBase.putShipmentPartitionedRegion_Persistence("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"));
member1.invoke(() -> FixedPartitioningTestBase.closeCache());
member2.invoke(() -> FixedPartitioningTestBase.closeCache());
member2.invoke(() -> FixedPartitioningTestBase.createCacheOnMember());
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));
Wait.pause(4000);
member2.invoke(() -> FixedPartitioningTestBase.getForColocation("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_ChildUsingAttributesOfParent_HA.
@Test
public void testColocation_FPR_Persistence_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, true));
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, true));
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, true));
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 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);
}
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);
}
}
Aggregations