You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2023/01/06 15:47:20 UTC

[GitHub] [solr] HoustonPutman commented on a diff in pull request #1267: SOLR-16608: Ability to compress the collection state

HoustonPutman commented on code in PR #1267:
URL: https://github.com/apache/solr/pull/1267#discussion_r1063543337


##########
solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientCompressedDataTest.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.common.cloud;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.util.Map;
+import org.apache.lucene.util.IOUtils;
+import org.apache.solr.SolrTestCase;
+import org.apache.solr.cloud.ZkController;
+import org.apache.solr.cloud.ZkTestServer;
+import org.apache.solr.common.util.CompressionUtil;
+import org.apache.solr.common.util.Utils;
+import org.apache.zookeeper.CreateMode;
+import org.junit.Test;
+
+public class SolrZkClientCompressedDataTest extends SolrTestCase {
+
+  @Test
+  public void getData() throws Exception {
+    Path zkDir = createTempDir("testGetData");
+
+    ZkTestServer server = new ZkTestServer(zkDir);
+
+    SolrZkClient zkClient = null;
+
+    try {
+      server.run();
+
+      zkClient = new SolrZkClient(server.getZkAddress(), 60000);
+      ZkController.createClusterZkNodes(zkClient);
+      zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true);
+
+      String state =
+          "{\"c1\":{\n"
+              + "\"pullReplicas\":\"0\",\n"
+              + "\"replicationFactor\":\"1\",\n"
+              + "\"router\":{\"name\":\"compositeId\"},\n"
+              + "\"maxShardsPerNode\":\"1\",\n"
+              + "\"autoAddReplicas\":\"false\",\n"
+              + "\"nrtReplicas\":\"1\",\n"
+              + "\"tlogReplicas\":\"0\",\n"
+              + "\"shards\":{\"shard1\":{\n"
+              + "\"range\":\"80000000-7fffffff\",\n"
+              + "\"state\":\"active\",\n"
+              + "\"replicas\":{\"core_node2\":{\n"
+              + "\"core\":\"test_shard1_replica_n1\",\n"
+              + "\"node_name\":\"127.0.0.1:8983_solr\",\n"
+              + "\"base_url\":\"http://127.0.0.1:8983/solr\",\n"
+              + "\"state\":\"active\",\n"
+              + "\"type\":\"NRT\",\n"
+              + "\"force_set_state\":\"false\",\n"
+              + "\"leader\":\"true\"}}}}}}";
+      byte[] arr = state.getBytes(StandardCharsets.UTF_8);
+      byte[] compressedData = CompressionUtil.compressBytes(arr);
+      ZkACLProvider aclProvider = new DefaultZkACLProvider();
+      String path = ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json";
+      zkClient
+          .getZooKeeper()
+          .create(path, compressedData, aclProvider.getACLsToAdd(path), CreateMode.PERSISTENT);
+
+      byte[] data =
+          zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null, true);
+      Map<?, ?> map = (Map<?, ?>) Utils.fromJSON(data);

Review Comment:
   Don't we want to also verify that the bytes are the same before compression and after decompression?



##########
solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateWriterTest.java:
##########
@@ -407,4 +409,89 @@ public void testExternalModification() throws Exception {
       server.shutdown();
     }
   }
+
+  public void testSingleExternalCollectionCompressedState() throws Exception {
+    Path zkDir = createTempDir("testSingleExternalCollection");
+
+    ZkTestServer server = new ZkTestServer(zkDir);
+
+    SolrZkClient zkClient = null;
+
+    try {
+      server.run();
+
+      zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
+      ZkController.createClusterZkNodes(zkClient);
+
+      try (ZkStateReader reader = new ZkStateReader(zkClient)) {
+        reader.createClusterStateWatchersAndUpdate();
+
+        ZkStateWriter writer = new ZkStateWriter(reader, new Stats(), 500000);
+
+        zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true);
+
+        // create new collection with stateFormat = 2
+        ZkWriteCommand c1 =
+            new ZkWriteCommand(
+                "c1",
+                new DocCollection(
+                    "c1",
+                    new HashMap<String, Slice>(),
+                    new HashMap<String, Object>(),
+                    DocRouter.DEFAULT,
+                    0));
+
+        writer.enqueueUpdate(reader.getClusterState(), Collections.singletonList(c1), null);
+        writer.writePendingUpdates();
+
+        byte[] data =
+            zkClient
+                .getZooKeeper()
+                .getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null);
+        Map<?, ?> map = (Map<?, ?>) Utils.fromJSON(data);
+        assertNotNull(map.get("c1"));
+      }
+
+      try (ZkStateReader reader = new ZkStateReader(zkClient)) {
+        reader.createClusterStateWatchersAndUpdate();
+
+        ZkStateWriter writer = new ZkStateWriter(reader, new Stats(), 500000);
+
+        zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c2", true);
+
+        // create new collection with stateFormat = 2 that is large enough to exceed the minimum
+        // size for compression
+        Map<String, Slice> slices = new HashMap<>();
+        for (int i = 0; i < 4096; i++) {
+          Map<String, Replica> replicas = new HashMap<>();
+          Map<String, Object> replicaProps = new HashMap<>();
+          replicaProps.put(ZkStateReader.NODE_NAME_PROP, "node1:8983_8983");
+          replicaProps.put(ZkStateReader.CORE_NAME_PROP, "coreNode" + i);
+          replicaProps.put(ZkStateReader.REPLICA_TYPE, "NRT");
+          replicaProps.put(ZkStateReader.BASE_URL_PROP, "http://localhost:8983");
+          replicas.put(
+              "coreNode" + i, new Replica("coreNode" + i, replicaProps, "c2", "shard" + i));
+          slices.put("shard" + i, new Slice("shard" + i, replicas, new HashMap<>(), "c2"));
+        }
+        ZkWriteCommand c1 =
+            new ZkWriteCommand(
+                "c2", new DocCollection("c2", slices, new HashMap<>(), DocRouter.DEFAULT, 0));
+
+        writer.enqueueUpdate(reader.getClusterState(), Collections.singletonList(c1), null);
+        writer.writePendingUpdates();
+
+        byte[] data =
+            zkClient
+                .getZooKeeper()
+                .getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c2/state.json", null, null);

Review Comment:
   Do we want to ensure that the size is within the acceptable range here?



##########
solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SolrZkClient.java:
##########
@@ -433,6 +435,14 @@ public byte[] getData(
     } else {
       result = keeper.getData(path, wrapWatcher(watcher), stat);
     }
+    if (CompressionUtil.isCompressedBytes(result)) {
+      log.debug("Zookeeper data at path {} is compressed", path);
+      try {
+        result = CompressionUtil.decompressBytes(result);
+      } catch (DataFormatException e) {
+        throw new RuntimeException(e);

Review Comment:
   Please don't introduce random RuntimeExceptions that have no additional context. You can probably use a SolrException and explain the context where the decompression was happening.



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org