@Override public CacheObject update(int pos, CacheObject rec) { CacheObject old = find(pos); if (old == null) { put(rec); } else { if (SysProperties.CHECK) { if (old != rec) { DbException.throwInternalError("old!=record pos:" + pos + " old:" + old + " new:" + rec); } } if (!fifo) { removeFromLinkedList(rec); addToFront(rec); } } return old; }
CacheLRU(CacheWriter writer, int maxMemoryKb, boolean fifo) { this.writer = writer; this.fifo = fifo; this.setMaxMemory(maxMemoryKb); try { // Since setMaxMemory() ensures that maxMemory is >=0, // we don't have to worry about an underflow. long tmpLen = maxMemory / 64; if (tmpLen > Integer.MAX_VALUE) { throw new IllegalArgumentException(); } this.len = MathUtils.nextPowerOf2((int) tmpLen); } catch (IllegalArgumentException e) { throw new IllegalStateException("This much cache memory is not supported: " + maxMemoryKb + "kb", e); } this.mask = len - 1; clear(); }
@Override public CacheObject get(int pos) { CacheObject rec = find(pos); if (rec != null) { if (!fifo) { removeFromLinkedList(rec); addToFront(rec); } } return rec; }
@Override public void put(CacheObject rec) { if (SysProperties.CHECK) { int pos = rec.getPos(); CacheObject old = find(pos); if (old != null) { DbException .throwInternalError("try to add a record twice at pos " + pos); } } int index = rec.getPos() & mask; rec.cacheChained = values[index]; values[index] = rec; recordCount++; memory += rec.getMemory(); addToFront(rec); removeOldIfRequired(); }
removeFromLinkedList(check); addToFront(check); continue; changed.add(check); } else { remove(check.getPos()); remove(rec.getPos()); if (SysProperties.CHECK) { if (rec.cacheNext != null) {
removeFromLinkedList(rec); if (SysProperties.CHECK) { rec.cacheChained = null; CacheObject o = find(pos); if (o != null) { DbException.throwInternalError("not removed: " + o);
private void removeOldIfRequired() { // a small method, to allow inlining if (memory >= maxMemory) { removeOld(); } }
@Override public void setMaxMemory(int maxKb) { long newSize = maxKb * 1024L / 4; maxMemory = newSize < 0 ? 0 : newSize; // can not resize, otherwise existing records are lost // resize(maxSize); removeOldIfRequired(); }
public CacheLRU(CacheWriter writer, int maxKb) { int maxSize = maxKb * 1024 / 4; this.writer = writer; this.maxSize = maxSize; this.len = MathUtils.nextPowerOf2(maxSize / 64); this.mask = len - 1; MathUtils.checkPowerOf2(len); clear(); }
/** * Create a new page store object. * * @param database the database * @param fileName the file name * @param accessMode the access mode * @param cacheSizeDefault the default cache size */ public PageStore(Database database, String fileName, String accessMode, int cacheSizeDefault) { this.fileName = fileName; this.accessMode = accessMode; this.database = database; trace = database.getTrace(Trace.PAGE_STORE); // if (fileName.endsWith("X.h2.db")) // trace.setLevel(TraceSystem.DEBUG); String cacheType = database.getCacheType(); this.cache = CacheLRU.getCache(this, cacheType, cacheSizeDefault); pageStoreSession = new Session(database, null, 0); }
public CacheObject get(int pos) { CacheObject rec = find(pos); if (rec != null) { removeFromLinkedList(rec); addToFront(rec); } return rec; }
@Override public void put(CacheObject rec) { if (SysProperties.CHECK) { int pos = rec.getPos(); CacheObject old = find(pos); if (old != null) { DbException .throwInternalError("try to add a record twice at pos " + pos); } } int index = rec.getPos() & mask; rec.cacheChained = values[index]; values[index] = rec; recordCount++; memory += rec.getMemory(); addToFront(rec); removeOldIfRequired(); }
removeFromLinkedList(check); addToFront(check); continue; changed.add(check); } else { remove(check.getPos()); remove(rec.getPos()); if (SysProperties.CHECK) { if (rec.cacheNext != null) {
public void remove(int pos) { int index = pos & mask; CacheObject rec = values[index]; if (rec == null) { return; } if (rec.getPos() == pos) { values[index] = rec.chained; } else { CacheObject last; do { last = rec; rec = rec.chained; if (rec == null) { return; } } while (rec.getPos() != pos); last.chained = rec.chained; } recordCount--; sizeMemory -= rec.getMemorySize(); removeFromLinkedList(rec); if (SysProperties.CHECK) { rec.chained = null; if (find(pos) != null) { throw Message.getInternalError("not removed!"); } } }
private void removeOldIfRequired() { // a small method, to allow inlining if (memory >= maxMemory) { removeOld(); } }
public void setMaxSize(int maxKb) throws SQLException { int newSize = maxKb * 1024 / 4; maxSize = newSize < 0 ? 0 : newSize; // can not resize, otherwise existing records are lost // resize(maxSize); removeOldIfRequired(); }
/** * Create a new page store object. * * @param database the database * @param fileName the file name * @param accessMode the access mode * @param cacheSizeDefault the default cache size */ public PageStore(Database database, String fileName, String accessMode, int cacheSizeDefault) { this.fileName = fileName; this.accessMode = accessMode; this.database = database; trace = database.getTrace(Trace.PAGE_STORE); // if (fileName.endsWith("X.h2.db")) // trace.setLevel(TraceSystem.DEBUG); String cacheType = database.getCacheType(); this.cache = CacheLRU.getCache(this, cacheType, cacheSizeDefault); pageStoreSession = new Session(database, null, 0); }
public CacheObject update(int pos, CacheObject rec) throws SQLException { CacheObject old = find(pos); if (old == null) { put(rec); } else { if (SysProperties.CHECK) { if (old != rec) { throw Message.getInternalError("old != record old=" + old + " new=" + rec); } } removeFromLinkedList(rec); addToFront(rec); } return old; }
@Override public CacheObject get(int pos) { CacheObject rec = find(pos); if (rec != null) { if (!fifo) { removeFromLinkedList(rec); addToFront(rec); } } return rec; }