Example usage for org.apache.solr.search SolrIndexSearcher getPath

List of usage examples for org.apache.solr.search SolrIndexSearcher getPath

Introduction

In this page you can find the example usage for org.apache.solr.search SolrIndexSearcher getPath.

Prototype

public String getPath() 

Source Link

Usage

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

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override/*from   w  w  w  .  j av  a  2 s. c  o m*/
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;
}