use of org.teiid.common.buffer.CacheEntry in project teiid by teiid.
the class BufferFrontedFileStoreCache method get.
@Override
public CacheEntry get(PhysicalInfo info, Long oid, WeakReference<? extends Serializer<?>> ref) throws TeiidComponentException {
if (info == null) {
return null;
}
Serializer<?> serializer = ref.get();
if (serializer == null) {
return null;
}
readAttempts.incrementAndGet();
InputStream is = null;
Lock lock = null;
ExtensibleBufferedInputStream eis = null;
int memoryBlocks = 0;
try {
synchronized (info) {
// load should be locked
assert !info.pinned && info.loading;
// not necessary, but should make things safer
info.await(true, false);
if (info.inode != EMPTY_ADDRESS) {
info.pinned = true;
memoryBufferEntries.touch(info);
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Getting object at inode", info.inode, serializer.getId(), oid);
}
BlockManager manager = getBlockManager(serializer.getId(), oid, info.inode);
is = new BlockInputStream(manager, info.memoryBlockCount);
} else if (info.block != EMPTY_ADDRESS) {
info.pinned = true;
memoryBufferEntries.recordAccess(info);
storageReads.incrementAndGet();
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Getting object at block", info.block, info.sizeIndex, serializer.getId(), oid);
}
BlockStore blockStore = sizeBasedStores[info.sizeIndex];
int segment = info.block / blockStore.blocksInUse.getBitsPerSegment();
FileStore fs = blockStore.stores[segment];
long blockOffset = (info.block % blockStore.blocksInUse.getBitsPerSegment()) * blockStore.blockSize;
eis = fs.createInputStream(blockOffset, info.memoryBlockCount << LOG_BLOCK_SIZE);
lock = blockStore.locks[segment].writeLock();
memoryBlocks = info.memoryBlockCount;
} else {
return null;
}
}
if (lock != null) {
is = readIntoMemory(info, eis, lock, memoryBlocks);
}
for (int i = 0; i < HEADER_BYTES; i++) {
is.read();
}
ObjectInput dis = new ObjectInputStream(is);
CacheEntry ce = new CacheEntry(new CacheKey(oid, 1, 1), info.sizeEstimate, serializer.deserialize(dis), ref, true);
return ce;
} catch (IOException e) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30048, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30048, info.gid, oid));
} catch (ClassNotFoundException e) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30048, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30048, info.gid, oid));
} catch (InterruptedException e) {
throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30049, e);
} finally {
synchronized (info) {
info.pinned = false;
info.notifyAll();
}
}
}
use of org.teiid.common.buffer.CacheEntry in project teiid by teiid.
the class TestBufferFrontedFileStoreCache method testDefragTruncateCompact.
@Test
public void testDefragTruncateCompact() throws Exception {
cache = createLayeredCache(1 << 15, 1 << 15, true, true);
cache.setCompactBufferFiles(true);
cache.setTruncateInterval(1);
cache.setMinDefrag(10000000);
Serializer<Integer> s = new SimpleSerializer();
WeakReference<? extends Serializer<?>> ref = new WeakReference<Serializer<?>>(s);
cache.createCacheGroup(s.getId());
Integer cacheObject = Integer.valueOf(5000);
for (int i = 0; i < 30; i++) {
CacheEntry ce = new CacheEntry((long) i);
ce.setSerializer(ref);
ce.setObject(cacheObject);
cache.addToCacheGroup(s.getId(), ce.getId());
cache.add(ce, s);
}
assertEquals(950272, cache.getDiskUsage());
for (int i = 0; i < 25; i++) {
cache.remove(1l, (long) i);
}
assertEquals(950272, cache.getDiskUsage());
cache.setMinDefrag(0);
cache.setTruncateInterval(1);
cache.defragTask.run();
assertEquals(131072, cache.getDiskUsage());
cache.defragTask.run();
// we've reached a stable size
assertEquals(131072, cache.getDiskUsage());
}
use of org.teiid.common.buffer.CacheEntry in project teiid by teiid.
the class TestBufferFrontedFileStoreCache method testAddGetMultiBlock.
@Test
public void testAddGetMultiBlock() throws Exception {
cache = createLayeredCache(1 << 26, 1 << 26, true, true);
CacheEntry ce = new CacheEntry(2l);
Serializer<Integer> s = new SimpleSerializer();
cache.createCacheGroup(s.getId());
Integer cacheObject = Integer.valueOf(2);
ce.setObject(cacheObject);
cache.addToCacheGroup(s.getId(), ce.getId());
cache.add(ce, s);
ce = get(cache, 2l, s);
assertEquals(cacheObject, ce.getObject());
// test something that exceeds the direct inode data blocks
ce = new CacheEntry(3l);
cacheObject = Integer.valueOf(80000);
ce.setObject(cacheObject);
cache.addToCacheGroup(s.getId(), ce.getId());
cache.add(ce, s);
ce = get(cache, 3l, s);
assertEquals(cacheObject, ce.getObject());
// repeat the test to ensure proper cleanup
ce = new CacheEntry(4l);
cacheObject = Integer.valueOf(60000);
ce.setObject(cacheObject);
cache.addToCacheGroup(s.getId(), ce.getId());
cache.add(ce, s);
ce = get(cache, 4l, s);
assertEquals(cacheObject, ce.getObject());
cache.removeCacheGroup(1l);
assertEquals(0, cache.getDataBlocksInUse());
assertEquals(0, cache.getInodesInUse());
// test something that exceeds the indirect data blocks
ce = new CacheEntry(3l);
cache.createCacheGroup(s.getId());
cacheObject = Integer.valueOf(5000000);
ce.setObject(cacheObject);
cache.addToCacheGroup(s.getId(), ce.getId());
cache.add(ce, s);
ce = get(cache, 3l, s);
assertEquals(cacheObject, ce.getObject());
cache.removeCacheGroup(1l);
assertEquals(0, cache.getDataBlocksInUse());
assertEquals(0, cache.getInodesInUse());
// test something that exceeds the allowable object size
ce = new CacheEntry(3l);
cache.createCacheGroup(s.getId());
cacheObject = Integer.valueOf(500000000);
ce.setObject(cacheObject);
cache.addToCacheGroup(s.getId(), ce.getId());
cache.add(ce, s);
ce = get(cache, 3l, s);
assertNull(ce);
cache.removeCacheGroup(1l);
assertEquals(0, cache.getDataBlocksInUse());
assertEquals(0, cache.getInodesInUse());
}
use of org.teiid.common.buffer.CacheEntry in project teiid by teiid.
the class TestBufferFrontedFileStoreCache method testMultipleAdds.
@Test
public void testMultipleAdds() throws Exception {
cache = createLayeredCache(1 << 18, 1 << 18, true, true);
Serializer<Integer> s = new SimpleSerializer() {
@Override
public void serialize(Integer obj, ObjectOutput oos) throws IOException {
throw new IOException();
}
};
CacheEntry ce = new CacheEntry(new CacheKey(31l, 0, 0), 1000000, null, null, false);
cache.createCacheGroup(s.getId());
Integer cacheObject = Integer.valueOf(50000);
ce.setObject(cacheObject);
cache.addToCacheGroup(s.getId(), ce.getId());
assertTrue(cache.add(ce, s));
s = new SimpleSerializer();
assertTrue(cache.add(ce, s));
assertNotNull(get(cache, ce.getId(), s));
}
use of org.teiid.common.buffer.CacheEntry in project teiid by teiid.
the class TestBufferFrontedFileStoreCache method testDefragTruncate.
@Test
public void testDefragTruncate() throws Exception {
cache = createLayeredCache(1 << 15, 1 << 15, true, true);
cache.setMinDefrag(10000000);
Serializer<Integer> s = new SimpleSerializer();
WeakReference<? extends Serializer<?>> ref = new WeakReference<Serializer<?>>(s);
cache.createCacheGroup(s.getId());
Integer cacheObject = Integer.valueOf(5000);
for (int i = 0; i < 30; i++) {
CacheEntry ce = new CacheEntry((long) i);
ce.setSerializer(ref);
ce.setObject(cacheObject);
cache.addToCacheGroup(s.getId(), ce.getId());
cache.add(ce, s);
}
assertEquals(950272, cache.getDiskUsage());
for (int i = 0; i < 25; i++) {
cache.remove(1l, (long) i);
}
assertEquals(950272, cache.getDiskUsage());
cache.setMinDefrag(0);
cache.setTruncateInterval(1);
cache.defragTask.run();
assertEquals(622592, cache.getDiskUsage());
cache.defragTask.run();
assertEquals(262144, cache.getDiskUsage());
cache.defragTask.run();
assertEquals(131072, cache.getDiskUsage());
cache.defragTask.run();
// we've reached a stable size
assertEquals(131072, cache.getDiskUsage());
}
Aggregations