Search in sources :

Example 1 with IndexItemEntry

use of com.zimbra.cs.mailbox.Mailbox.IndexItemEntry 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)

Aggregations

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