Author: manik.surtani(a)jboss.com
Date: 2009-03-07 07:56:38 -0500 (Sat, 07 Mar 2009)
New Revision: 7876
Added:
core/branches/flat/src/main/java/org/horizon/container/UpdateableEntry.java
Modified:
core/branches/flat/src/main/java/org/horizon/container/MVCCEntry.java
core/branches/flat/src/main/java/org/horizon/container/ReadCommittedEntry.java
core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java
core/branches/flat/src/test/java/org/horizon/loader/CacheLoaderFunctionalTest.java
Log:
MVCC fixes
Modified: core/branches/flat/src/main/java/org/horizon/container/MVCCEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/container/MVCCEntry.java 2009-03-07
12:41:42 UTC (rev 7875)
+++ core/branches/flat/src/main/java/org/horizon/container/MVCCEntry.java 2009-03-07
12:56:38 UTC (rev 7876)
@@ -30,8 +30,6 @@
public interface MVCCEntry {
boolean isNullEntry();
- void copyForUpdate(DataContainer container, boolean writeSkewCheck);
-
void commitUpdate(DataContainer container);
void rollbackUpdate();
Modified: core/branches/flat/src/main/java/org/horizon/container/ReadCommittedEntry.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/container/ReadCommittedEntry.java 2009-03-07
12:41:42 UTC (rev 7875)
+++
core/branches/flat/src/main/java/org/horizon/container/ReadCommittedEntry.java 2009-03-07
12:56:38 UTC (rev 7876)
@@ -32,7 +32,7 @@
* @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
* @since 1.0
*/
-public class ReadCommittedEntry implements MVCCEntry {
+public class ReadCommittedEntry implements UpdateableEntry {
private static final Log log = LogFactory.getLog(ReadCommittedEntry.class);
private static final boolean trace = log.isTraceEnabled();
Added: core/branches/flat/src/main/java/org/horizon/container/UpdateableEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/container/UpdateableEntry.java
(rev 0)
+++ core/branches/flat/src/main/java/org/horizon/container/UpdateableEntry.java 2009-03-07
12:56:38 UTC (rev 7876)
@@ -0,0 +1,10 @@
+package org.horizon.container;
+
+/**
+ * // TODO: Manik: Document this!
+ *
+ * @author Manik Surtani
+ */
+public interface UpdateableEntry extends MVCCEntry {
+ void copyForUpdate(DataContainer container, boolean writeSkewCheck);
+}
Modified: core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java 2009-03-07
12:41:42 UTC (rev 7875)
+++
core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java 2009-03-07
12:56:38 UTC (rev 7876)
@@ -28,6 +28,7 @@
import org.horizon.container.NullMarkerEntry;
import org.horizon.container.ReadCommittedEntry;
import org.horizon.container.RepeatableReadEntry;
+import org.horizon.container.UpdateableEntry;
import org.horizon.context.InvocationContext;
import org.horizon.factories.annotations.Inject;
import org.horizon.factories.annotations.Start;
@@ -65,7 +66,7 @@
writeSkewCheck = configuration.isWriteSkewCheck();
}
- public final MVCCEntry createWrappedEntry(Object key, Object value, boolean
isForInsert, long lifespan) {
+ public final UpdateableEntry createWrappedEntry(Object key, Object value, boolean
isForInsert, long lifespan) {
if (value == null && !isForInsert) return useRepeatableRead ? NULL_MARKER :
null;
return useRepeatableRead ? new RepeatableReadEntry(key, value, lifespan) : new
ReadCommittedEntry(key, value, lifespan);
@@ -106,8 +107,18 @@
{
// acquire lock if needed
if (alreadyLocked || acquireLock(ctx, key)) {
+ UpdateableEntry ue;
+ if (mvccEntry instanceof UpdateableEntry) {
+ ue = (UpdateableEntry) mvccEntry;
+ } else {
+ // this is a read-only entry that needs to be copied to a proper
read-write entry!!
+ ue = createWrappedEntry(key, mvccEntry.getValue(), false,
mvccEntry.getLifespan());
+ mvccEntry = ue;
+ ctx.putLookedUpEntry(key, mvccEntry);
+ }
+
// create a copy of the underlying entry
- mvccEntry.copyForUpdate(container, writeSkewCheck);
+ ue.copyForUpdate(container, writeSkewCheck);
}
if (trace) log.trace("Exists in context.");
if (mvccEntry.isDeleted() && createIfAbsent) {
@@ -123,20 +134,22 @@
// exists in cache! Just acquire lock if needed, and wrap.
// do we need a lock?
boolean needToCopy = alreadyLocked || acquireLock(ctx, key) ||
ctx.hasOption(Options.SKIP_LOCKING); // even if we do not acquire a lock, if skip-locking
is enabled we should copy
- mvccEntry = createWrappedEntry(key, cachedValue.getValue(), false,
cachedValue.getLifespan());
- ctx.putLookedUpEntry(key, mvccEntry);
- if (needToCopy) mvccEntry.copyForUpdate(container, writeSkewCheck);
+ UpdateableEntry ue = createWrappedEntry(key, cachedValue.getValue(), false,
cachedValue.getLifespan());
+ ctx.putLookedUpEntry(key, ue);
+ if (needToCopy) ue.copyForUpdate(container, writeSkewCheck);
+ mvccEntry = ue;
} else if (createIfAbsent) {
// this is the *only* point where new entries can be created!!
if (trace) log.trace("Creating new entry.");
// now to lock and create the entry. Lock first to prevent concurrent
creation!
if (!alreadyLocked) acquireLock(ctx, key);
notifier.notifyCacheEntryCreated(key, true, ctx);
- mvccEntry = createWrappedEntry(key, null, true, -1);
- mvccEntry.setCreated(true);
- ctx.putLookedUpEntry(key, mvccEntry);
- mvccEntry.copyForUpdate(container, writeSkewCheck);
+ UpdateableEntry ue = createWrappedEntry(key, null, true, -1);
+ ue.setCreated(true);
+ ctx.putLookedUpEntry(key, ue);
+ ue.copyForUpdate(container, writeSkewCheck);
notifier.notifyCacheEntryCreated(key, false, ctx);
+ mvccEntry = ue;
}
}
Modified:
core/branches/flat/src/test/java/org/horizon/loader/CacheLoaderFunctionalTest.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/loader/CacheLoaderFunctionalTest.java 2009-03-07
12:41:42 UTC (rev 7875)
+++
core/branches/flat/src/test/java/org/horizon/loader/CacheLoaderFunctionalTest.java 2009-03-07
12:56:38 UTC (rev 7876)
@@ -118,7 +118,7 @@
assertInCacheAndStore("k" + i, "v" + i, lifespan);
}
- cache.remove("k1", "some rubbish");
+ assert !cache.remove("k1", "some rubbish");
for (int i = 1; i < 8; i++) {
// even numbers have lifespans