[teiid-commits] teiid SVN: r2264 - in trunk: engine/src/main/java/org/teiid/common/buffer and 4 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri Jun 18 22:54:57 EDT 2010


Author: shawkins
Date: 2010-06-18 22:54:56 -0400 (Fri, 18 Jun 2010)
New Revision: 2264

Modified:
   trunk/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml
   trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java
   trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
   trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java
   trunk/engine/src/main/resources/org/teiid/query/execution/i18n.properties
   trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStorageManager.java
   trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java
Log:
TEIID-954 adding the ability to limit the amount of disk buffer space used.  also adding buffermanager stats to the bufferservice for monitoring.

Modified: trunk/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml
===================================================================
--- trunk/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml	2010-06-18 23:56:02 UTC (rev 2263)
+++ trunk/build/kits/jboss-container/deploy/teiid/teiid-jboss-beans.xml	2010-06-19 02:54:56 UTC (rev 2264)
@@ -56,6 +56,8 @@
         <property name="maxProcessingBatchesColumns">128</property>
         <!--  Max File size in MB (default 2GB)-->
         <property name="maxFileSize">2048</property>
+        <!-- Max storage space, in MB, to be used for buffer files (default 50G) -->
+        <property name="maxBufferSpace">51200</property>
         <!-- Max open buffer files (default 64) -->
         <property name="maxOpenFiles">64</property> 
     </bean>

Modified: trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java	2010-06-18 23:56:02 UTC (rev 2263)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/FileStore.java	2010-06-19 02:54:56 UTC (rev 2264)
@@ -132,7 +132,7 @@
 	}
 	
 	private boolean removed;
-	private long len;
+	protected long len;
 	
 	public void setCleanupReference(Object o) {
 		REFERENCES.add(new CleanupReference(o, this));

Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java	2010-06-18 23:56:02 UTC (rev 2263)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java	2010-06-19 02:54:56 UTC (rev 2264)
@@ -274,6 +274,22 @@
 	private AtomicInteger readAttempts = new AtomicInteger();
 	private AtomicInteger referenceHit = new AtomicInteger();
 	
+	public long getBatchesAdded() {
+		return batchAdded.get();
+	}
+	
+	public long getReadCount() {
+		return readCount.get();
+	}
+	
+	public long getWriteCount() {
+		return writeCount.get();
+	}
+	
+	public long getReadAttempts() {
+		return readAttempts.get();
+	}
+	
 	@Override
     public int getMaxProcessingBatchColumns() {
 		return maxProcessingBatches;

Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java	2010-06-18 23:56:02 UTC (rev 2263)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/FileStorageManager.java	2010-06-19 02:54:56 UTC (rev 2264)
@@ -30,6 +30,7 @@
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.TreeMap;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.teiid.common.buffer.FileStore;
 import org.teiid.common.buffer.StorageManager;
@@ -47,8 +48,12 @@
 	
 	public static final int DEFAULT_MAX_OPEN_FILES = 64;
 	public static final long DEFAULT_MAX_FILESIZE = 2L * 1024L;
+	public static final long DEFAULT_MAX_BUFFERSPACE = 50L * 1024L * 1024L * 1024L;
 	private static final String FILE_PREFIX = "b_"; //$NON-NLS-1$
 	
+	private long maxBufferSpace = DEFAULT_MAX_BUFFERSPACE;
+	private AtomicLong usedBufferSpace = new AtomicLong();
+	
 	private class FileInfo {
     	private File file;
         private RandomAccessFile fileData;       // may be null if not open
@@ -122,6 +127,11 @@
 	     * Concurrent writes are prevented by FileStore, but in general should not happen since processing is single threaded.
 	     */
 		public void writeDirect(byte[] bytes, int offset, int length) throws TeiidComponentException {
+			long used = usedBufferSpace.addAndGet(length);
+			if (used > maxBufferSpace) {
+				usedBufferSpace.addAndGet(-length);
+				throw new TeiidComponentException(QueryExecPlugin.Util.getString("FileStoreageManager.space_exhausted", maxBufferSpace)); //$NON-NLS-1$
+			}
 			Map.Entry<Long, FileInfo> entry = this.storageFiles.lastEntry();
 			boolean createNew = false;
 			FileInfo fileInfo = null;
@@ -157,6 +167,7 @@
 		}
 		
 		public synchronized void removeDirect() {
+			usedBufferSpace.addAndGet(-len);
 			for (FileInfo info : storageFiles.values()) {
 				info.delete();
 			}
@@ -252,5 +263,21 @@
     public int getOpenFiles() {
     	return this.fileCache.size();
     }
+    
+    /**
+     * Get the used buffer space in bytes
+     * @return
+     */
+    public long getUsedBufferSpace() {
+		return usedBufferSpace.get();
+	}
+    
+    /**
+     * Set the max amount of buffer space in bytes
+     * @param maxBufferSpace
+     */
+    public void setMaxBufferSpace(long maxBufferSpace) {
+		this.maxBufferSpace = maxBufferSpace;
+	}
 
 }

Modified: trunk/engine/src/main/resources/org/teiid/query/execution/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/execution/i18n.properties	2010-06-18 23:56:02 UTC (rev 2263)
+++ trunk/engine/src/main/resources/org/teiid/query/execution/i18n.properties	2010-06-19 02:54:56 UTC (rev 2264)
@@ -208,6 +208,7 @@
 FileStorageManager.error_getting_free_disk_space=Error while seeking free disk space for directory: {0}
 FileStorageManager.can_not_save_lobs=Can not save *Reference Lobs* into persistent disk storage.
 FileStorageManager.batch_error=Error while converting batched data to file storage.
+FileStoreageManager.space_exhausted=Max buffer space of {0} bytes has been exceed.  The current operation will be aborted.
 
 TextTableNode.no_value=No value found for column \"{0}\" in the row ending on text line {1} in {2}.
 TextTableNode.conversion_error=Could not convert value for column \"{0}\" in the row ending on text line {1} in {2}.

Modified: trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStorageManager.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStorageManager.java	2010-06-18 23:56:02 UTC (rev 2263)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/impl/TestFileStorageManager.java	2010-06-19 02:54:56 UTC (rev 2264)
@@ -32,12 +32,9 @@
 
 import org.junit.Test;
 import org.teiid.common.buffer.FileStore;
-import org.teiid.common.buffer.StorageManager;
-import org.teiid.common.buffer.impl.FileStorageManager;
 import org.teiid.core.TeiidComponentException;
 import org.teiid.core.util.UnitTestUtil;
 
-
 public class TestFileStorageManager {
 		
 	public FileStorageManager getStorageManager(Integer maxFileSize, Integer openFiles, String dir) throws TeiidComponentException {
@@ -53,14 +50,14 @@
         return sm;
 	}
     
-    @Test public void testAddGetBatch1() throws Exception {
-        StorageManager sm = getStorageManager(null, null, null);        
+    @Test public void testWrite() throws Exception {
+        FileStorageManager sm = getStorageManager(null, null, null);        
         String tsID = "0";     //$NON-NLS-1$
-        // Add one batch
         FileStore store = sm.createFileStore(tsID);
         writeBytes(store);
-        // Get that batch
+        assertEquals(2048, sm.getUsedBufferSpace());
         store.remove();
+        assertEquals(0, sm.getUsedBufferSpace());
     }
             
     @Test public void testCreatesSpillFiles() throws Exception {
@@ -81,6 +78,15 @@
         
         assertEquals(0, cache.size());
     }
+    
+    @Test(expected=TeiidComponentException.class) public void testMaxSpace() throws Exception {
+    	FileStorageManager sm = getStorageManager(null, null, null); 
+    	sm.setMaxBufferSpace(1);
+        String tsID = "0";     //$NON-NLS-1$
+        // Add one batch
+        FileStore store = sm.createFileStore(tsID);
+        writeBytes(store);
+    }
 
     static Random r = new Random();
     

Modified: trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java	2010-06-18 23:56:02 UTC (rev 2263)
+++ trunk/runtime/src/main/java/org/teiid/services/BufferServiceImpl.java	2010-06-19 02:54:56 UTC (rev 2264)
@@ -44,14 +44,15 @@
 
 
 /**
- * Implement the BufferService for the DQP Embedded component.  This implementation
- * may use either an all-memory model (which is prone to OutOfMemoryErrors) or 
+ * Implements the BufferService.  This implementation
+ * may use either an all-memory model (which is typically only for testing) or 
  * a mixed disk/memory model which requires use of a directory on the disk 
  * for file service access.
  */
 @ManagementObject(componentType=@ManagementComponent(type="teiid",subtype="dqp"), properties=ManagementProperties.EXPLICIT)
 public class BufferServiceImpl implements BufferService, Serializable {
 	private static final long serialVersionUID = -6217808623863643531L;
+	private static final long MB = 1<<20;
 
     // Instance
     private BufferManagerImpl bufferMgr;
@@ -65,6 +66,8 @@
     private long maxFileSize = FileStorageManager.DEFAULT_MAX_FILESIZE; // 2GB
     private int maxProcessingBatchesColumns = BufferManager.DEFAULT_MAX_PROCESSING_BATCHES;
     private int maxReserveBatchColumns = BufferManager.DEFAULT_RESERVE_BUFFERS;
+    private long maxBufferSpace = FileStorageManager.DEFAULT_MAX_BUFFERSPACE;
+	private FileStorageManager fsm;
 	
     /**
      * Clean the file storage directory on startup 
@@ -90,10 +93,11 @@
             // If necessary, add disk storage manager
             if(useDisk) {
                 // Get the properties for FileStorageManager and create.
-                FileStorageManager fsm = new FileStorageManager();
+                fsm = new FileStorageManager();
                 fsm.setStorageDirectory(bufferDir.getCanonicalPath());
                 fsm.setMaxFileSize(maxFileSize);
                 fsm.setMaxOpenFiles(maxOpenFiles);
+                fsm.setMaxBufferSpace(maxBufferSpace*MB);
                 fsm.initialize();        
                 this.bufferMgr.setStorageManager(fsm);
                 
@@ -139,7 +143,7 @@
 	}
 
 	public void setDiskDirectory(String dir) {
-		this.bufferDir = new File(dir, "buffer");
+		this.bufferDir = new File(dir, "buffer"); //$NON-NLS-1$
 		if (!bufferDir.exists()) {
 			this.bufferDir.mkdirs();
 		}
@@ -191,7 +195,7 @@
     	this.maxProcessingBatchesColumns  = value;
     }
 
-    @ManagementProperty(description="Max file size for buffer files (default 2GB)")
+    @ManagementProperty(description="Max file size, in MB, for buffer files (default 2GB)")
 	public long getMaxFileSize() {
 		return maxFileSize;
 	}
@@ -201,17 +205,54 @@
 		this.maxOpenFiles = maxOpenFiles;
 	}
 
-    @ManagementProperty(description="#The number of batch columns guarenteed to a processing operation.  Set this value lower if the workload typically" + 
+    @ManagementProperty(description="The number of batch columns guarenteed to a processing operation.  Set this value lower if the workload typically" + 
     		"processes larger numbers of concurrent queries with large intermediate results from operations such as sorting, " + 
     		"grouping, etc. (default 128)")
 	public int getMaxProcessingBatchesColumns() {
 		return maxProcessingBatchesColumns;
 	}
 
-    @ManagementProperty(description="#The number of batch columns to allow in memory (default 16384).  " + 
+    @ManagementProperty(description="The number of batch columns to allow in memory (default 16384).  " + 
     		"This value should be set lower or higher depending on the available memory to Teiid in the VM.  " + 
     		"16384 is considered a good default for a dedicated 32-bit VM running Teiid with a 1 gig heap.")
 	public int getMaxReserveBatchColumns() {
 		return maxReserveBatchColumns;
 	}
+    
+    @ManagementProperty(description="Max file storage space, in MB, to be used for buffer files (default 256G)")
+	public long getMaxBufferSpace() {
+		return maxBufferSpace;
+	}
+    
+    public void setMaxBufferSpace(long maxBufferSpace) {
+		this.maxBufferSpace = maxBufferSpace;
+	}
+
+    @ManagementProperty(description="The currently used file buffer space in MB.", readOnly=true)
+    public long getUserBufferSpace() {
+    	if (fsm != null) {
+    		return fsm.getUsedBufferSpace()/MB;
+    	}
+    	return 0;
+    }
+
+    @ManagementProperty(description="The total number of batches added to the buffer mananger.", readOnly=true)
+	public long getBatchesAdded() {
+		return bufferMgr.getBatchesAdded();
+	}
+
+    @ManagementProperty(description="The total number of batches read from storage.", readOnly=true)
+	public long getReadCount() {
+		return bufferMgr.getReadCount();
+	}
+
+    @ManagementProperty(description="The total number of batches written to storage.", readOnly=true)
+    public long getWriteCount() {
+		return bufferMgr.getWriteCount();
+	}
+
+    @ManagementProperty(description="The total number of batch read attempts.", readOnly=true)
+	public long getReadAttempts() {
+		return bufferMgr.getReadAttempts();
+	}
 }



More information about the teiid-commits mailing list