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

The following examples show how to use com.gemstone.gemfire.cache.Region#isDestroyed() . 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: IndexUtils.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static IndexManager getIndexManager(Region region,
    boolean createIfNotAvailable) {
  if (region == null || region.isDestroyed()) return null;
  LocalRegion lRegion = (LocalRegion) region;
  IndexManager idxMgr = lRegion.getIndexManager();
  if (idxMgr == null && createIfNotAvailable) {
    // JUst before creating new IndexManager. 
    if (testHook != null && region instanceof PartitionedRegion) {
      testHook.hook(0);
    }
    Object imSync = lRegion.getIMSync();
    synchronized (imSync) {
      //Double checked locking
      if (lRegion.getIndexManager() == null) {
        idxMgr = new IndexManager(region);
        lRegion.setIndexManager(idxMgr);
      }
      else {
        idxMgr = lRegion.getIndexManager();
      }
    }
  }
  return idxMgr;
}
 
Example 2
Source File: RegionAdvisor.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void waitForProfileStatus(int status) {
  ProfileShutdownListener listener = new ProfileShutdownListener();
  addProfileChangeListener(listener);
  try {
    int memberNum = 0;
    String regionName = getPartitionedRegion().getFullPath();
    do {
      Region pr = getPartitionedRegion().getCache().getRegion(regionName);
      if (pr == null || pr.isDestroyed()) break;
      Set members = adviseNotAtShutDownAllStatus(status);
      memberNum = members.size();
      if (memberNum >0) {
        getDistributionManager().getLoggerI18n().fine("waitForProfileStatus "+status+" at PR:"+getPartitionedRegion().getFullPath()+", expecting "+memberNum+" members:"+members);
        listener.waitForChange();
      }
    } while (memberNum > 0);
  } finally {
    removeProfileChangeListener(listener);
  }
}
 
Example 3
Source File: RegionAdvisor.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void waitForProfileStatus(int status) {
  ProfileShutdownListener listener = new ProfileShutdownListener();
  addProfileChangeListener(listener);
  try {
    int memberNum = 0;
    String regionName = getPartitionedRegion().getFullPath();
    do {
      Region pr = getPartitionedRegion().getCache().getRegion(regionName);
      if (pr == null || pr.isDestroyed()) break;
      Set members = adviseNotAtShutDownAllStatus(status);
      memberNum = members.size();
      if (memberNum >0) {
        getDistributionManager().getLoggerI18n().fine("waitForProfileStatus "+status+" at PR:"+getPartitionedRegion().getFullPath()+", expecting "+memberNum+" members:"+members);
        listener.waitForChange();
      }
    } while (memberNum > 0);
  } finally {
    removeProfileChangeListener(listener);
  }
}
 
Example 4
Source File: ConcCQMultRegionsClient.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
protected void handleRegionDestroyedException(Region aRegion, RegionDestroyedException anException) {
   // make sure the region destroyed is this region
   if (!anException.getRegionFullPath().equals(aRegion.getFullPath())) {
     TestException te = new TestException("Got a RegionDestroyedException when operating on region " +
     TestHelper.regionToString(aRegion, false) + ", but the region destroyed is '" +
     anException.getRegionFullPath() +"'");
     te.initCause(anException);
     throw te;
   }

   // Note: the test only creates a region with a given name once. Once that region
   // has been destroyed, the test will never create another region with the same name
   boolean isDestroyed = aRegion.isDestroyed();
   if (isDestroyed) {
      // Make sure it really is destoyed and is not causing the RegionDestroyedException to be
      // thrown because one of its subregions was destroyed. 
      Log.getLogWriter().info("Got " + RegionDestroyedException.class.getName() + 
          " on " + TestHelper.regionToString(aRegion, false) + "; exception expected, continuing test");
   } else { // the region was not destroyed, but we got RegionDestroyedException anyway
      throw new TestException("Bug 30645 (likely): isDestroyed returned " + isDestroyed + " for region " +
         TestHelper.regionToString(aRegion, false) + ", but a region destroyed exception was thrown: " +
         TestHelper.getStackTrace(anException));
   }
}
 
Example 5
Source File: IndexUtils.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public static IndexManager getIndexManager(Region region,
    boolean createIfNotAvailable) {
  if (region == null || region.isDestroyed()) return null;
  LocalRegion lRegion = (LocalRegion) region;
  IndexManager idxMgr = lRegion.getIndexManager();
  if (idxMgr == null && createIfNotAvailable) {
    // JUst before creating new IndexManager. 
    if (testHook != null && region instanceof PartitionedRegion) {
      testHook.hook(0);
    }
    Object imSync = lRegion.getIMSync();
    synchronized (imSync) {
      //Double checked locking
      if (lRegion.getIndexManager() == null) {
        idxMgr = new IndexManager(region);
        lRegion.setIndexManager(idxMgr);
      }
      else {
        idxMgr = lRegion.getIndexManager();
      }
    }
  }
  return idxMgr;
}
 
Example 6
Source File: ConcCQMultRegionsClient.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
protected void handleRegionDestroyedException(Region aRegion, RegionDestroyedException anException) {
   // make sure the region destroyed is this region
   if (!anException.getRegionFullPath().equals(aRegion.getFullPath())) {
     TestException te = new TestException("Got a RegionDestroyedException when operating on region " +
     TestHelper.regionToString(aRegion, false) + ", but the region destroyed is '" +
     anException.getRegionFullPath() +"'");
     te.initCause(anException);
     throw te;
   }

   // Note: the test only creates a region with a given name once. Once that region
   // has been destroyed, the test will never create another region with the same name
   boolean isDestroyed = aRegion.isDestroyed();
   if (isDestroyed) {
      // Make sure it really is destoyed and is not causing the RegionDestroyedException to be
      // thrown because one of its subregions was destroyed. 
      Log.getLogWriter().info("Got " + RegionDestroyedException.class.getName() + 
          " on " + TestHelper.regionToString(aRegion, false) + "; exception expected, continuing test");
   } else { // the region was not destroyed, but we got RegionDestroyedException anyway
      throw new TestException("Bug 30645 (likely): isDestroyed returned " + isDestroyed + " for region " +
         TestHelper.regionToString(aRegion, false) + ", but a region destroyed exception was thrown: " +
         TestHelper.getStackTrace(anException));
   }
}
 
Example 7
Source File: HARegionQueue.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void close() {
  Region r = getRegion();
  if (r != null && !r.isDestroyed()) {
    try {
      r.close();
    } catch (RegionDestroyedException e) {
    }
  }
}
 
Example 8
Source File: RegionAdvisor.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void waitForChange() {
  Region pr = getPartitionedRegion();

  synchronized(this) {
    while (!profileChanged && pr != null && !pr.isDestroyed()) {
      // the advisee might have been destroyed due to initialization failure
      try {
        this.wait(1000);
      } catch (InterruptedException e) {
      }
    }
    this.profileChanged = false;
  }
}
 
Example 9
Source File: SerialGatewaySenderQueue.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void close() {
  Region r = getRegion();
  if (r != null && !r.isDestroyed()) {
    try {
      r.close();
    } catch (RegionDestroyedException e) {
    }
  }
}
 
Example 10
Source File: GemFireStore.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Delete a Schema in the store in given transaction context.
 * 
 * @param schemaName
 *          the name of the schema
 * @param tc
 *          the {@link TransactionManager} for this operation
 */
public void dropSchemaRegion(String schemaName, TransactionController tc)
    throws StandardException {
  boolean locked = false;
  final GemFireTransaction tran = (GemFireTransaction)tc;
  LockingPolicy locking = null;
  if (!tran.skipLocks(schemaName, null)) {
    locking = new GFContainerLocking(
        new DefaultGfxdLockable(schemaName, null), false, null);
    // take distributed write lock before destroy
    // the lock will be released when transaction ends
    locked = locking.lockContainer(tran, null, true, true);
  }
  Region<?, ?> region = this.gemFireCache.getRegion(schemaName);
  if (region == null || region.isDestroyed()) {
    // [sumedh] Should we throw an exception here?
    // A genuine case should be caught at the derby level
    // while other case where it can arise is receiving a GfxdDDLMessage
    // for a region destruction that has already been replayed using
    // the hidden _DDL_STMTS_REGION.
    /*
    throw new RegionDestroyedException(
        "dropSchemaRegion: region for schema '" + schemaName
            + "' already destroyed", '/' + schemaName);
    */
    final LogWriterI18n logger = this.gemFireCache.getLoggerI18n();
    if (logger.fineEnabled()) {
      logger.fine("dropSchemaRegion: region [/" + schemaName
          + "] for schema '" + schemaName + "' already destroyed");
    }
    if (locked) {
      locking.unlockContainer(tran, null);
    }
  }
  else {
    // Do not distribute region destruction to other caches since the
    // distribution is already handled by GfxdDDLMessages.
    region.localDestroyRegion();
  }
}
 
Example 11
Source File: RegionAdvisor.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void waitForChange() {
  Region pr = getPartitionedRegion();

  synchronized(this) {
    while (!profileChanged && pr != null && !pr.isDestroyed()) {
      // the advisee might have been destroyed due to initialization failure
      try {
        this.wait(1000);
      } catch (InterruptedException e) {
      }
    }
    this.profileChanged = false;
  }
}
 
Example 12
Source File: SerialGatewaySenderQueue.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void close() {
  Region r = getRegion();
  if (r != null && !r.isDestroyed()) {
    try {
      r.close();
    } catch (RegionDestroyedException e) {
    }
  }
}
 
Example 13
Source File: SingleWriteSingleReadRegionQueue.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void close() {
  Region r = getRegion();
  if (r != null && !r.isDestroyed()) {
    try {
      r.close();
    } catch (RegionDestroyedException e) {
    }
  }
}
 
Example 14
Source File: GemFireStore.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Delete a Schema in the store in given transaction context.
 * 
 * @param schemaName
 *          the name of the schema
 * @param tc
 *          the {@link TransactionManager} for this operation
 */
public void dropSchemaRegion(String schemaName, TransactionController tc)
    throws StandardException {
  boolean locked = false;
  final GemFireTransaction tran = (GemFireTransaction)tc;
  LockingPolicy locking = null;
  if (!tran.skipLocks(schemaName, null)) {
    locking = new GFContainerLocking(
        new DefaultGfxdLockable(schemaName, null), false, null);
    // take distributed write lock before destroy
    // the lock will be released when transaction ends
    locked = locking.lockContainer(tran, null, true, true);
  }
  Region<?, ?> region = this.gemFireCache.getRegion(schemaName);
  if (region == null || region.isDestroyed()) {
    // [sumedh] Should we throw an exception here?
    // A genuine case should be caught at the derby level
    // while other case where it can arise is receiving a GfxdDDLMessage
    // for a region destruction that has already been replayed using
    // the hidden _DDL_STMTS_REGION.
    /*
    throw new RegionDestroyedException(
        "dropSchemaRegion: region for schema '" + schemaName
            + "' already destroyed", '/' + schemaName);
    */
    final LogWriterI18n logger = this.gemFireCache.getLoggerI18n();
    if (logger.fineEnabled()) {
      logger.fine("dropSchemaRegion: region [/" + schemaName
          + "] for schema '" + schemaName + "' already destroyed");
    }
    if (locked) {
      locking.unlockContainer(tran, null);
    }
  }
  else {
    // Do not distribute region destruction to other caches since the
    // distribution is already handled by GfxdDDLMessages.
    region.localDestroyRegion();
  }
}
 
Example 15
Source File: MultipleDiskRegions.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected synchronized void recoverRegion(String regionName) {
  final List<Boolean> revoking = new ArrayList();
  revoking.add(new Boolean(true));
  Thread revokeThread = new Thread(new Runnable() {
    public void run() {
      while (revoking.get(0)) {
        RecoveryTestVersionHelper.forceRecovery(false);
        MasterController.sleepForMs(1000);
      }
    }
  });

  try {
    Region region = cache.getRegion(regionName);
    if (region == null || region.isDestroyed()) {
      // //this is dirty fix...awaiting a feedback from fabricdev here
      // on what to do?
      // // darrel said it's a bug. Logged as BUG #34269
      Log.getLogWriter().info("recovering region...");
      Thread.sleep(4 * 1000);
      RegionAttributes attr = RegionHelper
          .getRegionAttributes(ConfigPrms.getRegionConfig());
      Log.getLogWriter().info("Starting thread to revoke members...");
      revokeThread.start();
      RegionHelper.createRegion(regionName, attr);
      Log.getLogWriter().info("region recovered..." + regionName);
      revoking.set(0, new Boolean(false));
      revokeThread.join();
      Log.getLogWriter().info("Thread to revoke members terminated");
    }
  } catch (Exception ex) {
    String stack = util.TestHelper.getStackTrace(ex);
    if (stack.indexOf("RegionExistsException") != -1) {
      Log
          .getLogWriter()
          .warning(
              "RegionExistsException is caught. It may appear in concurrent environment...continuing with the test");
    } else {
      throw new TestException(TestHelper.getStackTrace(ex));
    }
  }
}
 
Example 16
Source File: MultipleDiskRegions.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected void performEntryOperations() {
  String regionName = TestConfig.tab().stringAt(MapPrms.regionForOps);
  lowerThreshold = TestConfig.tab().intAt(MapPrms.lowerThreshold, -1);
  upperThreshold = TestConfig.tab().intAt(MapPrms.upperThreshold, Integer.MAX_VALUE);

  Log.getLogWriter().info("lowerThreshold " + lowerThreshold + ", " + "upperThreshold " + upperThreshold );

  long startTime = System.currentTimeMillis();
  do {
    int whichOp = getEntryOperation(MapPrms.entryOperationName);
    Region region = cache.getRegion(regionName);
    
    if (region == null || region.isDestroyed()) {
        recoverRegion(regionName);
        continue;
    }

 
  try {
    int size = region.size();
    
 
    if (size >= upperThreshold) {
       whichOp = getEntryOperation(MapPrms.upperThresholdOperations);
    }else if (size <= lowerThreshold) {
       whichOp = getEntryOperation(MapPrms.lowerThresholdOperations);
    }


    switch (whichOp) {
    case PUT:
      putObject(regionName);
      break;
    case PUT_ALL:
      putAllObjects(regionName);
      break;
    case REMOVE:
      removeObject(regionName);
      break;
    case INVALIDATE:
      invalidateObject(regionName);
      break;
        case PUT_IF_ABSENT:
          putIfAbsent(regionName);
          break;
        case CM_REMOVE:
          cm_remove(regionName);
          break;
    default: {
      throw new TestException("Unknown operation " + whichOp);
    }
    }
  } catch (RegionDestroyedException rdex) {
      Log.getLogWriter().info("RegionDestroyedException...may occur in concurrent environment. Continuing with test.");
    recoverRegion(regionName);
  } catch (Exception ex) {
    throw new TestException(TestHelper.getStackTrace(ex));
  }
  } while ((System.currentTimeMillis() - startTime) < minTaskGranularityMS);
}
 
Example 17
Source File: MultipleDiskRegions.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected synchronized void recoverRegion(String regionName) {
  final List<Boolean> revoking = new ArrayList();
  revoking.add(new Boolean(true));
  Thread revokeThread = new Thread(new Runnable() {
    public void run() {
      while (revoking.get(0)) {
        RecoveryTestVersionHelper.forceRecovery(false);
        MasterController.sleepForMs(1000);
      }
    }
  });

  try {
    Region region = cache.getRegion(regionName);
    if (region == null || region.isDestroyed()) {
      // //this is dirty fix...awaiting a feedback from fabricdev here
      // on what to do?
      // // darrel said it's a bug. Logged as BUG #34269
      Log.getLogWriter().info("recovering region...");
      Thread.sleep(4 * 1000);
      RegionAttributes attr = RegionHelper
          .getRegionAttributes(ConfigPrms.getRegionConfig());
      Log.getLogWriter().info("Starting thread to revoke members...");
      revokeThread.start();
      RegionHelper.createRegion(regionName, attr);
      Log.getLogWriter().info("region recovered..." + regionName);
      revoking.set(0, new Boolean(false));
      revokeThread.join();
      Log.getLogWriter().info("Thread to revoke members terminated");
    }
  } catch (Exception ex) {
    String stack = util.TestHelper.getStackTrace(ex);
    if (stack.indexOf("RegionExistsException") != -1) {
      Log
          .getLogWriter()
          .warning(
              "RegionExistsException is caught. It may appear in concurrent environment...continuing with the test");
    } else {
      throw new TestException(TestHelper.getStackTrace(ex));
    }
  }
}
 
Example 18
Source File: ParallelGatewaySenderQueue.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
@Override
public void remove() throws CacheException {
  if (!this.peekedEvents.isEmpty()) {

    GatewaySenderEventImpl event = this.peekedEvents.remove();
    try {
    // PartitionedRegion prQ = this.userPRToshadowPRMap.get(ColocationHelper
    // .getLeaderRegion((PartitionedRegion)event.getRegion()).getFullPath());
    //
    PartitionedRegion prQ = null;
    int bucketId = -1;
    Object key = null;
    if (event.getRegion() != null) {
      if (isDREvent(event)) {
        prQ = this.userRegionNameToshadowPRMap.get(event.getRegion()
            .getFullPath());
        bucketId = event.getEventId().getBucketID();
        key = event.getEventId();
      } else {
        prQ = this.userRegionNameToshadowPRMap.get(ColocationHelper
            .getLeaderRegion((PartitionedRegion)event.getRegion())
            .getFullPath());
        bucketId = event.getBucketId();
        key = event.getShadowKey();
      }
    } else {
      String regionPath = event.getRegionPath();
      GemFireCacheImpl cache = (GemFireCacheImpl)this.sender.getCache();
      Region region = (PartitionedRegion)cache.getRegion(regionPath);
      if (region != null && !region.isDestroyed()) {
        // TODO: Suranjan We have to get colocated parent region for this
        // region
        if (region instanceof DistributedRegion) {
          prQ = this.userRegionNameToshadowPRMap.get(region.getFullPath());
          event.getBucketId();
          key = event.getEventId();
        } else {
          prQ = this.userRegionNameToshadowPRMap.get(ColocationHelper
              .getLeaderRegion((PartitionedRegion)region).getFullPath());
          event.getBucketId();
          key = event.getShadowKey();
        }
      }
    }

    if (prQ != null) {        
      destroyEventFromQueue(prQ, bucketId, key);
    }
    } finally {
      event.release();
    }
  }
}
 
Example 19
Source File: ParallelGatewaySenderQueue.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
@Override
public void remove() throws CacheException {
  if (!this.peekedEvents.isEmpty()) {

    GatewaySenderEventImpl event = this.peekedEvents.remove();
    try {
    // PartitionedRegion prQ = this.userPRToshadowPRMap.get(ColocationHelper
    // .getLeaderRegion((PartitionedRegion)event.getRegion()).getFullPath());
    //
    PartitionedRegion prQ = null;
    int bucketId = -1;
    Object key = null;
    if (event.getRegion() != null) {
      if (isDREvent(event)) {
        prQ = this.userRegionNameToshadowPRMap.get(event.getRegion()
            .getFullPath());
        bucketId = event.getEventId().getBucketID();
        key = event.getEventId();
      } else {
        prQ = this.userRegionNameToshadowPRMap.get(ColocationHelper
            .getLeaderRegion((PartitionedRegion)event.getRegion())
            .getFullPath());
        bucketId = event.getBucketId();
        key = event.getShadowKey();
      }
    } else {
      String regionPath = event.getRegionPath();
      GemFireCacheImpl cache = (GemFireCacheImpl)this.sender.getCache();
      Region region = (PartitionedRegion)cache.getRegion(regionPath);
      if (region != null && !region.isDestroyed()) {
        // TODO: Suranjan We have to get colocated parent region for this
        // region
        if (region instanceof DistributedRegion) {
          prQ = this.userRegionNameToshadowPRMap.get(region.getFullPath());
          event.getBucketId();
          key = event.getEventId();
        } else {
          prQ = this.userRegionNameToshadowPRMap.get(ColocationHelper
              .getLeaderRegion((PartitionedRegion)region).getFullPath());
          event.getBucketId();
          key = event.getShadowKey();
        }
      }
    }

    if (prQ != null) {        
      destroyEventFromQueue(prQ, bucketId, key);
    }
    } finally {
      event.release();
    }
  }
}
 
Example 20
Source File: MultipleDiskRegions.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected void performEntryOperations() {
  String regionName = TestConfig.tab().stringAt(MapPrms.regionForOps);
  lowerThreshold = TestConfig.tab().intAt(MapPrms.lowerThreshold, -1);
  upperThreshold = TestConfig.tab().intAt(MapPrms.upperThreshold, Integer.MAX_VALUE);

  Log.getLogWriter().info("lowerThreshold " + lowerThreshold + ", " + "upperThreshold " + upperThreshold );

  long startTime = System.currentTimeMillis();
  do {
    int whichOp = getEntryOperation(MapPrms.entryOperationName);
    Region region = cache.getRegion(regionName);
    
    if (region == null || region.isDestroyed()) {
        recoverRegion(regionName);
        continue;
    }

 
  try {
    int size = region.size();
    
 
    if (size >= upperThreshold) {
       whichOp = getEntryOperation(MapPrms.upperThresholdOperations);
    }else if (size <= lowerThreshold) {
       whichOp = getEntryOperation(MapPrms.lowerThresholdOperations);
    }


    switch (whichOp) {
    case PUT:
      putObject(regionName);
      break;
    case PUT_ALL:
      putAllObjects(regionName);
      break;
    case REMOVE:
      removeObject(regionName);
      break;
    case INVALIDATE:
      invalidateObject(regionName);
      break;
        case PUT_IF_ABSENT:
          putIfAbsent(regionName);
          break;
        case CM_REMOVE:
          cm_remove(regionName);
          break;
    default: {
      throw new TestException("Unknown operation " + whichOp);
    }
    }
  } catch (RegionDestroyedException rdex) {
      Log.getLogWriter().info("RegionDestroyedException...may occur in concurrent environment. Continuing with test.");
    recoverRegion(regionName);
  } catch (Exception ex) {
    throw new TestException(TestHelper.getStackTrace(ex));
  }
  } while ((System.currentTimeMillis() - startTime) < minTaskGranularityMS);
}