From: Wolfgang M. M. <wol...@us...> - 2004-06-04 09:47:37
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/storage/store In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30013/src/org/exist/storage/store Modified Files: CollectionStore.java DOMFile.java BFile.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: DOMFile.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/store/DOMFile.java,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** DOMFile.java 25 May 2004 09:26:10 -0000 1.29 --- DOMFile.java 4 Jun 2004 09:47:25 -0000 1.30 *************** *** 41,44 **** --- 41,45 ---- import org.exist.dom.NodeProxy; import org.exist.dom.XMLUtil; + import org.exist.storage.BrokerPool; import org.exist.storage.BufferStats; import org.exist.storage.NativeBroker; *************** *** 49,52 **** --- 50,54 ---- import org.exist.util.ByteConversion; import org.exist.util.Lock; + import org.exist.util.LockException; import org.exist.util.Lockable; import org.exist.util.ReadOnlyException; *************** *** 101,109 **** // page types public final static byte LOB = 21; - public final static byte RECORD = 20; ! protected final static short OVERFLOW = 0; ! private final Cache dataCache; --- 103,111 ---- // page types public final static byte LOB = 21; public final static byte RECORD = 20; + public final static short OVERFLOW = 0; ! public final static long DATA_SYNC_PERIOD = 1000; ! private final Cache dataCache; *************** *** 119,124 **** private DocumentImpl currentDocument = null; ! public DOMFile(int buffers, int dataBuffers) { ! super(buffers); lock = new ReentrantReadWriteLock("dom.dbx"); fileHeader = (DOMFileHeader) getFileHeader(); --- 121,126 ---- private DocumentImpl currentDocument = null; ! public DOMFile(BrokerPool pool, int buffers, int dataBuffers) { ! super(pool, buffers); lock = new ReentrantReadWriteLock("dom.dbx"); fileHeader = (DOMFileHeader) getFileHeader(); *************** *** 127,144 **** dataCache = new ClockCache(dataBuffers); dataCache.setFileName("dom.dbx"); } ! public DOMFile(File file) { ! this(256, 256); ! setFile(file); ! } ! ! public DOMFile(File file, int buffers) { ! this(buffers, 256); ! setFile(file); ! } ! ! public DOMFile(File file, int buffers, int dataBuffers) { ! this(buffers, dataBuffers); setFile(file); } --- 129,151 ---- dataCache = new ClockCache(dataBuffers); dataCache.setFileName("dom.dbx"); + + Runnable syncAction = new Runnable() { + public void run() { + try { + // LOG.debug("Triggering cache sync"); + lock.acquire(Lock.WRITE_LOCK); + dataCache.flush(); + } catch (LockException e) { + LOG.warn("Failed to acquire lock on dom.dbx"); + } finally { + lock.release(); + } + } + }; + pool.getSyncDaemon().executePeriodically(DATA_SYNC_PERIOD, syncAction, false); } ! public DOMFile(BrokerPool pool, File file, int buffers, int dataBuffers) { ! this(pool, buffers, dataBuffers); setFile(file); } *************** *** 624,628 **** public boolean create() throws DBException { ! if (super.create((short) 12)) return true; else --- 631,635 ---- public boolean create() throws DBException { ! if (super.create((short) 12, lock)) return true; else *************** *** 958,962 **** */ public boolean open() throws DBException { ! if (super.open(FILE_FORMAT_VERSION_ID)) return true; else --- 965,969 ---- */ public boolean open() throws DBException { ! if (super.open(FILE_FORMAT_VERSION_ID, lock)) return true; else *************** *** 1705,1715 **** } ! /* ! * (non-Javadoc) ! * ! * @see org.exist.storage.cache.Cacheable#release() ! */ ! public void sync() { ! if (isDirty()) write(); } --- 1712,1721 ---- } ! public boolean sync() { ! if (isDirty()) { ! write(); ! return true; ! } ! return false; } Index: BFile.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/store/BFile.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** BFile.java 2 Jun 2004 11:34:36 -0000 1.24 --- BFile.java 4 Jun 2004 09:47:25 -0000 1.25 *************** *** 37,40 **** --- 37,41 ---- import org.dbxml.core.filer.BTreeException; import org.dbxml.core.indexer.IndexQuery; + import org.exist.storage.BrokerPool; import org.exist.storage.BufferStats; import org.exist.storage.cache.Cache; *************** *** 80,83 **** --- 81,86 ---- public final static short FILE_FORMAT_VERSION_ID = 3; + public final static long DATA_SYNC_PERIOD = 15000; + // minimum free space a page should have to be // considered for reusing *************** *** 103,132 **** public int fixedKeyLen = -1; ! public BFile() { ! super(); ! fileHeader = (BFileHeader) getFileHeader(); ! minFree = PAGE_MIN_FREE; ! } ! ! public BFile(File file) { ! super(file); ! fileHeader = (BFileHeader) getFileHeader(); ! dataCache = new LRDCache(256); ! dataCache.setFileName(getFile().getName()); ! minFree = PAGE_MIN_FREE; ! lock = new ReentrantReadWriteLock(file.getName()); ! } ! ! public BFile(File file, int buffers) { ! super(file, buffers); ! fileHeader = (BFileHeader) getFileHeader(); ! dataCache = new LRDCache(buffers); ! dataCache.setFileName(getFile().getName()); ! minFree = PAGE_MIN_FREE; ! lock = new ReentrantReadWriteLock(file.getName()); ! } ! ! public BFile(File file, int btreeBuffers, int dataBuffers) { ! super(file, btreeBuffers); fileHeader = (BFileHeader) getFileHeader(); dataCache = new LRDCache(dataBuffers); --- 106,111 ---- public int fixedKeyLen = -1; ! public BFile(BrokerPool pool, File file, int btreeBuffers, int dataBuffers) { ! super(pool, file, btreeBuffers); fileHeader = (BFileHeader) getFileHeader(); dataCache = new LRDCache(dataBuffers); *************** *** 134,137 **** --- 113,131 ---- minFree = PAGE_MIN_FREE; lock = new ReentrantReadWriteLock(file.getName()); + + Runnable syncAction = new Runnable() { + public void run() { + try { + // LOG.debug("Triggering cache sync for " + getFile().getName()); + lock.acquire(Lock.WRITE_LOCK); + dataCache.flush(); + } catch (LockException e) { + LOG.warn("Failed to acquire lock on dom.dbx"); + } finally { + lock.release(); + } + } + }; + pool.getSyncDaemon().executePeriodically(getDataSyncPeriod(), syncAction, false); } *************** *** 152,155 **** --- 146,153 ---- } + protected long getDataSyncPeriod() { + return DATA_SYNC_PERIOD; + } + /** * Append the given data fragment to the value associated *************** *** 239,243 **** public boolean create() throws DBException { ! if (super.create((short) fixedKeyLen)) { fileHeader.setLastDataPage(-1); return true; --- 237,241 ---- public boolean create() throws DBException { ! if (super.create((short) fixedKeyLen, lock)) { fileHeader.setLastDataPage(-1); return true; *************** *** 540,544 **** public boolean open() throws DBException { ! return super.open(FILE_FORMAT_VERSION_ID); } --- 538,542 ---- public boolean open() throws DBException { ! return super.open(FILE_FORMAT_VERSION_ID, lock); } *************** *** 1189,1196 **** * @see org.exist.storage.cache.Cacheable#release() */ ! public void sync() { if (isDirty()) { try { write(); } catch (IOException e) { LOG.error("IO exception occurred while saving page " --- 1187,1195 ---- * @see org.exist.storage.cache.Cacheable#release() */ ! public boolean sync() { if (isDirty()) { try { write(); + return true; } catch (IOException e) { LOG.error("IO exception occurred while saving page " *************** *** 1198,1201 **** --- 1197,1201 ---- } } + return false; } Index: CollectionStore.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/store/CollectionStore.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CollectionStore.java 3 May 2004 12:58:12 -0000 1.4 --- CollectionStore.java 4 Jun 2004 09:47:25 -0000 1.5 *************** *** 9,12 **** --- 9,13 ---- import org.exist.collections.CollectionCache; + import org.exist.storage.BrokerPool; public class CollectionStore extends BFile { *************** *** 16,41 **** private CollectionCache collectionsCache = new CollectionCache(COLLECTION_BUFFER_SIZE); - - /** - * - */ - public CollectionStore() { - super(); - } - - /** - * @param file - */ - public CollectionStore(File file) { - super(file); - } - - /** - * @param file - * @param buffers - */ - public CollectionStore(File file, int buffers) { - super(file, buffers); - } /** --- 17,20 ---- *************** *** 44,49 **** * @param dataBuffers */ ! public CollectionStore(File file, int btreeBuffers, int dataBuffers) { ! super(file, btreeBuffers, dataBuffers); } --- 23,28 ---- * @param dataBuffers */ ! public CollectionStore(BrokerPool pool, File file, int btreeBuffers, int dataBuffers) { ! super(pool, file, btreeBuffers, dataBuffers); } *************** *** 51,53 **** --- 30,48 ---- return collectionsCache; } + + + /* (non-Javadoc) + * @see org.dbxml.core.filer.BTree#getBTreeSyncPeriod() + */ + protected long getBTreeSyncPeriod() { + return 1000; + } + + + /* (non-Javadoc) + * @see org.exist.storage.store.BFile#getDataSyncPeriod() + */ + protected long getDataSyncPeriod() { + return 1000; + } } |