SOLR-5295: The CREATESHARD collection API creates maxShardsPerNode number of replicas if replicationFactor is not specified

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1528426 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2013-10-02 11:11:15 +00:00
parent 02d8e37328
commit b883f6f5b8
3 changed files with 51 additions and 6 deletions

View File

@ -82,6 +82,9 @@ Bug Fixes
* SOLR-4590: Collections API should return a nice error when not in SolrCloud mode.
(Anshum Gupta, Mark Miller)
* SOLR-5295: The CREATESHARD collection API creates maxShardsPerNode number of
replicas if replicationFactor is not specified. (Brett Hoerner, shalin)
Security
----------------------

View File

@ -386,7 +386,7 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
}
private boolean createShard(ClusterState clusterState, ZkNodeProps message, NamedList results) throws KeeperException, InterruptedException {
log.info("create shard invoked");
log.info("Create shard invoked: {}", message);
String collectionName = message.getStr(COLLECTION_PROP);
String shard = message.getStr(SHARD_ID_PROP);
if(collectionName == null || shard ==null)
@ -395,19 +395,18 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
DocCollection collection = clusterState.getCollection(collectionName);
int maxShardsPerNode = collection.getInt(MAX_SHARDS_PER_NODE, 1);
int repFactor = message.getInt(REPLICATION_FACTOR, collection.getInt(MAX_SHARDS_PER_NODE, 1));
// int minReplicas = message.getInt("minReplicas",repFactor);
String createNodeSetStr =message.getStr(CREATE_NODE_SET);
int repFactor = message.getInt(REPLICATION_FACTOR, collection.getInt(REPLICATION_FACTOR, 1));
String createNodeSetStr = message.getStr(CREATE_NODE_SET);
ArrayList<Node> sortedNodeList = getNodesForNewShard(clusterState, collectionName, numSlices, maxShardsPerNode, repFactor, createNodeSetStr);
Overseer.getInQueue(zkStateReader.getZkClient()).offer(ZkStateReader.toJSON(message));
// wait for a while until we don't see the collection
// wait for a while until we see the shard
long waitUntil = System.currentTimeMillis() + 30000;
boolean created = false;
while (System.currentTimeMillis() < waitUntil) {
Thread.sleep(100);
created = zkStateReader.getClusterState().getCollection(collectionName).getSlice(shard) !=null;
created = zkStateReader.getClusterState().getCollection(collectionName).getSlice(shard) != null;
if (created) break;
}
if (!created)

View File

@ -135,6 +135,7 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase {
public void doTest() throws Exception {
testCustomCollectionsAPI();
testRouteFieldForHashRouter();
testCreateShardRepFactor();
if (DEBUG) {
super.printLayout();
}
@ -423,7 +424,49 @@ public class CustomCollectionTest extends AbstractFullDistribZkTestBase {
}
private void testCreateShardRepFactor() throws Exception {
String collectionName = "testCreateShardRepFactor";
HashMap<String, List<Integer>> collectionInfos = new HashMap<String, List<Integer>>();
CloudSolrServer client = null;
try {
client = createCloudClient(null);
Map<String, Object> props = ZkNodeProps.makeMap(
REPLICATION_FACTOR, 1,
MAX_SHARDS_PER_NODE, 5,
NUM_SLICES, 2,
"shards", "a,b",
"router.name", "implicit");
createCollection(collectionInfos, collectionName, props, client);
} finally {
if (client != null) client.shutdown();
}
ZkStateReader zkStateReader = getCommonCloudSolrServer().getZkStateReader();
waitForRecoveriesToFinish(collectionName, zkStateReader, false);
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionAction.CREATESHARD.toString());
params.set("collection", collectionName);
params.set("shard", "x");
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
createNewSolrServer("", getBaseUrl((HttpSolrServer) clients.get(0))).request(request);
waitForRecoveriesToFinish(collectionName, zkStateReader, false);
int replicaCount = 0;
int attempts = 0;
while (true) {
if (attempts > 30) fail("Not enough active replicas in the shard 'x'");
zkStateReader.updateClusterState(true);
attempts++;
replicaCount = zkStateReader.getClusterState().getSlice(collectionName, "x").getReplicas().size();
if (replicaCount >= 1) break;
Thread.sleep(500);
}
assertEquals("CREATESHARD API created more than replicationFactor number of replicas", 1, replicaCount);
}
public static String getUrlFromZk(ClusterState clusterState, String collection) {