Search in sources :

Example 1 with Indexer

use of com.zimbra.cs.index.Indexer in project zm-mailbox by Zimbra.

the class MailboxIndex method add.

/**
     * Adds index documents. The caller must hold the mailbox lock.
     */
synchronized void add(List<IndexItemEntry> entries) throws ServiceException {
    assert (mailbox.lock.isWriteLockedByCurrentThread());
    if (entries.isEmpty()) {
        return;
    }
    Indexer indexer;
    try {
        indexer = indexStore.openIndexer();
    } catch (IndexPendingDeleteException e) {
        ZimbraLog.index.debug("add of entries to index aborted as index is pending delete");
        lastFailedTime = System.currentTimeMillis();
        return;
    } catch (IOException e) {
        ZimbraLog.index.warn("Failed to open Indexer", e);
        lastFailedTime = System.currentTimeMillis();
        return;
    }
    List<MailItem> indexed = new ArrayList<MailItem>(entries.size());
    try {
        for (IndexItemEntry entry : entries) {
            if ((indexStore != null) && indexStore.isPendingDelete()) {
                ZimbraLog.index.debug("add of list of entries to index aborted as index is pending delete");
                lastFailedTime = System.currentTimeMillis();
                // No point in indexing if we are going to delete the index
                return;
            }
            if (entry.documents == null) {
                ZimbraLog.index.warn("NULL index data item=%s", entry);
                continue;
            }
            ZimbraLog.index.debug("Indexing id=%d", entry.item.getId());
            try {
                indexer.addDocument(entry.item.getFolder(), entry.item, entry.documents);
            } catch (IOException e) {
                ZimbraLog.index.warn("Failed to index item=%s", entry, e);
                lastFailedTime = System.currentTimeMillis();
                continue;
            }
            indexed.add(entry.item);
        }
    } finally {
        try {
            indexer.close();
        } catch (IOException e) {
            ZimbraLog.index.error("Failed to close Indexer", e);
            return;
        }
    }
    List<Integer> ids = new ArrayList<Integer>(indexed.size());
    for (MailItem item : indexed) {
        ids.add(item.getId());
    }
    DbMailItem.setIndexIds(mailbox.getOperationConnection(), mailbox, ids);
    for (MailItem item : indexed) {
        item.mData.indexId = item.getId();
        removeDeferredId(item.getId());
    }
}
Also used : DbMailItem(com.zimbra.cs.db.DbMailItem) Indexer(com.zimbra.cs.index.Indexer) IndexPendingDeleteException(com.zimbra.cs.index.IndexPendingDeleteException) IndexItemEntry(com.zimbra.cs.mailbox.Mailbox.IndexItemEntry) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 2 with Indexer

use of com.zimbra.cs.index.Indexer in project zm-mailbox by Zimbra.

the class MailboxIndex method getIndexStats.

public IndexStats getIndexStats() throws ServiceException {
    int maxDocs = 0;
    int numDeletedDocs = 0;
    try {
        Indexer indexer = indexStore.openIndexer();
        try {
            maxDocs = indexer.maxDocs();
        } finally {
            indexer.close();
        }
        numDeletedDocs = numDeletedDocs();
    } catch (IOException e) {
        throw ServiceException.FAILURE("Failed to open Indexer", e);
    }
    return new IndexStats(maxDocs, numDeletedDocs);
}
Also used : Indexer(com.zimbra.cs.index.Indexer) IOException(java.io.IOException)

Example 3 with Indexer

use of com.zimbra.cs.index.Indexer in project zm-mailbox by Zimbra.

the class MailboxIndex method delete.

/**
     * Deletes index documents. The caller doesn't necessarily hold the mailbox lock.
     */
synchronized void delete(List<Integer> ids) {
    if (ids.isEmpty()) {
        return;
    }
    Indexer indexer;
    try {
        indexer = indexStore.openIndexer();
    } catch (IndexPendingDeleteException e) {
        ZimbraLog.index.debug("delete of ids from index aborted as it is pending delete");
        lastFailedTime = System.currentTimeMillis();
        return;
    } catch (IOException e) {
        ZimbraLog.index.warn("Failed to open Indexer", e);
        lastFailedTime = System.currentTimeMillis();
        return;
    }
    try {
        indexer.deleteDocument(ids);
    } catch (IOException e) {
        ZimbraLog.index.warn("Failed to delete index documents", e);
    } finally {
        try {
            indexer.close();
        } catch (IOException e) {
            ZimbraLog.index.error("Failed to close Indexer", e);
            return;
        }
    }
    removeDeferredId(ids);
}
Also used : Indexer(com.zimbra.cs.index.Indexer) IndexPendingDeleteException(com.zimbra.cs.index.IndexPendingDeleteException) IOException(java.io.IOException)

Aggregations

Indexer (com.zimbra.cs.index.Indexer)3 IOException (java.io.IOException)3 IndexPendingDeleteException (com.zimbra.cs.index.IndexPendingDeleteException)2 DbMailItem (com.zimbra.cs.db.DbMailItem)1 IndexItemEntry (com.zimbra.cs.mailbox.Mailbox.IndexItemEntry)1 ArrayList (java.util.ArrayList)1