Java Code Examples for com.gemstone.gemfire.cache.Region#getName()

The following examples show how to use com.gemstone.gemfire.cache.Region#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SnapshotPerformanceDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private void doExport(Region<Integer, MyObject> region) throws Exception {
  File f = new File(getDiskDirs()[0], region.getName());
  
  long start = System.currentTimeMillis();
  region.getSnapshotService().save(f, SnapshotFormat.GEMFIRE);
  long elapsed = System.currentTimeMillis() - start;
  
  int size = region.size();
  long bytes = f.length();

  double eps = 1000.0 * size / elapsed;
  double mbps = 1000.0 * bytes / elapsed / (1024 * 1024);

  getLogWriter().info("SNP: Exported " + size + " entries (" + bytes + " bytes) in " + elapsed + " ms");
  getLogWriter().info("SNP: Export entry rate: " + eps + " entries / sec");
  getLogWriter().info("SNP: Export data rate: " + mbps + " MB / sec");
}
 
Example 2
Source File: SnapshotTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private static void verifyColocatedRegions(Region regionA) {
  Object[] keys = PartitionRegionHelper.getLocalPrimaryData(regionA).keySet().toArray();
  Map colocatedRegionsMap = PartitionRegionHelper.getColocatedRegions(regionA);
  Object[] regionNames = colocatedRegionsMap.keySet().toArray();
  Log.getLogWriter().info("Verifying PR " + regionA.getFullPath() + " with " + colocatedRegionsMap.size() + " colocated regions");
  for (Object regionName: regionNames) {
    Region regionB = (Region)colocatedRegionsMap.get(regionName);
    for (Object aKey: keys) {
      DistributedMember primaryA = PartitionRegionHelper.getPrimaryMemberForKey(regionA, aKey);
      DistributedMember primaryB = PartitionRegionHelper.getPrimaryMemberForKey(regionB, aKey);
      if ((primaryB != null) && !(primaryA.equals(primaryB))) {
        throw new TestException("verifyColocatedRegions reports that primary for " + aKey + " is " + primaryA + " for " + regionA.getName() + ", but the primary for the same entry in " + regionB.getName() + " is " + primaryB);
      } 
    }
    Log.getLogWriter().info("Done verifying consistency in colocated regions");
  }
}
 
Example 3
Source File: FixedPartitioningTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static void HydraTask_verifyPRMetaData() {
  //Set<Region<?, ?>> regionSet = theCache.rootRegions();
  Set<Region<?, ?>> regionSet = ((FixedPartitioningTest)testInstance)
      .getTestRegions();
  for (Region aRegion : regionSet) {
    String regionName = aRegion.getName();
    if (aRegion instanceof PartitionedRegion) {
      verifyPRMetaData(aRegion);
      Log.getLogWriter().info(
          "verified Meta Data for the region " + regionName);
    }
    else {
      Log
          .getLogWriter()
          .info(
              "The region "
                  + regionName
                  + " is not partitioned region and hence need not verify metadata");
    }
  }
}
 
Example 4
Source File: SnapshotPerformanceDUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private void doImport(Region<Integer, MyObject> region) throws Exception {
  File f = new File(getDiskDirs()[0], region.getName());
  
  long start = System.currentTimeMillis();
  region.getSnapshotService().load(f, SnapshotFormat.GEMFIRE);
  long elapsed = System.currentTimeMillis() - start;
  
  int size = region.size();
  long bytes = f.length();
  
  double eps = 1000.0 * size / elapsed;
  double mbps = 1000.0 * bytes / elapsed / (1024 * 1024);

  getLogWriter().info("SNP: Imported " + size + " entries (" + bytes + " bytes) in " + elapsed + " ms");
  getLogWriter().info("SNP: Import entry rate: " + eps + " entries / sec");
  getLogWriter().info("SNP: Import data rate: " + mbps + " MB / sec");
}
 
Example 5
Source File: RegionUtil.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void checkRegionKeyDoesNotExistsValueDoesNotExists(Region r, Object key) {
  if (HydraUtil.isSerialTest()) {
    if (r.containsKey(key)) {
      throw new TestException("Region " + r.getName() + " contains key " + key + " but was destroyed before");
    }

    if (!r.containsValueForKey(key)) {
      return;
    } else {
      throw new TestException("Region " + r.getName() + " contains value for " + key
          + " but was destroyed/invalidated before");
    }
  }
}
 
Example 6
Source File: RegionUtil.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void checkRegionValueDoesNotExists(Region r, Object key) {
  if (HydraUtil.isSerialTest()) {
    if (!r.containsValueForKey(key)) {
      return;
    } else {
      throw new TestException("Region " + r.getName() + " contains value for " + key + " but was invalidated before");
    }
  }
}
 
Example 7
Source File: RegionOperations.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void _clearedRegion(Region region) {
  if (region != null) {
    String name = region.getName();
    String callback = callback("RegionOperations: Clearing region" + name + " in ");
    logInfo(callback);
    try {
      region.clear();
      operationRecorder.regionCleared(name);
    } catch (Exception e) {
      handleException("RegionOperationError : clearedRegion", e, region);
    }
  } else {
    logInfo("No region Found continuing test list : " + availableRegions);
  }
}
 
Example 8
Source File: RegionOperations.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void _invalidateRegion(Region region) {
  if (region != null) {
    String name = region.getName();
    logInfo("RegionOperations: Invalidating region named : " + name);
    String callback = callback("Invalidating region" + name + " in ");
    try {
      region.invalidateRegion(callback);
      operationRecorder.regionInvalidated(name);
    } catch (Exception e) {
      handleException("RegionOperationError : invalidateRegion", e, region);
    }
  } else {
    logInfo("No region Found continuing test list : " + availableRegions);
  }
}
 
Example 9
Source File: FixedPartitioningTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * The method will give the primary member for the buckets of primary
 * partitions of the crashed member. This method will also verify that only
 * one member will always host the primary buckets of a partition.
 * 
 * @param crashedOrRecycledVm -
 *                ClientVMInfo of the crashed/recycled Member
 * @return InternalDistributedMember of the primary node for the primary
 *         partitions of crashed/recycled member.
 * 
 * TODO Aneesh: This method is valid if each member have only one primary
 * partition max.
 */
public InternalDistributedMember getPrimaryOwner(
    ClientVmInfo crashedOrRecycledVm) {
  hydra.MasterController.sleepForMs(30000);
  int targetVmId = crashedOrRecycledVm.getVmid();
  Map vmInfo = (Map)ParRegBB.getBB().getSharedMap().get(targetVmId);
  List<Integer> primaryBucketsOnVm = (List<Integer>)vmInfo
      .get(PRIMARY_BUCKETS);
  InternalDistributedMember newMember = null;

  //Set<Region<?, ?>> regionSet = theCache.rootRegions();
  Set<Region<?, ?>> regionSet = ((FixedPartitioningTest)testInstance)
      .getTestRegions();
  for (Region aRegion : regionSet) {
    PartitionedRegion pr = (PartitionedRegion)aRegion;
    HashSet memberSet = new HashSet();

    for (int bucketId : primaryBucketsOnVm) {
      newMember = pr.getBucketPrimary(bucketId);
      hydra.Log.getLogWriter().info("For the bucketId "+bucketId+" the primary member is "+newMember);
      memberSet.add(newMember);
    }

    // Verify that only one member holds primary status of buckets of primary
    // partition
    if (memberSet.size() != 1) {
      throw new TestException("For the recycled vm "
          + crashedOrRecycledVm.getVmid() + " primary buckets "
          + primaryBucketsOnVm + " for the region " + aRegion.getName()
          + " is hosted by " + memberSet.size() + " members - " + memberSet);
    }
  }
  return newMember;
}
 
Example 10
Source File: GfxdCacheLoader.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private GfxdCacheLoader getRowLoaderFromRegion(Region<?, ?> region) {
  Object ldr = region.getAttributes().getCacheLoader();
  if (ldr instanceof GfxdCacheLoader) {
    return (GfxdCacheLoader)ldr;
  }
  throw new IllegalStateException("Expected a GfxdCacheLoader in region: "
      + region.getName());
}
 
Example 11
Source File: QueryPerfClient.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
protected List<Integer> getPrimaryBucketList(String tableName) {
  for (PartitionRegionInfo pri :
       PartitionRegionHelper.getPartitionRegionInfo(CacheHelper.getCache())) {
    String regionPath = pri.getRegionPath();
    if (regionPath.contains(tableName)) {
      Log.getLogWriter().info("Region path is " + regionPath);
      Region region = CacheHelper.getCache().getRegion(regionPath);
      String regionName = region.getName();
      Log.getLogWriter().info("Region name is " + regionName);
      return (List<Integer>)((PartitionedRegion)region).getLocalPrimaryBucketsListTestOnly();
    }
  }
  return null;
}
 
Example 12
Source File: RegionUtil.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void checkRegionKeyDoesNotExistsValueDoesNotExists(Region r, Object key) {
  if (HydraUtil.isSerialTest()) {
    if (r.containsKey(key)) {
      throw new TestException("Region " + r.getName() + " contains key " + key + " but was destroyed before");
    }

    if (!r.containsValueForKey(key)) {
      return;
    } else {
      throw new TestException("Region " + r.getName() + " contains value for " + key
          + " but was destroyed/invalidated before");
    }
  }
}
 
Example 13
Source File: RegionUtil.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void checkRegionValueDoesNotExists(Region r, Object key) {
  if (HydraUtil.isSerialTest()) {
    if (!r.containsValueForKey(key)) {
      return;
    } else {
      throw new TestException("Region " + r.getName() + " contains value for " + key + " but was invalidated before");
    }
  }
}
 
Example 14
Source File: FixedPartitioningTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * The method will give the primary member for the buckets of primary
 * partitions of the crashed member. This method will also verify that only
 * one member will always host the primary buckets of a partition.
 * 
 * @param crashedOrRecycledVm -
 *                ClientVMInfo of the crashed/recycled Member
 * @return InternalDistributedMember of the primary node for the primary
 *         partitions of crashed/recycled member.
 * 
 * TODO Aneesh: This method is valid if each member have only one primary
 * partition max.
 */
public InternalDistributedMember getPrimaryOwner(
    ClientVmInfo crashedOrRecycledVm) {
  hydra.MasterController.sleepForMs(30000);
  int targetVmId = crashedOrRecycledVm.getVmid();
  Map vmInfo = (Map)ParRegBB.getBB().getSharedMap().get(targetVmId);
  List<Integer> primaryBucketsOnVm = (List<Integer>)vmInfo
      .get(PRIMARY_BUCKETS);
  InternalDistributedMember newMember = null;

  //Set<Region<?, ?>> regionSet = theCache.rootRegions();
  Set<Region<?, ?>> regionSet = ((FixedPartitioningTest)testInstance)
      .getTestRegions();
  for (Region aRegion : regionSet) {
    PartitionedRegion pr = (PartitionedRegion)aRegion;
    HashSet memberSet = new HashSet();

    for (int bucketId : primaryBucketsOnVm) {
      newMember = pr.getBucketPrimary(bucketId);
      hydra.Log.getLogWriter().info("For the bucketId "+bucketId+" the primary member is "+newMember);
      memberSet.add(newMember);
    }

    // Verify that only one member holds primary status of buckets of primary
    // partition
    if (memberSet.size() != 1) {
      throw new TestException("For the recycled vm "
          + crashedOrRecycledVm.getVmid() + " primary buckets "
          + primaryBucketsOnVm + " for the region " + aRegion.getName()
          + " is hosted by " + memberSet.size() + " members - " + memberSet);
    }
  }
  return newMember;
}
 
Example 15
Source File: SerialCompressionTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 *
 */
private void compressionStats() {
  StringBuilder errorString = new StringBuilder();
  String regionName;
  Compressor compressor;
  CachePerfStats regionPerfStats;
  DataPolicy dataPolicy;
  long totalPreCompressedBytes;
  long totalCompressionTime;
  long totalCompressions;
  long totalPostCompressedBytes;
  long totalDecompressionTime;
  long totalDecompressions;
  for (Region aRegion : theRegions) {
    regionName = aRegion.getName();
    Log.getLogWriter().info("MDP-S-SerialCompressionTest.stats regionName = " + regionName);

    RegionAttributes attributes = aRegion.getAttributes();
    compressor = attributes.getCompressor();
    Log.getLogWriter().info("MDP-S-  Compressor=" + (compressor == null ? null : compressor.getClass().getName()));

    regionPerfStats = ((LocalRegion) aRegion).getRegionPerfStats();
    if (regionPerfStats == null) {
      continue;
    }
    totalPreCompressedBytes = regionPerfStats.getTotalPreCompressedBytes();
    totalCompressionTime = regionPerfStats.getTotalCompressionTime();
    totalCompressions = regionPerfStats.getTotalCompressions();
    totalPostCompressedBytes = regionPerfStats.getTotalPostCompressedBytes();
    totalDecompressionTime = regionPerfStats.getTotalDecompressionTime();
    totalDecompressions = regionPerfStats.getTotalDecompressions();
    Log.getLogWriter().info("\n        totalPreCompressedBytes   = " + totalPreCompressedBytes +
                            "\n        totalCompressionTime   = " + totalCompressionTime/1000000000d + " (sec)" +
                            "\nMDP-S-  totalCompressions      = " + totalCompressions +
                            "\n        totalPostCompressedBytes = " + totalPostCompressedBytes +
                            "\n        totalDecompressionTime = " + totalDecompressionTime/1000000000d + " (sec)" +
                            "\n        totalDecompressions    = " + totalDecompressions);

    dataPolicy = attributes.getDataPolicy();
    Log.getLogWriter().info("MDP-S-SerialCompressionTest.stats dataPolicy=" + dataPolicy);
    if (dataPolicy.equals(DataPolicy.EMPTY) || compressor == null) {
      if (totalCompressions != 0) {
        errorString.append("The total number of compressions for the region '" + regionName + "' should be zero.\n");
      }
      if (totalPreCompressedBytes != 0) {
        errorString.append("The total number of pre-compressed bytes for the region '" + regionName + "' should be zero.\n");
      }
      if (totalCompressionTime != 0) {
        errorString.append("The total compression time for the region '" + regionName + "' should be zero.\n");
      }
      if (totalDecompressions != 0) {
        errorString.append("The total number of decompressions for the region '" + regionName + "' should be zero.\n");
      }
      if (totalPostCompressedBytes != 0) {
        errorString.append("The total number of post-decompressed bytes for the region '" + regionName + "' should be zero.\n");
      }
      if (totalDecompressionTime != 0) {
        errorString.append("The total decompression time for the region '" + regionName + "' should be zero.\n");
      }
    } else {
      if (totalCompressions <= 0) {
        errorString.append("The total number of compressions for the region '" + regionName + "' should be greater than zero.\n");
      }
      if (totalPreCompressedBytes <= 0) {
        errorString.append("The total number of pre-compressed bytes for the region '" + regionName + "' should be greater than zero.\n");
      }
      if (totalCompressionTime <= 0) {
        errorString.append("The total compression time for the region '" + regionName + "' should be greater than zero.\n");
      }
      if (totalDecompressions <= 0) {
        errorString.append("The total number of decompressions for the region '" + regionName + "' should be greater than zero.\n");
      }
      if (totalPostCompressedBytes <= 0) {
        errorString.append("The total number of post-decompressed bytes for the region '" + regionName + "' should be greater than zero.\n");
      }
      if (totalDecompressionTime <= 0) {
        errorString.append("The total decompression time for the region '" + regionName + "' should be greater than zero.\n");
      }
    }
  }
  if (errorString.length() > 0) {
    throw new TestException("MDP9-Fail! There is a problem with the compression statistics.\n" + errorString.toString());
  }
}
 
Example 16
Source File: ParRegColocation.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Task that does the verification of region size
 * 
 * @param aRegion
 *                Region whose size is to be verified
 */
protected void verifyRegionSize(Region aRegion) {
  // we already completed this check once; we can't do it again without
  // reinitializing the
  // verify state variables

  int size = aRegion.size();
  long numOriginalKeysCreated = InitImageBB.getBB().getSharedCounters().read(
      InitImageBB.NUM_ORIGINAL_KEYS_CREATED);
  int numKeysToCreate = keyIntervals.getNumKeys();
  long nameCounter = NameFactory.getPositiveNameCounter();
  Log.getLogWriter().info(
      "In HydraTask_verifyRegionSize, region size is " + size
          + ", numKeysToCreate is " + numKeysToCreate
          + ", numOriginalKeysCreated is " + numOriginalKeysCreated
          + ", nameCounter is " + nameCounter);

  // make sure the test agrees with itself
  if ((numOriginalKeysCreated != numKeysToCreate)
      || (numOriginalKeysCreated != nameCounter)) {
    throw new TestException("Error in test, numOriginalKeysCreated "
        + numOriginalKeysCreated + ", numKeysToCreate " + numKeysToCreate
        + ", nameCounter " + nameCounter);
  }

  int verifyRegionSizeIndex = 0;
  while (verifyRegionSizeIndex < numKeysToCreate) {
    verifyRegionSizeIndex++;
    Object key = NameFactory.getObjectNameForCounter(verifyRegionSizeIndex);
    Log.getLogWriter().info(
        "For region : " + aRegion.getName()
            + " : Key : " + key);
    if (!aRegion.containsKey(key))
      throw new TestException("Key " + key + " not found in the region "
          + aRegion.getName());
    if (!aRegion.containsValueForKey(key))
      throw new TestException("For the key " + key
          + " value is not found in the region " + aRegion.getName());
  }

  if (size != numKeysToCreate) {
    throw new TestException("Unexpected region size " + size + "; expected "
        + numKeysToCreate);
  }
  String aStr = "In HydraTask_verifyRegionSize, verified "
      + verifyRegionSizeIndex + " keys and values";
  Log.getLogWriter().info(aStr);
}
 
Example 17
Source File: RegionTestMBean.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void destroyRegion(JMXOperations ops, ObjectName targetMbean)throws IOException{
  logInfo(prefix + " Calling destroyRegion");
  RegionOperations regionOps = JMXTest.getRegionOperations();
  List<String> regions = RegionEvents.getAllRegions(RemoteTestModule.getMyClientName());
  List deletedRegions = JMXBlackboard.getBB().getList(JMXBlackboard.REGION_DELETE_LIST);
  //Set<Region> regions = regionOps.getAvailableRegions();
  logInfo(prefix + " Regions Created in this VM : " + regions);
  logInfo(prefix + " Regions Deleted in all VMs : " + deletedRegions);
  
  Region regionToDelete = null;
  for(int i=0;i<regions.size();i++){
    regionToDelete = RegionHelper.getRegion(regions.get(i));
    if(regionToDelete!=null && !deletedRegions.equals(regionToDelete))
      break;
  }
  if(regionToDelete!=null){
    String name = regionToDelete.getName();
    String regionPath = regionToDelete.getFullPath();
    regionOps.destroyRegion(regionToDelete);
    JMXBlackboard.getBB().addToList(JMXBlackboard.REGION_DELETE_LIST, regionPath);
    logInfo(prefix + " Finished with destroying region named " + name + " adding a notif expectation");
    addRegionDestroyNotificationExp(regionPath);
    logInfo(prefix + " Waiting for sleepReplication");
    HydraUtil.sleepForReplicationJMX();      
    DistributedMember distributedMember = InternalDistributedSystem.getConnectedInstance().getDistributedMember();
    ObjectName regionName = JMXTest.getManagementService().getRegionMBeanName(distributedMember, regionPath);
    ObjectName distributedRegionName = MBeanJMXAdapter.getDistributedRegionMbeanName(regionPath);
    String url = ops.selectManagingNode();
    MBeanServerConnection server = ManagementUtil.connectToUrlOrGemfireProxy(url);
    logInfo(prefix + " Checking for " + regionPath + " MBeans at node " + url);
    targetMbean = regionName;
    if (ManagementUtil.checkIfMBeanExists(server, targetMbean))
      throw new TestException("Proxy to " + targetMbean + " is stil present at " + url);
    
    targetMbean = distributedRegionName;
    if (ManagementUtil.checkIfMBeanExists(server, targetMbean))
      throw new TestException("Proxy to " + targetMbean + " is stil present at " + url);
    
  }else{
    throw new TestException("No Regions found in this VM for destoroRegion Test case");
  }
  logInfo(prefix + " Completed destroyRegion test successfully");
}
 
Example 18
Source File: ParRegExpirationTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Controls the thread that has an expiration action set in the entry for
 * region IdleTOInval (custom expiry)
 */
public void customEntryIdleTODestroy() {
  String regionName = regionNames[CustomIdleTODestroyIndex];
  Region aRegion = CacheHelper.getCache().getRegion(regionName);

  String expiryKeyPrefix = "Expire_" + regionName + "_";
  int expireNumKeys = populateRegion(aRegion, expiryKeyPrefix);
  Object expireKey = regionName + "_expireNumKeys";
  Log.getLogWriter().info(
      "Putting " + expireKey + ", " + expireNumKeys + " into ExpirationBB");
  ExpirationBB.getBB().getSharedMap().put(expireKey,
      new Integer(expireNumKeys));

  String noExpiryKeyPrefix = "NotExpire_" + regionName + "_";
  int noExpireNumKeys = populateRegion(aRegion, noExpiryKeyPrefix);
  Object noExpireKey = regionName + "_noExpireNumKeys";
  Log.getLogWriter().info(
      "Putting " + noExpireKey + ", " + noExpireNumKeys
          + " into ExpirationBB");
  ExpirationBB.getBB().getSharedMap().put(noExpireKey,
      new Integer(noExpireNumKeys));

  
  int expectedVmsForEvents = 1;

  if (TestConfig.tab()
      .booleanAt(ExpirPrms.isBridgeClientConfiguration, false)) {
    expectedVmsForEvents = TestConfig.tab().intAt(ExpirPrms.numClientVms) + 1;
  }

  // Wait for this VM to receive all create events
  TestHelper.waitForCounter(ParRegExpirationBB.getBB(),
      "numAfterCreateEvents_CustomExpiryIdleTODestroy",
      ParRegExpirationBB.numAfterCreateEvents_CustomExpiryIdleTODestroy,
      expireNumKeys * expectedVmsForEvents, true, 600000);

  TestHelper.waitForCounter(ParRegExpirationBB.getBB(),
      "numAfterCreateEvents_CustomNoExpiryIdleTODestroy",
      ParRegExpirationBB.numAfterCreateEvents_CustomNoExpiryIdleTODestroy,
      noExpireNumKeys * expectedVmsForEvents, true, 600000);

  ParRegExpirationBB.getBB().getSharedCounters().increment(
      ParRegExpirationBB.numPopulationTask_Completed);

  // Wait for this VM to receive all invalidate events
  TestHelper.waitForCounter(ParRegExpirationBB.getBB(),
      "numAfterDestroyEvents_CustomIdleTODestroy",
      ParRegExpirationBB.numAfterDestroyEvents_CustomIdleTODestroy,
      expireNumKeys * expectedVmsForEvents, true, 600000);

  // Check that all entries with prefix Expire_ were destroyed

  Set keySet = aRegion.keySet();

  if (keySet.size() != noExpireNumKeys) {
    throw new TestException(
        "Expected the region size after expiration to be the number of non expiry keys put into region "
            + noExpireNumKeys + " but has " + aRegion.size());
  }
  else {
    Log.getLogWriter().info(
        "Got the expected size of region after expiration as "
            + noExpireNumKeys);
  }

  Iterator iterator = keySet.iterator();
  while (iterator.hasNext()) {
    String key = iterator.next().toString();
    if (key.startsWith("Expire_")) {
      throw new TestException("Unexpected key " + key + " in the region "
          + aRegion.getName() + " after expiration");
    }
  }

  ParRegExpirationBB.getBB().printSharedCounters();
  ParRegExpirationBB.getBB().getSharedCounters().zero(
      ParRegExpirationBB.numAfterCreateEvents_CustomExpiryIdleTODestroy);
  ParRegExpirationBB.getBB().getSharedCounters().zero(
      ParRegExpirationBB.numAfterCreateEvents_CustomNoExpiryIdleTODestroy);
  ParRegExpirationBB.getBB().getSharedCounters().zero(
      ParRegExpirationBB.numAfterDestroyEvents_CustomIdleTODestroy);
}
 
Example 19
Source File: ClientMetadataService.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public ServerLocation getBucketServerLocation(Region region,
    Operation operation, Object key, Object value, Object callbackArg) {
  ClientPartitionAdvisor prAdvisor  = this.getClientPartitionAdvisor(region.getFullPath());
  if (prAdvisor == null) {
    return null;
  }
  int totalNumberOfBuckets = prAdvisor.getTotalNumBuckets();

  final PartitionResolver resolver = getResolver(region, key, callbackArg);
  Object resolveKey;
  EntryOperation entryOp = null;
  if (resolver == null) {
    // client has not registered PartitionResolver
    // Assuming even PR at server side is not using PartitionResolver
    resolveKey = key;
  }
  else {
    entryOp = new EntryOperationImpl(region, operation, key,
        value, callbackArg);
    resolveKey = resolver.getRoutingObject(entryOp);
    if (resolveKey == null) {
      throw new IllegalStateException(
          LocalizedStrings.PartitionedRegionHelper_THE_ROUTINGOBJECT_RETURNED_BY_PARTITIONRESOLVER_IS_NULL
              .toLocalizedString());
    }
  }
  int bucketId;
  if (resolver instanceof FixedPartitionResolver) {
    if (entryOp == null) {
      entryOp = new EntryOperationImpl(region,
          Operation.FUNCTION_EXECUTION, key, null, null);
    }
    String partition = ((FixedPartitionResolver)resolver).getPartitionName(
        entryOp, prAdvisor.getFixedPartitionNames());
    if (partition == null) {
      Object[] prms = new Object[] { region.getName(), resolver };
      throw new IllegalStateException(
          LocalizedStrings.PartitionedRegionHelper_FOR_REGION_0_PARTITIONRESOLVER_1_RETURNED_PARTITION_NAME_NULL
              .toLocalizedString(prms));
    }
    else {
      bucketId = prAdvisor.assignFixedBucketId(region, partition, resolveKey);
      if (bucketId == -1) {
        // scheduleGetPRMetaData((LocalRegion)region);
        return null;
      }

    }
  }else {
    bucketId = PartitionedRegionHelper.getHashKey(resolveKey, totalNumberOfBuckets);
  }
  
  ServerLocation bucketServerLocation = getServerLocation(region, operation,
      bucketId);
  ServerLocation location = null;
  if (bucketServerLocation != null)
    location = new ServerLocation(bucketServerLocation.getHostName(),
        bucketServerLocation.getPort());
  return location;
}
 
Example 20
Source File: ParRegExpirationTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Controls the thread that has an expiration action set for the entry in the
 * region TTLDestroy. (custom expiry)
 */
public void customEntryTTLDestroy() {
  String regionName = regionNames[CustomTTLDestroyIndex];
  Region aRegion = CacheHelper.getCache().getRegion(regionName);

  String expiryKeyPrefix = "Expire_" + regionName + "_";
  int expireNumKeys = populateRegion(aRegion, expiryKeyPrefix);
  Object expireKey = regionName + "_expireNumKeys";
  Log.getLogWriter().info(
      "Putting " + expireKey + ", " + expireNumKeys + " into ExpirationBB");
  ExpirationBB.getBB().getSharedMap().put(expireKey,
      new Integer(expireNumKeys));

  String noExpiryKeyPrefix = "NotExpire_" + regionName + "_";
  int noExpireNumKeys = populateRegion(aRegion, noExpiryKeyPrefix);
  Object noExpireKey = regionName + "_noExpireNumKeys";
  Log.getLogWriter().info(
      "Putting " + noExpireKey + ", " + noExpireNumKeys
          + " into ExpirationBB");
  ExpirationBB.getBB().getSharedMap().put(noExpireKey,
      new Integer(noExpireNumKeys));
  
  int expectedVmsForEvents = 1;

  if (TestConfig.tab()
      .booleanAt(ExpirPrms.isBridgeClientConfiguration, false)) {
    expectedVmsForEvents = TestConfig.tab().intAt(ExpirPrms.numClientVms) + 1;
  }

  TestHelper.waitForCounter(ParRegExpirationBB.getBB(),
      "numAfterCreateEvents_CustomExpiryTTLDestroy",
      ParRegExpirationBB.numAfterCreateEvents_CustomExpiryTTLDestroy,
      expireNumKeys * expectedVmsForEvents, true, 600000);

  TestHelper.waitForCounter(ParRegExpirationBB.getBB(),
      "numAfterCreateEvents_CustomNoExpiryTTLDestroy",
      ParRegExpirationBB.numAfterCreateEvents_CustomNoExpiryTTLDestroy,
      noExpireNumKeys * expectedVmsForEvents, true, 600000);

  ParRegExpirationBB.getBB().getSharedCounters().increment(
      ParRegExpirationBB.numPopulationTask_Completed);

  // Wait for remote caches to receive all destroy events
  TestHelper.waitForCounter(ParRegExpirationBB.getBB(),
      "numAfterDestroyEvents_CustomTTLDestroy",
      ParRegExpirationBB.numAfterDestroyEvents_CustomTTLDestroy,
      expireNumKeys * expectedVmsForEvents, true, 600000);

  // Check that all were destroyed

  Set keySet = aRegion.keySet();

  if (keySet.size() != noExpireNumKeys) {
    throw new TestException(
        "Expected the region size after expiration to be the number of non expiry keys put into region "
            + noExpireNumKeys + " but has " + aRegion.size());
  }
  else {
    Log.getLogWriter().info(
        "Got the expected size of region after expiration as "
            + noExpireNumKeys);
  }

  Iterator iterator = keySet.iterator();
  while (iterator.hasNext()) {
    String key = iterator.next().toString();
    if (key.startsWith("Expire_")) {
      throw new TestException("Unexpected key " + key + " in the region "
          + aRegion.getName() + " after expiration");
    }
  }

  ParRegExpirationBB.getBB().printSharedCounters();
  ParRegExpirationBB.getBB().getSharedCounters().zero(
      ParRegExpirationBB.numAfterCreateEvents_CustomExpiryTTLDestroy);
  ParRegExpirationBB.getBB().getSharedCounters().zero(
      ParRegExpirationBB.numAfterCreateEvents_CustomNoExpiryTTLDestroy);
  ParRegExpirationBB.getBB().getSharedCounters().zero(
      ParRegExpirationBB.numAfterDestroyEvents_CustomTTLDestroy);
}