Author: rareddy
Date: 2010-09-10 16:18:13 -0400 (Fri, 10 Sep 2010)
New Revision: 2557
Modified:
branches/7.1.x/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCache.java
branches/7.1.x/engine/src/main/java/org/teiid/cache/Cache.java
branches/7.1.x/engine/src/main/java/org/teiid/cache/DefaultCache.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestSessionAwareCache.java
branches/7.1.x/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java
Log:
TEIID-1256: Only removing the caches that are of the VDB that is being un-deployed.
Modified:
branches/7.1.x/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCache.java
===================================================================
---
branches/7.1.x/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCache.java 2010-09-10
19:34:56 UTC (rev 2556)
+++
branches/7.1.x/cache-jbosscache/src/main/java/org/teiid/cache/jboss/JBossCache.java 2010-09-10
20:18:13 UTC (rev 2557)
@@ -128,4 +128,15 @@
void setCacheConfiguration(CacheConfiguration config) {
this.config = config;
}
+
+ @Override
+ public Set<K> keys() {
+ HashSet keys = new HashSet();
+ Node<K, V> node = getRootNode();
+ Set<Node<K, V>> children = node.getChildren();
+ for (Node<K, V> child:children) {
+ keys.addAll(child.getData().keySet());
+ }
+ return keys;
+ }
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/cache/Cache.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/cache/Cache.java 2010-09-10 19:34:56 UTC
(rev 2556)
+++ branches/7.1.x/engine/src/main/java/org/teiid/cache/Cache.java 2010-09-10 20:18:13 UTC
(rev 2557)
@@ -22,6 +22,8 @@
package org.teiid.cache;
+import java.util.Set;
+
/**
* Abstraction over cache providers
*/
@@ -94,4 +96,10 @@
* @return
*/
String getName();
+
+ /**
+ * Return all the keys
+ * @return
+ */
+ Set<K> keys();
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/cache/DefaultCache.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/cache/DefaultCache.java 2010-09-10
19:34:56 UTC (rev 2556)
+++ branches/7.1.x/engine/src/main/java/org/teiid/cache/DefaultCache.java 2010-09-10
20:18:13 UTC (rev 2557)
@@ -217,5 +217,10 @@
public String getName() {
return name;
}
+
+ @Override
+ public Set<K> keys() {
+ return map.keySet();
+ }
}
\ No newline at end of file
Modified: branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
---
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-09-10
19:34:56 UTC (rev 2556)
+++
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-09-10
20:18:13 UTC (rev 2557)
@@ -555,6 +555,18 @@
}
}
+ private void clearPlanCache(String vdbName, int version){
+ LogManager.logInfo(LogConstants.CTX_DQP,
QueryPlugin.Util.getString("DQPCore.Clearing_prepared_plan_cache"));
//$NON-NLS-1$
+ this.prepPlanCache.clearForVDB(vdbName, version);
+ }
+
+ private void clearResultSetCache(String vdbName, int version) {
+ //clear cache in server
+ if(rsCache != null){
+ rsCache.clearForVDB(vdbName, version);
+ }
+ }
+
public CacheStatisticsMetadata getCacheStatistics(String cacheType) {
if (cacheType.equalsIgnoreCase(Admin.Cache.PREPARED_PLAN_CACHE.toString())) {
return buildCacheStats(Admin.Cache.PREPARED_PLAN_CACHE.toString(),
this.prepPlanCache);
@@ -592,6 +604,18 @@
break;
}
}
+
+ public void clearCache(String cacheType, String vdbName, int version) {
+ Admin.Cache cache = Admin.Cache.valueOf(cacheType);
+ switch (cache) {
+ case PREPARED_PLAN_CACHE:
+ clearPlanCache(vdbName, version);
+ break;
+ case QUERY_SERVICE_RESULT_SET_CACHE:
+ clearResultSetCache(vdbName, version);
+ break;
+ }
+ }
public Collection<org.teiid.adminapi.Transaction> getTransactions() {
return this.transactionService.getTransactions();
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
===================================================================
---
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java 2010-09-10
19:34:56 UTC (rev 2556)
+++
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java 2010-09-10
20:18:13 UTC (rev 2557)
@@ -25,6 +25,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.teiid.cache.Cachable;
@@ -174,6 +175,20 @@
this.distributedCache.clear();
}
+ public void clearForVDB(String vdbName, int version) {
+ clearCache(this.localCache, vdbName, version);
+ clearCache(this.distributedCache, vdbName, version);
+ }
+
+ private void clearCache(Cache<CacheID, T> cache, String vdbName, int version) {
+ Set<CacheID> keys = cache.keys();
+ for (CacheID key:keys) {
+ if (key.vdbInfo.getName().equalsIgnoreCase(vdbName) &&
key.vdbInfo.getVersion() == version) {
+ cache.remove(key);
+ }
+ }
+ }
+
public static class CacheID implements Serializable {
private static final long serialVersionUID = 8261905111156764744L;
private String sql;
Modified:
branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestSessionAwareCache.java
===================================================================
---
branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestSessionAwareCache.java 2010-09-10
19:34:56 UTC (rev 2556)
+++
branches/7.1.x/engine/src/test/java/org/teiid/dqp/internal/process/TestSessionAwareCache.java 2010-09-10
20:18:13 UTC (rev 2557)
@@ -111,6 +111,29 @@
assertTrue(result==c);
}
+
+ @Test
+ public void testVDBRemoval() {
+
+ SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>();
+
+ CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM
FOO");
+
+ Cachable result = Mockito.mock(Cachable.class);
+ Mockito.stub(result.prepare((Cache)anyObject(),
(BufferManager)anyObject())).toReturn(true);
+ Mockito.stub(result.restore((Cache)anyObject(),
(BufferManager)anyObject())).toReturn(true);
+
+ id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
+ cache.put(id, FunctionMethod.VDB_DETERMINISTIC, result, null);
+
+ Object c = cache.get(id);
+
+ assertTrue(result==c);
+
+ cache.clearForVDB("vdb-name", 1);
+
+ assertNull(cache.get(id));
+ }
public static DQPWorkContext buildWorkContext() {
Modified:
branches/7.1.x/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java
===================================================================
---
branches/7.1.x/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java 2010-09-10
19:34:56 UTC (rev 2556)
+++
branches/7.1.x/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java 2010-09-10
20:18:13 UTC (rev 2557)
@@ -206,10 +206,9 @@
//ignore
}
- // dump the caches. TODO:It would have nice if only removed this VDB
- // specific cache, but based on JBoss cache structure it is hard to just get keys
- dqpCore.clearCache(Cache.PREPARED_PLAN_CACHE.toString());
- dqpCore.clearCache(Cache.QUERY_SERVICE_RESULT_SET_CACHE.toString());
+ // dump the caches.
+ dqpCore.clearCache(Cache.PREPARED_PLAN_CACHE.toString(), name, version);
+ dqpCore.clearCache(Cache.QUERY_SERVICE_RESULT_SET_CACHE.toString(), name, version);
}
});
}