use of org.apache.solr.common.cloud.DocCollection in project lucene-solr by apache.
the class TestPullReplica method testCreateDelete.
// 2 times to make sure cleanup is complete and we can create the same collection
@Repeat(iterations = 2)
public void testCreateDelete() throws Exception {
try {
switch(random().nextInt(3)) {
case 0:
// Sometimes use SolrJ
CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1, 0, 3).setMaxShardsPerNode(100).process(cluster.getSolrClient());
break;
case 1:
// Sometimes use v1 API
String url = String.format(Locale.ROOT, "%s/admin/collections?action=CREATE&name=%s&numShards=%s&pullReplicas=%s&maxShardsPerNode=%s", cluster.getRandomJetty(random()).getBaseUrl(), collectionName, // numShards
2, // pullReplicas
3, // maxShardsPerNode
100);
// These options should all mean the same
url = url + pickRandom("", "&nrtReplicas=1", "&replicationFactor=1");
HttpGet createCollectionGet = new HttpGet(url);
cluster.getSolrClient().getHttpClient().execute(createCollectionGet);
break;
case 2:
// Sometimes use V2 API
url = cluster.getRandomJetty(random()).getBaseUrl().toString() + "/____v2/c";
String requestBody = String.format(Locale.ROOT, "{create:{name:%s, numShards:%s, pullReplicas:%s, maxShardsPerNode:%s %s}}", collectionName, // numShards
2, // pullReplicas
3, // maxShardsPerNode
100, // These options should all mean the same
pickRandom("", ", nrtReplicas:1", ", replicationFactor:1"));
HttpPost createCollectionPost = new HttpPost(url);
createCollectionPost.setHeader("Content-type", "application/json");
createCollectionPost.setEntity(new StringEntity(requestBody));
HttpResponse httpResponse = cluster.getSolrClient().getHttpClient().execute(createCollectionPost);
assertEquals(200, httpResponse.getStatusLine().getStatusCode());
break;
}
boolean reloaded = false;
while (true) {
DocCollection docCollection = getCollectionState(collectionName);
assertNotNull(docCollection);
assertEquals("Expecting 4 relpicas per shard", 8, docCollection.getReplicas().size());
assertEquals("Expecting 6 pull replicas, 3 per shard", 6, docCollection.getReplicas(EnumSet.of(Replica.Type.PULL)).size());
assertEquals("Expecting 2 writer replicas, one per shard", 2, docCollection.getReplicas(EnumSet.of(Replica.Type.NRT)).size());
for (Slice s : docCollection.getSlices()) {
// read-only replicas can never become leaders
assertFalse(s.getLeader().getType() == Replica.Type.PULL);
List<String> shardElectionNodes = cluster.getZkClient().getChildren(ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), null, true);
assertEquals("Unexpected election nodes for Shard: " + s.getName() + ": " + Arrays.toString(shardElectionNodes.toArray()), 1, shardElectionNodes.size());
}
assertUlogPresence(docCollection);
if (reloaded) {
break;
} else {
// reload
CollectionAdminResponse response = CollectionAdminRequest.reloadCollection(collectionName).process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
reloaded = true;
}
}
} finally {
zkClient().printLayoutToStdOut();
}
}
use of org.apache.solr.common.cloud.DocCollection in project lucene-solr by apache.
the class TestPullReplica method testKillPullReplica.
public void testKillPullReplica() throws Exception {
CollectionAdminRequest.createCollection(collectionName, "conf", 1, 1, 0, 1).setMaxShardsPerNode(100).process(cluster.getSolrClient());
// cluster.getSolrClient().getZkStateReader().registerCore(collectionName); //TODO: Is this needed?
waitForState("Expected collection to be created with 1 shard and 2 replicas", collectionName, clusterShape(1, 2));
DocCollection docCollection = assertNumberOfReplicas(1, 0, 1, false, true);
assertEquals(1, docCollection.getSlices().size());
waitForNumDocsInAllActiveReplicas(0);
cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "1", "foo", "bar"));
cluster.getSolrClient().commit(collectionName);
waitForNumDocsInAllActiveReplicas(1);
JettySolrRunner pullReplicaJetty = cluster.getReplicaJetty(docCollection.getSlice("shard1").getReplicas(EnumSet.of(Replica.Type.PULL)).get(0));
ChaosMonkey.kill(pullReplicaJetty);
waitForState("Replica not removed", collectionName, activeReplicaCount(1, 0, 0));
// Also wait for the replica to be placed in state="down"
waitForState("Didn't update state", collectionName, clusterStateReflectsActiveAndDownReplicas());
cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "2", "foo", "bar"));
cluster.getSolrClient().commit(collectionName);
waitForNumDocsInAllActiveReplicas(2);
ChaosMonkey.start(pullReplicaJetty);
waitForState("Replica not added", collectionName, activeReplicaCount(1, 0, 1));
waitForNumDocsInAllActiveReplicas(2);
}
use of org.apache.solr.common.cloud.DocCollection in project lucene-solr by apache.
the class TestPullReplica method testAddRemovePullReplica.
public void testAddRemovePullReplica() throws Exception {
CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1, 0, 0).setMaxShardsPerNode(100).process(cluster.getSolrClient());
//TODO: Why is this needed? see SOLR-9440
cluster.getSolrClient().getZkStateReader().registerCore(collectionName);
waitForState("Expected collection to be created with 2 shards and 1 replica each", collectionName, clusterShape(2, 1));
DocCollection docCollection = assertNumberOfReplicas(2, 0, 0, false, true);
assertEquals(2, docCollection.getSlices().size());
addReplicaToShard("shard1", Replica.Type.PULL);
docCollection = assertNumberOfReplicas(2, 0, 1, true, false);
addReplicaToShard("shard2", Replica.Type.PULL);
docCollection = assertNumberOfReplicas(2, 0, 2, true, false);
waitForState("Expecting collection to have 2 shards and 2 replica each", collectionName, clusterShape(2, 2));
//Delete pull replica from shard1
CollectionAdminRequest.deleteReplica(collectionName, "shard1", docCollection.getSlice("shard1").getReplicas(EnumSet.of(Replica.Type.PULL)).get(0).getName()).process(cluster.getSolrClient());
assertNumberOfReplicas(2, 0, 1, true, true);
}
use of org.apache.solr.common.cloud.DocCollection in project lucene-solr by apache.
the class TestPullReplica method testRealTimeGet.
public void testRealTimeGet() throws SolrServerException, IOException, KeeperException, InterruptedException {
// should be redirected to Replica.Type.NRT
int numReplicas = random().nextBoolean() ? 1 : 2;
CollectionAdminRequest.createCollection(collectionName, "conf", 1, numReplicas, 0, numReplicas).setMaxShardsPerNode(100).process(cluster.getSolrClient());
waitForState("Unexpected replica count", collectionName, activeReplicaCount(numReplicas, 0, numReplicas));
DocCollection docCollection = assertNumberOfReplicas(numReplicas, 0, numReplicas, false, true);
HttpClient httpClient = cluster.getSolrClient().getHttpClient();
int id = 0;
Slice slice = docCollection.getSlice("shard1");
List<String> ids = new ArrayList<>(slice.getReplicas().size());
for (Replica rAdd : slice.getReplicas()) {
try (HttpSolrClient client = getHttpSolrClient(rAdd.getCoreUrl(), httpClient)) {
client.add(new SolrInputDocument("id", String.valueOf(id), "foo_s", "bar"));
}
SolrDocument docCloudClient = cluster.getSolrClient().getById(collectionName, String.valueOf(id));
assertEquals("bar", docCloudClient.getFieldValue("foo_s"));
for (Replica rGet : slice.getReplicas()) {
try (HttpSolrClient client = getHttpSolrClient(rGet.getCoreUrl(), httpClient)) {
SolrDocument doc = client.getById(String.valueOf(id));
assertEquals("bar", doc.getFieldValue("foo_s"));
}
}
ids.add(String.valueOf(id));
id++;
}
SolrDocumentList previousAllIdsResult = null;
for (Replica rAdd : slice.getReplicas()) {
try (HttpSolrClient client = getHttpSolrClient(rAdd.getCoreUrl(), httpClient)) {
SolrDocumentList allIdsResult = client.getById(ids);
if (previousAllIdsResult != null) {
assertTrue(compareSolrDocumentList(previousAllIdsResult, allIdsResult));
} else {
// set the first response here
previousAllIdsResult = allIdsResult;
assertEquals("Unexpected number of documents", ids.size(), allIdsResult.getNumFound());
}
}
id++;
}
}
use of org.apache.solr.common.cloud.DocCollection in project lucene-solr by apache.
the class TestHashPartitioner method testNonConformingCompositeIds.
/** Make sure CompositeIdRouter doesn't throw exceptions for non-conforming IDs */
public void testNonConformingCompositeIds() throws Exception {
DocRouter router = DocRouter.getDocRouter(CompositeIdRouter.NAME);
DocCollection coll = createCollection(4, router);
String[] ids = { "A!B!C!D", "!!!!!!", "A!!!!B", "A!!B!!C", "A/59!B", "A/8/!B/19/", "A!B/-5", "!/130!", "!!A/1000", "A//8!B///10!C////" };
for (int i = 0; i < ids.length; ++i) {
try {
Slice targetSlice = coll.getRouter().getTargetSlice(ids[i], null, null, null, coll);
assertNotNull(targetSlice);
} catch (Exception e) {
throw new Exception("Exception routing id '" + ids[i] + "'", e);
}
}
}
Aggregations