public void clearForVDB(String vdbName, String version) { VDBKey vdbKey = new VDBKey(vdbName, version); clearForVDB(vdbKey); }
public CacheStatisticsMetadata buildCacheStats(String name) { CacheStatisticsMetadata stats = new CacheStatisticsMetadata(); stats.setName(name); stats.setHitRatio(getCacheHitRatio()); stats.setTotalEntries(this.getTotalCacheEntries()); stats.setRequestCount(this.getRequestCount()); return stats; } }
id.setSessionId(id.originalSessionId); LogManager.logTrace(LogConstants.CTX_DQP, "Adding to session/local cache", id); //$NON-NLS-1$ ttl = computeTtl(id, t, ttl); if (ttl != null && ttl == 0) { return; ttl = computeTtl(id, t, ttl); if (ttl != null && ttl == 0) { return;
public double getCacheHitRatio() { return this.getRequestCount() == 0?0:((double)this.getCacheHitCount()/this.getRequestCount())*100; }
public CacheStatisticsMetadata buildCacheStats(String name) { CacheStatisticsMetadata stats = new CacheStatisticsMetadata(); stats.setName(name); stats.setHitRatio(this.getRequestCount() == 0?0:((double)this.getCacheHitCount()/this.getRequestCount())*100); stats.setTotalEntries(this.getTotalCacheEntries()); stats.setRequestCount(this.getRequestCount()); return stats; } }
@Test public void testPutPreparedPlan(){ SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0); CacheID id = new CacheID(token, pi, EXAMPLE_QUERY + 1); //No PreparedPlan at the begining assertNull(cache.get(id)); //create one cache.put(id, Determinism.SESSION_DETERMINISTIC, new PreparedPlan(), null); //should have one now assertNotNull("Unable to get prepared plan from cache", cache.get(id)); //$NON-NLS-1$ }
@Test public void testClear() { SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0); DQPWorkContext context = buildWorkContext(); CacheID id = new CacheID(context, new ParseInfo(), "SELECT * FROM FOO"); Cachable result = Mockito.mock(Cachable.class); Mockito.stub(result.prepare((BufferManager)anyObject())).toReturn(true); Mockito.stub(result.restore((BufferManager)anyObject())).toReturn(true); id = new CacheID(context, new ParseInfo(), "SELECT * FROM FOO"); cache.put(id, Determinism.VDB_DETERMINISTIC, result, null); id = new CacheID(context, new ParseInfo(), "SELECT * FROM FOO1"); cache.put(id, Determinism.VDB_DETERMINISTIC, result, null); assertEquals(2, cache.getTotalCacheEntries()); cache.clearForVDB(context.getVdbName(), context.getVdbVersion()); assertEquals(0, cache.getTotalCacheEntries()); }
@Test public void testVDBRemoval() { SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0); CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO"); Cachable result = Mockito.mock(Cachable.class); Mockito.stub(result.prepare((BufferManager)anyObject())).toReturn(true); Mockito.stub(result.restore((BufferManager)anyObject())).toReturn(true); id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO"); cache.put(id, Determinism.VDB_DETERMINISTIC, result, null); Object c = cache.get(id); assertTrue(result==c); cache.clearForVDB("vdb-name", "1"); assertNull(cache.get(id)); }
@Test public void testRemove() { SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0); CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO"); Cachable result = Mockito.mock(Cachable.class); Mockito.stub(result.prepare((BufferManager)anyObject())).toReturn(true); Mockito.stub(result.restore((BufferManager)anyObject())).toReturn(true); id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO"); cache.put(id, Determinism.VDB_DETERMINISTIC, result, null); Object c = cache.get(id); assertTrue(result==c); assertTrue(cache.remove(id, Determinism.VDB_DETERMINISTIC) != null); assertNull(cache.get(id)); //session scope cache.put(id, Determinism.SESSION_DETERMINISTIC, result, null); assertTrue(cache.get(id) != null); assertTrue(cache.remove(id, Determinism.SESSION_DETERMINISTIC) != null); assertNull(cache.get(id)); }
public void putPlan(String key, PreparedPlan plan, Determinism determinismLevel) { if (this.globalState.planCache == null) { return; } CacheID id = new CacheID(new ParseInfo(), key, getVdbName(), getVdbVersion(), getConnectionId(), getUserName()); this.globalState.planCache.put(id, determinismLevel, plan, null); }
cid.setParameters(cv.parameters); if (cd.getInvalidation() == null || cd.getInvalidation() == Invalidation.NONE) { CachedResults cr = workItem.getRsCache().get(cid); if (cr != null && (cr.getRowLimit() == 0 || (parameterObject.limit > 0 && cr.getRowLimit() >= parameterObject.limit))) { parameterObject.doNotCache = true; workItem.getRsCache().remove(cid, CachingTupleSource.getDeterminismLevel(cd.getScope()));
@Test public void testLimit() throws Exception { // Create query String preparedSql = "SELECT pm1.g1.e1, e2, pm1.g1.e3 as a, e4 as b FROM pm1.g1 WHERE pm1.g1.e2=?"; //$NON-NLS-1$ List<?> values = Arrays.asList("0"); //$NON-NLS-1$ SessionAwareCache<PreparedPlan> planCache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0); //$NON-NLS-1$ helpGetProcessorPlan(preparedSql, values, new DefaultCapabilitiesFinder(), RealMetadataFactory.example1Cached(), planCache, SESSION_ID, false, true, RealMetadataFactory.example1VDB()); helpGetProcessorPlan(preparedSql, values, new DefaultCapabilitiesFinder(), RealMetadataFactory.example1Cached(), planCache, SESSION_ID, false, true, RealMetadataFactory.example1VDB()); //make sure the plan wasn't reused assertEquals(1, planCache.getCacheHitCount()); }
public void setUp(QueryMetadataInterface qmi, ProcessorDataManager dm, BufferManager bm) { tempStore = new TempTableStore("1", TransactionMode.ISOLATE_WRITES); //$NON-NLS-1$ metadata = new TempMetadataAdapter(qmi, tempStore.getMetadataStore()); metadata.setSession(true); SessionAwareCache<CachedResults> cache = new SessionAwareCache<CachedResults>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0); cache.setTupleBufferCache(bm); dataManager = new TempTableDataManager(dm, bm, cache); }
@Test public void testValidateCorrectValues() throws Exception { // Create query String preparedSql = "SELECT pm1.g1.e1, e2, pm1.g1.e3 as a, e4 as b FROM pm1.g1 WHERE pm1.g1.e1=?"; //$NON-NLS-1$ List<?> values = Arrays.asList("a"); //$NON-NLS-1$ //Create plan helpGetProcessorPlan(preparedSql, values, new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0)); }
private MetadataResult obtainMetadataForPreparedSql(String sql, DQPWorkContext workContext, boolean isDoubleQuotedVariablesAllowed) throws QueryParserException, QueryResolverException, TeiidComponentException { Command command = null; ParseInfo info = new ParseInfo(); // Defect 19747 - the parser needs the following connection property to decide whether to treat double-quoted strings as variable names info.ansiQuotedIdentifiers = isDoubleQuotedVariablesAllowed; CacheID id = new CacheID(workContext, info, sql); PreparedPlan plan = planCache.get(id); if(plan != null) { command = plan.getCommand(); } else { command = QueryParser.getQueryParser().parseCommand(sql, info); QueryResolver.resolveCommand(command, this.metadata); } return getMetadataForCommand(command); }
if (cachable) { if (rsCache.isTransactional()) { TransactionContext tc = request.getTransactionContext(false); if (tc != null && tc.getTransactionType() != Scope.NONE) { CachedResults cr = rsCache.get(cacheId);
@Test public void testClearAll(){ SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0); //create one for each session token helpPutPreparedPlans(cache, token, 1, 1); helpPutPreparedPlans(cache, token2, 1, 1); //should have one assertNotNull("Unable to get prepared plan from cache for token", cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 1))); //$NON-NLS-1$ cache.clearAll(); //should not exist for token assertNull("Failed remove from cache", cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 1))); //$NON-NLS-1$ //should not exist for token2 assertNull("Unable to get prepared plan from cache for token2", cache.get(new CacheID(token2, pi, EXAMPLE_QUERY + 1))); //$NON-NLS-1$ }
private Command helpTest(String userSql, String viewSql, String expectedSql, ProcessorDataManager dm) throws Exception { TransformationMetadata metadata = TestUpdateValidator.example1(); TestUpdateValidator.createView(viewSql, metadata, "gx"); Command command = TestQueryRewriter.helpTestRewriteCommand(userSql, expectedSql, metadata); if (dm != null) { CommandContext context = createCommandContext(); SessionAwareCache<PreparedPlan> planCache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0); context.setPreparedPlanCache(planCache); //$NON-NLS-1$ BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities(); caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true); ProcessorPlan plan = helpGetPlan(helpParse(userSql), metadata, new DefaultCapabilitiesFinder(caps), context); List<?>[] expected = new List[] {Arrays.asList(1)}; helpProcess(plan, context, dm, expected); assertEquals(0, planCache.getTotalCacheEntries()); } return command; }
@Test public void testPreparedPlanInvalidation() throws Exception { helpTestPlanInvalidation("select * from #temp a, #temp b limit 10"); assertEquals(2, this.core.getPrepPlanCache().getCacheHitCount()); }