SOLR-9484: The modify collection API should wait for the modified properties to show up in the cluster state

This commit is contained in:
Shalin Shekhar Mangar 2016-09-15 11:04:48 +05:30
parent 5b770b56d0
commit 70fd627ca7
3 changed files with 34 additions and 20 deletions

View File

@ -126,6 +126,9 @@ Bug Fixes
one or more sub-shards replicas do not recover due to the leader crashing or restarting between the time
the replicas are created and before they can recover. This can cause data loss. (shalin)
* SOLR-9484: The modify collection API should wait for the modified properties to show up in the
cluster state. (Cao Manh Dat, shalin)
Optimizations
----------------------

View File

@ -662,6 +662,26 @@ public class OverseerCollectionMessageHandler implements OverseerMessageHandler
}
overseer.getStateUpdateQueue(zkStateReader.getZkClient()).offer(Utils.toJSON(message));
TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS);
boolean areChangesVisible = true;
while (!timeout.hasTimedOut()) {
DocCollection collection = zkStateReader.getClusterState().getCollection(collectionName);
areChangesVisible = true;
for (Map.Entry<String,Object> updateEntry : message.getProperties().entrySet()) {
String updateKey = updateEntry.getKey();
if (!updateKey.equals(ZkStateReader.COLLECTION_PROP)
&& !updateKey.equals(Overseer.QUEUE_OPERATION)
&& !collection.get(updateKey).equals(updateEntry.getValue())){
areChangesVisible = false;
break;
}
}
if (areChangesVisible) break;
Thread.sleep(100);
}
if (!areChangesVisible)
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not modify collection " + message);
}
void cleanupCollection(String collectionName, NamedList results) throws Exception {

View File

@ -234,25 +234,16 @@ public class RulesTest extends AbstractFullDistribZkTestBase {
}
for (int i = 0; i < 20; i++) {
DocCollection rulesCollection = ZkStateReader.getCollectionLive(cloudClient.getZkStateReader(), rulesColl);
log.info("version_of_coll {} ", rulesCollection.getZNodeVersion());
List list = (List) rulesCollection.get("rule");
assertEquals(3, list.size());
if (!"<5".equals(((Map) list.get(0)).get("cores"))) {
if (i < 19) {
Thread.sleep(100);
continue;
}
}
assertEquals("<5", ((Map) list.get(0)).get("cores"));
assertEquals("1", ((Map) list.get(1)).get("replica"));
assertEquals(">"+minGB2, ((Map) list.get(2)).get("freedisk"));
assertEquals("true", String.valueOf(rulesCollection.getProperties().get("autoAddReplicas")));
list = (List) rulesCollection.get("snitch");
assertEquals(1, list.size());
assertEquals("ImplicitSnitch", ((Map) list.get(0)).get("class"));
}
DocCollection rulesCollection = ZkStateReader.getCollectionLive(cloudClient.getZkStateReader(), rulesColl);
log.info("version_of_coll {} ", rulesCollection.getZNodeVersion());
List list = (List) rulesCollection.get("rule");
assertEquals(3, list.size());
assertEquals("<5", ((Map) list.get(0)).get("cores"));
assertEquals("1", ((Map) list.get(1)).get("replica"));
assertEquals(">"+minGB2, ((Map) list.get(2)).get("freedisk"));
assertEquals("true", String.valueOf(rulesCollection.getProperties().get("autoAddReplicas")));
list = (List) rulesCollection.get("snitch");
assertEquals(1, list.size());
assertEquals("ImplicitSnitch", ((Map) list.get(0)).get("class"));
}
}