janhoy commented on code in PR #2391:
URL: https://github.com/apache/solr/pull/2391#discussion_r2486414044


##########
solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java:
##########
@@ -342,6 +344,185 @@ public MiniSolrCloudCluster(
     }
   }
 
+  /**
+   * Create a MiniSolrCloudCluster with embedded ZooKeeper quorum mode. Each 
Solr node runs its own
+   * embedded ZooKeeper server, and together they form a quorum.
+   *
+   * @param numServers number of Solr servers (must be at least 3 for quorum)
+   * @param baseDir base directory that the mini cluster should be run from
+   * @param solrXml solr.xml file content
+   * @param jettyConfig Jetty configuration
+   * @param securityJson Optional security.json configuration
+   * @param trackJettyMetrics whether to track Jetty metrics
+   * @throws Exception if there was an error starting the cluster
+   */
+  MiniSolrCloudCluster(
+      int numServers,
+      Path baseDir,
+      String solrXml,
+      JettyConfig jettyConfig,
+      Optional<String> securityJson,
+      boolean trackJettyMetrics,
+      boolean useEmbeddedZkQuorum)
+      throws Exception {
+
+    if (!useEmbeddedZkQuorum) {
+      throw new IllegalArgumentException("This constructor is only for 
embedded ZK quorum mode");
+    }
+    if (numServers < 3) {
+      throw new IllegalArgumentException(
+          "ZooKeeper quorum requires at least 3 nodes, got: " + numServers);
+    }
+
+    Objects.requireNonNull(securityJson);
+    this.baseDir = Objects.requireNonNull(baseDir);
+    this.jettyConfig = Objects.requireNonNull(jettyConfig);
+    this.solrXml = solrXml == null ? DEFAULT_CLOUD_SOLR_XML : solrXml;
+    this.trackJettyMetrics = trackJettyMetrics;
+    this.externalZkServer = true; // No ZkTestServer in quorum mode
+    this.zkServer = null; // No single ZK server
+
+    log.info("Starting cluster of {} servers with embedded ZK quorum in {}", 
numServers, baseDir);
+    Files.createDirectories(baseDir);
+
+    // Phase 1: Reserve random ports for all nodes
+    int[] ports = new int[numServers];
+    for (int i = 0; i < numServers; i++) {
+      try (java.net.ServerSocket socket = new java.net.ServerSocket(0)) {
+        ports[i] = socket.getLocalPort();
+      }
+    }
+
+    // Build the zkHost string with all ZK ports (Solr port + 1000)
+    StringBuilder zkHostBuilder = new StringBuilder();
+    for (int i = 0; i < numServers; i++) {
+      if (i > 0) {
+        zkHostBuilder.append(",");
+      }
+      int zkPort = ports[i] + 1000;
+      zkHostBuilder.append("127.0.0.1:").append(zkPort);
+    }
+    this.zkHost = zkHostBuilder.toString(); // Save for later use
+
+    if (log.isInfoEnabled()) {
+      log.info("Reserved ports for {} nodes: {}", numServers, 
java.util.Arrays.toString(ports));
+      log.info("ZK connection string: {}", this.zkHost);
+    }
+
+    // Set system properties for embedded ZK quorum mode
+    System.setProperty("solr.zookeeper.server.enabled", "true");

Review Comment:
   I wonder if `-z` should be reserved for connecting to an external ZK quorum, 
and we invent a new option for telling SolrCloud which solr nodes will run the 
zk node role? That would make it less confusing, e.g. 
   
   ```bash
   bin/solr start 
--quorum-nodes=solr-node-1:8983,solr-node-2:8983,solr-node-3:8983
   ```
   
   That would mean we want Solr to manage our ZK, and translate into the 
correct `solr.zk.host` setting for each host, no matter if the host you are 
starting is one of the quorum nodes or not. And if the node you are starting is 
a quorum node, it will detect that it's own host name matches a quorum host, 
and add `-Dsolr.node.roles...` during startup, and the ZK bootstrap code will 
configure its internal ZK config using the `--quorum` / `-Dsolr.quorum.nodes` 
values.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to