From: Wolfgang M. M. <wol...@us...> - 2004-08-04 14:48:17
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/storage In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2454/src/org/exist/storage Modified Files: DBBroker.java BrokerPool.java NativeBroker.java Log Message: Fixed some deadlocks introduced by yesterday's changes. Moved the global CollectionCache object in DBBroker to BrokerPool (it should not be declared static or it will not be re-initialized upon database restart). Index: NativeBroker.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/NativeBroker.java,v retrieving revision 1.94 retrieving revision 1.95 diff -C2 -d -r1.94 -r1.95 *** NativeBroker.java 3 Aug 2004 16:45:47 -0000 1.94 --- NativeBroker.java 4 Aug 2004 14:48:06 -0000 1.95 *************** *** 46,49 **** --- 46,50 ---- import org.exist.EXistException; import org.exist.collections.Collection; + import org.exist.collections.CollectionCache; import org.exist.collections.triggers.TriggerException; import org.exist.dom.ArraySet; *************** *** 76,79 **** --- 77,81 ---- import org.exist.util.ByteArrayPool; import org.exist.util.ByteConversion; + import org.exist.util.CollectionScanner; import org.exist.util.Configuration; import org.exist.util.Lock; *************** *** 253,257 **** elementIndex = new NativeElementIndex(this, config, elementsDb); user = new User("admin", null, "dba"); ! getOrCreateCollection(ROOT_COLLECTION); } catch (DBException e) { LOG.debug("failed to initialize database: " + e.getMessage(), e); --- 255,260 ---- elementIndex = new NativeElementIndex(this, config, elementsDb); user = new User("admin", null, "dba"); ! if(pool.isInitializing()) ! getOrCreateCollection(ROOT_COLLECTION); } catch (DBException e) { LOG.debug("failed to initialize database: " + e.getMessage(), e); *************** *** 387,390 **** --- 390,394 ---- name = name.substring(0, name.length() - 1); + CollectionCache collectionsCache = pool.getCollectionsCache(); synchronized(collectionsCache) { Collection collection = collectionsCache.get(name); *************** *** 426,432 **** if(lockMode != Lock.NO_LOCK) { try { ! // LOG.debug("acquiring lock on " + collection.getName()); collection.getLock().acquire(lockMode); ! // Thread.dumpStack(); } catch (LockException e1) { LOG.warn("Could not acquire lock on collection " + name); --- 430,436 ---- if(lockMode != Lock.NO_LOCK) { try { ! LOG.debug("acquiring lock on " + collection.getName()); collection.getLock().acquire(lockMode); ! LOG.debug("lock acquired"); } catch (LockException e1) { LOG.warn("Could not acquire lock on collection " + name); *************** *** 1515,1519 **** return result; } ! /** * get collection object If the collection does not yet exists, it is --- 1519,1523 ---- return result; } ! /** * get collection object If the collection does not yet exists, it is *************** *** 1538,1542 **** if (name.endsWith("/") && name.length() > 1) name = name.substring(0, name.length() - 1); ! synchronized(collectionsCache) { try { --- 1542,1546 ---- if (name.endsWith("/") && name.length() > 1) name = name.substring(0, name.length() - 1); ! final CollectionCache collectionsCache = pool.getCollectionsCache(); synchronized(collectionsCache) { try { *************** *** 1585,1589 **** } } ! /** * Gets a range of nodes, starting with first, ending with last --- 1589,1593 ---- } } ! /** * Gets a range of nodes, starting with first, ending with last *************** *** 1748,1751 **** --- 1752,1756 ---- throw new PermissionDeniedException("not allowed to remove collection"); + final CollectionCache collectionsCache = pool.getCollectionsCache(); synchronized(collectionsCache) { String name = collection.getName(); *************** *** 2009,2013 **** if (readOnly) throw new PermissionDeniedException(DATABASE_IS_READ_ONLY); ! collectionsCache.add(collection); Lock lock = null; try { --- 2014,2018 ---- if (readOnly) throw new PermissionDeniedException(DATABASE_IS_READ_ONLY); ! pool.getCollectionsCache().add(collection); Lock lock = null; try { *************** *** 2191,2194 **** --- 2196,2200 ---- } String name = collection.getName(); + final CollectionCache collectionsCache = pool.getCollectionsCache(); synchronized(collectionsCache) { Collection parent = openCollection(collection.getParentPath(), Lock.WRITE_LOCK); Index: DBBroker.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/DBBroker.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** DBBroker.java 3 Aug 2004 15:25:58 -0000 1.40 --- DBBroker.java 4 Aug 2004 14:48:06 -0000 1.41 *************** *** 34,38 **** import org.exist.EXistException; import org.exist.collections.Collection; - import org.exist.collections.CollectionCache; import org.exist.dom.BinaryDocument; import org.exist.dom.DocumentImpl; --- 34,37 ---- *************** *** 73,82 **** public final static int POSTGRESQL = 2; public final static int DBM = 3; - - // size of the internal buffer for collection objects - public static final int COLLECTION_BUFFER_SIZE = 128; - - protected static CollectionCache collectionsCache = - new CollectionCache(COLLECTION_BUFFER_SIZE); protected final static Logger LOG = Logger.getLogger(DBBroker.class); --- 72,75 ---- *************** *** 155,162 **** return symbols; } - - public CollectionCache getCollectionsCache() { - return collectionsCache; - } public DBBroker(BrokerPool pool, Configuration config) --- 148,151 ---- Index: BrokerPool.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/BrokerPool.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** BrokerPool.java 3 Aug 2004 15:25:58 -0000 1.26 --- BrokerPool.java 4 Aug 2004 14:48:06 -0000 1.27 *************** *** 31,34 **** --- 31,35 ---- import org.apache.log4j.Logger; import org.exist.EXistException; + import org.exist.collections.CollectionCache; import org.exist.security.User; import org.exist.storage.sync.Sync; *************** *** 53,60 **** --- 54,67 ---- private final static Logger LOG = Logger.getLogger(BrokerPool.class); + private final static TreeMap instances = new TreeMap(); + private static long timeOut = 30000L; + private final static ShutdownThread shutdownThread = new ShutdownThread(); + // size of the internal buffer for collection objects + public static final int COLLECTION_BUFFER_SIZE = 128; + public final static String DEFAULT_INSTANCE = "exist"; *************** *** 164,173 **** private Stack pool = new Stack(); private Map threads = new HashMap(); - private org.exist.security.SecurityManager secManager = null; private String instanceId; private boolean syncRequired = false; private SyncDaemon syncDaemon; private ShutdownListener shutdownListener = null; private XQueryPool xqueryCache; private Lock globalXUpdateLock = new ReentrantReadWriteLock("xupdate"); --- 171,183 ---- private Stack pool = new Stack(); private Map threads = new HashMap(); private String instanceId; private boolean syncRequired = false; + private boolean initializing = true; + + private org.exist.security.SecurityManager secManager = null; private SyncDaemon syncDaemon; private ShutdownListener shutdownListener = null; private XQueryPool xqueryCache; + protected CollectionCache collectionsCache; private Lock globalXUpdateLock = new ReentrantReadWriteLock("xupdate"); *************** *** 198,201 **** --- 208,212 ---- conf = config; xqueryCache = new XQueryPool(); + collectionsCache = new CollectionCache(COLLECTION_BUFFER_SIZE); initialize(); } *************** *** 225,228 **** --- 236,243 ---- } + public CollectionCache getCollectionsCache() { + return collectionsCache; + } + protected DBBroker createBroker() throws EXistException { DBBroker broker = BrokerFactory.getInstance(this, conf); *************** *** 314,319 **** --- 329,336 ---- protected void initialize() throws EXistException { LOG.debug("initializing database " + instanceId); + initializing = true; for (int i = 0; i < min; i++) createBroker(); + initializing = false; DBBroker broker = (DBBroker) pool.peek(); secManager = new org.exist.security.SecurityManager(this, broker); *************** *** 321,324 **** --- 338,345 ---- } + protected boolean isInitializing() { + return initializing; + } + /** * Release a DBBroker instance into the pool. |