Author: manik.surtani(a)jboss.com
Date: 2008-09-23 07:39:22 -0400 (Tue, 23 Sep 2008)
New Revision: 6779
Modified:
core/branches/2.2.X/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java
core/branches/2.2.X/src/main/java/org/jboss/cache/lock/StripedLock.java
Log:
JBCACHE-1410: JDBCCacheLoader may attempt to create a node entry in the DB twice
Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java
===================================================================
---
core/branches/2.2.X/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java 2008-09-23
11:39:06 UTC (rev 6778)
+++
core/branches/2.2.X/src/main/java/org/jboss/cache/loader/JDBCCacheLoader.java 2008-09-23
11:39:22 UTC (rev 6779)
@@ -240,18 +240,23 @@
Fqn currentNode = name;
do
{
- if (currentNode.equals(name))
+ try
{
- insertNode(currentNode, attributes);
+ lock.acquireLock(currentNode, true);
+ if (currentNode.equals(name))
+ {
+ insertNode(currentNode, attributes);
+ }
+ else
+ {
+ insertNode(currentNode, null);
+ }
}
- else
+ finally
{
- insertNode(currentNode, null);
+ lock.releaseLock(currentNode);
}
- if (currentNode.isRoot())
- {
- break;
- }
+ if (currentNode.isRoot()) break;
currentNode = currentNode.getParent();
}
while (!exists(currentNode));
Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/lock/StripedLock.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/lock/StripedLock.java 2008-09-23
11:39:06 UTC (rev 6778)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/lock/StripedLock.java 2008-09-23
11:39:22 UTC (rev 6779)
@@ -94,8 +94,8 @@
{
lock.writeLock().unlock();
// check that we still don't have a stale WL
- if (lock.isWriteLockedByCurrentThread() && log.isWarnEnabled())
- log.warn("Write lock still exists on Fqn " + fqn + " for
current thread. Perhaps this was write-locked more than once?");
+// if (lock.isWriteLockedByCurrentThread() && log.isWarnEnabled())
+// log.warn("Write lock still exists on Fqn " + fqn + " for
current thread. Perhaps this was write-locked more than once?");
}
else
{
@@ -110,12 +110,12 @@
}
}
- ReentrantReadWriteLock getLock(Object o)
+ final ReentrantReadWriteLock getLock(Object o)
{
return sharedLocks[hashToIndex(o)];
}
- int hashToIndex(Object o)
+ final int hashToIndex(Object o)
{
return (hash(o) >>> lockSegmentShift) & lockSegmentMask;
}
@@ -128,7 +128,7 @@
* @param x the object serving as a key
* @return the hash code
*/
- int hash(Object x)
+ final int hash(Object x)
{
int h = x.toString().hashCode();
h += ~(h << 9);
Show replies by date