Search in sources :

Example 1 with StorageManager

use of org.teiid.common.buffer.StorageManager in project teiid by teiid.

the class TestBufferFrontedFileStoreCache method createLayeredCache.

private static BufferFrontedFileStoreCache createLayeredCache(int bufferSpace, int objectSize, boolean memStorage, boolean allocate) throws TeiidComponentException {
    BufferFrontedFileStoreCache fsc = new BufferFrontedFileStoreCache();
    // prevent asynch affects
    fsc.cleanerRunning.set(true);
    fsc.setMemoryBufferSpace(bufferSpace);
    fsc.setMaxStorageObjectSize(objectSize);
    fsc.setDirect(false);
    if (memStorage) {
        SplittableStorageManager ssm = new SplittableStorageManager(new MemoryStorageManager());
        ssm.setMaxFileSizeDirect(MemoryStorageManager.MAX_FILE_SIZE);
        fsc.setStorageManager(ssm);
    } else {
        StorageManager sm = new StorageManager() {

            @Override
            public void initialize() throws TeiidComponentException {
            }

            @Override
            public FileStore createFileStore(String name) {
                return new FileStore() {

                    @Override
                    public void setLength(long length) throws IOException {
                        throw new OutOfDiskException(null);
                    }

                    @Override
                    protected void removeDirect() {
                    }

                    @Override
                    protected int readWrite(long fileOffset, byte[] b, int offSet, int length, boolean write) throws IOException {
                        return 0;
                    }

                    @Override
                    public long getLength() {
                        return 0;
                    }
                };
            }

            @Override
            public long getMaxStorageSpace() {
                return -1;
            }
        };
        fsc.setStorageManager(sm);
    }
    fsc.initialize(allocate);
    return fsc;
}
Also used : FileStore(org.teiid.common.buffer.FileStore) StorageManager(org.teiid.common.buffer.StorageManager)

Example 2 with StorageManager

use of org.teiid.common.buffer.StorageManager in project teiid by teiid.

the class BufferServiceImpl method start.

public void start() {
    try {
        // Construct and initialize the buffer manager
        this.bufferMgr = new BufferManagerImpl(false);
        this.bufferMgr.setProcessorBatchSize(processorBatchSize);
        this.bufferMgr.setMaxReserveKB(this.maxReserveKb);
        this.bufferMgr.setMaxProcessingKB(this.maxProcessingKb);
        this.bufferMgr.setInlineLobs(inlineLobs);
        this.bufferMgr.initialize();
        // If necessary, add disk storage manager
        if (useDisk) {
            // $NON-NLS-1$
            LogManager.logDetail(LogConstants.CTX_DQP, "Starting BufferManager using", bufferDir);
            if (!bufferDir.exists()) {
                this.bufferDir.mkdirs();
            }
            // start the file storage manager in clean state
            // wise FileStorageManager is smart enough to clean up after itself
            cleanDirectory(bufferDir);
            // Get the properties for FileStorageManager and create.
            fsm = new FileStorageManager();
            fsm.setStorageDirectory(bufferDir.getCanonicalPath());
            fsm.setMaxOpenFiles(maxOpenFiles);
            fsm.setMaxBufferSpace(maxBufferSpace * MB);
            SplittableStorageManager ssm = new SplittableStorageManager(fsm);
            ssm.setMaxFileSize(maxFileSize);
            StorageManager sm = ssm;
            if (encryptFiles) {
                sm = new EncryptedStorageManager(ssm);
            }
            fsc = new BufferFrontedFileStoreCache();
            fsc.setBufferManager(this.bufferMgr);
            fsc.setMaxStorageObjectSize(maxStorageObjectSize);
            fsc.setDirect(memoryBufferOffHeap);
            // use approximately 40% of what's set aside for the reserved accounting for conversion from kb to bytes
            long autoMaxBufferSpace = 4 * (((long) this.bufferMgr.getMaxReserveKB()) << 10) / 10;
            // estimate inode/batch overhead
            if (memoryBufferSpace < 0) {
                fsc.setMemoryBufferSpace(autoMaxBufferSpace);
            } else {
                // scale from MB to bytes
                fsc.setMemoryBufferSpace(memoryBufferSpace << 20);
            }
            long batchAndInodeOverheadKB = fsc.getMemoryBufferSpace() >> (memoryBufferOffHeap ? 19 : 17);
            this.bufferMgr.setMaxReserveKB((int) Math.max(0, this.bufferMgr.getMaxReserveKB() - batchAndInodeOverheadKB));
            if (this.maxReserveKb < 0) {
                if (memoryBufferOffHeap) {
                    // the default is too large if off heap
                    this.bufferMgr.setMaxReserveKB(8 * this.bufferMgr.getMaxReserveKB() / 10);
                } else {
                    // adjust the value for the main memory buffer
                    this.bufferMgr.setMaxReserveKB((int) Math.max(0, this.bufferMgr.getMaxReserveKB() - (fsc.getMemoryBufferSpace() >> 10)));
                }
            }
            fsc.setStorageManager(sm);
            fsc.initialize();
            this.bufferMgr.setCache(fsc);
            this.workingMaxReserveKb = this.bufferMgr.getMaxReserveKB();
        } else {
            MemoryStorageManager msm = new MemoryStorageManager();
            SplittableStorageManager ssm = new SplittableStorageManager(msm);
            ssm.setMaxFileSizeDirect(MemoryStorageManager.MAX_FILE_SIZE);
            this.bufferMgr.setCache(msm);
            this.bufferMgr.setStorageManager(ssm);
        }
    } catch (TeiidComponentException e) {
        throw new TeiidRuntimeException(RuntimePlugin.Event.TEIID40039, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40039));
    } catch (IOException e) {
        throw new TeiidRuntimeException(RuntimePlugin.Event.TEIID40039, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40039));
    }
}
Also used : BufferFrontedFileStoreCache(org.teiid.common.buffer.impl.BufferFrontedFileStoreCache) SplittableStorageManager(org.teiid.common.buffer.impl.SplittableStorageManager) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) SplittableStorageManager(org.teiid.common.buffer.impl.SplittableStorageManager) StorageManager(org.teiid.common.buffer.StorageManager) EncryptedStorageManager(org.teiid.common.buffer.impl.EncryptedStorageManager) MemoryStorageManager(org.teiid.common.buffer.impl.MemoryStorageManager) FileStorageManager(org.teiid.common.buffer.impl.FileStorageManager) FileStorageManager(org.teiid.common.buffer.impl.FileStorageManager) TeiidComponentException(org.teiid.core.TeiidComponentException) EncryptedStorageManager(org.teiid.common.buffer.impl.EncryptedStorageManager) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) IOException(java.io.IOException) MemoryStorageManager(org.teiid.common.buffer.impl.MemoryStorageManager)

Aggregations

StorageManager (org.teiid.common.buffer.StorageManager)2 IOException (java.io.IOException)1 FileStore (org.teiid.common.buffer.FileStore)1 BufferFrontedFileStoreCache (org.teiid.common.buffer.impl.BufferFrontedFileStoreCache)1 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)1 EncryptedStorageManager (org.teiid.common.buffer.impl.EncryptedStorageManager)1 FileStorageManager (org.teiid.common.buffer.impl.FileStorageManager)1 MemoryStorageManager (org.teiid.common.buffer.impl.MemoryStorageManager)1 SplittableStorageManager (org.teiid.common.buffer.impl.SplittableStorageManager)1 TeiidComponentException (org.teiid.core.TeiidComponentException)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1