use of org.alfresco.solr.client.Transaction 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
}
use of org.alfresco.solr.client.Transaction 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);
}
}
use of org.alfresco.solr.client.Transaction in project SearchServices by Alfresco.
the class MetadataTrackerTest method doTrackWithNoTransactionsDoesNothing.
@Test
@Ignore("Superseded by AlfrescoSolrTrackerTest")
public void doTrackWithNoTransactionsDoesNothing() throws AuthenticationException, IOException, JSONException, EncoderException {
TrackerState state = new TrackerState();
when(srv.getTrackerInitialState()).thenReturn(state);
when(this.metadataTracker.getTrackerState()).thenReturn(state);
Transactions txs = mock(Transactions.class);
List<Transaction> txsList = new ArrayList<>();
when(txs.getTransactions()).thenReturn(txsList);
when(repositoryClient.getTransactions(anyLong(), anyLong(), anyLong(), anyLong(), anyInt(), isNull(ShardState.class))).thenReturn(txs);
when(repositoryClient.getTransactions(anyLong(), anyLong(), anyLong(), anyLong(), anyInt(), any(ShardState.class))).thenReturn(txs);
when(repositoryClient.getTransactions(anyLong(), anyLong(), anyLong(), anyLong(), anyInt())).thenReturn(txs);
this.metadataTracker.doTrack();
verify(srv, never()).commit();
}
use of org.alfresco.solr.client.Transaction 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);
}
use of org.alfresco.solr.client.Transaction in project SearchServices by Alfresco.
the class MetadataTracker method indexTransactions.
private void indexTransactions() throws IOException, AuthenticationException, JSONException {
long startElapsed = System.nanoTime();
int docCount = 0;
boolean requiresCommit = false;
while (transactionsToIndex.peek() != null) {
Long transactionId = transactionsToIndex.poll();
if (transactionId != null) {
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);
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());
gnp.setShardProperty(shardProperty);
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, false);
checkShutdown();
}
// Index the transaction doc after the node - if this is not found then a reindex will be done.
this.infoSrv.indexTransaction(info, false);
requiresCommit = true;
trackerStats.addTxDocs(nodes.size());
}
}
if (docCount > batchCount) {
if (this.infoSrv.getRegisteredSearcherCount() < getMaxLiveSearchers()) {
checkShutdown();
// this.infoSrv.commit();
long endElapsed = System.nanoTime();
trackerStats.addElapsedNodeTime(docCount, endElapsed - startElapsed);
startElapsed = endElapsed;
docCount = 0;
requiresCommit = false;
}
}
}
if (requiresCommit || (docCount > 0)) {
checkShutdown();
// this.infoSrv.commit();
long endElapsed = System.nanoTime();
trackerStats.addElapsedNodeTime(docCount, endElapsed - startElapsed);
}
}
Aggregations