use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class Oplog method basicRemove.
/**
* A helper function which identifies whether to record a removal of entry in the current oplog or
* to make the switch to the next oplog. This function enables us to reuse the byte buffer which
* got created for an oplog which no longer permits us to use itself. It will also take acre of
* compaction if required
*
* @param entry DiskEntry object representing the current Entry
*/
private void basicRemove(DiskRegionView dr, DiskEntry entry, boolean async, boolean isClear) throws IOException, InterruptedException {
DiskId id = entry.getDiskId();
boolean useNextOplog = false;
long startPosForSynchOp = -1;
Oplog emptyOplog = null;
if (DiskStoreImpl.KRF_DEBUG) {
// wait for cache close to create krf
System.out.println("basicRemove KRF_DEBUG");
Thread.sleep(1000);
}
synchronized (this.lock) {
if (getOplogSet().getChild() != this) {
useNextOplog = true;
} else if ((this.drf.currSize + MAX_DELETE_ENTRY_RECORD_BYTES) > getMaxDrfSize() && !isFirstRecord()) {
switchOpLog(dr, MAX_DELETE_ENTRY_RECORD_BYTES, entry);
useNextOplog = true;
} else {
if (this.lockedForKRFcreate) {
CacheClosedException cce = new CacheClosedException("The disk store is closed.");
dr.getCancelCriterion().checkCancelInProgress(cce);
throw cce;
}
long oldOplogId = id.setOplogId(getOplogId());
if (!isClear) {
this.firstRecord = false;
// Ok now we can go ahead and find out its actual size
// This is the only place to set notToUseUserBits=true
initOpState(OPLOG_DEL_ENTRY_1ID, dr, entry, null, (byte) 0, true);
int adjustment = getOpStateSize();
this.drf.currSize += adjustment;
// do the io while holding lock so that switch can set doneAppending
if (logger.isTraceEnabled()) {
logger.trace("Oplog::basicRemove: Recording the Deletion of entry in the Oplog with id = {} The Oplog Disk ID for the entry being deleted = {} Mode is Synch", getOplogId(), id);
}
// Write the data to the opLog for the synch mode
// TODO: if we don't sync write destroys what will happen if
// we do 1. create k1 2. destroy k1 3. create k1?
// It would be possible for the crf to be flushed but not the drf.
// Then during recovery we will find identical keys with different
// entryIds.
// I think we can safely have drf writes be async as long as we flush
// the drf
// before we flush the crf.
// However we can't have removes by async if we are doing a sync write
// because we might be killed right after we do this write.
startPosForSynchOp = writeOpLogBytes(this.drf, async, true);
setHasDeletes(true);
if (logger.isDebugEnabled(LogMarker.PERSIST_WRITES)) {
logger.debug("basicRemove: id=<{}> key=<{}> drId={} oplog#{}", abs(id.getKeyId()), entry.getKey(), dr.getId(), getOplogId());
}
if (logger.isTraceEnabled()) {
logger.trace("Oplog::basicRemove:Released ByteBuffer for Disk ID = {}", id);
}
this.dirHolder.incrementTotalOplogSize(adjustment);
}
// Set the oplog size change for stats
id.setOffsetInOplog(-1);
EntryLogger.logPersistDestroy(dr.getName(), entry.getKey(), dr.getDiskStoreID());
Oplog rmOplog = null;
if (oldOplogId == getOplogId()) {
rmOplog = this;
} else {
rmOplog = getOplogSet().getChild(oldOplogId);
}
if (rmOplog != null) {
rmOplog.rmLive(dr, entry);
emptyOplog = rmOplog;
}
clearOpState();
}
}
if (useNextOplog) {
if (LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER) {
CacheObserverHolder.getInstance().afterSwitchingOplog();
}
Assert.assertTrue(getOplogSet().getChild() != this);
getOplogSet().getChild().basicRemove(dr, entry, async, isClear);
} else {
if (LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER) {
CacheObserverHolder.getInstance().afterSettingOplogOffSet(startPosForSynchOp);
}
if (emptyOplog != null && (!emptyOplog.isCompacting() || emptyOplog.calledByCompactorThread())) {
emptyOplog.handleNoLiveValues();
}
}
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class FunctionStreamingResultCollector method getResult.
public Object getResult(long timeout, TimeUnit unit) throws FunctionException, InterruptedException {
long timeoutInMillis = unit.toMillis(timeout);
if (this.resultCollected) {
throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_ALREADY_COLLECTED.toLocalizedString());
}
this.resultCollected = true;
// Should convert it from unit to milliseconds
if (this.userRC != null) {
try {
long timeBefore = System.currentTimeMillis();
boolean isNotTimedOut;
if (execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) {
isNotTimedOut = this.waitForCacheOrFunctionException(timeoutInMillis);
} else {
isNotTimedOut = this.waitForRepliesUninterruptibly(timeoutInMillis);
}
if (!isNotTimedOut) {
throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_NOT_COLLECTED_IN_TIME_PROVIDED.toLocalizedString());
}
long timeAfter = System.currentTimeMillis();
timeoutInMillis = timeoutInMillis - (timeAfter - timeBefore);
if (timeoutInMillis < 0)
timeoutInMillis = 0;
if (this.removedNodes != null) {
if (this.removedNodes.size() != 0) {
// end the rc and clear it
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(fn);
} else {
newRc = this.execution.execute(fn.getId());
}
return newRc.getResult(timeoutInMillis, unit);
}
}
if (!this.execution.getWaitOnExceptionFlag() && this.fites.size() > 0) {
throw new FunctionException(this.fites.get(0));
}
} catch (FunctionInvocationTargetException fite) {
// function.
if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
clearResults();
FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(fite.getMessage());
throw new FunctionException(iFITE);
} else {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(fn);
} else {
newRc = this.execution.execute(fn.getId());
}
return newRc.getResult(timeoutInMillis, unit);
}
} catch (CacheClosedException e) {
if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
clearResults();
FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(fn);
} else {
newRc = this.execution.execute(fn.getId());
}
return newRc.getResult(timeoutInMillis, unit);
}
}// }
catch (ForceReattemptException e) {
if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
clearResults();
FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(fn);
} else {
newRc = this.execution.execute(fn.getId());
}
return newRc.getResult(timeoutInMillis, unit);
}
} catch (ReplyException e) {
if (!(execution.waitOnException || execution.forwardExceptions)) {
throw new FunctionException(e.getCause());
}
}
return this.userRC.getResult(timeoutInMillis, unit);
}
return null;
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class FunctionStreamingResultCollector method getResult.
public Object getResult() throws FunctionException {
if (this.resultCollected) {
throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_ALREADY_COLLECTED.toLocalizedString());
}
this.resultCollected = true;
if (this.userRC != null) {
try {
if (execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) {
this.waitForCacheOrFunctionException(0);
} else {
waitForRepliesUninterruptibly(0);
}
if (this.removedNodes != null) {
if (this.removedNodes.size() != 0) {
// end the rc and clear it
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(fn);
} else {
newRc = this.execution.execute(fn.getId());
}
return newRc.getResult();
}
}
if (!this.execution.getWaitOnExceptionFlag() && this.fites.size() > 0) {
throw new FunctionException(this.fites.get(0));
}
} catch (FunctionInvocationTargetException fite) {
if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
clearResults();
FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(fite.getMessage());
throw new FunctionException(iFITE);
} else {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(fn);
} else {
newRc = this.execution.execute(fn.getId());
}
return newRc.getResult();
}
} catch (CacheClosedException e) {
if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
clearResults();
FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(fn);
} else {
newRc = this.execution.execute(fn.getId());
}
return newRc.getResult();
}
}// }
catch (ForceReattemptException e) {
if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
clearResults();
FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(fn);
} else {
newRc = this.execution.execute(fn.getId());
}
return newRc.getResult();
}
} catch (ReplyException e) {
if (!(execution.waitOnException || execution.forwardExceptions)) {
throw new FunctionException(e.getCause());
}
}
return this.userRC.getResult();
}
return null;
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class DataType method getDataType.
public static String getDataType(byte[] bytes) {
final DataInput in = getDataInput(bytes);
byte header = 0;
try {
header = in.readByte();
} catch (IOException e) {
return "IOException: " + e.getMessage();
}
try {
switch(header) {
case DS_FIXED_ID_BYTE:
{
return "org.apache.geode.internal.DataSerializableFixedID:" + DSFIDFactory.create(in.readByte(), in).getClass().getName();
}
case DS_FIXED_ID_SHORT:
{
return "org.apache.geode.internal.DataSerializableFixedID:" + DSFIDFactory.create(in.readShort(), in).getClass().getName();
}
case DS_FIXED_ID_INT:
{
return "org.apache.geode.internal.DataSerializableFixedID:" + DSFIDFactory.create(in.readInt(), in).getClass().getName();
}
case DS_NO_FIXED_ID:
return "org.apache.geode.internal.DataSerializableFixedID:" + DataSerializer.readClass(in).getName();
case NULL:
return "null";
case NULL_STRING:
case STRING:
case HUGE_STRING:
case STRING_BYTES:
case HUGE_STRING_BYTES:
return "java.lang.String";
case CLASS:
return "java.lang.Class";
case DATE:
return "java.util.Date";
case FILE:
return "java.io.File";
case INET_ADDRESS:
return "java.net.InetAddress";
case BOOLEAN:
return "java.lang.Boolean";
case CHARACTER:
return "java.lang.Character";
case BYTE:
return "java.lang.Byte";
case SHORT:
return "java.lang.Short";
case INTEGER:
return "java.lang.Integer";
case LONG:
return "java.lang.Long";
case FLOAT:
return "java.lang.Float";
case DOUBLE:
return "java.lang.Double";
case BYTE_ARRAY:
return "byte[]";
case ARRAY_OF_BYTE_ARRAYS:
return "byte[][]";
case SHORT_ARRAY:
return "short[]";
case STRING_ARRAY:
return "java.lang.String[]";
case INT_ARRAY:
return "int[]";
case LONG_ARRAY:
return "long[]";
case FLOAT_ARRAY:
return "float[]";
case DOUBLE_ARRAY:
return "double[]";
case BOOLEAN_ARRAY:
return "boolean[]";
case CHAR_ARRAY:
return "char[]";
case OBJECT_ARRAY:
return "java.lang.Object[]";
case ARRAY_LIST:
return "java.util.ArrayList";
case LINKED_LIST:
return "java.util.LinkedList";
case HASH_SET:
return "java.util.HashSet";
case LINKED_HASH_SET:
return "java.util.LinkedHashSet";
case HASH_MAP:
return "java.util.HashMap";
case IDENTITY_HASH_MAP:
return "java.util.IdentityHashMap";
case HASH_TABLE:
return "java.util.Hashtable";
// return "java.util.concurrent.ConcurrentHashMap";
case PROPERTIES:
return "java.util.Properties";
case TIME_UNIT:
return "java.util.concurrent.TimeUnit";
case USER_CLASS:
byte userClassDSId = in.readByte();
return "DataSerializer: with Id:" + userClassDSId;
case USER_CLASS_2:
short userClass2DSId = in.readShort();
return "DataSerializer: with Id:" + userClass2DSId;
case USER_CLASS_4:
int userClass4DSId = in.readInt();
return "DataSerializer: with Id:" + userClass4DSId;
case VECTOR:
return "java.util.Vector";
case STACK:
return "java.util.Stack";
case TREE_MAP:
return "java.util.TreeMap";
case TREE_SET:
return "java.util.TreeSet";
case BOOLEAN_TYPE:
return "java.lang.Boolean.class";
case CHARACTER_TYPE:
return "java.lang.Character.class";
case BYTE_TYPE:
return "java.lang.Byte.class";
case SHORT_TYPE:
return "java.lang.Short.class";
case INTEGER_TYPE:
return "java.lang.Integer.class";
case LONG_TYPE:
return "java.lang.Long.class";
case FLOAT_TYPE:
return "java.lang.Float.class";
case DOUBLE_TYPE:
return "java.lang.Double.class";
case VOID_TYPE:
return "java.lang.Void.class";
case USER_DATA_SERIALIZABLE:
{
Instantiator instantiator = InternalInstantiator.getInstantiator(in.readByte());
return "org.apache.geode.Instantiator:" + instantiator.getInstantiatedClass().getName();
}
case USER_DATA_SERIALIZABLE_2:
{
Instantiator instantiator = InternalInstantiator.getInstantiator(in.readShort());
return "org.apache.geode.Instantiator:" + instantiator.getInstantiatedClass().getName();
}
case USER_DATA_SERIALIZABLE_4:
{
Instantiator instantiator = InternalInstantiator.getInstantiator(in.readInt());
return "org.apache.geode.Instantiator:" + instantiator.getInstantiatedClass().getName();
}
case DATA_SERIALIZABLE:
return "org.apache.geode.DataSerializable:" + DataSerializer.readClass(in).getName();
case SERIALIZABLE:
{
String name = null;
try {
Object obj = InternalDataSerializer.basicReadObject(getDataInput(bytes));
name = obj.getClass().getName();
} catch (ClassNotFoundException e) {
name = e.getMessage();
}
return "java.io.Serializable:" + name;
}
case PDX:
{
int typeId = in.readInt();
try {
InternalCache gfc = GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed.");
PdxType pdxType = gfc.getPdxRegistry().getType(typeId);
if (pdxType == null) {
// fix 52164
return "org.apache.geode.pdx.PdxInstance: unknown id=" + typeId;
}
return "org.apache.geode.pdx.PdxInstance:" + pdxType.getClassName();
} catch (CacheClosedException e) {
return "org.apache.geode.pdx.PdxInstance:PdxRegistryClosed";
}
}
case PDX_ENUM:
{
int dsId = in.readByte();
int tmp = InternalDataSerializer.readArrayLength(in);
int enumId = (dsId << 24) | (tmp & 0xFFFFFF);
try {
InternalCache gfc = GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed.");
EnumInfo enumInfo = gfc.getPdxRegistry().getEnumInfoById(enumId);
return "PdxRegistry/java.lang.Enum:" + enumInfo.getClassName();
} catch (CacheClosedException e) {
return "PdxRegistry/java.lang.Enum:PdxRegistryClosed";
}
}
case GEMFIRE_ENUM:
{
String name = DataSerializer.readString(in);
return "java.lang.Enum:" + name;
}
case PDX_INLINE_ENUM:
{
String name = DataSerializer.readString(in);
return "java.lang.Enum:" + name;
}
case BIG_INTEGER:
return "java.math.BigInteger";
case BIG_DECIMAL:
return "java.math.BigDecimal";
case UUID:
return "java.util.UUID";
case TIMESTAMP:
return "java.sql.Timestamp";
default:
}
return "Unknown header byte: " + header;
} catch (IOException e) {
throw new Error(e);
} catch (ClassNotFoundException e) {
throw new Error(e);
}
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class DeployFunction method execute.
@Override
public void execute(FunctionContext context) {
// Declared here so that it's available when returning a Throwable
String memberId = "";
try {
final Object[] args = (Object[]) context.getArguments();
final String[] jarFilenames = (String[]) args[0];
final byte[][] jarBytes = (byte[][]) args[1];
InternalCache cache = getCache();
final JarDeployer jarDeployer = new JarDeployer(cache.getInternalDistributedSystem().getConfig().getDeployWorkingDir());
DistributedMember member = cache.getDistributedSystem().getDistributedMember();
memberId = member.getId();
// If they set a name use it instead
if (!member.getName().equals("")) {
memberId = member.getName();
}
List<String> deployedList = new ArrayList<String>();
List<DeployedJar> jarClassLoaders = ClassPathLoader.getLatest().getJarDeployer().deploy(jarFilenames, jarBytes);
for (int i = 0; i < jarFilenames.length; i++) {
deployedList.add(jarFilenames[i]);
if (jarClassLoaders.get(i) != null) {
deployedList.add(jarClassLoaders.get(i).getFileCanonicalPath());
} else {
deployedList.add("Already deployed");
}
}
CliFunctionResult result = new CliFunctionResult(memberId, deployedList.toArray(new String[0]));
context.getResultSender().lastResult(result);
} catch (CacheClosedException cce) {
CliFunctionResult result = new CliFunctionResult(memberId, false, null);
context.getResultSender().lastResult(result);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable th) {
SystemFailure.checkFailure();
logger.error("Could not deploy JAR file {}", th.getMessage(), th);
CliFunctionResult result = new CliFunctionResult(memberId, th, null);
context.getResultSender().lastResult(result);
}
}
Aggregations