Skip to content

Commit

Permalink
GEODE-669
Browse files Browse the repository at this point in the history
Add CacheObserver for ShutdownAll

Let GatewayReceiverCommand to throw CacheClosedException instead of
RegionDestroyedException when ShutdownAll happened.
  • Loading branch information
gesterzhou committed Dec 15, 2015
1 parent 0b288a2 commit ae2d529
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,9 @@ public interface CacheObserver
*/
public void beforeDeletingEmptyOplog(Oplog emptyOplog);

/**
* Invoked just before ShutdownAll operation
* @param emptyOplog
*/
void beforeShutdownAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,8 @@ public void beforeDeletingCompactedOplog(Oplog compactedOplog)
public void beforeDeletingEmptyOplog(Oplog emptyOplog)
{
}

@Override
public void beforeShutdownAll() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,13 @@ public synchronized void shutDownAll() {
// it's already doing shutdown by another thread
return;
}
if (LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER) {
try {
CacheObserverHolder.getInstance().beforeShutdownAll();
} finally {
LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = false;
}
}
this.isShutDownAll = true;

// bug 44031 requires multithread shutdownall should be grouped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

import com.gemstone.gemfire.CancelException;
import com.gemstone.gemfire.cache.CacheClosedException;
import com.gemstone.gemfire.cache.EntryNotFoundException;
import com.gemstone.gemfire.cache.RegionDestroyedException;
import com.gemstone.gemfire.cache.operations.DestroyOperationContext;
Expand All @@ -36,6 +37,7 @@
import com.gemstone.gemfire.internal.Version;
import com.gemstone.gemfire.internal.cache.EntryEventImpl;
import com.gemstone.gemfire.internal.cache.EventID;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
import com.gemstone.gemfire.internal.cache.KeyWithRegionContext;
import com.gemstone.gemfire.internal.cache.LocalRegion;
import com.gemstone.gemfire.internal.cache.tier.CachedRegionHelper;
Expand Down Expand Up @@ -67,6 +69,16 @@ public static Command getCommand() {
private GatewayReceiverCommand() {
}

private void handleRegionNull(ServerConnection servConn, String regionName, int batchId) {
GemFireCacheImpl gfc = (GemFireCacheImpl)servConn.getCachedRegionHelper().getCache();
if (gfc != null && gfc.isCacheAtShutdownAll()) {
throw new CacheClosedException("Shutdown occurred during message processing");
} else {
String reason = LocalizedStrings.ProcessBatch_WAS_NOT_FOUND_DURING_BATCH_CREATE_REQUEST_0.toLocalizedString(new Object[] {regionName, Integer.valueOf(batchId)});
throw new RegionDestroyedException(reason, regionName);
}
}

@Override
public void cmdExecute(Message msg, ServerConnection servConn, long start)
throws IOException, InterruptedException {
Expand Down Expand Up @@ -292,8 +304,7 @@ public void cmdExecute(Message msg, ServerConnection servConn, long start)
}
region = (LocalRegion)crHelper.getRegion(regionName);
if (region == null) {
String reason = LocalizedStrings.ProcessBatch_WAS_NOT_FOUND_DURING_BATCH_CREATE_REQUEST_0.toLocalizedString(new Object[] {regionName, Integer.valueOf(batchId)});
throw new RegionDestroyedException(reason, regionName);
handleRegionNull(servConn, regionName, batchId);
} else {
clientEvent = new EntryEventImpl(eventId);
if (versionTimeStamp > 0) {
Expand Down Expand Up @@ -402,8 +413,7 @@ public void cmdExecute(Message msg, ServerConnection servConn, long start)
}
region = (LocalRegion)crHelper.getRegion(regionName);
if (region == null) {
String reason = LocalizedStrings.ProcessBatch_WAS_NOT_FOUND_DURING_BATCH_CREATE_REQUEST_0.toLocalizedString(new Object[] {regionName, Integer.valueOf(batchId)});
throw new RegionDestroyedException(reason, regionName);
handleRegionNull(servConn, regionName, batchId);
} else {
clientEvent = new EntryEventImpl(eventId);
if (versionTimeStamp > 0) {
Expand Down Expand Up @@ -502,8 +512,7 @@ public void cmdExecute(Message msg, ServerConnection servConn, long start)
}
region = (LocalRegion)crHelper.getRegion(regionName);
if (region == null) {
String reason = LocalizedStrings.ProcessBatch_WAS_NOT_FOUND_DURING_BATCH_CREATE_REQUEST_0.toLocalizedString(new Object[] {regionName, Integer.valueOf(batchId)});
throw new RegionDestroyedException(reason, regionName);
handleRegionNull(servConn, regionName, batchId);
} else {
clientEvent = new EntryEventImpl(eventId);
if (versionTimeStamp > 0) {
Expand Down Expand Up @@ -584,8 +593,7 @@ public void cmdExecute(Message msg, ServerConnection servConn, long start)
region = (LocalRegion)crHelper.getRegion(regionName);

if (region == null) {
String reason = LocalizedStrings.ProcessBatch_WAS_NOT_FOUND_DURING_BATCH_UPDATE_VERSION_REQUEST_0.toLocalizedString(new Object[] {regionName});
throw new RegionDestroyedException(reason, regionName);
handleRegionNull(servConn, regionName, batchId);
} else {

clientEvent = new EntryEventImpl(eventId);
Expand Down

0 comments on commit ae2d529

Please sign in to comment.