[infinispan-commits] Infinispan SVN: r2508 - in branches/4.2.x: core/src/main/java/org/infinispan/interceptors and 2 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Thu Oct 14 08:49:03 EDT 2010
Author: mircea.markus
Date: 2010-10-14 08:49:03 -0400 (Thu, 14 Oct 2010)
New Revision: 2508
Modified:
branches/4.2.x/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/stringbased/JdbcStringBasedCacheStore.java
branches/4.2.x/core/src/main/java/org/infinispan/interceptors/CacheStoreInterceptor.java
branches/4.2.x/core/src/test/java/org/infinispan/loaders/BaseCacheStoreTest.java
branches/4.2.x/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java
Log:
[ISPN-687]-JdbcStringBasedCacheStore fails to store value, uses INSERT statement on existing value when the existing one is expired
Modified: branches/4.2.x/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/stringbased/JdbcStringBasedCacheStore.java
===================================================================
--- branches/4.2.x/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/stringbased/JdbcStringBasedCacheStore.java 2010-10-14 10:46:14 UTC (rev 2507)
+++ branches/4.2.x/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/stringbased/JdbcStringBasedCacheStore.java 2010-10-14 12:49:03 UTC (rev 2508)
@@ -184,7 +184,7 @@
@Override
public void storeLockSafe(InternalCacheEntry ed, String lockingKey) throws CacheLoaderException {
- InternalCacheEntry existingOne = loadLockSafe(ed, lockingKey);
+ InternalCacheEntry existingOne = readStoredEntry(ed, lockingKey);
String sql;
if (existingOne == null) {
sql = tableManipulation.getInsertRowSql();
@@ -284,40 +284,17 @@
@Override
protected InternalCacheEntry loadLockSafe(Object key, String lockingKey) throws CacheLoaderException {
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- try {
- String sql = tableManipulation.getSelectRowSql();
- conn = connectionFactory.getConnection();
- ps = conn.prepareStatement(sql);
- ps.setString(1, lockingKey);
- rs = ps.executeQuery();
- if (rs.next()) {
- InputStream inputStream = rs.getBinaryStream(2);
- InternalCacheValue icv = (InternalCacheValue) JdbcUtil.unmarshall(getMarshaller(), inputStream);
- InternalCacheEntry storedEntry = icv.toInternalCacheEntry(key);
- if (storedEntry.isExpired()) {
- if (log.isTraceEnabled()) {
- log.trace("Not returning '" + storedEntry + "' as it is expired. It will be removed from DB by purging thread!");
- }
- return null;
- }
- return storedEntry;
+ InternalCacheEntry storedEntry = null;
+ storedEntry = readStoredEntry(key, lockingKey);
+ if (storedEntry != null && storedEntry.isExpired()) {
+ if (log.isTraceEnabled()) {
+ log.trace("Not returning '" + storedEntry + "' as it is expired. It will be removed from DB by purging thread!");
}
return null;
- } catch (SQLException e) {
- String message = "SQL error while fetching stored entry with key:" + key + " lockingKey: " + lockingKey;
- log.error(message, e);
- throw new CacheLoaderException(message, e);
- } finally {
- JdbcUtil.safeClose(rs);
- JdbcUtil.safeClose(ps);
- connectionFactory.releaseConnection(conn);
}
+ return storedEntry;
}
-
public Class<? extends CacheLoaderConfig> getConfigurationClass() {
return JdbcStringBasedCacheStoreConfig.class;
}
@@ -370,4 +347,32 @@
public boolean isDistributed() {
return cache.getConfiguration() != null && cache.getConfiguration().getCacheMode().isDistributed();
}
+
+ private InternalCacheEntry readStoredEntry(Object key, String lockingKey) throws CacheLoaderException {
+ Connection conn = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ InternalCacheEntry storedEntry = null;
+ try {
+ String sql = tableManipulation.getSelectRowSql();
+ conn = connectionFactory.getConnection();
+ ps = conn.prepareStatement(sql);
+ ps.setString(1, lockingKey);
+ rs = ps.executeQuery();
+ if (rs.next()) {
+ InputStream inputStream = rs.getBinaryStream(2);
+ InternalCacheValue icv = (InternalCacheValue) JdbcUtil.unmarshall(getMarshaller(), inputStream);
+ storedEntry = icv.toInternalCacheEntry(key);
+ }
+ } catch (SQLException e) {
+ String message = "SQL error while fetching stored entry with key:" + key + " lockingKey: " + lockingKey;
+ log.error(message, e);
+ throw new CacheLoaderException(message, e);
+ } finally {
+ JdbcUtil.safeClose(rs);
+ JdbcUtil.safeClose(ps);
+ connectionFactory.releaseConnection(conn);
+ }
+ return storedEntry;
+ }
}
Modified: branches/4.2.x/core/src/main/java/org/infinispan/interceptors/CacheStoreInterceptor.java
===================================================================
--- branches/4.2.x/core/src/main/java/org/infinispan/interceptors/CacheStoreInterceptor.java 2010-10-14 10:46:14 UTC (rev 2507)
+++ branches/4.2.x/core/src/main/java/org/infinispan/interceptors/CacheStoreInterceptor.java 2010-10-14 12:49:03 UTC (rev 2508)
@@ -105,7 +105,7 @@
*/
public final boolean skip(InvocationContext ctx, VisitableCommand command) {
if (store == null) return true; // could be because the cache loader oes not implement cache store
- if ((!ctx.isOriginLocal() && loaderConfig.isShared()) || ctx.hasFlag(Flag.SKIP_CACHE_STORE)) {
+ if ((!ctx.isOriginLocal() && loaderConfig. isShared()) || ctx.hasFlag(Flag.SKIP_CACHE_STORE)) {
if (trace) log.trace("Passing up method call and bypassing this interceptor since the cache loader is shared and this call originated remotely.");
return true;
}
Modified: branches/4.2.x/core/src/test/java/org/infinispan/loaders/BaseCacheStoreTest.java
===================================================================
--- branches/4.2.x/core/src/test/java/org/infinispan/loaders/BaseCacheStoreTest.java 2010-10-14 10:46:14 UTC (rev 2507)
+++ branches/4.2.x/core/src/test/java/org/infinispan/loaders/BaseCacheStoreTest.java 2010-10-14 12:49:03 UTC (rev 2508)
@@ -654,4 +654,11 @@
if (!exceptions.isEmpty()) throw exceptions.get(0);
}
+ public void testReplaceExpiredEntry() throws Exception {
+ cs.store(InternalEntryFactory.create("k1", "v1", 100));
+ Thread.sleep(200);
+ assert null == cs.load("k1");
+ cs.store(InternalEntryFactory.create("k1", "v2", 100));
+ assert cs.load("k1").getValue().equals("v2");
+ }
}
\ No newline at end of file
Modified: branches/4.2.x/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java
===================================================================
--- branches/4.2.x/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java 2010-10-14 10:46:14 UTC (rev 2507)
+++ branches/4.2.x/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java 2010-10-14 12:49:03 UTC (rev 2508)
@@ -1,5 +1,6 @@
package org.infinispan.test;
+import org.infinispan.AdvancedCache;
import org.infinispan.Cache;
import org.infinispan.config.Configuration;
import org.infinispan.distribution.BaseDistFunctionalTest;
@@ -159,6 +160,10 @@
protected void addClusterEnabledCacheManagers(Configuration.CacheMode mode, boolean transactional, int count) {
for (int i = 0; i < count; i++) addClusterEnabledCacheManager(mode, transactional);
}
+
+ protected void addClusterEnabledCacheManagers(Configuration config, int count) {
+ for (int i = 0; i < count; i++) addClusterEnabledCacheManager(config);
+ }
protected void addClusterEnabledCacheManagers(Configuration.CacheMode mode, int count) {
for (int i = 0; i < count; i++) addClusterEnabledCacheManager(mode, true);
@@ -273,4 +278,12 @@
public Address address(int cacheIndex) {
return cache(cacheIndex).getAdvancedCache().getRpcManager().getAddress();
}
+
+ public AdvancedCache advancedCache(int i) {
+ return cache(i).getAdvancedCache();
+ }
+
+ public AdvancedCache advancedCache(int i, String cacheName) {
+ return cache(i, cacheName).getAdvancedCache();
+ }
}
More information about the infinispan-commits
mailing list