murblanc commented on a change in pull request #1528: URL: https://github.com/apache/lucene-solr/pull/1528#discussion_r430012046
########## File path: solr/core/src/java/org/apache/solr/cloud/ZkController.java ########## @@ -491,6 +494,41 @@ public boolean isClosed() { assert ObjectReleaseTracker.track(this); } + /** + * <p>Verifies if /clusterstate.json exists in Zookeepeer, and if it does and is not empty, refuses to start and outputs + * a helpful message regarding collection migration.</p> + * + * <p>If /clusterstate.json exists and is empty, it is removed.</p> + */ + private void checkNoOldClusterstate(final SolrZkClient zkClient) throws InterruptedException { + try { + if (!zkClient.exists(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, true)) { + return; + } + + final byte[] data = zkClient.getData(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, null, null, true); + + if (Arrays.equals("{}".getBytes(StandardCharsets.UTF_8), data)) { + // Empty json. This log will only occur once. + log.warn("{} no longer supported starting with Solr 9. Found empty file on Zookeeper, deleting it.", ZkStateReader.UNSUPPORTED_CLUSTER_STATE); + zkClient.delete(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, -1, true); Review comment: Looking at pre PR master branch. The watcher on /clusterstate.json is an instance of LegacyClusterStateWatcher (subclass of ZkStateReader). The watcher processing is done in refreshAndWatch() that calls ZkStateReader.refreshLegacyClusterState() and does some exception handling. Even though refreshAndWatch() handles KeeperException.NoNodeException by throwing a SolrException SERVICE_UNAVAILABLE, this never happens: refreshLegacyClusterState() catches that exception, a comment says "Ignore missing legacy clusterstate.json." and the catch builds what would be an empty clusterstate. We should be fine. ########## File path: solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java ########## @@ -210,47 +200,42 @@ public boolean liveNodesContain(String name) { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("znodeVersion: ").append(znodeVersion); - sb.append("\n"); sb.append("live nodes:").append(liveNodes); sb.append("\n"); sb.append("collections:").append(collectionStates); return sb.toString(); } - public static ClusterState load(Integer version, byte[] bytes, Set<String> liveNodes) { - return load(version, bytes, liveNodes, ZkStateReader.CLUSTER_STATE); - } /** - * Create ClusterState from json string that is typically stored in zookeeper. + * Create a ClusterState from Json. * - * @param version zk version of the clusterstate.json file (bytes) - * @param bytes clusterstate.json as a byte array + * @param bytes a byte array of a Json representation of a mapping from collection name to the Json representation of a + * {@link DocCollection} as written by {@link #write(JSONWriter)}. It can represent + * one or more collections. * @param liveNodes list of live nodes * @return the ClusterState */ - public static ClusterState load(Integer version, byte[] bytes, Set<String> liveNodes, String znode) { - // System.out.println("######## ClusterState.load:" + (bytes==null ? null : new String(bytes))); + public static ClusterState createFromJson(int version, byte[] bytes, Set<String> liveNodes) { if (bytes == null || bytes.length == 0) { - return new ClusterState(version, liveNodes, Collections.<String, DocCollection>emptyMap()); + return new ClusterState(liveNodes, Collections.<String, DocCollection>emptyMap()); } Map<String, Object> stateMap = (Map<String, Object>) Utils.fromJSON(bytes); - return load(version, stateMap, liveNodes, znode); + return createFromData(version, stateMap, liveNodes); } - public static ClusterState load(Integer version, Map<String, Object> stateMap, Set<String> liveNodes, String znode) { + public static ClusterState createFromData(int version, Map<String, Object> stateMap, Set<String> liveNodes) { Review comment: `createFromCollectionMap` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org