Search in sources :

Example 1 with IndexStore

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

the class MailboxTestUtil method cleanupIndexStore.

public static void cleanupIndexStore(Mailbox mbox) {
    IndexStore index = mbox.index.getIndexStore();
    if (index instanceof ElasticSearchIndex) {
        String key = mbox.getAccountId();
        String indexUrl = String.format("%s%s/", LC.zimbra_index_elasticsearch_url_base.value(), key);
        HttpMethod method = new DeleteMethod(indexUrl);
        try {
            ElasticSearchConnector connector = new ElasticSearchConnector();
            int statusCode = connector.executeMethod(method);
            if (statusCode == HttpStatus.SC_OK) {
                boolean ok = connector.getBooleanAtJsonPath(new String[] { "ok" }, false);
                boolean acknowledged = connector.getBooleanAtJsonPath(new String[] { "acknowledged" }, false);
                if (!ok || !acknowledged) {
                    ZimbraLog.index.debug("Delete index status ok=%b acknowledged=%b", ok, acknowledged);
                }
            } else {
                String error = connector.getStringAtJsonPath(new String[] { "error" });
                if (error != null && error.startsWith("IndexMissingException")) {
                    ZimbraLog.index.debug("Unable to delete index for key=%s.  Index is missing", key);
                } else {
                    ZimbraLog.index.error("Problem deleting index for key=%s error=%s", key, error);
                }
            }
        } catch (HttpException e) {
            ZimbraLog.index.error("Problem Deleting index with key=" + key, e);
        } catch (IOException e) {
            ZimbraLog.index.error("Problem Deleting index with key=" + key, e);
        }
    }
}
Also used : DeleteMethod(org.apache.commons.httpclient.methods.DeleteMethod) ElasticSearchConnector(com.zimbra.cs.index.elasticsearch.ElasticSearchConnector) HttpException(org.apache.commons.httpclient.HttpException) ElasticSearchIndex(com.zimbra.cs.index.elasticsearch.ElasticSearchIndex) IOException(java.io.IOException) IndexStore(com.zimbra.cs.index.IndexStore) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 2 with IndexStore

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

the class MailboxManager method endMaintenance.

public void endMaintenance(MailboxMaintenance maintenance, boolean success, boolean removeFromCache) throws ServiceException {
    Preconditions.checkNotNull(maintenance);
    Mailbox availableMailbox = null;
    synchronized (this) {
        Object obj = cache.get(maintenance.getMailboxId());
        if (obj != maintenance) {
            ZimbraLog.mailbox.debug("maintenance ended with wrong object. passed %s; expected %s", maintenance, obj);
            throw MailServiceException.MAINTENANCE(maintenance.getMailboxId(), "attempting to end maintenance with wrong object");
        }
        // start by removing the lock from the Mailbox object cache
        cache.remove(maintenance.getMailboxId());
        Mailbox mbox = maintenance.getMailbox();
        if (success) {
            // XXX: don't recall the rationale for re-setting this...
            cacheAccount(maintenance.getAccountId(), maintenance.getMailboxId());
            if (mbox != null) {
                // restore case
                assert (maintenance == mbox.getMaintenance() || mbox.getMaintenance() == null);
                if (removeFromCache) {
                    mbox.purge(MailItem.Type.UNKNOWN);
                    // We're going to let the Mailbox drop out of the cache and eventually get GC'd.
                    // Some immediate cleanup is necessary though.
                    IndexStore index = mbox.index.getIndexStore();
                    if (index != null) {
                        index.evict();
                    }
                // Note: mbox is left in maintenance mode.
                } else {
                    if (mbox.endMaintenance(success)) {
                        ZimbraLog.mailbox.debug("no longer in maintenace; caching mailbox");
                        cacheMailbox(maintenance.getMailbox());
                    } else {
                        ZimbraLog.mailbox.debug("still in maintenance; caching lock");
                        cache.put(mbox.getId(), mbox.getMaintenance());
                    }
                }
                availableMailbox = mbox;
            }
        } else {
            // on failed maintenance, mark the Mailbox object as off-limits to everyone
            if (mbox != null) {
                mbox.endMaintenance(success);
            }
            maintenance.markUnavailable();
        }
    }
    if (availableMailbox != null)
        notifyMailboxAvailable(availableMailbox);
}
Also used : DbMailbox(com.zimbra.cs.db.DbMailbox) CreateMailbox(com.zimbra.cs.redolog.op.CreateMailbox) IndexStore(com.zimbra.cs.index.IndexStore)

Aggregations

IndexStore (com.zimbra.cs.index.IndexStore)2 DbMailbox (com.zimbra.cs.db.DbMailbox)1 ElasticSearchConnector (com.zimbra.cs.index.elasticsearch.ElasticSearchConnector)1 ElasticSearchIndex (com.zimbra.cs.index.elasticsearch.ElasticSearchIndex)1 CreateMailbox (com.zimbra.cs.redolog.op.CreateMailbox)1 IOException (java.io.IOException)1 HttpException (org.apache.commons.httpclient.HttpException)1 HttpMethod (org.apache.commons.httpclient.HttpMethod)1 DeleteMethod (org.apache.commons.httpclient.methods.DeleteMethod)1