From: Wolfgang M. M. <wol...@us...> - 2004-06-23 12:45:21
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/storage In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22580/src/org/exist/storage Modified Files: NativeElementIndex.java DBBroker.java NativeBroker.java Log Message: Added an automatic defragmentation method to the XUpdate implementation. Index: NativeBroker.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/NativeBroker.java,v retrieving revision 1.82 retrieving revision 1.83 diff -C2 -d -r1.82 -r1.83 *** NativeBroker.java 21 Jun 2004 15:27:34 -0000 1.82 --- NativeBroker.java 23 Jun 2004 12:45:12 -0000 1.83 *************** *** 579,582 **** --- 579,589 ---- } + /** + * Release the collection id assigned to a collection so it can be + * reused later. + * + * @param id + * @throws PermissionDeniedException + */ protected void freeCollection(short id) throws PermissionDeniedException { // LOG.debug("freeing collection " + id); *************** *** 606,609 **** --- 613,623 ---- } + /** + * Get the next free collection id. If a collection is removed, its collection id + * is released so it can be reused. + * + * @return + * @throws ReadOnlyException + */ protected short getFreeCollectionId() throws ReadOnlyException { short freeCollectionId = -1; *************** *** 633,636 **** --- 647,656 ---- } + /** + * Get the next available unique collection id. + * + * @return + * @throws ReadOnlyException + */ protected short getNextCollectionId() throws ReadOnlyException { short nextCollectionId = getFreeCollectionId(); *************** *** 658,661 **** --- 678,688 ---- } + /** + * Release the document id reserved for a document so it + * can be reused. + * + * @param id + * @throws PermissionDeniedException + */ protected void freeDocument(int id) throws PermissionDeniedException { // LOG.debug("freeing document " + id); *************** *** 685,688 **** --- 712,722 ---- } + /** + * Get the next unused document id. If a document is removed, its doc id is + * released, so it can be reused. + * + * @return + * @throws ReadOnlyException + */ protected int getFreeDocId() throws ReadOnlyException { int freeDocId = -1; *************** *** 1153,1157 **** new NodeProxy(oldDoc, n.getGID(), n.getInternalAddress())); iterator.next(); ! copyNodes(iterator, n, new NodePath(), newDoc); } flush(); --- 1187,1191 ---- new NodeProxy(oldDoc, n.getGID(), n.getInternalAddress())); iterator.next(); ! copyNodes(iterator, n, new NodePath(), newDoc, true); } flush(); *************** *** 1159,1163 **** } ! public void defrag(final DocumentImpl doc) throws PermissionDeniedException { LOG.debug("--------------------> Defragmenting document " + doc.getFileName()); final long start = System.currentTimeMillis(); --- 1193,1197 ---- } ! public void defrag(final DocumentImpl doc) { LOG.debug("--------------------> Defragmenting document " + doc.getFileName()); final long start = System.currentTimeMillis(); *************** *** 1165,1169 **** // dropping old index elementIndex.dropIndex(doc); - textEngine.dropIndex(doc); // dropping dom index NodeRef ref = new NodeRef(doc.getDocId()); --- 1199,1202 ---- *************** *** 1190,1193 **** --- 1223,1227 ---- DocumentImpl tempDoc = new DocumentImpl(this, doc.getFileName(), doc.getCollection()); tempDoc.copyOf(doc); + tempDoc.setDocId(doc.getDocId()); Iterator iterator; *************** *** 1200,1208 **** new NodeProxy(doc, n.getGID(), n.getInternalAddress())); iterator.next(); ! copyNodes(iterator, n, new NodePath(), tempDoc); } flush(); - LOG.debug("Removing old dom..."); new DOMTransaction(this, domDb) { public Object start() { --- 1234,1241 ---- new NodeProxy(doc, n.getGID(), n.getInternalAddress())); iterator.next(); ! copyNodes(iterator, n, new NodePath(), tempDoc, false); } flush(); new DOMTransaction(this, domDb) { public Object start() { *************** *** 1215,1226 **** doc.copyChildren(tempDoc); saveCollection(doc.getCollection()); LOG.debug("Defragmentation took " + (System.currentTimeMillis() - start) + "ms."); } catch (ReadOnlyException e) { ! throw new PermissionDeniedException(DATABASE_IS_READ_ONLY); ! } } ! private void copyNodes(Iterator iterator, NodeImpl node, NodePath currentPath, DocumentImpl newDoc) { if (node.getNodeType() == Node.ELEMENT_NODE) currentPath.addComponent(node.getNodeName()); --- 1248,1268 ---- doc.copyChildren(tempDoc); + doc.setSplitCount(0); + doc.setAddress(-1); + doc.setPageCount(tempDoc.getPageCount()); + LOG.debug("New doc size: " + doc.getContentLength()); + storeDocument(doc); + saveCollection(doc.getCollection()); LOG.debug("Defragmentation took " + (System.currentTimeMillis() - start) + "ms."); } catch (ReadOnlyException e) { ! LOG.warn(DATABASE_IS_READ_ONLY, e); ! } catch (PermissionDeniedException e) { ! LOG.warn(DATABASE_IS_READ_ONLY, e); ! } } ! private void copyNodes(Iterator iterator, NodeImpl node, NodePath currentPath, ! DocumentImpl newDoc, boolean index) { if (node.getNodeType() == Node.ELEMENT_NODE) currentPath.addComponent(node.getNodeName()); *************** *** 1228,1232 **** node.setOwnerDocument(newDoc); node.setInternalAddress(-1); ! store(node, currentPath); node.setOwnerDocument(doc); --- 1270,1276 ---- node.setOwnerDocument(newDoc); node.setInternalAddress(-1); ! store(node, currentPath, index); ! if(node.getGID() == 1) ! newDoc.appendChild(node); node.setOwnerDocument(doc); *************** *** 1251,1255 **** "; last = " + lastChildId + "; children = " + node.getChildCount()); child.setGID(gid); ! copyNodes(iterator, child, currentPath, newDoc); } } --- 1295,1299 ---- "; last = " + lastChildId + "; children = " + node.getChildCount()); child.setGID(gid); ! copyNodes(iterator, child, currentPath, newDoc, index); } } *************** *** 2067,2071 **** * fulltext-indexed). */ ! public void store(final NodeImpl node, NodePath currentPath) { // first, check available memory if (nodesCount > MEM_LIMIT_CHECK) { --- 2111,2115 ---- * fulltext-indexed). */ ! public void store(final NodeImpl node, NodePath currentPath, boolean index) { // first, check available memory if (nodesCount > MEM_LIMIT_CHECK) { *************** *** 2135,2144 **** // check if attribute value should be fulltext-indexed // by calling IndexPaths.match(path) ! boolean indexAttribs = true; ! if(idx != null) { if(idx.getIncludeAttributes()) { ! currentPath.addComponent('@' + nodeName); ! indexAttribs = idx.match(currentPath); ! currentPath.removeLastComponent(); } else indexAttribs = false; --- 2179,2188 ---- // check if attribute value should be fulltext-indexed // by calling IndexPaths.match(path) ! boolean indexAttribs = index; ! if(index && idx != null) { if(idx.getIncludeAttributes()) { ! currentPath.addComponent('@' + nodeName); ! indexAttribs = idx.match(currentPath); ! currentPath.removeLastComponent(); } else indexAttribs = false; *************** *** 2158,2162 **** // check if this textual content should be fulltext-indexed // by calling IndexPaths.match(path) ! if (idx == null || idx.match(currentPath)){ boolean valore = (idx == null ? false : idx.preserveContent(currentPath)); textEngine.storeText(idx, (TextImpl) node, valore); --- 2202,2206 ---- // check if this textual content should be fulltext-indexed // by calling IndexPaths.match(path) ! if (index && (idx == null || idx.match(currentPath))){ boolean valore = (idx == null ? false : idx.preserveContent(currentPath)); textEngine.storeText(idx, (TextImpl) node, valore); Index: NativeElementIndex.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/NativeElementIndex.java,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** NativeElementIndex.java 16 Jun 2004 13:36:54 -0000 1.30 --- NativeElementIndex.java 23 Jun 2004 12:45:12 -0000 1.31 *************** *** 110,114 **** public NodeSet findElementsByTagName(byte type, DocumentSet docs, QName qname, NodeSelector selector) { ! // final long start = System.currentTimeMillis(); final ExtArrayNodeSet result = new ExtArrayNodeSet(docs.getLength(), 256); --- 110,114 ---- public NodeSet findElementsByTagName(byte type, DocumentSet docs, QName qname, NodeSelector selector) { ! final long start = System.currentTimeMillis(); final ExtArrayNodeSet result = new ExtArrayNodeSet(docs.getLength(), 256); *************** *** 167,170 **** --- 167,171 ---- len = is.readInt(); if ((doc = docs.getDoc(docId)) == null) { + LOG.debug("skipping doc " + docId); is.skip(len * 4); continue; *************** *** 195,206 **** } // result.sort(); ! // LOG.debug( ! // "found " ! // + qname ! // + ": " ! // + result.getLength() ! // + " in " ! // + (System.currentTimeMillis() - start) ! // + "ms."); return result; } --- 196,207 ---- } // result.sort(); ! LOG.debug( ! "found " ! + qname ! + ": " ! + result.getLength() ! + " in " ! + (System.currentTimeMillis() - start) ! + "ms."); return result; } Index: DBBroker.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/storage/DBBroker.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** DBBroker.java 21 Jun 2004 15:27:34 -0000 1.34 --- DBBroker.java 23 Jun 2004 12:45:12 -0000 1.35 *************** *** 55,60 **** /** ! * This is the base class for all database backends. All other components rely ! * on the methods defined here. * *@author Wolfgang Meier <wol...@ex...> --- 55,60 ---- /** ! * This is the base class for all database backends. All the basic database operations like storing, ! * removing or index access are provided by subclasses of this class. * *@author Wolfgang Meier <wol...@ex...> *************** *** 92,95 **** --- 92,103 ---- protected int xupdateGrowthFactor = 1; + protected int docFragmentationLimit = 25; + + /** + * Save the global symbol table. The global symbol table stores + * QNames and namespace/prefix mappings. + * + * @throws EXistException + */ protected void saveSymbols() throws EXistException { synchronized (symbols) { *************** *** 110,114 **** } } ! protected void loadSymbols() throws EXistException { try { --- 118,128 ---- } } ! ! /** ! * Read the global symbol table. The global symbol table stores ! * QNames and namespace/prefix mappings. ! * ! * @throws EXistException ! */ protected void loadSymbols() throws EXistException { try { *************** *** 155,170 **** --- 169,202 ---- if ((xupdateGrowthFactor = config.getInteger("xupdate.growth-factor")) < 0) xupdateGrowthFactor = 1; + if ((docFragmentationLimit = config.getInteger("xupdate.fragmentation")) < 0) + docFragmentationLimit = 50; + this.pool = pool; xqueryService = new XQuery(this); } + /** + * Set the user that is currently using this DBBroker object. + * + * @param user + */ public void setUser(User user) { this.user = user; } + /** + * Get the user that is currently using this DBBroker object. + * + * @return + */ public User getUser() { return user; } + /** + * Returns a reference to the global {@link XQuery} service. + * + * @return + */ public XQuery getXQueryService() { return xqueryService; *************** *** 372,375 **** --- 404,413 ---- throws PermissionDeniedException; + /** + * Reindex a collection. + * + * @param collectionName + * @throws PermissionDeniedException + */ public abstract void reindex(String collectionName) throws PermissionDeniedException; *************** *** 405,414 **** * fulltext-indexed). */ ! public abstract void store(NodeImpl node, NodePath currentPath); /** ! * Store a document into the database. * ! *@param doc Description of the Parameter */ public abstract void storeDocument(DocumentImpl doc); --- 443,457 ---- * fulltext-indexed). */ ! public abstract void store(NodeImpl node, NodePath currentPath, boolean index); + public void store(NodeImpl node, NodePath currentPath) { + store(node, currentPath, true); + } + /** ! * Store a document into the database. This method will save the document ! * metadata and add the document to the collection. * ! *@param doc */ public abstract void storeDocument(DocumentImpl doc); *************** *** 432,442 **** throws PermissionDeniedException, LockException; public abstract void moveResource(DocumentImpl doc, Collection destination, String newName) throws PermissionDeniedException, LockException; public abstract void copyResource(DocumentImpl doc, Collection destination, String newName) throws PermissionDeniedException, LockException; ! public abstract void defrag(DocumentImpl doc) throws PermissionDeniedException; public void sync() { --- 475,501 ---- throws PermissionDeniedException, LockException; + /** + * Move a resource to the destination collection and rename it. + * + * @param doc the resource to move + * @param destination the destination collection + * @param new Name the new name the resource should have in the destination collection + */ public abstract void moveResource(DocumentImpl doc, Collection destination, String newName) throws PermissionDeniedException, LockException; + /** + * Copy a resource to the destination collection and rename it. + * + * @param doc the resource to copy + * @param destination the destination collection + * @param newName the new name the resource should have in the destination collection + * @throws PermissionDeniedException + * @throws LockException + */ public abstract void copyResource(DocumentImpl doc, Collection destination, String newName) throws PermissionDeniedException, LockException; ! public abstract void defrag(DocumentImpl doc); public void sync() { *************** *** 447,454 **** /** ! * Update a node's data. This method is only used by the NativeBroker. To ! * keep nodes in a correct sequential order, it sometimes needs to update a ! * previous written node. Warning: don't use it for other purposes. ! * RelationalBroker does not implement this method. * *@param node Description of the Parameter --- 506,511 ---- /** ! * Update a node's data. To keep nodes in a correct sequential order, it is sometimes ! * necessary to update a previous written node. Warning: don't use it for other purposes. * *@param node Description of the Parameter *************** *** 501,505 **** /** ! * get all the documents in this database matching the given document-type's name.@param doctypeName Description of the Parameter@param user Description of the Parameter@return The documentsByDoctype value */ public abstract DocumentSet getDocumentsByDoctype( --- 558,562 ---- /** ! * */ public abstract DocumentSet getDocumentsByDoctype( *************** *** 523,526 **** --- 580,587 ---- } + public int getFragmentationLimit() { + return docFragmentationLimit; + } + public abstract int getPageSize(); } \ No newline at end of file |