use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.
the class SyncSliceTest method waitTillAllNodesActive.
private void waitTillAllNodesActive() throws Exception {
for (int i = 0; i < 60; i++) {
Thread.sleep(3000);
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
ClusterState clusterState = zkStateReader.getClusterState();
DocCollection collection1 = clusterState.getCollection("collection1");
Slice slice = collection1.getSlice("shard1");
Collection<Replica> replicas = slice.getReplicas();
boolean allActive = true;
for (Replica replica : replicas) {
if (!clusterState.liveNodesContain(replica.getNodeName()) || replica.getState() != Replica.State.ACTIVE) {
allActive = false;
break;
}
}
if (allActive) {
return;
}
}
printLayout();
fail("timeout waiting to see all nodes active");
}
use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.
the class SharedFSAutoReplicaFailoverTest method assertUlogDir.
/**
* After failover, ulogDir should not be changed.
*/
private void assertUlogDir(String... collections) {
for (String collection : collections) {
Collection<Slice> slices = cloudClient.getZkStateReader().getClusterState().getCollection(collection).getSlices();
for (Slice slice : slices) {
for (Replica replica : slice.getReplicas()) {
Map<String, Object> properties = replica.getProperties();
String coreName = replica.getCoreName();
String curUlogDir = (String) properties.get(CoreDescriptor.CORE_ULOGDIR);
String prevUlogDir = collectionUlogDirMap.get(coreName);
if (curUlogDir != null) {
if (prevUlogDir == null) {
collectionUlogDirMap.put(coreName, curUlogDir);
} else {
assertEquals(prevUlogDir, curUlogDir);
}
}
}
}
}
}
use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.
the class SliceStateTest method testDefaultSliceState.
@Test
public void testDefaultSliceState() {
Map<String, DocCollection> collectionStates = new HashMap<>();
Set<String> liveNodes = new HashSet<>();
liveNodes.add("node1");
Map<String, Slice> slices = new HashMap<>();
Map<String, Replica> sliceToProps = new HashMap<>();
Map<String, Object> props = new HashMap<>();
Replica replica = new Replica("node1", props);
sliceToProps.put("node1", replica);
Slice slice = new Slice("shard1", sliceToProps, null);
assertSame("Default state not set to active", Slice.State.ACTIVE, slice.getState());
slices.put("shard1", slice);
collectionStates.put("collection1", new DocCollection("collection1", slices, null, DocRouter.DEFAULT));
ClusterState clusterState = new ClusterState(-1, liveNodes, collectionStates);
byte[] bytes = Utils.toJSON(clusterState);
ClusterState loadedClusterState = ClusterState.load(-1, bytes, liveNodes);
assertSame("Default state not set to active", Slice.State.ACTIVE, loadedClusterState.getSlice("collection1", "shard1").getState());
}
use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.
the class TestTlogReplica method doReplaceLeader.
/*
* validate leader election and that replication still happens on a new leader
*/
private void doReplaceLeader(boolean removeReplica) throws Exception {
DocCollection docCollection = createAndWaitForCollection(1, 0, 2, 0);
// Add a document and commit
cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "1", "foo", "bar"));
cluster.getSolrClient().commit(collectionName);
Slice s = docCollection.getSlices().iterator().next();
try (HttpSolrClient leaderClient = getHttpSolrClient(s.getLeader().getCoreUrl())) {
assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound());
}
waitForNumDocsInAllReplicas(1, docCollection.getReplicas(EnumSet.of(Replica.Type.TLOG)), REPLICATION_TIMEOUT_SECS);
// Delete leader replica from shard1
JettySolrRunner leaderJetty = null;
if (removeReplica) {
CollectionAdminRequest.deleteReplica(collectionName, "shard1", s.getLeader().getName()).process(cluster.getSolrClient());
} else {
leaderJetty = cluster.getReplicaJetty(s.getLeader());
ChaosMonkey.kill(leaderJetty);
waitForState("Leader replica not removed", collectionName, clusterShape(1, 1));
// Wait for cluster state to be updated
waitForState("Replica state not updated in cluster state", collectionName, clusterStateReflectsActiveAndDownReplicas());
}
docCollection = assertNumberOfReplicas(0, 1, 0, true, true);
// Wait until a new leader is elected
TimeOut t = new TimeOut(30, TimeUnit.SECONDS);
while (!t.hasTimedOut()) {
docCollection = getCollectionState(collectionName);
Replica leader = docCollection.getSlice("shard1").getLeader();
if (leader != null && leader.isActive(cluster.getSolrClient().getZkStateReader().getClusterState().getLiveNodes())) {
break;
}
Thread.sleep(500);
}
assertFalse("Timeout waiting for a new leader to be elected", t.hasTimedOut());
// There is a new leader, I should be able to add and commit
cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "2", "foo", "zoo"));
cluster.getSolrClient().commit(collectionName);
// Queries should still work
waitForNumDocsInAllReplicas(2, docCollection.getReplicas(EnumSet.of(Replica.Type.TLOG)), REPLICATION_TIMEOUT_SECS);
// Start back the node
if (removeReplica) {
CollectionAdminRequest.addReplicaToShard(collectionName, "shard1", Replica.Type.TLOG).process(cluster.getSolrClient());
} else {
ChaosMonkey.start(leaderJetty);
}
waitForState("Expected collection to be 1x2", collectionName, clusterShape(1, 2));
// added replica should replicate from the leader
waitForNumDocsInAllReplicas(2, docCollection.getReplicas(EnumSet.of(Replica.Type.TLOG)), REPLICATION_TIMEOUT_SECS);
}
use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.
the class TestTlogReplica method assertUlogPresence.
/**
* Asserts that Update logs exist for replicas of type {@link org.apache.solr.common.cloud.Replica.Type#NRT}, but not
* for replicas of type {@link org.apache.solr.common.cloud.Replica.Type#PULL}
*/
private void assertUlogPresence(DocCollection collection) {
for (Slice s : collection.getSlices()) {
for (Replica r : s.getReplicas()) {
SolrCore core = null;
try {
core = cluster.getReplicaJetty(r).getCoreContainer().getCore(r.getCoreName());
assertNotNull(core);
assertTrue("Update log should exist for replicas of type Append", new java.io.File(core.getUlogDir()).exists());
} finally {
core.close();
}
}
}
}
Aggregations