We initially were using indexed disk cache but ran into cache corruption
where the data returned for a key would not be the data associated for
that key. I haven't been able to come up with a good repro scenario...
We had to work around it with the following code:
/**
* is the cache element not the correct object for the key
* @param key the current key
* @param element the current element associated with the key
* @param hasReadLock whether caller has read lock
* @return true if key mismatch els false
* @throws InterruptedException if locking fails
*/
private boolean isCorrupt(String key, ICacheElement element, boolean
hasReadLock) throws InterruptedException
{
boolean corrupt = !key.equals(element.getKey());
if (corrupt)
{
mLogger.error("cache corruption!!! [" + (mCorruptionCounter++) +
"]");
if (mLogger.isDebugEnabled())
{
mLogger.error("culprit stack...", new Exception("cache
corruption"));
}
try
{
if (hasReadLock)
{
mLock.readLock().release();
}
mLock.writeLock().acquire();
try
{
mLogger.error("purging " + key);
mCache.remove(key);
mCache.remove(key + ":");
}
catch (Exception e)
{
mLogger.error("failed to purge key " + key, e);
}
try
{
String k = (String)element.getKey();
mLogger.error("purging " + k);
mCache.remove(k);
mCache.remove(k + ":");
}
catch (Exception e)
{
mLogger.error("failed to purge key " + element.getKey(), e);
}
}
finally
{
if (hasReadLock)
{
mLock.readLock().acquire();
}
mLock.writeLock().release();
}
}
return corrupt;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]