Skip to content

Commit

Permalink
TEIID-3392 addressing lob result caching
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Mar 18, 2015
1 parent 526fbaf commit e84832b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Expand Up @@ -60,7 +60,7 @@ public enum ReferenceMode {
}

private static class LobHolder {
Streamable<?> lob;
volatile Streamable<?> lob;
int referenceCount = 1;

public LobHolder(Streamable<?> lob) {
Expand Down
Expand Up @@ -506,12 +506,6 @@ protected void close() {
rowcount = resultsBuffer.getRowCount();
if (this.cid == null || !this.doneProducingBatches) {
resultsBuffer.remove();
} else {
try {
this.resultsBuffer.persistLobs();
} catch (TeiidComponentException e) {
LogManager.logDetail(LogConstants.CTX_DQP, QueryPlugin.Util.getString("failed_to_cache")); //$NON-NLS-1$
}
}

for (DataTierTupleSource connectorRequest : getConnectorRequests()) {
Expand Down Expand Up @@ -655,7 +649,7 @@ protected void flushBatchDirect(TupleBatch batch, boolean add) throws TeiidCompo
super.flushBatchDirect(batch, add);
}
synchronized (lobStreams) {
if (resultsBuffer.isLobs()) {
if (cid == null && resultsBuffer.isLobs()) {
super.flushBatchDirect(batch, false);
}
if (batch.getTerminationFlag()) {
Expand Down Expand Up @@ -802,6 +796,11 @@ private void addToCache() {
if (determinismLevel.compareTo(Determinism.SESSION_DETERMINISTIC) <= 0) {
LogManager.logInfo(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30008, originalCommand));
}
try {
this.resultsBuffer.persistLobs();
} catch (TeiidComponentException e) {
LogManager.logDetail(LogConstants.CTX_DQP, e, QueryPlugin.Util.getString("failed_to_cache")); //$NON-NLS-1$
}
dqpCore.getRsCache().put(cid, determinismLevel, cr, originalCommand.getCacheHint() != null?originalCommand.getCacheHint().getTtl():null);
}

Expand Down
Expand Up @@ -109,4 +109,17 @@ public class TestResultsCache {
assertFalse(rs.next());
}

@Test public void testCacheHintWithLargeSQLXML() throws Exception {
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("/* cache */ WITH t(n) AS ( VALUES (1) UNION ALL SELECT n+1 FROM t WHERE n < 10000 ) SELECT xmlelement(root, xmlagg(xmlelement(val, n))) FROM t");
assertTrue(rs.next());
rs.getString(1);
assertFalse(rs.next());
rs.close();
rs = s.executeQuery("/* cache */ WITH t(n) AS ( VALUES (1) UNION ALL SELECT n+1 FROM t WHERE n < 10000 ) SELECT xmlelement(root, xmlagg(xmlelement(val, n))) FROM t");
assertTrue(rs.next());
//rs.getString(1);
assertFalse(rs.next());
}

}

0 comments on commit e84832b

Please sign in to comment.