geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ash...@apache.org
Subject [2/2] incubator-geode git commit: GEODE-124: Add logic to compute getTotalSize
Date Mon, 27 Jul 2015 19:17:34 GMT
GEODE-124: Add logic to compute getTotalSize

getTotalSize collects current size of a partitioned region on all members. The
sum of these sizes is used to check if rebalance is needed.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/d307eda9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/d307eda9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/d307eda9

Branch: refs/heads/feature/GEODE-124
Commit: d307eda9253e9d8929806f5421ef12059eed71eb
Parents: a0ada76
Author: Ashvin Agrawal <ashvin@apache.org>
Authored: Mon Jul 27 10:02:24 2015 -0700
Committer: Ashvin Agrawal <ashvin@apache.org>
Committed: Mon Jul 27 10:02:24 2015 -0700

----------------------------------------------------------------------
 .../gemfire/cache/util/AutoBalancer.java        |  21 +++-
 .../cache/util/AutoBalancerJUnitTest.java       | 103 ++++++++++++++++++-
 2 files changed, 117 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d307eda9/gemfire-rebalancer/src/main/java/com/gemstone/gemfire/cache/util/AutoBalancer.java
----------------------------------------------------------------------
diff --git a/gemfire-rebalancer/src/main/java/com/gemstone/gemfire/cache/util/AutoBalancer.java
b/gemfire-rebalancer/src/main/java/com/gemstone/gemfire/cache/util/AutoBalancer.java
index decbd89..1de7031 100644
--- a/gemfire-rebalancer/src/main/java/com/gemstone/gemfire/cache/util/AutoBalancer.java
+++ b/gemfire-rebalancer/src/main/java/com/gemstone/gemfire/cache/util/AutoBalancer.java
@@ -2,6 +2,7 @@ package com.gemstone.gemfire.cache.util;
 
 import java.util.Date;
 import java.util.Properties;
+import java.util.Set;
 import java.util.concurrent.CancellationException;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
@@ -17,9 +18,13 @@ import com.gemstone.gemfire.cache.Declarable;
 import com.gemstone.gemfire.cache.GemFireCache;
 import com.gemstone.gemfire.cache.control.RebalanceOperation;
 import com.gemstone.gemfire.cache.control.RebalanceResults;
+import com.gemstone.gemfire.cache.partition.PartitionMemberInfo;
 import com.gemstone.gemfire.distributed.DistributedLockService;
 import com.gemstone.gemfire.distributed.internal.locks.DLockService;
 import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
+import com.gemstone.gemfire.internal.cache.PartitionedRegion;
+import com.gemstone.gemfire.internal.cache.partitioned.InternalPRInfo;
+import com.gemstone.gemfire.internal.cache.partitioned.LoadProbe;
 import com.gemstone.gemfire.internal.logging.LogService;
 
 /**
@@ -271,8 +276,20 @@ public class AutoBalancer implements Declarable {
   static class GeodeCacheFacade implements CacheOperationFacade {
     @Override
     public long getTotalDataSize() {
-      // TODO Auto-generated method stub
-      return getTotalTransferSize();
+      long totalSize = 0;
+      GemFireCacheImpl cache = getCache();
+      for (PartitionedRegion region : cache.getPartitionedRegions()) {
+        LoadProbe probe = cache.getResourceManager().getLoadProbe();
+        InternalPRInfo info = region.getRedundancyProvider().buildPartitionedRegionInfo(true,
probe);
+        Set<PartitionMemberInfo> membersInfo = info.getPartitionMemberInfo();
+        for (PartitionMemberInfo member : membersInfo) {
+          if (logger.isDebugEnabled()) {
+            logger.debug("Region:{}, Member: {}, Size: {}", region.getFullPath(), member,
member.getSize());
+          }
+          totalSize += member.getSize();
+        }
+      }
+      return totalSize;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d307eda9/gemfire-rebalancer/src/test/java/com/gemstone/gemfire/cache/util/AutoBalancerJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-rebalancer/src/test/java/com/gemstone/gemfire/cache/util/AutoBalancerJUnitTest.java
b/gemfire-rebalancer/src/test/java/com/gemstone/gemfire/cache/util/AutoBalancerJUnitTest.java
index 90ddbc3..888ea20 100644
--- a/gemfire-rebalancer/src/test/java/com/gemstone/gemfire/cache/util/AutoBalancerJUnitTest.java
+++ b/gemfire-rebalancer/src/test/java/com/gemstone/gemfire/cache/util/AutoBalancerJUnitTest.java
@@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.ByteArrayInputStream;
+import java.util.HashSet;
 import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -27,6 +28,7 @@ import com.gemstone.gemfire.cache.CacheFactory;
 import com.gemstone.gemfire.cache.control.RebalanceFactory;
 import com.gemstone.gemfire.cache.control.RebalanceOperation;
 import com.gemstone.gemfire.cache.control.RebalanceResults;
+import com.gemstone.gemfire.cache.partition.PartitionMemberInfo;
 import com.gemstone.gemfire.cache.util.AutoBalancer.AuditScheduler;
 import com.gemstone.gemfire.cache.util.AutoBalancer.CacheOperationFacade;
 import com.gemstone.gemfire.cache.util.AutoBalancer.GeodeCacheFacade;
@@ -36,7 +38,11 @@ import com.gemstone.gemfire.cache.util.AutoBalancer.TimeProvider;
 import com.gemstone.gemfire.distributed.DistributedLockService;
 import com.gemstone.gemfire.distributed.internal.locks.DLockService;
 import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
+import com.gemstone.gemfire.internal.cache.PRHARedundancyProvider;
+import com.gemstone.gemfire.internal.cache.PartitionedRegion;
 import com.gemstone.gemfire.internal.cache.control.InternalResourceManager;
+import com.gemstone.gemfire.internal.cache.partitioned.InternalPRInfo;
+import com.gemstone.gemfire.internal.cache.partitioned.LoadProbe;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
@@ -570,7 +576,7 @@ public class AutoBalancerJUnitTest {
   public void testFacadeTotalTransferSize() throws Exception {
     assertEquals(12345, getFacadeForResourceManagerOps(true).getTotalTransferSize());
   }
-  
+
   @Test
   public void testFacadeRebalance() throws Exception {
     getFacadeForResourceManagerOps(false).rebalance();
@@ -582,7 +588,7 @@ public class AutoBalancerJUnitTest {
     final RebalanceFactory mockRebalanceFactory = mockContext.mock(RebalanceFactory.class);
     final RebalanceOperation mockRebalanceOperation = mockContext.mock(RebalanceOperation.class);
     final RebalanceResults mockRebalanceResults = mockContext.mock(RebalanceResults.class);
-    
+
     mockContext.checking(new Expectations() {
       {
         oneOf(mockCache).getResourceManager();
@@ -604,17 +610,104 @@ public class AutoBalancerJUnitTest {
         allowing(mockRebalanceResults);
       }
     });
-    
+
     GeodeCacheFacade facade = new GeodeCacheFacade() {
       @Override
       GemFireCacheImpl getCache() {
         return mockCache;
       }
     };
-    
+
     return facade;
   }
-  
+
+  @Test
+  public void testFacadeTotalBytesNoRegion() {
+    final GemFireCacheImpl mockCache = mockContext.mock(GemFireCacheImpl.class);
+    mockContext.checking(new Expectations() {
+      {
+        oneOf(mockCache).getPartitionedRegions();
+        will(returnValue(new HashSet<PartitionedRegion>()));
+      }
+    });
+
+    GeodeCacheFacade facade = new GeodeCacheFacade() {
+      @Override
+      GemFireCacheImpl getCache() {
+        return mockCache;
+      }
+    };
+
+    assertEquals(0, facade.getTotalDataSize());
+  }
+
+  @Test
+  public void testFacadeTotalBytes2Regions() {
+    cache = createBasicCache();
+
+    final GemFireCacheImpl mockCache = mockContext.mock(GemFireCacheImpl.class);
+
+    final PartitionedRegion mockR1 = mockContext.mock(PartitionedRegion.class, "r1");
+    final PartitionedRegion mockR2 = mockContext.mock(PartitionedRegion.class, "r2");
+    final HashSet<PartitionedRegion> regions = new HashSet<>();
+    regions.add(mockR1);
+    regions.add(mockR2);
+
+    final PRHARedundancyProvider mockRedundancyProviderR1 = mockContext.mock(PRHARedundancyProvider.class,
"prhaR1");
+    final InternalPRInfo mockR1PRInfo = mockContext.mock(InternalPRInfo.class, "prInforR1");
+    final PartitionMemberInfo mockR1M1Info = mockContext.mock(PartitionMemberInfo.class,
"r1M1");
+    final PartitionMemberInfo mockR1M2Info = mockContext.mock(PartitionMemberInfo.class,
"r1M2");
+    final HashSet<PartitionMemberInfo> r1Members = new HashSet<>();
+    r1Members.add(mockR1M1Info);
+    r1Members.add(mockR1M2Info);
+
+    final PRHARedundancyProvider mockRedundancyProviderR2 = mockContext.mock(PRHARedundancyProvider.class,
"prhaR2");
+    final InternalPRInfo mockR2PRInfo = mockContext.mock(InternalPRInfo.class, "prInforR2");
+    final PartitionMemberInfo mockR2M1Info = mockContext.mock(PartitionMemberInfo.class,
"r2M1");
+    final HashSet<PartitionMemberInfo> r2Members = new HashSet<>();
+    r2Members.add(mockR2M1Info);
+
+    mockContext.checking(new Expectations() {
+      {
+        oneOf(mockCache).getPartitionedRegions();
+        will(returnValue(regions));
+        exactly(2).of(mockCache).getResourceManager();
+        will(returnValue(cache.getResourceManager()));
+        allowing(mockR1).getFullPath();
+        oneOf(mockR1).getRedundancyProvider();
+        will(returnValue(mockRedundancyProviderR1));
+        allowing(mockR2).getFullPath();
+        oneOf(mockR2).getRedundancyProvider();
+        will(returnValue(mockRedundancyProviderR2));
+
+        oneOf(mockRedundancyProviderR1).buildPartitionedRegionInfo(with(true), with(any(LoadProbe.class)));
+        will(returnValue(mockR1PRInfo));
+        oneOf(mockR1PRInfo).getPartitionMemberInfo();
+        will(returnValue(r1Members));
+        atLeast(1).of(mockR1M1Info).getSize();
+        will(returnValue(123L));
+        atLeast(1).of(mockR1M2Info).getSize();
+        will(returnValue(74L));
+
+        oneOf(mockRedundancyProviderR2).buildPartitionedRegionInfo(with(true), with(any(LoadProbe.class)));
+        will(returnValue(mockR2PRInfo));
+        oneOf(mockR2PRInfo).getPartitionMemberInfo();
+        will(returnValue(r2Members));
+        atLeast(1).of(mockR2M1Info).getSize();
+        will(returnValue(3475L));
+      }
+    });
+
+    GeodeCacheFacade facade = new GeodeCacheFacade() {
+      @Override
+      GemFireCacheImpl getCache() {
+        return mockCache;
+      }
+    };
+
+    assertEquals(123 + 74 + 3475, facade.getTotalDataSize());
+  }
+
   private Properties getBasicConfig() {
     Properties props = new Properties();
     // every second schedule


Mime
View raw message