use of org.apache.geode.InternalGemFireError in project geode by apache.
the class GeodeRedisServer method initializeRedis.
private void initializeRedis() {
synchronized (this.cache) {
Region<ByteArrayWrapper, ByteArrayWrapper> stringsRegion;
Region<ByteArrayWrapper, HyperLogLogPlus> hLLRegion;
Region<String, RedisDataType> redisMetaData;
InternalCache gemFireCache = (InternalCache) cache;
try {
if ((stringsRegion = cache.getRegion(STRING_REGION)) == null) {
RegionFactory<ByteArrayWrapper, ByteArrayWrapper> regionFactory = gemFireCache.createRegionFactory(this.DEFAULT_REGION_TYPE);
stringsRegion = regionFactory.create(STRING_REGION);
}
if ((hLLRegion = cache.getRegion(HLL_REGION)) == null) {
RegionFactory<ByteArrayWrapper, HyperLogLogPlus> regionFactory = gemFireCache.createRegionFactory(this.DEFAULT_REGION_TYPE);
hLLRegion = regionFactory.create(HLL_REGION);
}
if ((redisMetaData = cache.getRegion(REDIS_META_DATA_REGION)) == null) {
AttributesFactory af = new AttributesFactory();
af.addCacheListener(metaListener);
af.setDataPolicy(DataPolicy.REPLICATE);
InternalRegionArguments ira = new InternalRegionArguments().setInternalRegion(true).setIsUsedForMetaRegion(true);
redisMetaData = gemFireCache.createVMRegion(REDIS_META_DATA_REGION, af.create(), ira);
}
} catch (IOException | ClassNotFoundException e) {
// only if loading snapshot, not here
InternalGemFireError assErr = new InternalGemFireError(LocalizedStrings.GemFireCache_UNEXPECTED_EXCEPTION.toLocalizedString());
assErr.initCause(e);
throw assErr;
}
this.regionCache = new RegionProvider(stringsRegion, hLLRegion, redisMetaData, expirationFutures, expirationExecutor, this.DEFAULT_REGION_TYPE);
redisMetaData.put(REDIS_META_DATA_REGION, RedisDataType.REDIS_PROTECTED);
redisMetaData.put(HLL_REGION, RedisDataType.REDIS_PROTECTED);
redisMetaData.put(STRING_REGION, RedisDataType.REDIS_PROTECTED);
}
checkForRegions();
}
use of org.apache.geode.InternalGemFireError in project geode by apache.
the class DLockService method lockInterruptibly.
/**
* @param name the name of the lock to acquire in this service. This object must conform to the
* general contract of <code>equals(Object)</code> and <code>hashCode()</code> as described
* in {@link java.lang.Object#hashCode()}.
*
* @param waitTimeMillis the number of milliseconds to try to acquire the lock before giving up
* and returning false. A value of -1 causes this method to block until the lock is
* acquired.
*
* @param leaseTimeMillis the number of milliseconds to hold the lock after granting it, before
* automatically releasing it if it hasn't already been released by invoking
* {@link #unlock(Object)}. If <code>leaseTimeMillis</code> is -1, hold the lock until
* explicitly unlocked.
*
* @param tryLock true if the lock should be acquired or fail if currently held. waitTimeMillis
* will be ignored if the lock is currently held by another client.
*
* @param interruptible true if this lock request is interruptible
*
* @param disableAlerts true to disable logging alerts if the dlock is taking a long time to
* acquired.
*
* @return true if the lock was acquired, false if the timeout <code>waitTimeMillis</code> passed
* without acquiring the lock.
*
* @throws InterruptedException if the thread is interrupted before or during this method.
*
* @throws UnsupportedOperationException if attempt to lock batch involves non-tryLocks
*/
public boolean lockInterruptibly(final Object name, final long waitTimeMillis, final long leaseTimeMillis, final boolean tryLock, final boolean interruptible, final boolean disallowReentrant, final boolean disableAlerts) throws InterruptedException {
checkDestroyed();
final boolean isDebugEnabled_DLS = logger.isTraceEnabled(LogMarker.DLS);
boolean interrupted = Thread.interrupted();
if (interrupted && interruptible) {
throw new InterruptedException();
}
boolean abnormalExit = true;
boolean safeExit = true;
try {
// try-block for abnormalExit and safeExit
long statStart = getStats().startLockWait();
long startTime = getLockTimeStamp(dm);
long requestWaitTime = waitTimeMillis;
long requestLeaseTime = leaseTimeMillis;
// -1 means "lease forever". Long.MAX_VALUE is pretty close.
if (requestLeaseTime == -1)
requestLeaseTime = Long.MAX_VALUE;
// -1 means "wait forever". Long.MAX_VALUE is pretty close.
if (requestWaitTime == -1)
requestWaitTime = Long.MAX_VALUE;
long waitLimit = startTime + requestWaitTime;
if (waitLimit < 0)
waitLimit = Long.MAX_VALUE;
if (isDebugEnabled_DLS) {
logger.trace(LogMarker.DLS, "{}, name: {} - entering lock()", this, name);
}
DLockToken token = getOrCreateToken(name);
boolean gotLock = false;
blockedOn.set(name);
try {
// try-block for end stats, token cleanup, and interrupt check
ThreadRequestState requestState = (ThreadRequestState) this.threadRequestState.get();
if (requestState == null) {
requestState = new ThreadRequestState(incThreadSequence(), interruptible);
this.threadRequestState.set(requestState);
} else {
requestState.interruptible = interruptible;
}
final int threadId = requestState.threadId;
// if reentry and no change to expiration then grantor is not bothered
long leaseExpireTime = 0;
boolean keepTrying = true;
int lockId = -1;
incActiveLocks();
int loopCount = 0;
while (keepTrying) {
if (DEBUG_LOCK_REQUEST_LOOP) {
loopCount++;
if (loopCount > DEBUG_LOCK_REQUEST_LOOP_COUNT) {
Integer count = Integer.valueOf(DEBUG_LOCK_REQUEST_LOOP_COUNT);
String s = LocalizedStrings.DLockService_DEBUG_LOCKINTERRUPTIBLY_HAS_GONE_HOT_AND_LOOPED_0_TIMES.toLocalizedString(count);
InternalGemFireError e = new InternalGemFireError(s);
logger.error(LogMarker.DLS, LocalizedMessage.create(LocalizedStrings.DLockService_DEBUG_LOCKINTERRUPTIBLY_HAS_GONE_HOT_AND_LOOPED_0_TIMES, count), e);
throw e;
}
/*
* if (loopCount > 1) { Thread.sleep(1000); }
*/
}
checkDestroyed();
// clear
interrupted = Thread.interrupted() || interrupted;
if (interrupted && interruptible) {
throw new InterruptedException();
}
// Check for recursive lock
boolean reentrant = false;
int recursionBefore = -1;
synchronized (token) {
token.checkForExpiration();
if (token.isLeaseHeldByCurrentThread()) {
if (isDebugEnabled_DLS) {
logger.trace(LogMarker.DLS, "{} , name: {} - lock() is reentrant: {}", this, name, token);
}
reentrant = true;
if (reentrant && disallowReentrant) {
throw new IllegalStateException(LocalizedStrings.DLockService_0_ATTEMPTED_TO_REENTER_NONREENTRANT_LOCK_1.toLocalizedString(new Object[] { Thread.currentThread(), token }));
}
recursionBefore = token.getRecursion();
// moved here from processor null-check
leaseExpireTime = token.getLeaseExpireTime();
// under gotLock
// keep lockId
lockId = token.getLeaseId();
if (lockId < 0) {
// loop back around due to expiration
continue;
}
}
// isLeaseHeldByCurrentThread
}
// token sync
LockGrantorId theLockGrantorId = getLockGrantorId();
if (reentrant) {
Assert.assertTrue(lockId > -1, "Reentrant lock must have lockId > -1");
// lockId = token.getLockId(); // keep lockId
} else {
// this thread is not current owner...
// reset lockId back to -1
lockId = -1;
}
DLockRequestProcessor processor = null;
// if reentrant w/ infinite lease TODO: remove false to restore this...
if (false && reentrant && leaseTimeMillis == Long.MAX_VALUE) {
// Optimization:
// thread is reentering lock and lease time is infinite so no
// need to trouble the poor grantor
gotLock = true;
// check for race condition...
Assert.assertTrue(token.isLeaseHeldByCurrentThread());
} else // non-reentrant or reentrant w/ non-infinite lease
{
processor = createRequestProcessor(theLockGrantorId, name, threadId, startTime, requestLeaseTime, requestWaitTime, reentrant, tryLock, disableAlerts);
if (reentrant) {
// related to bug 32765, but client-side... see bug 33402
synchronized (token) {
if (!token.isLeaseHeldByCurrentThread()) {
reentrant = false;
recursionBefore = -1;
token.checkForExpiration();
}
}
} else {
// set lockId since this is the first granting (non-reentrant)
lockId = processor.getProcessorId();
}
try {
safeExit = false;
gotLock = processor.requestLock(interruptible, lockId);
} catch (InterruptedException e) {
// LOST INTERRUPT
if (interruptible) {
// TODO: BUG 37158: this can cause a stuck lock
throw e;
} else {
interrupted = true;
Assert.assertTrue(false, "Non-interruptible lock is trying to throw InterruptedException");
}
}
if (isDebugEnabled_DLS) {
logger.trace(LogMarker.DLS, "Grantor {} replied {}", theLockGrantorId, processor.getResponseCodeString());
}
}
if (gotLock) {
// if (processor != null) (cannot be null)
{
// TODO: can be null after restoring above optimization
// non-reentrant lock needs to getLeaseExpireTime
leaseExpireTime = processor.getLeaseExpireTime();
}
int recursion = recursionBefore + 1;
boolean granted = false;
boolean needToReleaseOrphanedGrant = false;
Assert.assertHoldsLock(this.destroyLock, false);
synchronized (this.lockGrantorIdLock) {
if (!checkLockGrantorId(theLockGrantorId)) {
safeExit = true;
// race: grantor changed
if (isDebugEnabled_DLS) {
logger.trace(LogMarker.DLS, "Cannot honor grant from {} because {} is now a grantor.", theLockGrantorId, this.lockGrantorId);
}
continue;
} else if (isDestroyed()) {
// race: dls was destroyed
if (isDebugEnabled_DLS) {
logger.trace(LogMarker.DLS, "Cannot honor grant from {} because this lock service has been destroyed.", theLockGrantorId);
}
needToReleaseOrphanedGrant = true;
} else {
safeExit = true;
synchronized (this.tokens) {
checkDestroyed();
Assert.assertTrue(token == basicGetToken(name));
RemoteThread rThread = new RemoteThread(getDistributionManager().getId(), threadId);
granted = token.grantLock(leaseExpireTime, lockId, recursion, rThread);
}
// tokens sync
}
}
if (needToReleaseOrphanedGrant) /* && processor != null */
{
processor.getResponse().releaseOrphanedGrant(this.dm);
safeExit = true;
continue;
}
if (!granted) {
Assert.assertTrue(granted, "Failed to perform client-side granting on " + token + " which was granted by " + theLockGrantorId);
}
if (isDebugEnabled_DLS) {
logger.trace(LogMarker.DLS, "{}, name: {} - granted lock: {}", this, name, token);
}
keepTrying = false;
} else // grantor replied destroyed (getLock is false)
if (processor.repliedDestroyed()) {
safeExit = true;
checkDestroyed();
// should have thrown LockServiceDestroyedException
Assert.assertTrue(isDestroyed(), "Grantor reports service " + this + " is destroyed: " + name);
} else // grantor replied NOT_GRANTOR or departed (getLock is false)
if (processor.repliedNotGrantor() || processor.hadNoResponse()) {
safeExit = true;
notLockGrantorId(theLockGrantorId, 0, TimeUnit.MILLISECONDS);
// keepTrying is still true... loop back around
} else // grantor replied NOT_HOLDER for reentrant lock (getLock is false)
if (processor.repliedNotHolder()) {
safeExit = true;
if (DEBUG_DISALLOW_NOT_HOLDER) {
String s = LocalizedStrings.DLockService_DEBUG_GRANTOR_REPORTS_NOT_HOLDER_FOR_0.toLocalizedString(token);
InternalGemFireError e = new InternalGemFireError(s);
logger.error(LogMarker.DLS, LocalizedMessage.create(LocalizedStrings.DLockService_DEBUG_GRANTOR_REPORTS_NOT_HOLDER_FOR_0, token), e);
throw e;
}
// fix part of bug 32765 - reentrant/expiration problem
// probably expired... try to get non-reentrant lock
reentrant = false;
recursionBefore = -1;
synchronized (token) {
token.checkForExpiration();
if (token.isLeaseHeldByCurrentThread()) {
// THIS SHOULDN'T HAPPEN -- some sort of weird consistency
// problem. Do what the grantor says and release the lock...
logger.warn(LogMarker.DLS, LocalizedMessage.create(LocalizedStrings.DLockService_GRANTOR_REPORTS_REENTRANT_LOCK_NOT_HELD_0, token));
// Attempt at fault tolerance: We thought we owned it, but we
// don't; let's release it. Removes hot loop in bug 37276,
// but does not address underlying consistency failure.
RemoteThread rThread = new RemoteThread(getDistributionManager().getId(), threadId);
token.releaseLock(lockId, rThread, false);
}
}
// token sync
} else // grantor replied NOT_HOLDER for reentrant lock
// TODO: figure out when this else case can actually happen...
{
safeExit = true;
// fixed the math here... bug 32765
if (waitLimit > token.getCurrentTime() + 20) {
sleep(20, interruptible);
}
keepTrying = waitLimit > token.getCurrentTime();
}
}
// while (keepTrying)
} finally // try-block for end stats, token cleanup, and interrupt check
// finally-block for end stats, token cleanup, and interrupt check
{
getStats().endLockWait(statStart, gotLock);
// cleanup token if failed to get lock
if (!gotLock) {
synchronized (token) {
token.decUsage();
}
freeResources(token.getName());
}
// reset the interrupt state
if (interrupted) {
Thread.currentThread().interrupt();
}
// throw InterruptedException only if failed to get lock and interrupted
if (!gotLock && interruptible && Thread.interrupted()) {
throw new InterruptedException();
}
blockedOn.set(null);
}
if (isDebugEnabled_DLS) {
logger.trace(LogMarker.DLS, "{}, name: {} - exiting lock() returning {}", this, name, gotLock);
}
abnormalExit = false;
return gotLock;
} finally // try-block for abnormalExit and safeExit
// finally-block for abnormalExit and safeExit
{
if (isDebugEnabled_DLS) {
logger.trace(LogMarker.DLS, "{}, name: {} - exiting lock() without returning value", this, name);
}
if (interrupted) {
Thread.currentThread().interrupt();
}
if (DEBUG_ENFORCE_SAFE_EXIT) {
Assert.assertTrue(safeExit);
}
}
}
use of org.apache.geode.InternalGemFireError in project geode by apache.
the class DSFIDFactory method registerDSFID.
/** Register the constructor for a fixed ID class. */
public static void registerDSFID(int dsfid, Class dsfidClass) {
try {
Constructor<?> cons = dsfidClass.getConstructor((Class[]) null);
cons.setAccessible(true);
if (!cons.isAccessible()) {
throw new InternalGemFireError("default constructor not accessible " + "for DSFID=" + dsfid + ": " + dsfidClass);
}
if (dsfid >= Byte.MIN_VALUE && dsfid <= Byte.MAX_VALUE) {
dsfidMap[dsfid + Byte.MAX_VALUE + 1] = cons;
} else {
dsfidMap2.put(dsfid, cons);
}
} catch (NoSuchMethodException nsme) {
throw new InternalGemFireError(nsme);
}
}
use of org.apache.geode.InternalGemFireError in project geode by apache.
the class CreateRegionFunction method createRegionConfigurationMetadataRegion.
private Region<String, RegionConfiguration> createRegionConfigurationMetadataRegion() {
// a sessionFactory in hibernate could have been re-started
// so, it is possible that this region exists already
Region<String, RegionConfiguration> r = this.cache.getRegion(REGION_CONFIGURATION_METADATA_REGION);
if (r != null) {
return r;
}
GemFireCacheImpl gemFireCache = (GemFireCacheImpl) cache;
InternalRegionArguments ira = new InternalRegionArguments().setInternalRegion(true);
AttributesFactory af = new AttributesFactory();
af.setScope(Scope.LOCAL);
af.addCacheListener(new RegionConfigurationCacheListener());
RegionAttributes ra = af.create();
try {
return gemFireCache.createVMRegion(REGION_CONFIGURATION_METADATA_REGION, ra, ira);
} catch (IOException | ClassNotFoundException e) {
InternalGemFireError assErr = new InternalGemFireError(LocalizedStrings.GemFireCache_UNEXPECTED_EXCEPTION.toLocalizedString());
assErr.initCause(e);
throw assErr;
}
}
use of org.apache.geode.InternalGemFireError in project geode by apache.
the class SharedLibrary method loadLibrary.
public static void loadLibrary(boolean debug) throws UnsatisfiedLinkError {
String library = getName();
try {
URL gemfireJarURL = GemFireVersion.getJarURL();
if (gemfireJarURL == null) {
throw new InternalGemFireError("Unable to locate jar file.");
}
String gemfireJar = null;
try {
gemfireJar = URLDecoder.decode(gemfireJarURL.getFile(), "UTF-8");
} catch (java.io.UnsupportedEncodingException uee) {
// This should never happen because UTF-8 is required to be implemented
throw new RuntimeException(uee);
}
int index = gemfireJar.lastIndexOf("/");
if (index == -1) {
throw new InternalGemFireError("Unable to parse gemfire jar path.");
}
String libDir = gemfireJar.substring(0, index + 1);
File libraryPath = new File(libDir, System.mapLibraryName(library));
if (libraryPath.exists()) {
System.load(libraryPath.getPath());
return;
}
} catch (InternalGemFireError ige) {
/**
* Unable to make a guess as to where the gemfire native library is based on its position
* relative to gemfire jar.
*/
if (debug) {
System.out.println("Problem loading library from URL path: " + ige);
}
} catch (UnsatisfiedLinkError ule) {
/**
* Unable to load the gemfire native library in the product tree, This is very unexpected and
* should not happen. Reattempting using System.loadLibrary
*/
if (debug) {
System.out.println("Problem loading library from URL path: " + ule);
}
}
System.loadLibrary(library);
}
Aggregations