use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.
the class ForceLeaderTest method unsetLeader.
protected void unsetLeader(String collection, String slice) throws Exception {
DistributedQueue inQueue = Overseer.getStateUpdateQueue(cloudClient.getZkStateReader().getZkClient());
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, OverseerAction.LEADER.toLower(), ZkStateReader.SHARD_ID_PROP, slice, ZkStateReader.COLLECTION_PROP, collection);
inQueue.offer(Utils.toJSON(m));
ClusterState clusterState = null;
boolean transition = false;
for (int counter = 10; counter > 0; counter--) {
clusterState = zkStateReader.getClusterState();
Replica newLeader = clusterState.getSlice(collection, slice).getLeader();
if (newLeader == null) {
transition = true;
break;
}
Thread.sleep(1000);
}
if (!transition) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not unset replica leader" + ". Cluster state: " + printClusterStateInfo(collection));
}
}
use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.
the class DeleteReplicaTest method deleteReplicaAndVerifyDirectoryCleanup.
@Test
public void deleteReplicaAndVerifyDirectoryCleanup() throws Exception {
final String collectionName = "deletereplica_test";
CollectionAdminRequest.createCollection(collectionName, "conf", 1, 2).process(cluster.getSolrClient());
Replica leader = cluster.getSolrClient().getZkStateReader().getLeaderRetry(collectionName, "shard1");
//Confirm that the instance and data directory exist
CoreStatus coreStatus = getCoreStatus(leader);
assertTrue("Instance directory doesn't exist", Files.exists(Paths.get(coreStatus.getInstanceDirectory())));
assertTrue("DataDirectory doesn't exist", Files.exists(Paths.get(coreStatus.getDataDirectory())));
CollectionAdminRequest.deleteReplica(collectionName, "shard1", leader.getName()).process(cluster.getSolrClient());
Replica newLeader = cluster.getSolrClient().getZkStateReader().getLeaderRetry(collectionName, "shard1");
assertFalse(leader.equals(newLeader));
//Confirm that the instance and data directory were deleted by default
assertFalse("Instance directory still exists", Files.exists(Paths.get(coreStatus.getInstanceDirectory())));
assertFalse("DataDirectory still exists", Files.exists(Paths.get(coreStatus.getDataDirectory())));
}
use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.
the class DeleteReplicaTest method deleteLiveReplicaTest.
@Test
public void deleteLiveReplicaTest() throws Exception {
final String collectionName = "delLiveColl";
CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2).process(cluster.getSolrClient());
DocCollection state = getCollectionState(collectionName);
Slice shard = getRandomShard(state);
Replica replica = getRandomReplica(shard, (r) -> r.getState() == Replica.State.ACTIVE);
CoreStatus coreStatus = getCoreStatus(replica);
Path dataDir = Paths.get(coreStatus.getDataDirectory());
Exception e = expectThrows(Exception.class, () -> {
CollectionAdminRequest.deleteReplica(collectionName, shard.getName(), replica.getName()).setOnlyIfDown(true).process(cluster.getSolrClient());
});
assertTrue("Unexpected error message: " + e.getMessage(), e.getMessage().contains("state is 'active'"));
assertTrue("Data directory for " + replica.getName() + " should not have been deleted", Files.exists(dataDir));
CollectionAdminRequest.deleteReplica(collectionName, shard.getName(), replica.getName()).process(cluster.getSolrClient());
waitForState("Expected replica " + replica.getName() + " to have been removed", collectionName, (n, c) -> {
Slice testShard = c.getSlice(shard.getName());
return testShard.getReplica(replica.getName()) == null;
});
assertFalse("Data directory for " + replica.getName() + " should have been removed", Files.exists(dataDir));
}
use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.
the class CollectionsAPISolrJTest method testBalanceShardUnique.
@Test
public void testBalanceShardUnique() throws IOException, SolrServerException, KeeperException, InterruptedException {
final String collection = "balancedProperties";
CollectionAdminRequest.createCollection(collection, "conf", 2, 2).process(cluster.getSolrClient());
CollectionAdminResponse response = CollectionAdminRequest.balanceReplicaProperty(collection, "preferredLeader").process(cluster.getSolrClient());
assertEquals(0, response.getStatus());
waitForState("Expecting 'preferredleader' property to be balanced across all shards", collection, (n, c) -> {
for (Slice slice : c) {
int count = 0;
for (Replica replica : slice) {
if ("true".equals(replica.getStr("property.preferredleader")))
count += 1;
}
if (count != 1)
return false;
}
return true;
});
}
use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.
the class CollectionsAPIDistributedZkTest method testCreateNodeSet.
@Test
public void testCreateNodeSet() throws Exception {
JettySolrRunner jetty1 = cluster.getRandomJetty(random());
JettySolrRunner jetty2 = cluster.getRandomJetty(random());
List<String> baseUrls = ImmutableList.of(jetty1.getBaseUrl().toString(), jetty2.getBaseUrl().toString());
CollectionAdminRequest.createCollection("nodeset_collection", "conf", 2, 1).setCreateNodeSet(baseUrls.get(0) + "," + baseUrls.get(1)).process(cluster.getSolrClient());
DocCollection collectionState = getCollectionState("nodeset_collection");
for (Replica replica : collectionState.getReplicas()) {
String replicaUrl = replica.getCoreUrl();
boolean matchingJetty = false;
for (String jettyUrl : baseUrls) {
if (replicaUrl.startsWith(jettyUrl))
matchingJetty = true;
}
if (matchingJetty == false)
fail("Expected replica to be on " + baseUrls + " but was on " + replicaUrl);
}
}
Aggregations