Search in sources :

Example 21 with Node

use of org.alfresco.solr.client.Node in project SearchServices by Alfresco.

the class SolrInformationServer method categorizeNodes.

private void categorizeNodes(List<Node> nodes, Map<Long, Node> nodeIdsToNodes, EnumMap<SolrApiNodeStatus, List<Long>> nodeStatusToNodeIds) {
    for (Node node : nodes) {
        nodeIdsToNodes.put(node.getId(), node);
        List<Long> nodeIds = nodeStatusToNodeIds.get(node.getStatus());
        if (nodeIds == null) {
            nodeIds = new LinkedList<>();
            nodeStatusToNodeIds.put(node.getStatus(), nodeIds);
        }
        nodeIds.add(node.getId());
    }
}
Also used : Node(org.alfresco.solr.client.Node)

Example 22 with Node

use of org.alfresco.solr.client.Node in project SearchServices by Alfresco.

the class MetadataTracker method reindexTransactions.

private void reindexTransactions() throws IOException, AuthenticationException, JSONException {
    long startElapsed = System.nanoTime();
    int docCount = 0;
    while (transactionsToReindex.peek() != null) {
        Long transactionId = transactionsToReindex.poll();
        if (transactionId != null) {
            // make sure it is cleaned out so we do not miss deletes
            this.infoSrv.deleteByTransactionId(transactionId);
            Transactions transactions = client.getTransactions(null, transactionId, null, transactionId + 1, 1);
            if ((transactions.getTransactions().size() > 0) && (transactionId.equals(transactions.getTransactions().get(0).getId()))) {
                Transaction info = transactions.getTransactions().get(0);
                this.infoSrv.dirtyTransaction(info.getId());
                GetNodesParameters gnp = new GetNodesParameters();
                ArrayList<Long> txs = new ArrayList<Long>();
                txs.add(info.getId());
                gnp.setTransactionIds(txs);
                gnp.setStoreProtocol(storeRef.getProtocol());
                gnp.setStoreIdentifier(storeRef.getIdentifier());
                List<Node> nodes = client.getNodes(gnp, (int) info.getUpdates());
                for (Node node : nodes) {
                    docCount++;
                    if (log.isDebugEnabled()) {
                        log.debug(node.toString());
                    }
                    this.infoSrv.indexNode(node, true);
                    checkShutdown();
                }
                // Index the transaction doc after the node - if this is not found then a reindex will be done.
                this.infoSrv.indexTransaction(info, true);
            }
        }
        if (docCount > batchCount) {
            if (this.infoSrv.getRegisteredSearcherCount() < getMaxLiveSearchers()) {
                checkShutdown();
                long endElapsed = System.nanoTime();
                trackerStats.addElapsedNodeTime(docCount, endElapsed - startElapsed);
                startElapsed = endElapsed;
                docCount = 0;
            }
        }
    }
    if (docCount > 0) {
        checkShutdown();
        // this.infoSrv.commit();
        long endElapsed = System.nanoTime();
        trackerStats.addElapsedNodeTime(docCount, endElapsed - startElapsed);
    }
}
Also used : Transactions(org.alfresco.solr.client.Transactions) Transaction(org.alfresco.solr.client.Transaction) GetNodesParameters(org.alfresco.solr.client.GetNodesParameters) Node(org.alfresco.solr.client.Node) ArrayList(java.util.ArrayList)

Example 23 with Node

use of org.alfresco.solr.client.Node in project SearchServices by Alfresco.

the class MetadataTracker method checkNode.

public NodeReport checkNode(Long dbid) {
    NodeReport nodeReport = new NodeReport();
    nodeReport.setDbid(dbid);
    // In DB
    GetNodesParameters parameters = new GetNodesParameters();
    parameters.setFromNodeId(dbid);
    parameters.setToNodeId(dbid);
    List<Node> dbnodes;
    try {
        dbnodes = client.getNodes(parameters, 1);
        if (dbnodes.size() == 1) {
            Node dbnode = dbnodes.get(0);
            nodeReport.setDbNodeStatus(dbnode.getStatus());
            nodeReport.setDbTx(dbnode.getTxnId());
        } else {
            nodeReport.setDbNodeStatus(SolrApiNodeStatus.UNKNOWN);
            nodeReport.setDbTx(-1l);
        }
    } catch (IOException e) {
        nodeReport.setDbNodeStatus(SolrApiNodeStatus.UNKNOWN);
        nodeReport.setDbTx(-2l);
    } catch (JSONException e) {
        nodeReport.setDbNodeStatus(SolrApiNodeStatus.UNKNOWN);
        nodeReport.setDbTx(-3l);
    } catch (AuthenticationException e1) {
        nodeReport.setDbNodeStatus(SolrApiNodeStatus.UNKNOWN);
        nodeReport.setDbTx(-4l);
    }
    this.infoSrv.addCommonNodeReportInfo(nodeReport);
    return nodeReport;
}
Also used : AuthenticationException(org.alfresco.httpclient.AuthenticationException) GetNodesParameters(org.alfresco.solr.client.GetNodesParameters) Node(org.alfresco.solr.client.Node) JSONException(org.json.JSONException) IOException(java.io.IOException) NodeReport(org.alfresco.solr.NodeReport)

Example 24 with Node

use of org.alfresco.solr.client.Node in project SearchServices by Alfresco.

the class MetadataTracker method indexBatchOfTransactions.

private int indexBatchOfTransactions(List<Transaction> txBatch) throws AuthenticationException, IOException, JSONException {
    int nodeCount = 0;
    ArrayList<Transaction> nonEmptyTxs = new ArrayList<>(txBatch.size());
    GetNodesParameters gnp = new GetNodesParameters();
    ArrayList<Long> txIds = new ArrayList<Long>();
    for (Transaction tx : txBatch) {
        if (tx.getUpdates() > 0 || tx.getDeletes() > 0) {
            nonEmptyTxs.add(tx);
            txIds.add(tx.getId());
        }
    }
    gnp.setTransactionIds(txIds);
    gnp.setStoreProtocol(storeRef.getProtocol());
    gnp.setStoreIdentifier(storeRef.getIdentifier());
    gnp.setShardProperty(shardProperty);
    List<Node> nodes = client.getNodes(gnp, Integer.MAX_VALUE);
    ArrayList<Node> nodeBatch = new ArrayList<>();
    for (Node node : nodes) {
        if (log.isDebugEnabled()) {
            log.debug(node.toString());
        }
        nodeBatch.add(node);
        if (nodeBatch.size() > nodeBatchSize) {
            nodeCount += nodeBatch.size();
            NodeIndexWorkerRunnable niwr = new NodeIndexWorkerRunnable(this.threadHandler, nodeBatch, this.infoSrv);
            this.threadHandler.scheduleTask(niwr);
            nodeBatch = new ArrayList<>();
        }
    }
    if (nodeBatch.size() > 0) {
        nodeCount += nodeBatch.size();
        NodeIndexWorkerRunnable niwr = new NodeIndexWorkerRunnable(this.threadHandler, nodeBatch, this.infoSrv);
        this.threadHandler.scheduleTask(niwr);
        nodeBatch = new ArrayList<>();
    }
    return nodeCount;
}
Also used : Transaction(org.alfresco.solr.client.Transaction) GetNodesParameters(org.alfresco.solr.client.GetNodesParameters) Node(org.alfresco.solr.client.Node) ArrayList(java.util.ArrayList)

Example 25 with Node

use of org.alfresco.solr.client.Node in project SearchServices by Alfresco.

the class MetadataTracker method indexNodes.

private void indexNodes() throws IOException, AuthenticationException, JSONException {
    boolean requiresCommit = false;
    while (nodesToIndex.peek() != null) {
        Long nodeId = nodesToIndex.poll();
        if (nodeId != null) {
            Node node = new Node();
            node.setId(nodeId);
            node.setStatus(SolrApiNodeStatus.UNKNOWN);
            node.setTxnId(Long.MAX_VALUE);
            this.infoSrv.indexNode(node, false);
            requiresCommit = true;
        }
        checkShutdown();
    }
    if (requiresCommit) {
        checkShutdown();
    // this.infoSrv.commit();
    }
}
Also used : Node(org.alfresco.solr.client.Node)

Aggregations

Node (org.alfresco.solr.client.Node)25 ArrayList (java.util.ArrayList)14 Transaction (org.alfresco.solr.client.Transaction)12 Test (org.junit.Test)11 NodeMetaData (org.alfresco.solr.client.NodeMetaData)9 AlfrescoSolrUtils.getAcl (org.alfresco.solr.AlfrescoSolrUtils.getAcl)8 AlfrescoSolrUtils.getAclChangeSet (org.alfresco.solr.AlfrescoSolrUtils.getAclChangeSet)8 AlfrescoSolrUtils.getAclReaders (org.alfresco.solr.AlfrescoSolrUtils.getAclReaders)8 AlfrescoSolrUtils.getNode (org.alfresco.solr.AlfrescoSolrUtils.getNode)8 AlfrescoSolrUtils.getNodeMetaData (org.alfresco.solr.AlfrescoSolrUtils.getNodeMetaData)8 AlfrescoSolrUtils.getTransaction (org.alfresco.solr.AlfrescoSolrUtils.getTransaction)8 AlfrescoSolrUtils.indexAclChangeSet (org.alfresco.solr.AlfrescoSolrUtils.indexAclChangeSet)8 Acl (org.alfresco.solr.client.Acl)8 AclChangeSet (org.alfresco.solr.client.AclChangeSet)8 AclReaders (org.alfresco.solr.client.AclReaders)8 Term (org.apache.lucene.index.Term)8 TermQuery (org.apache.lucene.search.TermQuery)8 GetNodesParameters (org.alfresco.solr.client.GetNodesParameters)6 AbstractAlfrescoDistributedTest (org.alfresco.solr.AbstractAlfrescoDistributedTest)4 BooleanClause (org.apache.lucene.search.BooleanClause)4