Permalink
Browse files

[performance] When reindexing a collection, trigger a sync on the luc…

…ene-based indexes after the collection indexes got removed and before updated data is saved.
  • Loading branch information...
1 parent 425e97e commit 8845e3af8c5a2e13e997dc4e67a41c72a9d633ea @wolfgangmm wolfgangmm committed Feb 9, 2014
@@ -46,6 +46,7 @@
import org.exist.numbering.NodeId;
import org.exist.security.PermissionDeniedException;
import org.exist.storage.*;
+import org.exist.storage.btree.DBException;
import org.exist.storage.lock.Lock;
import org.exist.storage.txn.Txn;
import org.exist.util.ByteConversion;
@@ -290,7 +291,7 @@ protected void removePlainTextIndexes() {
}
}
- public void removeCollection(Collection collection, DBBroker broker) {
+ public void removeCollection(Collection collection, DBBroker broker, boolean reindex) {
if (LOG.isDebugEnabled())
LOG.debug("Removing collection " + collection.getURI());
IndexWriter writer = null;
@@ -309,6 +310,13 @@ public void removeCollection(Collection collection, DBBroker broker) {
LOG.error("Error while removing lucene index: " + e.getMessage(), e);
} finally {
index.releaseWriter(writer);
+ if (reindex) {
+ try {
+ index.sync();
+ } catch (DBException e) {
+ LOG.warn("Exception during reindex: " + e.getMessage(), e);
+ }
+ }
mode = StreamListener.STORE;
}
if (LOG.isDebugEnabled())
@@ -343,7 +343,7 @@ private void dropIndex(int mode) {
}
@Override
- public void removeCollection(Collection collection, DBBroker broker) {
+ public void removeCollection(Collection collection, DBBroker broker, boolean reindex) {
if (LOG.isDebugEnabled())
LOG.debug("Dropping NGram index for collection " + collection.getURI());
final Lock lock = index.db.getLock();
@@ -43,6 +43,7 @@
import org.exist.storage.ElementValue;
import org.exist.storage.IndexSpec;
import org.exist.storage.NodePath;
+import org.exist.storage.btree.DBException;
import org.exist.storage.txn.Txn;
import org.exist.util.ByteConversion;
import org.exist.util.DatabaseConfigurationException;
@@ -289,8 +290,7 @@ public StoredNode getReindexRoot(StoredNode node, NodePath path, boolean include
@Override
public QueryRewriter getQueryRewriter(XQueryContext context) {
- List<Object> configs = index.getBrokerPool().getConfigurationManager().getCustomIndexSpecs(getIndexId());
- return new RangeQueryRewriter(this, configs, context);
+ return new RangeQueryRewriter(context);
}
@Override
@@ -320,7 +320,7 @@ public void flush() {
}
@Override
- public void removeCollection(Collection collection, DBBroker broker) throws PermissionDeniedException {
+ public void removeCollection(Collection collection, DBBroker broker, boolean reindex) throws PermissionDeniedException {
if (LOG.isDebugEnabled())
LOG.debug("Removing collection " + collection.getURI());
IndexWriter writer = null;
@@ -339,6 +339,13 @@ public void removeCollection(Collection collection, DBBroker broker) throws Perm
LOG.error("Error while removing lucene index: " + e.getMessage(), e);
} finally {
index.releaseWriter(writer);
+ if (reindex) {
+ try {
+ index.sync();
+ } catch (DBException e) {
+ LOG.warn("Exception during reindex: " + e.getMessage(), e);
+ }
+ }
mode = StreamListener.STORE;
}
if (LOG.isDebugEnabled())
@@ -374,7 +374,7 @@ public MatchListener getMatchListener(DBBroker broker, NodeProxy proxy) {
return null;
}
- public void removeCollection(Collection collection, DBBroker broker) {
+ public void removeCollection(Collection collection, DBBroker broker, boolean reindex) {
}
public boolean checkIndex(DBBroker broker) {
@@ -375,7 +375,7 @@ private void removeDocument(Connection conn) throws SQLException {
LOG.debug("Dropped " + nodeCount + " nodes from GML index");
}
- public void removeCollection(Collection collection, DBBroker broker) {
+ public void removeCollection(Collection collection, DBBroker broker, boolean reindex) {
boolean isCollectionGMLAware = false;
IndexSpec idxConf = collection.getIndexConfiguration(broker);
if (idxConf != null) {
@@ -194,7 +194,7 @@ public void flush() {
}
}
- public void removeCollection(Collection collection, DBBroker broker) {
+ public void removeCollection(Collection collection, DBBroker broker, boolean reindex) {
engine.dropIndex(collection);
}
@@ -196,10 +196,10 @@ public void flush() {
* @param collection the collection to remove
* @param broker the broker that will perform the operation
*/
- public void removeCollection(Collection collection, DBBroker broker)
+ public void removeCollection(Collection collection, DBBroker broker, boolean reindex)
throws PermissionDeniedException {
for (final IndexWorker indexWorker : indexWorkers.values()) {
- indexWorker.removeCollection(collection, broker);
+ indexWorker.removeCollection(collection, broker, reindex);
}
}
@@ -176,7 +176,7 @@ Object configure(IndexController controller, NodeList configNodes,
* @param collection The collection to remove
* @param broker The broker that will perform the operation
*/
- void removeCollection(Collection collection, DBBroker broker) throws PermissionDeniedException;
+ void removeCollection(Collection collection, DBBroker broker, boolean reindex) throws PermissionDeniedException;
/**
* Checking index could be delegated to a worker. Use this method to do so.
@@ -1447,7 +1447,7 @@ public boolean removeCollection(final Txn transaction, Collection collection) th
notifyDropIndex(collection);
// Drop custom indexes
- indexController.removeCollection(collection, this);
+ indexController.removeCollection(collection, this, false);
if(!isRoot) {
// remove from parent collection
@@ -1809,8 +1809,9 @@ public void reindexCollection(Txn transaction, Collection collection, int mode)
if (!collection.getPermissionsNoLock().validate(getSubject(), Permission.WRITE))
{throw new PermissionDeniedException("Account "+getSubject().getName()+" have insufficient privileges on collection " + collection.getURI());}
LOG.debug("Reindexing collection " + collection.getURI());
- if (mode == NodeProcessor.MODE_STORE)
- {dropCollectionIndex(transaction, collection);}
+ if (mode == NodeProcessor.MODE_STORE) {
+ dropCollectionIndex(transaction, collection, true);
+ }
for(final Iterator<DocumentImpl> i = collection.iterator(this); i.hasNext(); ) {
final DocumentImpl next = i.next();
reindexXMLResource(transaction, next, mode);
@@ -1829,12 +1830,16 @@ public void reindexCollection(Txn transaction, Collection collection, int mode)
}
public void dropCollectionIndex(final Txn transaction, Collection collection) throws PermissionDeniedException {
+ dropCollectionIndex(transaction, collection, false);
+ }
+
+ public void dropCollectionIndex(final Txn transaction, Collection collection, boolean reindex) throws PermissionDeniedException {
if (pool.isReadOnly())
{throw new PermissionDeniedException(DATABASE_IS_READ_ONLY);}
if (!collection.getPermissionsNoLock().validate(getSubject(), Permission.WRITE))
{throw new PermissionDeniedException("Account "+getSubject().getName()+" have insufficient privileges on collection " +collection.getURI());}
notifyDropIndex(collection);
- indexController.removeCollection(collection, this);
+ indexController.removeCollection(collection, this, reindex);
for (final Iterator<DocumentImpl> i = collection.iterator(this); i.hasNext();) {
final DocumentImpl doc = i.next();
LOG.debug("Dropping index for document " + doc.getFileURI());
@@ -159,7 +159,7 @@ private void updateDocument(DBBroker broker, DocumentImpl doc) {
}
}
- public void removeCollection(Collection collection, DBBroker broker) {
+ public void removeCollection(Collection collection, DBBroker broker, boolean reindex) {
}
public boolean checkIndex(DBBroker broker) {
@@ -492,7 +492,7 @@ public boolean indexInfo(Value value, long pointer) throws TerminatedException {
}
@Override
- public void removeCollection(Collection collection, DBBroker broker) throws PermissionDeniedException {
+ public void removeCollection(Collection collection, DBBroker broker, boolean reindex) throws PermissionDeniedException {
for (final Iterator<DocumentImpl> i = collection.iterator(broker); i.hasNext(); ) {
final DocumentImpl doc = i.next();
removeDocument(doc);

0 comments on commit 8845e3a

Please sign in to comment.