narendly commented on a change in pull request #809: Add system property 
options to config auto compression
URL: https://github.com/apache/helix/pull/809#discussion_r385468426
 
 

 ##########
 File path: 
zookeeper-api/src/main/java/org/apache/helix/zookeeper/datamodel/serializer/ZNRecordStreamingSerializer.java
 ##########
 @@ -154,20 +155,31 @@ private static int getListFieldBound(ZNRecord record) {
       g.close();
       serializedBytes = baos.toByteArray();
       // apply compression if needed
-      if (record.getBooleanField("enableCompression", false) || 
serializedBytes.length > ZNRecord.SIZE_LIMIT) {
+      if (ZNRecordUtil.shouldCompress(record, serializedBytes.length)) {
         serializedBytes = GZipCompressionUtil.compress(serializedBytes);
       }
     } catch (Exception e) {
-      LOG.error("Exception during data serialization. Will not write to zk. 
Data (first 1k): "
-          + new String(baos.toByteArray()).substring(0, 1024), e);
+      if (serializedBytes.length == 0 || 
GZipCompressionUtil.isCompressed(serializedBytes)) {
+        serializedBytes = baos.toByteArray();
+      }
+      int firstBytesLength = Math.min(serializedBytes.length, 1024);
+      // TODO: remove logging first N bytes of data to reduce log size.
+      LOG.error("Exception during data serialization. Will not write to zk."
+              + " The first {} bytes of data: {}", firstBytesLength,
+          new String(serializedBytes, 0, firstBytesLength), e);
       throw new ZkClientException(e);
     }
     // check size
-    if (serializedBytes.length > ZNRecord.SIZE_LIMIT) {
-      LOG.error("Data size larger than 1M, ZNRecord.id: " + record.getId()
-          + ". Will not write to zk. Data (first 1k): "
-          + new String(serializedBytes).substring(0, 1024));
-      throw new ZkClientException("Data size larger than 1M, ZNRecord.id: " + 
record.getId());
+    int compressThreshold = ZNRecordUtil.getCompressThreshold();
+    if (serializedBytes.length > compressThreshold) {
 
 Review comment:
   Shouldn't this be 
   `serializedBytes.length > 1MB (or ZK's Djute.maxbuffer)?
   `
   A case to consider:
   
   Suppose some user wants every ZNode compressed. So sets this threshold to be 
1 byte.
   
   I write 1 byte, and this 1 byte gets compressed (and after compression, say 
it's greater than or equal to 1 byte), and this write will not go through even 
after compression because you won't ever allow any writes larger than 1 byte.
   
   Now I am confused because I set the "compression threshold", not the "ZNode 
size threshold"?
   
   I'm pretty sure this isn't the intended behavior?
   
   Same thing applies to ZNRecordSerializer.
   
   Hint: I think it might be a good idea to decouple compression threshold from 
ZNode size limit.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

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

Reply via email to