Search in sources :

Example 1 with Node

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

the class HandlerReportBuilder method buildTxReport.

/**
 * Builds TxReport
 * @param trackerRegistry
 * @param srv
 * @param coreName
 * @param tracker
 * @param txid
 * @return
 * @throws AuthenticationException
 * @throws IOException
 * @throws JSONException
 * @throws EncoderException
 */
public static NamedList<Object> buildTxReport(TrackerRegistry trackerRegistry, InformationServer srv, String coreName, MetadataTracker tracker, Long txid) throws AuthenticationException, IOException, JSONException, EncoderException {
    NamedList<Object> nr = new SimpleOrderedMap<Object>();
    nr.add("TXID", txid);
    nr.add("transaction", buildTrackerReport(trackerRegistry, srv, coreName, txid, txid, 0l, 0l, null, null));
    NamedList<Object> nodes = new SimpleOrderedMap<Object>();
    // add node reports ....
    List<Node> dbNodes = tracker.getFullNodesForDbTransaction(txid);
    for (Node node : dbNodes) {
        nodes.add("DBID " + node.getId(), buildNodeReport(tracker, node));
    }
    nr.add("txDbNodeCount", dbNodes.size());
    nr.add("nodes", nodes);
    return nr;
}
Also used : Node(org.alfresco.solr.client.Node) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

Example 2 with Node

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

the class SolrInformationServer method reindexNodeByQuery.

/* (non-Javadoc)
     * @see org.alfresco.solr.InformationServer#reindexNodeByQuery(java.lang.String)
     */
@Override
public void reindexNodeByQuery(String query) throws IOException, AuthenticationException, JSONException {
    SolrQueryRequest request = null;
    RefCounted<SolrIndexSearcher> refCounted = null;
    try {
        refCounted = core.getSearcher(false, true, null);
        SolrIndexSearcher solrIndexSearcher = refCounted.get();
        request = getLocalSolrQueryRequest();
        NumericDocValues dbidDocValues = solrIndexSearcher.getSlowAtomicReader().getNumericDocValues(QueryConstants.FIELD_DBID);
        ArrayList<Node> batch = new ArrayList<Node>(200);
        DocList docList = cloud.getDocList(nativeRequestHandler, request, query.startsWith("{") ? query : "{!afts}" + query);
        for (DocIterator it = docList.iterator(); it.hasNext(); ) /**/
        {
            int docID = it.nextDoc();
            // Obtain the ACL ID for this ACL doc.
            long dbid = dbidDocValues.get(docID);
            Node node = new Node();
            node.setId(dbid);
            node.setStatus(SolrApiNodeStatus.UNKNOWN);
            node.setTxnId(Long.MAX_VALUE);
            batch.add(node);
            if (batch.size() >= 200) {
                indexNodes(batch, true, true);
                batch.clear();
            }
        }
        if (batch.size() > 0) {
            indexNodes(batch, true, true);
            batch.clear();
        }
    } finally {
        if (request != null) {
            request.close();
        }
        if (refCounted != null) {
            refCounted.decref();
        }
    }
}
Also used : NumericDocValues(org.apache.lucene.index.NumericDocValues) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) DocIterator(org.apache.solr.search.DocIterator) Node(org.alfresco.solr.client.Node) IntArrayList(com.carrotsearch.hppc.IntArrayList) ArrayList(java.util.ArrayList) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) DocList(org.apache.solr.search.DocList)

Example 3 with Node

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

the class SolrInformationServer method indexNodes.

@Override
public void indexNodes(List<Node> nodes, boolean overwrite, boolean cascade) throws IOException, AuthenticationException, JSONException {
    SolrQueryRequest request = null;
    UpdateRequestProcessor processor = null;
    try {
        request = getLocalSolrQueryRequest();
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
        Map<Long, Node> nodeIdsToNodes = new HashMap<>();
        EnumMap<SolrApiNodeStatus, List<Long>> nodeStatusToNodeIds = new EnumMap<SolrApiNodeStatus, List<Long>>(SolrApiNodeStatus.class);
        categorizeNodes(nodes, nodeIdsToNodes, nodeStatusToNodeIds);
        List<Long> deletedNodeIds = mapNullToEmptyList(nodeStatusToNodeIds.get(SolrApiNodeStatus.DELETED));
        List<Long> shardDeletedNodeIds = mapNullToEmptyList(nodeStatusToNodeIds.get(SolrApiNodeStatus.NON_SHARD_DELETED));
        List<Long> shardUpdatedNodeIds = mapNullToEmptyList(nodeStatusToNodeIds.get(SolrApiNodeStatus.NON_SHARD_UPDATED));
        List<Long> unknownNodeIds = mapNullToEmptyList(nodeStatusToNodeIds.get(SolrApiNodeStatus.UNKNOWN));
        List<Long> updatedNodeIds = mapNullToEmptyList(nodeStatusToNodeIds.get(SolrApiNodeStatus.UPDATED));
        if (!deletedNodeIds.isEmpty() || !shardDeletedNodeIds.isEmpty() || !shardUpdatedNodeIds.isEmpty() || !unknownNodeIds.isEmpty()) {
            // fix up any secondary paths
            List<NodeMetaData> nodeMetaDatas = new ArrayList<>();
            // For all deleted nodes, fake the node metadata
            for (Long deletedNodeId : deletedNodeIds) {
                Node node = nodeIdsToNodes.get(deletedNodeId);
                NodeMetaData nodeMetaData = createDeletedNodeMetaData(node);
                nodeMetaDatas.add(nodeMetaData);
            }
            if (!unknownNodeIds.isEmpty()) {
                NodeMetaDataParameters nmdp = new NodeMetaDataParameters();
                nmdp.setNodeIds(unknownNodeIds);
                nodeMetaDatas.addAll(repositoryClient.getNodesMetaData(nmdp, Integer.MAX_VALUE));
            }
            for (NodeMetaData nodeMetaData : nodeMetaDatas) {
                Node node = nodeIdsToNodes.get(nodeMetaData.getId());
                if (nodeMetaData.getTxnId() > node.getTxnId()) {
                    // it will be indexed later
                    continue;
                }
                if (nodeMetaData != null) {
                    try {
                        // Lock the node to ensure that no other trackers work with this node until this code completes.
                        if (!spinLock(nodeMetaData.getId(), 120000)) {
                            // We haven't acquired the lock in over 2 minutes. This really shouldn't happen unless something has gone wrong.
                            throw new Exception("Unable to acquire lock on nodeId:" + nodeMetaData.getId());
                        }
                        solrContentStore.removeDocFromContentStore(nodeMetaData);
                    } finally {
                        unlock(nodeMetaData.getId());
                    }
                }
            }
            if (log.isDebugEnabled()) {
                log.debug(".. deleting");
            }
            DeleteUpdateCommand delDocCmd = new DeleteUpdateCommand(request);
            String query = this.cloud.getQuery(FIELD_DBID, OR, deletedNodeIds, shardDeletedNodeIds, shardUpdatedNodeIds, unknownNodeIds);
            delDocCmd.setQuery(query);
            processor.processDelete(delDocCmd);
        }
        if (!updatedNodeIds.isEmpty() || !unknownNodeIds.isEmpty() || !shardUpdatedNodeIds.isEmpty()) {
            log.info(".. updating");
            NodeMetaDataParameters nmdp = new NodeMetaDataParameters();
            List<Long> nodeIds = new LinkedList<>();
            nodeIds.addAll(updatedNodeIds);
            nodeIds.addAll(unknownNodeIds);
            nodeIds.addAll(shardUpdatedNodeIds);
            nmdp.setNodeIds(nodeIds);
            // Fetches bulk metadata
            List<NodeMetaData> nodeMetaDatas = repositoryClient.getNodesMetaData(nmdp, Integer.MAX_VALUE);
            NEXT_NODE: for (NodeMetaData nodeMetaData : nodeMetaDatas) {
                // System.out.println("####################### NodeMetaData:"+ nodeMetaData.getId());
                long start = System.nanoTime();
                Node node = nodeIdsToNodes.get(nodeMetaData.getId());
                long nodeId = node.getId();
                try {
                    // Lock the node to ensure that no other trackers work with this node until this code completes.
                    if (!spinLock(nodeId, 120000)) {
                        // We haven't acquired the lock in over 2 minutes. This really shouldn't happen unless something has gone wrong.
                        throw new Exception("Unable to acquire lock on nodeId:" + nodeId);
                    }
                    if (nodeMetaData.getTxnId() > node.getTxnId()) {
                        // it will be indexed later
                        continue;
                    }
                    if (nodeIdsToNodes.get(nodeMetaData.getId()).getStatus() == SolrApiNodeStatus.NON_SHARD_UPDATED) {
                        if (nodeMetaData.getProperties().get(ContentModel.PROP_CASCADE_TX) != null) {
                            indexNonShardCascade(nodeMetaData);
                        }
                        continue;
                    }
                    AddUpdateCommand addDocCmd = new AddUpdateCommand(request);
                    addDocCmd.overwrite = overwrite;
                    // check index control
                    Map<QName, PropertyValue> properties = nodeMetaData.getProperties();
                    StringPropertyValue pValue = (StringPropertyValue) properties.get(ContentModel.PROP_IS_INDEXED);
                    if (pValue != null) {
                        Boolean isIndexed = Boolean.valueOf(pValue.getValue());
                        if (!isIndexed.booleanValue()) {
                            if (log.isDebugEnabled()) {
                                log.debug(".. clearing unindexed");
                            }
                            deleteNode(processor, request, node);
                            SolrInputDocument doc = createNewDoc(nodeMetaData, DOC_TYPE_UNINDEXED_NODE);
                            addDocCmd.solrDoc = doc;
                            if (recordUnindexedNodes) {
                                solrContentStore.storeDocOnSolrContentStore(nodeMetaData, doc);
                                processor.processAdd(addDocCmd);
                            }
                            long end = System.nanoTime();
                            this.trackerStats.addNodeTime(end - start);
                            continue NEXT_NODE;
                        }
                    }
                    // Make sure any unindexed or error doc is removed.
                    if (log.isDebugEnabled()) {
                        log.debug(".. deleting node " + node.getId());
                    }
                    deleteNode(processor, request, node);
                    SolrInputDocument doc = createNewDoc(nodeMetaData, DOC_TYPE_NODE);
                    addToNewDocAndCache(nodeMetaData, doc);
                    addDocCmd.solrDoc = doc;
                    // System.out.println("###################### indexing doc:"+doc.toString());
                    processor.processAdd(addDocCmd);
                    long end = System.nanoTime();
                    this.trackerStats.addNodeTime(end - start);
                } finally {
                    // release the lock on the node so other trackers can access the node.
                    unlock(nodeId);
                }
            }
        // Ends iteration over nodeMetadatas
        }
    // Ends checking for the existence of updated or unknown node ids
    } catch (Exception e) {
        log.error("SolrInformationServer problem", e);
        // Bulk version failed, so do one at a time.
        for (Node node : nodes) {
            this.indexNode(node, true);
        }
    } finally {
        if (processor != null) {
            processor.finish();
        }
        if (request != null) {
            request.close();
        }
    }
}
Also used : StringPropertyValue(org.alfresco.solr.client.StringPropertyValue) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Node(org.alfresco.solr.client.Node) IntArrayList(com.carrotsearch.hppc.IntArrayList) ArrayList(java.util.ArrayList) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrApiNodeStatus(org.alfresco.solr.client.Node.SolrApiNodeStatus) UpdateRequestProcessor(org.apache.solr.update.processor.UpdateRequestProcessor) NodeMetaDataParameters(org.alfresco.solr.client.NodeMetaDataParameters) SolrDocumentList(org.apache.solr.common.SolrDocumentList) IntArrayList(com.carrotsearch.hppc.IntArrayList) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) DocList(org.apache.solr.search.DocList) List(java.util.List) LinkedList(java.util.LinkedList) EnumMap(java.util.EnumMap) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) NodeMetaData(org.alfresco.solr.client.NodeMetaData) JSONException(org.json.JSONException) AuthenticationException(org.alfresco.httpclient.AuthenticationException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LinkedList(java.util.LinkedList) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) DeleteUpdateCommand(org.apache.solr.update.DeleteUpdateCommand) AddUpdateCommand(org.apache.solr.update.AddUpdateCommand) Map(java.util.Map) SolrSimpleOrderedMap(org.alfresco.solr.adapters.SolrSimpleOrderedMap) EnumMap(java.util.EnumMap) LinkedHashMap(java.util.LinkedHashMap) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) HashMap(java.util.HashMap) ISimpleOrderedMap(org.alfresco.solr.adapters.ISimpleOrderedMap)

Example 4 with Node

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

the class DistributedExpandDbidRangeAlfrescoSolrTrackerTest method testDbIdRange.

@Test
public void testDbIdRange() throws Exception {
    putHandleDefaults();
    int numAcls = 250;
    AclChangeSet bulkAclChangeSet = getAclChangeSet(numAcls);
    List<Acl> bulkAcls = new ArrayList();
    List<AclReaders> bulkAclReaders = new ArrayList();
    for (int i = 0; i < numAcls; i++) {
        Acl bulkAcl = getAcl(bulkAclChangeSet);
        bulkAcls.add(bulkAcl);
        bulkAclReaders.add(getAclReaders(bulkAclChangeSet, bulkAcl, list("joel" + bulkAcl.getId()), list("phil" + bulkAcl.getId()), null));
    }
    indexAclChangeSet(bulkAclChangeSet, bulkAcls, bulkAclReaders);
    SolrQueryResponse response0 = rangeCheck(0);
    NamedList values0 = response0.getValues();
    // {start=0,end=100,nodeCount=0,maxDbid=0,density=NaN,expand=0,expanded=false}
    assertEquals((long) values0.get("start"), 0);
    assertEquals((long) values0.get("end"), 100);
    assertEquals((long) values0.get("nodeCount"), 0);
    assertEquals((long) values0.get("minDbid"), 0);
    assertEquals((long) values0.get("maxDbid"), 0);
    assertEquals((long) values0.get("expand"), 0);
    assertEquals((boolean) values0.get("expanded"), false);
    System.out.println("RANGECHECK0:" + values0);
    SolrQueryResponse response1 = rangeCheck(1);
    NamedList values1 = response1.getValues();
    // {start=100,end=200,nodeCount=0,maxDbid=0,density=0.0,expand=0,expanded=false}
    System.out.println("RANGECHECK1:" + values1);
    assertEquals((long) values1.get("start"), 100);
    assertEquals((long) values1.get("end"), 200);
    assertEquals((long) values1.get("nodeCount"), 0);
    assertEquals((long) values1.get("minDbid"), 0);
    assertEquals((long) values1.get("maxDbid"), 0);
    assertEquals((long) values1.get("expand"), 0);
    assertEquals((boolean) values1.get("expanded"), false);
    int numNodes = 25;
    List<Node> nodes = new ArrayList();
    List<NodeMetaData> nodeMetaDatas = new ArrayList();
    Transaction bigTxn = getTransaction(0, numNodes);
    for (int i = 0; i < numNodes; i++) {
        int aclIndex = i % numAcls;
        Node node = getNode((long) i, bigTxn, bulkAcls.get(aclIndex), Node.SolrApiNodeStatus.UPDATED);
        nodes.add(node);
        NodeMetaData nodeMetaData = getNodeMetaData(node, bigTxn, bulkAcls.get(aclIndex), "mike", null, false);
        nodeMetaDatas.add(nodeMetaData);
    }
    indexTransaction(bigTxn, nodes, nodeMetaDatas);
    waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), numNodes, 100000);
    waitForDocCountAllCores(new TermQuery(new Term(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_ACL)), numAcls, 80000);
    response0 = rangeCheck(0);
    values0 = response0.getValues();
    // {start=0,end=100,nodeCount=25,maxDbid=24,density=1.0416666666666667,expand=0,expanded=false}
    assertEquals((long) values0.get("start"), 0);
    assertEquals((long) values0.get("end"), 100);
    assertEquals((long) values0.get("nodeCount"), 25);
    assertEquals((long) values0.get("minDbid"), 0);
    assertEquals((long) values0.get("maxDbid"), 24);
    assertEquals((long) values0.get("expand"), 0);
    assertEquals((boolean) values0.get("expanded"), false);
    System.out.println("_RANGECHECK0:" + values0);
    response1 = rangeCheck(1);
    values1 = response1.getValues();
    assertEquals((long) values1.get("start"), 100);
    assertEquals((long) values1.get("end"), 200);
    assertEquals((long) values1.get("nodeCount"), 0);
    assertEquals((long) values0.get("minDbid"), 0);
    assertEquals((long) values1.get("maxDbid"), 0);
    assertEquals((long) values1.get("expand"), 0);
    assertEquals((boolean) values1.get("expanded"), false);
    System.out.println("_RANGECHECK1:" + values1);
    numNodes = 26;
    nodes = new ArrayList();
    nodeMetaDatas = new ArrayList();
    bigTxn = getTransaction(0, numNodes);
    for (int i = 0; i < numNodes; i++) {
        int aclIndex = i % numAcls;
        Node node = getNode((long) i + 35, bigTxn, bulkAcls.get(aclIndex), Node.SolrApiNodeStatus.UPDATED);
        nodes.add(node);
        NodeMetaData nodeMetaData = getNodeMetaData(node, bigTxn, bulkAcls.get(aclIndex), "mike", null, false);
        nodeMetaDatas.add(nodeMetaData);
    }
    indexTransaction(bigTxn, nodes, nodeMetaDatas);
    waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 51, 100000);
    response0 = rangeCheck(0);
    values0 = response0.getValues();
    // {start=0,end=100,nodeCount=51,maxDbid=60,density=0.85,expand=15,expanded=false}
    assertEquals((long) values0.get("start"), 0);
    assertEquals((long) values0.get("end"), 100);
    assertEquals((long) values0.get("nodeCount"), 51);
    assertEquals((long) values0.get("minDbid"), 0);
    assertEquals((long) values0.get("maxDbid"), 60);
    assertEquals((double) values0.get("density"), .85, 0.0);
    assertEquals((long) values0.get("expand"), 17);
    assertEquals((boolean) values0.get("expanded"), false);
    System.out.println("_RANGECHECK0:" + values0);
    response1 = rangeCheck(1);
    values1 = response1.getValues();
    assertEquals((long) values1.get("start"), 100);
    assertEquals((long) values1.get("end"), 200);
    assertEquals((long) values1.get("nodeCount"), 0);
    assertEquals((long) values0.get("minDbid"), 0);
    assertEquals((long) values1.get("maxDbid"), 0);
    assertEquals((long) values1.get("expand"), 0);
    assertEquals((boolean) values1.get("expanded"), false);
    System.out.println("_RANGECHECK1:" + values1);
    numNodes = 5;
    nodes = new ArrayList();
    nodeMetaDatas = new ArrayList();
    bigTxn = getTransaction(0, numNodes);
    for (int i = 0; i < numNodes; i++) {
        int aclIndex = i % numAcls;
        Node node = getNode((long) i + 72, bigTxn, bulkAcls.get(aclIndex), Node.SolrApiNodeStatus.UPDATED);
        nodes.add(node);
        NodeMetaData nodeMetaData = getNodeMetaData(node, bigTxn, bulkAcls.get(aclIndex), "mike", null, false);
        nodeMetaDatas.add(nodeMetaData);
    }
    indexTransaction(bigTxn, nodes, nodeMetaDatas);
    waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 56, 100000);
    response0 = rangeCheck(0);
    values0 = response0.getValues();
    // {start=0,end=100,nodeCount=56,maxDbid=76,density=0.7368421052631579,expand=-1,expanded=false}
    assertEquals((long) values0.get("start"), 0);
    assertEquals((long) values0.get("end"), 100);
    assertEquals((long) values0.get("nodeCount"), 56);
    assertEquals((long) values0.get("minDbid"), 0);
    assertEquals((long) values0.get("maxDbid"), 76);
    assertEquals((double) values0.get("density"), 0.7368421052631579, 0.0);
    assertEquals((long) values0.get("expand"), -1);
    assertEquals((boolean) values0.get("expanded"), false);
    SolrQueryResponse expandResponse = expand(0, 35);
    NamedList expandValues = expandResponse.getValues();
    String ex = (String) expandValues.get("exception");
    assertEquals(ex, "Expansion cannot occur if max DBID in the index is more then 75% of range.");
    Number expanded = (Number) expandValues.get("expand");
    assertEquals(expanded.intValue(), -1);
    System.out.println("_RANGECHECK0:" + values0);
    response1 = rangeCheck(1);
    values1 = response1.getValues();
    System.out.println("_RANGECHECK1:" + values1);
    assertEquals((long) values1.get("start"), 100);
    assertEquals((long) values1.get("end"), 200);
    assertEquals((long) values1.get("nodeCount"), 0);
    assertEquals((long) values0.get("minDbid"), 0);
    assertEquals((long) values1.get("maxDbid"), 0);
    assertEquals((long) values1.get("expand"), 0);
    assertEquals((boolean) values1.get("expanded"), false);
    numNodes = 5;
    nodes = new ArrayList();
    nodeMetaDatas = new ArrayList();
    bigTxn = getTransaction(0, numNodes);
    for (int i = 0; i < numNodes; i++) {
        int aclIndex = i % numAcls;
        Node node = getNode((long) i + 100, bigTxn, bulkAcls.get(aclIndex), Node.SolrApiNodeStatus.UPDATED);
        nodes.add(node);
        NodeMetaData nodeMetaData = getNodeMetaData(node, bigTxn, bulkAcls.get(aclIndex), "mike", null, false);
        nodeMetaDatas.add(nodeMetaData);
    }
    indexTransaction(bigTxn, nodes, nodeMetaDatas);
    waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 61, 100000);
    response0 = rangeCheck(0);
    values0 = response0.getValues();
    // {start=0,end=100,nodeCount=56,maxDbid=76,density=0.7368421052631579,expand=-1,expanded=false}
    assertEquals((long) values0.get("start"), 0);
    assertEquals((long) values0.get("end"), 100);
    assertEquals((long) values0.get("nodeCount"), 56);
    assertEquals((long) values0.get("minDbid"), 0);
    assertEquals((long) values0.get("maxDbid"), 76);
    assertEquals((double) values0.get("density"), 0.7368421052631579, 0.0);
    assertEquals((long) values0.get("expand"), -1);
    assertEquals((boolean) values0.get("expanded"), false);
    response1 = rangeCheck(1);
    values1 = response1.getValues();
    System.out.println("_RANGECHECK1:" + values1);
    assertEquals((long) values1.get("start"), 100);
    assertEquals((long) values1.get("end"), 200);
    assertEquals((long) values1.get("nodeCount"), 5);
    assertEquals((long) values1.get("minDbid"), 100);
    assertEquals((long) values1.get("maxDbid"), 104);
    assertEquals((long) values1.get("expand"), 0);
    assertEquals((boolean) values1.get("expanded"), false);
    numNodes = 35;
    nodes = new ArrayList();
    nodeMetaDatas = new ArrayList();
    bigTxn = getTransaction(0, numNodes);
    for (int i = 0; i < numNodes; i++) {
        int aclIndex = i % numAcls;
        Node node = getNode((long) i + 120, bigTxn, bulkAcls.get(aclIndex), Node.SolrApiNodeStatus.UPDATED);
        nodes.add(node);
        NodeMetaData nodeMetaData = getNodeMetaData(node, bigTxn, bulkAcls.get(aclIndex), "mike", null, false);
        nodeMetaDatas.add(nodeMetaData);
    }
    indexTransaction(bigTxn, nodes, nodeMetaDatas);
    waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 96, 100000);
    response0 = rangeCheck(0);
    values0 = response0.getValues();
    // {start=0,end=100,nodeCount=56,maxDbid=76,density=0.7368421052631579,expand=-1,expanded=false}
    assertEquals((long) values0.get("start"), 0);
    assertEquals((long) values0.get("end"), 100);
    assertEquals((long) values0.get("nodeCount"), 56);
    assertEquals((long) values0.get("minDbid"), 0);
    assertEquals((long) values0.get("maxDbid"), 76);
    assertEquals((double) values0.get("density"), 0.7368421052631579, 0.0);
    assertEquals((long) values0.get("expand"), -1);
    assertEquals((boolean) values0.get("expanded"), false);
    response1 = rangeCheck(1);
    values1 = response1.getValues();
    System.out.println("_RANGECHECK1:" + values1);
    // {start=100,end=200,nodeCount=40,maxDbid=154,density=0.7407407407407407,expand=35,expanded=false}
    assertEquals((long) values1.get("start"), 100);
    assertEquals((long) values1.get("end"), 200);
    assertEquals((long) values1.get("nodeCount"), 40);
    assertEquals((long) values1.get("minDbid"), 100);
    assertEquals((long) values1.get("maxDbid"), 154);
    assertEquals((double) values1.get("density"), 0.7407407407407407, 0.0);
    assertEquals((long) values1.get("expand"), 35);
    assertEquals((boolean) values1.get("expanded"), false);
    // expand shard1 by 20
    expandResponse = expand(1, 35);
    expandValues = expandResponse.getValues();
    expanded = (Number) expandValues.get("expand");
    assertEquals(expanded.intValue(), 235);
    waitForShardsCount(new TermQuery(new Term(FIELD_SOLR4_ID, "TRACKER!STATE!CAP")), 1, 100000, System.currentTimeMillis());
    response1 = rangeCheck(1);
    values1 = response1.getValues();
    System.out.println("_RANGECHECK1:" + values1);
    // {start=100,end=235,nodeCount=40,maxDbid=154,density=0.7407407407407407,expand=-1,expanded=true}
    assertEquals((long) values1.get("start"), 100);
    assertEquals((long) values1.get("end"), 235);
    assertEquals((long) values1.get("nodeCount"), 40);
    assertEquals((long) values1.get("minDbid"), 100);
    assertEquals((long) values1.get("maxDbid"), 154);
    assertEquals((double) values1.get("density"), 0.7407407407407407, 0.0);
    assertEquals((long) values1.get("expand"), -1);
    assertEquals((boolean) values1.get("expanded"), true);
    numNodes = 3;
    nodes = new ArrayList();
    nodeMetaDatas = new ArrayList();
    bigTxn = getTransaction(0, numNodes);
    for (int i = 0; i < numNodes; i++) {
        int aclIndex = i % numAcls;
        Node node = getNode((long) i + 230, bigTxn, bulkAcls.get(aclIndex), Node.SolrApiNodeStatus.UPDATED);
        nodes.add(node);
        NodeMetaData nodeMetaData = getNodeMetaData(node, bigTxn, bulkAcls.get(aclIndex), "mike", null, false);
        nodeMetaDatas.add(nodeMetaData);
    }
    indexTransaction(bigTxn, nodes, nodeMetaDatas);
    waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 99, 100000);
    response1 = rangeCheck(1);
    values1 = response1.getValues();
    System.out.println("_RANGECHECK1:" + values1);
    // {start=100,end=235,nodeCount=43,maxDbid=232,density=0.32575757575757575,expand=-1,expanded=true}
    assertEquals((long) values1.get("start"), 100);
    assertEquals((long) values1.get("end"), 235);
    assertEquals((long) values1.get("nodeCount"), 43);
    assertEquals((long) values1.get("minDbid"), 100);
    assertEquals((long) values1.get("maxDbid"), 232);
    assertEquals((double) values1.get("density"), 0.32575757575757575, 0.0);
    assertEquals((long) values1.get("expand"), -1);
    assertEquals((boolean) values1.get("expanded"), true);
// assert(false);
// Do a reload
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) NodeMetaData(org.alfresco.solr.client.NodeMetaData) AlfrescoSolrUtils.getNodeMetaData(org.alfresco.solr.AlfrescoSolrUtils.getNodeMetaData) NamedList(org.apache.solr.common.util.NamedList) Node(org.alfresco.solr.client.Node) AlfrescoSolrUtils.getNode(org.alfresco.solr.AlfrescoSolrUtils.getNode) ArrayList(java.util.ArrayList) Acl(org.alfresco.solr.client.Acl) AlfrescoSolrUtils.getAcl(org.alfresco.solr.AlfrescoSolrUtils.getAcl) Term(org.apache.lucene.index.Term) Transaction(org.alfresco.solr.client.Transaction) AlfrescoSolrUtils.getTransaction(org.alfresco.solr.AlfrescoSolrUtils.getTransaction) AlfrescoSolrUtils.getAclChangeSet(org.alfresco.solr.AlfrescoSolrUtils.getAclChangeSet) AlfrescoSolrUtils.indexAclChangeSet(org.alfresco.solr.AlfrescoSolrUtils.indexAclChangeSet) AclChangeSet(org.alfresco.solr.client.AclChangeSet) AlfrescoSolrUtils.getAclReaders(org.alfresco.solr.AlfrescoSolrUtils.getAclReaders) AclReaders(org.alfresco.solr.client.AclReaders) Test(org.junit.Test) AbstractAlfrescoDistributedTest(org.alfresco.solr.AbstractAlfrescoDistributedTest)

Example 5 with Node

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

the class AlfrescoSolrUtils method getNode.

/**
 * Get a node.
 * @param txn
 * @param acl
 * @param status
 * @return {@link Node}
 */
public static Node getNode(Transaction txn, Acl acl, Node.SolrApiNodeStatus status) {
    Node node = new Node();
    node.setTxnId(txn.getId());
    node.setId(generateId());
    node.setAclId(acl.getId());
    node.setStatus(status);
    return node;
}
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