From: Wolfgang M. M. <wol...@us...> - 2004-06-04 09:42:28
|
Update of /cvsroot/exist/eXist-1.0/src/org/dbxml/core/filer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29160/src/org/dbxml/core/filer Modified Files: BTree.java Log Message: Improved the periodic flushing of cache contents: this is now handled by a background thread (SyncDaemon) instead of the cache object itself. Different settings are possible for different files. The vital files, dom.dbx and collections.dbx, are flushed very often (every second). The other files can be reconstructed and are thus written less frequently. Index: BTree.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/dbxml/core/filer/BTree.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** BTree.java 17 May 2004 09:59:43 -0000 1.25 --- BTree.java 4 Jun 2004 09:42:19 -0000 1.26 *************** *** 61,64 **** --- 61,65 ---- import org.dbxml.core.data.Value; import org.dbxml.core.indexer.IndexQuery; + import org.exist.storage.BrokerPool; import org.exist.storage.BufferStats; import org.exist.storage.cache.Cache; *************** *** 67,70 **** --- 68,73 ---- import org.exist.storage.io.VariableByteArrayInput; import org.exist.util.ByteConversion; + import org.exist.util.Lock; + import org.exist.util.LockException; import org.exist.xquery.TerminatedException; *************** *** 91,94 **** --- 94,100 ---- public class BTree extends Paged { + + public final static long BTREE_SYNC_PERIOD = 15000; + protected final static byte LEAF = 1; protected final static byte BRANCH = 2; *************** *** 99,111 **** private BTreeFileHeader fileHeader; protected int buffers = 1024; protected Cache cache; ! public BTree() { ! this(256); ! } ! ! public BTree(int buffers) { super(); this.buffers = buffers; fileHeader = (BTreeFileHeader) getFileHeader(); --- 105,116 ---- private BTreeFileHeader fileHeader; + protected BrokerPool pool; + protected int buffers = 1024; protected Cache cache; ! public BTree(BrokerPool pool, int buffers) { super(); + this.pool = pool; this.buffers = buffers; fileHeader = (BTreeFileHeader) getFileHeader(); *************** *** 114,132 **** } ! public BTree(File file) { ! this(); ! setFile(file); ! } ! ! public BTree(File file, int buffers) { ! this(buffers); setFile(file); } ! public boolean open(short expectedVersion) throws DBException { if (super.open(expectedVersion)) { ! cache = new LRDCache(buffers); ! cache.setFileName(getFile().getName()); ! //rootNode = getBTreeNode( fileHeader.getRootPage(), null ); return true; } else --- 119,130 ---- } ! public BTree(BrokerPool pool, File file, int buffers) { ! this(pool, buffers); setFile(file); } ! public boolean open(short expectedVersion, Lock lock) throws DBException { if (super.open(expectedVersion)) { ! initCache(lock); return true; } else *************** *** 134,146 **** } ! public boolean create() throws DBException { ! return create((short) - 1); } ! public boolean create(short fixedKeyLen) throws DBException { if (super.create()) try { ! cache = new LRDCache(buffers); ! cache.setFileName(getFile().getName()); createRootNode(); fileHeader.setFixedKeyLen(fixedKeyLen); --- 132,143 ---- } ! public boolean create(Lock lock) throws DBException { ! return create((short) - 1, lock); } ! public boolean create(short fixedKeyLen, Lock lock) throws DBException { if (super.create()) try { ! initCache(lock); createRootNode(); fileHeader.setFixedKeyLen(fixedKeyLen); *************** *** 153,156 **** --- 150,177 ---- } + private void initCache(final Lock lock) { + cache = new LRDCache(buffers); + cache.setFileName(getFile().getName()); + + Runnable syncAction = new Runnable() { + public void run() { + try { + // LOG.debug("Triggering cache sync for " + getFile().getName()); + lock.acquire(Lock.WRITE_LOCK); + cache.flush(); + } catch (LockException e) { + LOG.warn("Failed to acquire lock on dom.dbx"); + } finally { + lock.release(); + } + } + }; + pool.getSyncDaemon().executePeriodically(getBTreeSyncPeriod(), syncAction, false); + } + + protected long getBTreeSyncPeriod() { + return BTREE_SYNC_PERIOD; + } + public short getFixedKeyLen() { BTreeFileHeader fileHeader = (BTreeFileHeader) getFileHeader(); *************** *** 375,385 **** } ! public void sync() { if(isDirty()) try { write(); } catch (IOException e) { LOG.warn("IO error while writing page: " + page.getPageNum(), e); } } --- 396,408 ---- } ! public boolean sync() { if(isDirty()) try { write(); + return true; } catch (IOException e) { LOG.warn("IO error while writing page: " + page.getPageNum(), e); } + return false; } |