use of org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl in project geode by apache.
the class BucketOperatorWrapper method moveBucket.
@Override
public boolean moveBucket(InternalDistributedMember sourceMember, InternalDistributedMember targetMember, int id, Map<String, Long> colocatedRegionBytes) {
long start = System.nanoTime();
boolean result = false;
long elapsed = 0;
long totalBytes = 0;
if (stats != null) {
stats.startBucketTransfer(regionCount);
}
try {
result = delegate.moveBucket(sourceMember, targetMember, id, colocatedRegionBytes);
elapsed = System.nanoTime() - start;
if (result) {
if (logger.isDebugEnabled()) {
logger.debug("Rebalancing {} bucket {} moved from {} to {}", leaderRegion, id, sourceMember, targetMember);
}
for (PartitionRebalanceDetailsImpl details : detailSet) {
String regionPath = details.getRegionPath();
Long regionBytes = colocatedRegionBytes.get(regionPath);
if (regionBytes != null) {
// only increment the elapsed time for the leader region
details.incTransfers(regionBytes.longValue(), details.getRegion().equals(leaderRegion) ? elapsed : 0);
totalBytes += regionBytes.longValue();
}
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Rebalancing {} bucket {} moved failed from {} to {}", leaderRegion, id, sourceMember, targetMember);
}
}
} finally {
if (stats != null) {
stats.endBucketTransfer(regionCount, result, totalBytes, elapsed);
}
}
return result;
}
use of org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl in project geode by apache.
the class BucketOperatorWrapper method movePrimary.
@Override
public boolean movePrimary(InternalDistributedMember source, InternalDistributedMember target, int bucketId) {
boolean result = false;
long elapsed = 0;
if (stats != null) {
stats.startPrimaryTransfer(regionCount);
}
try {
long start = System.nanoTime();
result = delegate.movePrimary(source, target, bucketId);
elapsed = System.nanoTime() - start;
if (result) {
if (logger.isDebugEnabled()) {
logger.debug("Rebalancing {} primary bucket {} moved from {} to {}", leaderRegion, bucketId, source, target);
}
for (PartitionRebalanceDetailsImpl details : detailSet) {
details.incPrimaryTransfers(details.getRegion().equals(leaderRegion) ? elapsed : 0);
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("Rebalancing {} primary bucket {} failed to move from {} to {}", leaderRegion, bucketId, source, target);
}
}
} finally {
if (stats != null) {
stats.endPrimaryTransfer(regionCount, result, elapsed);
}
}
return result;
}
use of org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl in project geode by apache.
the class BucketOperatorWrapperTest method bucketWrapperShouldRecordPrimaryTransfersPerRegionAfterMovePrimaryIsSuccessful.
@Test
public void bucketWrapperShouldRecordPrimaryTransfersPerRegionAfterMovePrimaryIsSuccessful() {
doReturn(true).when(delegate).movePrimary(sourceMember, targetMember, bucketId);
wrapper.movePrimary(sourceMember, targetMember, bucketId);
// verify the details is updated with bytes transfered
for (PartitionRebalanceDetailsImpl details : rebalanceDetails) {
if (details.getRegionPath().equalsIgnoreCase(PR_LEADER_REGION_NAME))
verify(details, times(1)).incPrimaryTransfers(anyLong());
else if (details.getRegionPath().equals(PR_COLOCATED_REGION_NAME))
// elapsed is recorded only if its leader
verify(details, times(1)).incPrimaryTransfers(0);
}
// verify we recorded necessary stats
verify(stats, times(1)).startPrimaryTransfer(anyInt());
verify(stats, times(1)).endPrimaryTransfer(anyInt(), anyBoolean(), anyLong());
}
use of org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl in project geode by apache.
the class BucketOperatorWrapperTest method setUp.
@Before
public void setUp() throws UnknownHostException {
colocatedRegionBytes = new HashMap<String, Long>();
colocatedRegionBytes.put(PR_LEADER_REGION_NAME, 100L);
colocatedRegionBytes.put(PR_COLOCATED_REGION_NAME, 50L);
sourceMember = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 1);
targetMember = new InternalDistributedMember(InetAddress.getByName("127.0.0.2"), 1);
stats = mock(ResourceManagerStats.class);
doNothing().when(stats).startBucketCreate(anyInt());
doNothing().when(stats).endBucketCreate(anyInt(), anyBoolean(), anyLong(), anyLong());
leaderRegion = mock(PartitionedRegion.class);
doReturn(PR_LEADER_REGION_NAME).when(leaderRegion).getFullPath();
colocatedRegion = mock(PartitionedRegion.class);
doReturn(PR_COLOCATED_REGION_NAME).when(colocatedRegion).getFullPath();
rebalanceDetails = new HashSet<PartitionRebalanceDetailsImpl>();
PartitionRebalanceDetailsImpl details = spy(new PartitionRebalanceDetailsImpl(leaderRegion));
rebalanceDetails.add(details);
delegate = mock(BucketOperatorImpl.class);
wrapper = new BucketOperatorWrapper(delegate, rebalanceDetails, stats, leaderRegion);
}
use of org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl in project geode by apache.
the class BucketOperatorWrapperTest method bucketWrapperShouldNotRecordPrimaryTransfersPerRegionAfterMovePrimaryFails.
@Test
public void bucketWrapperShouldNotRecordPrimaryTransfersPerRegionAfterMovePrimaryFails() {
doReturn(false).when(delegate).movePrimary(sourceMember, targetMember, bucketId);
wrapper.movePrimary(sourceMember, targetMember, bucketId);
// verify the details is not updated with bytes transfered
for (PartitionRebalanceDetailsImpl details : rebalanceDetails) {
verify(details, times(0)).incTransfers(anyLong(), anyLong());
}
// verify we recorded necessary stats
verify(stats, times(1)).startPrimaryTransfer(anyInt());
verify(stats, times(1)).endPrimaryTransfer(anyInt(), anyBoolean(), anyLong());
}
Aggregations