use of org.teiid.common.buffer.CacheKey in project teiid by teiid.
the class BufferFrontedFileStoreCache method shouldPlaceInMemoryBuffer.
/**
* Determine if an object should be in the memory buffer.
* @param currentTime
* @param info
* @return
*/
private boolean shouldPlaceInMemoryBuffer(PhysicalInfo info) {
if (info.evicting || info.inode != EMPTY_ADDRESS) {
return false;
}
if (info.block == EMPTY_ADDRESS) {
return true;
}
PhysicalInfo lowest = memoryBufferEntries.firstEntry(false);
CacheKey key = info.getKey();
return (blocksInuse.getTotalBits() - blocksInuse.getBitsSet()) > (cleaningThreshold + info.memoryBlockCount) || (lowest != null && lowest.block != EMPTY_ADDRESS && lowest.getKey().getOrderingValue() < key.getOrderingValue());
}
use of org.teiid.common.buffer.CacheKey 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.CacheKey in project teiid by teiid.
the class LrfuEvictionQueue method toString.
@Override
public String toString() {
StringBuilder result = new StringBuilder();
// $NON-NLS-1$ //$NON-NLS-2$
result.append("Size:").append(getSize()).append(" ");
int max = 2000;
for (CacheKey e : evictionQueue.keySet()) {
// $NON-NLS-1$ //$NON-NLS-2$
result.append("(").append(e.getOrderingValue()).append(", ").append(e.getLastAccess()).append(", ").append(// $NON-NLS-1$
e.getId()).append(// $NON-NLS-1$
") ");
if (--max == 0) {
// $NON-NLS-1$
result.append("...");
}
}
return result.toString();
}
use of org.teiid.common.buffer.CacheKey in project teiid by teiid.
the class LrfuEvictionQueue method recordAccess.
/**
* Callers should be synchronized on value
*/
void recordAccess(V value) {
CacheKey key = value.getKey();
long lastAccess = key.getLastAccess();
long currentClock = clock.get();
long orderingValue = key.getOrderingValue();
orderingValue = computeNextOrderingValue(currentClock, lastAccess, orderingValue);
assert !this.evictionQueue.containsKey(value.getKey());
value.setKey(new CacheKey(key.getId(), currentClock, orderingValue));
}
use of org.teiid.common.buffer.CacheKey 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));
}
Aggregations