[teiid-commits] teiid SVN: r2046 - trunk/engine/src/main/java/com/metamatrix/common/buffer/impl.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Sat Apr 10 21:03:24 EDT 2010


Author: shawkins
Date: 2010-04-10 21:03:23 -0400 (Sat, 10 Apr 2010)
New Revision: 2046

Modified:
   trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java
   trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/FileStorageManager.java
Log:
TEIID-913 adding a fix for buffer manager read errors and adding more logging

Modified: trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java	2010-04-09 21:22:55 UTC (rev 2045)
+++ trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/BufferManagerImpl.java	2010-04-11 01:03:23 UTC (rev 2046)
@@ -51,6 +51,7 @@
 import com.metamatrix.common.buffer.TupleBatch;
 import com.metamatrix.common.buffer.TupleBuffer;
 import com.metamatrix.common.buffer.BatchManager.ManagedBatch;
+import com.metamatrix.common.log.LogConstants;
 import com.metamatrix.common.log.LogManager;
 import com.metamatrix.common.types.DataTypeManager;
 import com.metamatrix.common.types.InputStreamFactory;
@@ -60,7 +61,6 @@
 import com.metamatrix.common.types.Streamable;
 import com.metamatrix.common.types.XMLType;
 import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.core.log.MessageLevel;
 import com.metamatrix.core.util.Assertion;
 import com.metamatrix.query.execution.QueryExecPlugin;
 import com.metamatrix.query.processor.xml.XMLUtil;
@@ -113,7 +113,7 @@
 		private int columnCount;
 		
 		public ManagedBatchImpl(String id, FileStore store, TupleBatch batch) {
-            LogManager.logTrace(com.metamatrix.common.log.LogConstants.CTX_BUFFER_MGR, "Add batch to BufferManager", batchAdded.incrementAndGet()); //$NON-NLS-1$
+            LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Add batch to BufferManager", batchAdded.incrementAndGet()); //$NON-NLS-1$
 			this.id = id;
 			this.store = store;
 			this.activeBatch = batch;
@@ -150,7 +150,8 @@
 
 		@Override
 		public TupleBatch getBatch(boolean cache, String[] types) throws MetaMatrixComponentException {
-			LogManager.logTrace(com.metamatrix.common.log.LogConstants.CTX_BUFFER_MGR, "Reading batch from disk", readAttempts.incrementAndGet(), "reference hits", referenceHit.get()); //$NON-NLS-1$ //$NON-NLS-2$
+			int reads = readAttempts.incrementAndGet();
+			LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, id, "getting batch", reads, "reference hits", referenceHit.get()); //$NON-NLS-1$ //$NON-NLS-2$
 			synchronized (activeBatches) {
 				TupleBufferInfo tbi = activeBatches.remove(this.id);
 				if (tbi != null) { 
@@ -186,7 +187,8 @@
 						return batch;
 					}
 				}
-				LogManager.logTrace(com.metamatrix.common.log.LogConstants.CTX_BUFFER_MGR, "Reading batch from disk", readCount.incrementAndGet()); //$NON-NLS-1$
+				int count = readCount.incrementAndGet();
+				LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, id, beginRow, "reading batch from disk, total reads:", count); //$NON-NLS-1$
 				try {
 		            ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(store.createInputStream(this.offset), IO_BUFFER_SIZE));
 		            batch = new TupleBatch();
@@ -211,15 +213,16 @@
 				TupleBatch batch = activeBatch;
 				if (batch != null) {
 					if (!persistent) {
-						LogManager.logTrace(com.metamatrix.common.log.LogConstants.CTX_BUFFER_MGR, "Writing batch to disk", writeCount.incrementAndGet()); //$NON-NLS-1$
+						int count = writeCount.incrementAndGet();
+						LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, id, beginRow, "writing batch to disk, total writes: ", count); //$NON-NLS-1$
 						synchronized (store) {
 							offset = store.getLength();
 							OutputStream fsos = new BufferedOutputStream(store.createOutputStream(), IO_BUFFER_SIZE);
 				            ObjectOutputStream oos = new ObjectOutputStream(fsos);
 				            batch.writeExternal(oos);
-				            oos.flush();
 				            oos.close();
 						}
+						LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, id, beginRow, "batch written starting at:", offset); //$NON-NLS-1$
 					}
 					this.batchReference = new WeakReference<TupleBatch>(batch);
 				}
@@ -349,17 +352,13 @@
     		}
     	};
         TupleBuffer tupleBuffer = new TupleBuffer(batchManager, newID, elements, getProcessorBatchSize());
-        if (LogManager.isMessageToBeRecorded(com.metamatrix.common.log.LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
-            LogManager.logDetail(com.metamatrix.common.log.LogConstants.CTX_BUFFER_MGR, new Object[]{"Creating TupleBuffer:", newID, "of type "+tupleSourceType}); //$NON-NLS-1$ //$NON-NLS-2$
-        }
+        LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Creating TupleBuffer:", newID, "of type ", tupleSourceType); //$NON-NLS-1$ //$NON-NLS-2$
         return tupleBuffer;
     }
     
     @Override
     public FileStore createFileStore(String name) {
-    	if (LogManager.isMessageToBeRecorded(com.metamatrix.common.log.LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
-            LogManager.logDetail(com.metamatrix.common.log.LogConstants.CTX_BUFFER_MGR, "Creating FileStore:", name); //$NON-NLS-1$ 
-        }
+        LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Creating FileStore:", name); //$NON-NLS-1$ 
     	return this.diskMgr.createFileStore(name);
     }
     
@@ -461,7 +460,7 @@
 			try {
 				mb.persist();
 			} catch (MetaMatrixComponentException e) {
-				LogManager.logDetail(com.metamatrix.common.log.LogConstants.CTX_BUFFER_MGR, e, "Error persisting batch, attempts to read that batch later will result in an exception"); //$NON-NLS-1$
+				LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, e, "Error persisting batch, attempts to read that batch later will result in an exception"); //$NON-NLS-1$
 			}
 		}
 	}

Modified: trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/FileStorageManager.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/FileStorageManager.java	2010-04-09 21:22:55 UTC (rev 2045)
+++ trunk/engine/src/main/java/com/metamatrix/common/buffer/impl/FileStorageManager.java	2010-04-11 01:03:23 UTC (rev 2046)
@@ -140,17 +140,19 @@
 	            storageFiles.put(fileOffset, newFileInfo);
 	            fileInfo = newFileInfo;
 	        }
-	        try {
-	        	RandomAccessFile fileAccess = fileInfo.open();
-	            long pointer = fileAccess.length();
-	            fileAccess.setLength(pointer + length);
-	            fileAccess.seek(pointer);
-	            fileAccess.write(bytes, offset, length);
-	        } catch(IOException e) {
-	            throw new MetaMatrixComponentException(e, QueryExecPlugin.Util.getString("FileStoreageManager.error_reading", fileInfo.file.getAbsoluteFile())); //$NON-NLS-1$
-	        } finally {
-	        	fileInfo.close();
-	        }
+			synchronized (fileInfo) {
+		        try {
+		        	RandomAccessFile fileAccess = fileInfo.open();
+		            long pointer = fileAccess.length();
+		            fileAccess.setLength(pointer + length);
+		            fileAccess.seek(pointer);
+		            fileAccess.write(bytes, offset, length);
+		        } catch(IOException e) {
+		            throw new MetaMatrixComponentException(e, QueryExecPlugin.Util.getString("FileStoreageManager.error_reading", fileInfo.file.getAbsoluteFile())); //$NON-NLS-1$
+		        } finally {
+		        	fileInfo.close();
+		        }
+			}
 		}
 		
 		public synchronized void removeDirect() {



More information about the teiid-commits mailing list