Author: mdrillin
Date: 2011-06-24 15:40:55 -0400 (Fri, 24 Jun 2011)
New Revision: 3271
Modified:
branches/7.1.1.CP3/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java
branches/7.1.1.CP3/engine/src/main/resources/org/teiid/query/i18n.properties
branches/7.1.1.CP3/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java
Log:
TEIID-1654 ensuring that missing cache entries are not restored
Modified:
branches/7.1.1.CP3/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java
===================================================================
---
branches/7.1.1.CP3/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java 2011-06-24
14:37:08 UTC (rev 3270)
+++
branches/7.1.1.CP3/engine/src/main/java/org/teiid/dqp/internal/process/CachedResults.java 2011-06-24
19:40:55 UTC (rev 3271)
@@ -35,6 +35,7 @@
import org.teiid.common.buffer.TupleBuffer;
import org.teiid.common.buffer.BufferManager.TupleSourceType;
import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.Assertion;
import org.teiid.logging.LogConstants;
@@ -118,15 +119,16 @@
@Override
public synchronized boolean restore(Cache cache, BufferManager bufferManager) {
- try {
- if (this.results == null) {
+ if (this.results == null) {
+ TupleBuffer buffer = null;
+ try {
List<ElementSymbol> schema = new ArrayList<ElementSymbol>(types.length);
for (String type : types) {
ElementSymbol es = new ElementSymbol("x"); //$NON-NLS-1$
es.setType(DataTypeManager.getDataTypeClass(type));
schema.add(es);
}
- TupleBuffer buffer = bufferManager.createTupleBuffer(schema, "cached",
TupleSourceType.FINAL); //$NON-NLS-1$
+ buffer = bufferManager.createTupleBuffer(schema, "cached",
TupleSourceType.FINAL); //$NON-NLS-1$
buffer.setBatchSize(this.batchSize);
if (this.hint != null) {
buffer.setPrefersMemory(this.hint.getPrefersMemory());
@@ -134,18 +136,24 @@
for (int row = 1; row <= this.rowCount; row+=this.batchSize) {
TupleBatch batch = (TupleBatch)cache.get(uuid+","+row); //$NON-NLS-1$
- if (batch != null) {
- buffer.addTupleBatch(batch, true);
- }
+ if (batch == null) {
+ LogManager.logInfo(LogConstants.CTX_DQP,
QueryPlugin.Util.getString("not_found_cache")); //$NON-NLS-1$
+ buffer.remove();
+ return false;
+ }
+ buffer.addTupleBatch(batch, true);
}
this.results = buffer;
bufferManager.addTupleBuffer(this.results);
this.results.close();
+ } catch (TeiidException e) {
+ LogManager.logWarning(LogConstants.CTX_DQP, e,
QueryPlugin.Util.getString("unexpected_exception_restoring_results"));
//$NON-NLS-1$
+ if (buffer != null) {
+ buffer.remove();
+ }
+ return false;
}
- return true;
- } catch (TeiidComponentException e) {
- LogManager.logDetail(LogConstants.CTX_DQP,
QueryPlugin.Util.getString("not_found_cache")); //$NON-NLS-1$
}
- return false;
+ return true;
}
}
Modified: branches/7.1.1.CP3/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
---
branches/7.1.1.CP3/engine/src/main/resources/org/teiid/query/i18n.properties 2011-06-24
14:37:08 UTC (rev 3270)
+++
branches/7.1.1.CP3/engine/src/main/resources/org/teiid/query/i18n.properties 2011-06-24
19:40:55 UTC (rev 3271)
@@ -869,7 +869,9 @@
datasource_not_found=Data Source {0} not accessible.
RequestWorkItem.cache_nondeterministic=Caching command "{0}" at a session
level, but less deterministic functions were evaluated.
-not_found_cache=Results not found in cache
+not_found_cache=Failed to restore results, since batch entries were missing. The entry
will be re-populated.
+unexpected_exception_restoring_results=Failed to restore results. The entry will be
re-populated.
+failed_to_cache=Failed to store the result set contents to disk.
failed_to_unwrap_connection=Failed to unwrap the source connection.
connection_factory_not_found=Failed to find the Connection Factory with JNDI name {0}.
Please check the name or deploy the Connection Factory with specified name.
Modified:
branches/7.1.1.CP3/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java
===================================================================
---
branches/7.1.1.CP3/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java 2011-06-24
14:37:08 UTC (rev 3270)
+++
branches/7.1.1.CP3/engine/src/test/java/org/teiid/dqp/internal/process/TestCachedResults.java 2011-06-24
19:40:55 UTC (rev 3271)
@@ -24,6 +24,7 @@
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -41,6 +42,7 @@
import org.teiid.common.buffer.TupleBuffer;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.UnitTestUtil;
import org.teiid.dqp.service.FakeBufferService;
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -101,7 +103,6 @@
results.setResults(tb);
results.setCommand(new Query());
Cache cache = new DefaultCache("dummy"); //$NON-NLS-1$
-
// simulate the jboss-cache remote transport, where the batches are remotely looked up
// in cache
for (int row=1; row<=tb.getRowCount();row+=4) {
@@ -119,7 +120,7 @@
CachedResults cachedResults = (CachedResults)ois.readObject();
ois.close();
- cachedResults.restore(cache, bm);
+ assertTrue(cachedResults.restore(cache, bm));
// since restored, simulate a async cache flush
cache.clear();
@@ -132,5 +133,9 @@
assertArrayEquals(tb.getBatch(1).getAllTuples(), cachedTb.getBatch(1).getAllTuples());
assertArrayEquals(tb.getBatch(9).getAllTuples(), cachedTb.getBatch(9).getAllTuples());
+
+ //ensure that an incomplete load fails
+ cache.remove(results.getId()+","+1); //$NON-NLS-1$
+ cachedResults = UnitTestUtil.helpSerialize(results);
}
}
Show replies by date