use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.
the class DeleteInactiveReplicaTest method deleteInactiveReplicaTest.
@Test
public void deleteInactiveReplicaTest() throws Exception {
String collectionName = "delDeadColl";
int replicationFactor = 2;
int numShards = 2;
int maxShardsPerNode = ((((numShards + 1) * replicationFactor) / cluster.getJettySolrRunners().size())) + 1;
CollectionAdminRequest.createCollection(collectionName, "conf", numShards, replicationFactor).setMaxShardsPerNode(maxShardsPerNode).process(cluster.getSolrClient());
waitForState("Expected a cluster of 2 shards and 2 replicas", collectionName, (n, c) -> {
return DocCollection.isFullyActive(n, c, numShards, replicationFactor);
});
DocCollection collectionState = getCollectionState(collectionName);
Slice shard = getRandomShard(collectionState);
Replica replica = getRandomReplica(shard);
JettySolrRunner jetty = cluster.getReplicaJetty(replica);
cluster.stopJettySolrRunner(jetty);
waitForState("Expected replica " + replica.getName() + " on down node to be removed from cluster state", collectionName, (n, c) -> {
Replica r = c.getReplica(replica.getCoreName());
return r == null || r.getState() != Replica.State.ACTIVE;
});
log.info("Removing replica {}/{} ", shard.getName(), replica.getName());
CollectionAdminRequest.deleteReplica(collectionName, shard.getName(), replica.getName()).process(cluster.getSolrClient());
waitForState("Expected deleted replica " + replica.getName() + " to be removed from cluster state", collectionName, (n, c) -> {
return c.getReplica(replica.getCoreName()) == null;
});
cluster.startJettySolrRunner(jetty);
log.info("restarted jetty");
CoreContainer cc = jetty.getCoreContainer();
CoreContainer.CoreLoadFailure loadFailure = cc.getCoreInitFailures().get(replica.getCoreName());
assertNotNull("Deleted core was still loaded!", loadFailure);
assertTrue("Unexpected load failure message: " + loadFailure.exception.getMessage(), loadFailure.exception.getMessage().contains("does not exist in shard"));
// Check that we can't create a core with no coreNodeName
try (SolrClient queryClient = getHttpSolrClient(jetty.getBaseUrl().toString())) {
Exception e = expectThrows(Exception.class, () -> {
CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create();
createRequest.setCoreName("testcore");
createRequest.setCollection(collectionName);
createRequest.setShardId("shard2");
queryClient.request(createRequest);
});
assertTrue("Unexpected error message: " + e.getMessage(), e.getMessage().contains("coreNodeName missing"));
}
}
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;
});
}
Aggregations