Search in sources :

Example 1 with AclChangeSet

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

the class SolrInformationServer method getMaxAclChangeSetIdAndCommitTimeInIndex.

@Override
public AclChangeSet getMaxAclChangeSetIdAndCommitTimeInIndex() {
    SolrQueryRequest request = null;
    try {
        request = getLocalSolrQueryRequest();
        SolrDocument aclState = getState(request, "TRACKER!STATE!ACLTX");
        AclChangeSet maxAclChangeSet = null;
        if (aclState != null) {
            long id = this.getFieldValueLong(aclState, FIELD_S_ACLTXID);
            long commitTime = this.getFieldValueLong(aclState, FIELD_S_ACLTXCOMMITTIME);
            // Irrelevant for this method
            int aclCount = -1;
            maxAclChangeSet = new AclChangeSet(id, commitTime, aclCount);
        } else {
            maxAclChangeSet = new AclChangeSet(0, 0, -1);
        }
        return maxAclChangeSet;
    } finally {
        if (request != null) {
            request.close();
        }
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrDocument(org.apache.solr.common.SolrDocument) AclChangeSet(org.alfresco.solr.client.AclChangeSet)

Example 2 with AclChangeSet

use of org.alfresco.solr.client.AclChangeSet 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 3 with AclChangeSet

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

the class DistributedAclIdAlfrescoSolrTrackerTest method testAclId.

@Test
public void testAclId() 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);
    int numNodes = 1000;
    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(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);
    waitForDocCount(new TermQuery(new Term(FIELD_DOC_TYPE, SolrInformationServer.DOC_TYPE_ACL)), numAcls, 100000);
    for (int i = 0; i < numAcls; i++) {
        Acl acl = bulkAcls.get(i);
        long aclId = acl.getId();
        QueryResponse response = query(getDefaultTestClient(), true, "{\"locales\":[\"en\"], \"templates\": [{\"name\":\"t1\", \"template\":\"%cm:content\"}], \"authorities\": [\"joel" + aclId + "\"], \"tenants\": [ \"\" ]}", params("q", "t1:world", "qt", "/afts", "shards.qt", "/afts", "start", "0", "rows", "100", "sort", "id asc", "fq", "{!afts}AUTHORITY_FILTER_FROM_JSON"));
        assertTrue(response.getResults().getNumFound() > 0);
    }
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) NodeMetaData(org.alfresco.solr.client.NodeMetaData) AlfrescoSolrUtils.getNodeMetaData(org.alfresco.solr.AlfrescoSolrUtils.getNodeMetaData) 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) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) 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 4 with AclChangeSet

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

the class AlfrescoSolrReloadTest method testReload.

@Test
public void testReload() throws Exception {
    long localId = 0L;
    logger.info("######### Starting tracker reload test NODES ###########");
    AclChangeSet aclChangeSet = getAclChangeSet(1, ++localId);
    Acl acl = getAcl(aclChangeSet);
    AclReaders aclReaders = getAclReaders(aclChangeSet, acl, list("joel"), list("phil"), null);
    indexAclChangeSet(aclChangeSet, list(acl), list(aclReaders));
    int numNodes = 1000;
    List<Node> nodes = new ArrayList();
    List<NodeMetaData> nodeMetaDatas = new ArrayList();
    Transaction bigTxn = getTransaction(0, numNodes, ++localId);
    for (int i = 0; i < numNodes; i++) {
        Node node = getNode(bigTxn, acl, Node.SolrApiNodeStatus.UPDATED);
        nodes.add(node);
        NodeMetaData nodeMetaData = getNodeMetaData(node, bigTxn, acl, "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")), 1000, 100000);
    Collection<Tracker> trackers = getTrackers();
    int numOfTrackers = trackers.size();
    int jobs = getJobsCount();
    reloadAndAssertCorrect(trackers, numOfTrackers, jobs);
    Transaction bigTxn2 = getTransaction(0, numNodes, ++localId);
    for (int i = 0; i < numNodes; i++) {
        Node node = getNode(bigTxn2, acl, Node.SolrApiNodeStatus.UPDATED);
        nodes.add(node);
        NodeMetaData nodeMetaData = getNodeMetaData(node, bigTxn2, acl, "mike", null, false);
        nodeMetaDatas.add(nodeMetaData);
    }
    indexTransaction(bigTxn2, nodes, nodeMetaDatas);
    waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 2000, 100000);
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Tracker(org.alfresco.solr.tracker.Tracker) NodeMetaData(org.alfresco.solr.client.NodeMetaData) AlfrescoSolrUtils.getNodeMetaData(org.alfresco.solr.AlfrescoSolrUtils.getNodeMetaData) 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)

Example 5 with AclChangeSet

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

the class AclTracker method checkRepoAndIndexConsistency.

/**
 * Checks the first and last TX time
 * @param state the state of this tracker
 * @throws AuthenticationException
 * @throws IOException
 * @throws JSONException
 */
private void checkRepoAndIndexConsistency(TrackerState state) throws AuthenticationException, IOException, JSONException {
    AclChangeSets firstChangeSets = null;
    if (state.getLastGoodChangeSetCommitTimeInIndex() == 0) {
        state.setCheckedLastAclTransactionTime(true);
        state.setCheckedFirstAclTransactionTime(true);
        log.info("No acl transactions found - no verification required");
        firstChangeSets = client.getAclChangeSets(null, 0L, null, 2000L, 1);
        if (!firstChangeSets.getAclChangeSets().isEmpty()) {
            AclChangeSet firstChangeSet = firstChangeSets.getAclChangeSets().get(0);
            long firstChangeSetCommitTime = firstChangeSet.getCommitTimeMs();
            state.setLastGoodChangeSetCommitTimeInIndex(firstChangeSetCommitTime);
            setLastChangeSetIdAndCommitTimeInTrackerState(firstChangeSets, state);
        }
    }
    if (!state.isCheckedFirstAclTransactionTime()) {
        firstChangeSets = client.getAclChangeSets(null, 0l, null, 2000L, 1);
        if (!firstChangeSets.getAclChangeSets().isEmpty()) {
            AclChangeSet firstAclChangeSet = firstChangeSets.getAclChangeSets().get(0);
            long firstAclTxId = firstAclChangeSet.getId();
            long firstAclTxCommitTime = firstAclChangeSet.getCommitTimeMs();
            int setSize = this.infoSrv.getAclTxDocsSize("" + firstAclTxId, "" + firstAclTxCommitTime);
            if (setSize == 0) {
                log.error("First acl transaction was not found with the correct timestamp.");
                log.error("SOLR has successfully connected to your repository  however the SOLR indexes and repository database do not match.");
                log.error("If this is a new or rebuilt database your SOLR indexes also need to be re-built to match the database.");
                log.error("You can also check your SOLR connection details in solrcore.properties.");
                throw new AlfrescoRuntimeException("Initial acl transaction not found with correct timestamp");
            } else if (setSize == 1) {
                state.setCheckedFirstTransactionTime(true);
                log.info("Verified first acl transaction and timestamp in index");
            } else {
                log.warn("Duplicate initial acl transaction found with correct timestamp");
            }
        }
    }
    // Checks that the last aclTxId in solr is <= last aclTxId in repo
    if (!state.isCheckedLastAclTransactionTime()) {
        if (firstChangeSets == null) {
            firstChangeSets = client.getAclChangeSets(null, 0l, null, 2000L, 1);
        }
        setLastChangeSetIdAndCommitTimeInTrackerState(firstChangeSets, state);
        Long maxChangeSetCommitTimeInRepo = firstChangeSets.getMaxChangeSetCommitTime();
        Long maxChangeSetIdInRepo = firstChangeSets.getMaxChangeSetId();
        if (maxChangeSetCommitTimeInRepo != null && maxChangeSetIdInRepo != null) {
            AclChangeSet maxAclTxInIndex = this.infoSrv.getMaxAclChangeSetIdAndCommitTimeInIndex();
            if (maxAclTxInIndex.getCommitTimeMs() > maxChangeSetCommitTimeInRepo) {
                log.error("Last acl transaction was found in index with timestamp later than that of repository.");
                log.error("Max Acl Tx In Index: " + maxAclTxInIndex.getId() + ", In Repo: " + maxChangeSetIdInRepo);
                log.error("Max Acl Tx Commit Time In Index: " + maxAclTxInIndex.getCommitTimeMs() + ", In Repo: " + maxChangeSetCommitTimeInRepo);
                log.error("SOLR has successfully connected to your repository  however the SOLR indexes and repository database do not match.");
                log.error("If this is a new or rebuilt database your SOLR indexes also need to be re-built to match the database.");
                log.error("You can also check your SOLR connection details in solrcore.properties.");
                throw new AlfrescoRuntimeException("Last acl transaction found in index with incorrect timestamp");
            } else {
                state.setCheckedLastAclTransactionTime(true);
                log.info("Verified last acl transaction timestamp in index less than or equal to that of repository.");
            }
        }
    }
}
Also used : AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AclChangeSets(org.alfresco.solr.client.AclChangeSets) AclChangeSet(org.alfresco.solr.client.AclChangeSet)

Aggregations

AclChangeSet (org.alfresco.solr.client.AclChangeSet)17 Acl (org.alfresco.solr.client.Acl)11 AclReaders (org.alfresco.solr.client.AclReaders)10 ArrayList (java.util.ArrayList)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 Node (org.alfresco.solr.client.Node)8 NodeMetaData (org.alfresco.solr.client.NodeMetaData)8 Transaction (org.alfresco.solr.client.Transaction)8 Term (org.apache.lucene.index.Term)8 TermQuery (org.apache.lucene.search.TermQuery)8 Test (org.junit.Test)8 AclChangeSets (org.alfresco.solr.client.AclChangeSets)6 AbstractAlfrescoDistributedTest (org.alfresco.solr.AbstractAlfrescoDistributedTest)4 BooleanClause (org.apache.lucene.search.BooleanClause)4