Example usage for org.apache.solr.core IndexDeletionPolicyWrapper setReserveDuration

List of usage examples for org.apache.solr.core IndexDeletionPolicyWrapper setReserveDuration

Introduction

In this page you can find the example usage for org.apache.solr.core IndexDeletionPolicyWrapper setReserveDuration.

Prototype

public void setReserveDuration(Long indexGen, long reserveTime) 

Source Link

Document

Set the duration for which commit point is to be reserved by the deletion policy.

Usage

From source file:org.alfresco.solr.LegacySolrInformationServer.java

License:Open Source License

@Override
public Iterable<Map.Entry<String, Object>> getCoreStats() throws IOException {
    DecimalFormat df = new DecimalFormat("###,###.######");

    NamedList<Object> coreSummary = new SimpleOrderedMap<Object>();
    RefCounted<SolrIndexSearcher> refCounted = null;
    try {/*ww w. j a  va  2 s . co  m*/
        refCounted = core.getSearcher(false, true, null);
        SolrIndexSearcher solrIndexSearcher = refCounted.get();
        OpenBitSet allLeafDocs = (OpenBitSet) solrIndexSearcher.cacheLookup(
                AlfrescoSolrEventListener.ALFRESCO_CACHE, AlfrescoSolrEventListener.KEY_ALL_LEAF_DOCS);
        long count = allLeafDocs.cardinality();
        coreSummary.add("Alfresco Nodes in Index", count);
        coreSummary.add("Searcher", solrIndexSearcher.getStatistics());
        Map<String, SolrInfoMBean> infoRegistry = core.getInfoRegistry();
        for (String key : infoRegistry.keySet()) {
            SolrInfoMBean infoMBean = infoRegistry.get(key);
            if (key.equals("/alfresco")) {
                coreSummary.add("/alfresco", fixStats(infoMBean.getStatistics()));
            }
            if (key.equals("/afts")) {
                coreSummary.add("/afts", fixStats(infoMBean.getStatistics()));
            }
            if (key.equals("/cmis")) {
                coreSummary.add("/cmis", fixStats(infoMBean.getStatistics()));
            }
            if (key.equals("filterCache")) {
                coreSummary.add("/filterCache", infoMBean.getStatistics());
            }
            if (key.equals("queryResultCache")) {
                coreSummary.add("/queryResultCache", infoMBean.getStatistics());
            }
            if (key.equals("alfrescoAuthorityCache")) {
                coreSummary.add("/alfrescoAuthorityCache", infoMBean.getStatistics());
            }
            if (key.equals("alfrescoPathCache")) {
                coreSummary.add("/alfrescoPathCache", infoMBean.getStatistics());
            }
        }

        // Find searchers and do memory use for each .. and add them all up7

        long memory = 0L;
        int searcherCount = 0;
        List<SolrIndexSearcher> searchers = getRegisteredSearchers();
        for (SolrIndexSearcher searcher : searchers) {
            memory += addSearcherStats(coreSummary, searcher, searcherCount);
            searcherCount++;
        }

        coreSummary.add("Number of Searchers", searchers.size());
        coreSummary.add("Total Searcher Cache (GB)", df.format(memory / 1024.0f / 1024.0f / 1024.0f));

        IndexDeletionPolicyWrapper delPolicy = core.getDeletionPolicy();
        IndexCommit indexCommit = delPolicy.getLatestCommit();
        // race?
        if (indexCommit == null) {
            indexCommit = solrIndexSearcher.getReader().getIndexCommit();
        }
        if (indexCommit != null) {
            delPolicy.setReserveDuration(indexCommit.getVersion(), 20000);
            Long fileSize = 0L;

            File dir = new File(solrIndexSearcher.getIndexDir());
            for (String name : (Collection<String>) indexCommit.getFileNames()) {
                File file = new File(dir, name);
                if (file.exists()) {
                    fileSize += file.length();
                }
            }

            coreSummary.add("On disk (GB)", df.format(fileSize / 1024.0f / 1024.0f / 1024.0f));
            coreSummary.add("Per node B", count > 0 ? fileSize / count : 0);
        }
    } finally {
        if (refCounted != null) {
            refCounted.decref();
        }
    }

    return coreSummary;
}

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override/*from  ww w.ja  v  a 2 s  .c om*/
public Iterable<Entry<String, Object>> getCoreStats() throws IOException {
    // This is still local, not totally cloud-friendly
    // TODO Make this cloud-friendly by aggregating the stats across the cloud

    NamedList<Object> coreSummary = new SimpleOrderedMap<>();
    RefCounted<SolrIndexSearcher> refCounted = null;
    try (SolrQueryRequest request = newSolrQueryRequest()) {
        NamedList docTypeCounts = this.getFacets(request, "*:*", FIELD_DOC_TYPE, 0);
        long aclCount = getSafeCount(docTypeCounts, DOC_TYPE_ACL);
        coreSummary.add("Alfresco Acls in Index", aclCount);
        long nodeCount = getSafeCount(docTypeCounts, DOC_TYPE_NODE);
        coreSummary.add("Alfresco Nodes in Index", nodeCount);
        long txCount = getSafeCount(docTypeCounts, DOC_TYPE_TX);
        coreSummary.add("Alfresco Transactions in Index", txCount);
        long aclTxCount = getSafeCount(docTypeCounts, DOC_TYPE_ACL_TX);
        coreSummary.add("Alfresco Acl Transactions in Index", aclTxCount);
        long stateCount = getSafeCount(docTypeCounts, DOC_TYPE_STATE);
        coreSummary.add("Alfresco States in Index", stateCount);
        long unindexedNodeCount = getSafeCount(docTypeCounts, DOC_TYPE_UNINDEXED_NODE);
        coreSummary.add("Alfresco Unindexed Nodes", unindexedNodeCount);
        long errorNodeCount = getSafeCount(docTypeCounts, DOC_TYPE_ERROR_NODE);
        coreSummary.add("Alfresco Error Nodes in Index", errorNodeCount);

        refCounted = core.getSearcher(false, true, null);
        SolrIndexSearcher solrIndexSearcher = refCounted.get();
        coreSummary.add("Searcher", solrIndexSearcher.getStatistics());
        Map<String, SolrInfoMBean> infoRegistry = core.getInfoRegistry();
        for (Entry<String, SolrInfoMBean> infos : infoRegistry.entrySet()) {
            SolrInfoMBean infoMBean = infos.getValue();
            String key = infos.getKey();
            if (key.equals("/alfresco")) {
                // TODO Do we really need to fixStats in solr4?
                coreSummary.add("/alfresco", fixStats(infoMBean.getStatistics()));
            }

            if (key.equals("/afts")) {
                coreSummary.add("/afts", fixStats(infoMBean.getStatistics()));
            }

            if (key.equals("/cmis")) {
                coreSummary.add("/cmis", fixStats(infoMBean.getStatistics()));
            }

            if (key.equals("filterCache")) {
                coreSummary.add("/filterCache", infoMBean.getStatistics());
            }

            if (key.equals("queryResultCache")) {
                coreSummary.add("/queryResultCache", infoMBean.getStatistics());
            }

            if (key.equals("alfrescoAuthorityCache")) {
                coreSummary.add("/alfrescoAuthorityCache", infoMBean.getStatistics());
            }

            if (key.equals("alfrescoPathCache")) {
                coreSummary.add("/alfrescoPathCache", infoMBean.getStatistics());
            }
        }

        // Adds detailed stats for each registered searcher
        int searcherIndex = 0;
        List<SolrIndexSearcher> searchers = getRegisteredSearchers();
        for (SolrIndexSearcher searcher : searchers) {
            NamedList<Object> details = new SimpleOrderedMap<>();
            details.add("Searcher", searcher.getStatistics());
            coreSummary.add("Searcher-" + searcherIndex, details);
            searcherIndex++;
        }

        coreSummary.add("Number of Searchers", searchers.size());
        // This is zero for Solr4, whereas we had some local caches before
        coreSummary.add("Total Searcher Cache (GB)", 0);

        IndexDeletionPolicyWrapper delPolicy = core.getDeletionPolicy();
        IndexCommit indexCommit = delPolicy.getLatestCommit();
        // race?
        if (indexCommit == null) {
            indexCommit = solrIndexSearcher.getIndexReader().getIndexCommit();
        }

        if (indexCommit != null) {
            // Tells Solr to stop deleting things for 20 seconds so we can get a snapshot of all the files on the index
            delPolicy.setReserveDuration(solrIndexSearcher.getIndexReader().getVersion(), 20000);
            long fileSize = 0L;

            File dir = new File(solrIndexSearcher.getPath());
            for (String name : indexCommit.getFileNames()) {
                File file = new File(dir, name);
                if (file.exists()) {
                    fileSize += file.length();
                }
            }

            DecimalFormat df = new DecimalFormat("###,###.######");
            coreSummary.add("On disk (GB)", df.format(fileSize / 1024.0f / 1024.0f / 1024.0f));
            coreSummary.add("Per node B", nodeCount > 0 ? fileSize / nodeCount : 0);
        }
    } finally {
        ofNullable(refCounted).ifPresent(RefCounted::decref);
    }

    return coreSummary;
}