Search in sources :

Example 11 with PartitionRebalanceDetailsImpl

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;
}
Also used : PartitionRebalanceDetailsImpl(org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl)

Example 12 with PartitionRebalanceDetailsImpl

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;
}
Also used : PartitionRebalanceDetailsImpl(org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl)

Example 13 with PartitionRebalanceDetailsImpl

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());
}
Also used : PartitionRebalanceDetailsImpl(org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 14 with PartitionRebalanceDetailsImpl

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);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ResourceManagerStats(org.apache.geode.internal.cache.control.ResourceManagerStats) Matchers.anyLong(org.mockito.Matchers.anyLong) PartitionRebalanceDetailsImpl(org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl) Before(org.junit.Before)

Example 15 with PartitionRebalanceDetailsImpl

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());
}
Also used : PartitionRebalanceDetailsImpl(org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

PartitionRebalanceDetailsImpl (org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl)15 UnitTest (org.apache.geode.test.junit.categories.UnitTest)8 Test (org.junit.Test)8 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)4 BucketOperatorWrapper (org.apache.geode.internal.cache.partitioned.rebalance.BucketOperatorWrapper)3 CancelException (org.apache.geode.CancelException)2 PartitionRebalanceInfo (org.apache.geode.cache.partition.PartitionRebalanceInfo)2 InternalCache (org.apache.geode.internal.cache.InternalCache)2 InternalResourceManager (org.apache.geode.internal.cache.control.InternalResourceManager)2 Completion (org.apache.geode.internal.cache.partitioned.rebalance.BucketOperator.Completion)2 ParallelBucketOperator (org.apache.geode.internal.cache.partitioned.rebalance.ParallelBucketOperator)2 PartitionedRegionLoadModel (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 MembershipListener (org.apache.geode.distributed.internal.MembershipListener)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 RecoveryLock (org.apache.geode.internal.cache.PartitionedRegion.RecoveryLock)1 ResourceManagerStats (org.apache.geode.internal.cache.control.ResourceManagerStats)1