You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/02/18 02:52:51 UTC

[GitHub] [incubator-inlong] wardlican opened a new pull request #2575: [INLONG-2382] Sort-sdk support Pulsar consumer of PB compression cache message protocol

wardlican opened a new pull request #2575:
URL: https://github.com/apache/incubator-inlong/pull/2575


   
   [INLONG-2382]  Sort-sdk support Pulsar consumer of PB compression cache message protocol
   
   
   ### Title Name: [INLONG-2382]  [Sort-sdk] support Pulsar consumer of PB compression cache message protocol
   
   where *XYZ* should be replaced by the actual issue number.
   
   Fixes #2382
   
   ### Motivation
   
   *Explain here the context, and why you're making that change. What is the problem you're trying to solve.*
   
   ### Modifications
   
   *Describe the modifications you've done.*
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a followup issue for adding the documentation
   


-- 
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: commits-unsubscribe@inlong.apache.org

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



[GitHub] [incubator-inlong] dockerzhang merged pull request #2575: [INLONG-2382][Sort-sdk] Support Pulsar consumer of PB compression cache message protocol

Posted by GitBox <gi...@apache.org>.
dockerzhang merged pull request #2575:
URL: https://github.com/apache/incubator-inlong/pull/2575


   


-- 
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: commits-unsubscribe@inlong.apache.org

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



[GitHub] [incubator-inlong] wardlican commented on a change in pull request #2575: [INLONG-2382][Sort-sdk] Support Pulsar consumer of PB compression cache message protocol

Posted by GitBox <gi...@apache.org>.
wardlican commented on a change in pull request #2575:
URL: https://github.com/apache/incubator-inlong/pull/2575#discussion_r810813257



##########
File path: inlong-sdk/sort-sdk/src/main/java/org/apache/inlong/sdk/sort/impl/decode/MessageDeserializer.java
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.inlong.sdk.sort.impl.decode;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.inlong.sdk.commons.protocol.ProxySdk.MapFieldEntry;
+import org.apache.inlong.sdk.commons.protocol.ProxySdk.MessageObj;
+import org.apache.inlong.sdk.commons.protocol.ProxySdk.MessageObjs;
+import org.apache.inlong.sdk.sort.api.ClientContext;
+import org.apache.inlong.sdk.sort.api.Deserializer;
+import org.apache.inlong.sdk.sort.entity.InLongMessage;
+import org.apache.inlong.sdk.sort.entity.InLongTopic;
+import org.apache.inlong.sdk.sort.util.Utils;
+
+public class MessageDeserializer implements Deserializer {
+
+    private static final int MESSAGE_VERSION_NONE = 0;
+    private static final int MESSAGE_VERSION_PB = 1;
+    private static final int COMPRESS_TYPE_NONE = 0;
+    private static final int COMPRESS_TYPE_GZIP = 1;
+    private static final int COMPRESS_TYPE_SNAPPY = 2;
+    private static final String VERSION_KEY = "version";
+    private static final String COMPRESS_TYPE_KEY = "compressType";
+    private static final String MSG_TIME_KEY = "msgTime";
+    private static final String SOURCE_IP_KEY = "sourceIp";
+    private static final String INLONG_GROUPID_KEY = "inlongGroupId";
+    private static final String INLONG_STREAMID_KEY = "inlongStreamId";
+
+    public MessageDeserializer() {
+    }
+
+    @Override
+    public List<InLongMessage> deserialize(ClientContext context, InLongTopic inLongTopic, Map<String, String> headers,
+            byte[] data) throws Exception {
+
+        //1. version
+        int version = Integer.parseInt(headers.getOrDefault(VERSION_KEY, "0"));
+        switch (version) {
+            case MESSAGE_VERSION_NONE: {
+                return decode(context, inLongTopic, data, headers);
+            }
+            case MESSAGE_VERSION_PB: {
+                return decodePB(context, inLongTopic, data, headers);
+            }
+            default:
+                throw new IllegalArgumentException("Unknown version type:" + version);
+        }
+    }
+
+    private List<InLongMessage> decode(ClientContext context, InLongTopic inLongTopic, byte[] msgBytes,
+            Map<String, String> headers) {
+        long msgTime = Long.parseLong(headers.getOrDefault(MSG_TIME_KEY, "0"));
+        String sourceIp = headers.getOrDefault(SOURCE_IP_KEY, "");
+        String inlongGroupId = headers.getOrDefault(INLONG_GROUPID_KEY, "");
+        String inlongStreamId = headers.getOrDefault(INLONG_STREAMID_KEY, "");
+        context.getStatManager()
+                .getStatistics(context.getConfig().getSortTaskId(),
+                        inLongTopic.getInLongCluster().getClusterId(), inLongTopic.getTopic())
+                .addDecompressionConsumeSize(msgBytes.length);
+        return Collections
+                .singletonList(new InLongMessage(inlongGroupId, inlongStreamId, msgTime, sourceIp, msgBytes, headers));
+    }
+
+    /**
+     * uncompress and decode byte[]
+     *
+     * @param msgBytes byte[]
+     * @return {@link MessageObjs}
+     */
+    private List<InLongMessage> decodePB(ClientContext context, InLongTopic inLongTopic, byte[] msgBytes,
+            Map<String, String> headers) throws IOException {
+        int compressType = Integer.parseInt(headers.getOrDefault(COMPRESS_TYPE_KEY, "0"));
+        String inlongGroupId = headers.getOrDefault(INLONG_GROUPID_KEY, "");
+        String inlongStreamId = headers.getOrDefault(INLONG_STREAMID_KEY, "");
+        switch (compressType) {
+            case COMPRESS_TYPE_NONE: {
+                return transformMessageObjs(context, inLongTopic, MessageObjs.parseFrom(msgBytes), inlongGroupId,
+                        inlongStreamId);
+            }
+            case COMPRESS_TYPE_SNAPPY: {
+                byte[] values = Utils.snappyDecompress(msgBytes, 0, msgBytes.length);
+                return transformMessageObjs(context, inLongTopic, MessageObjs.parseFrom(values), inlongGroupId,
+                        inlongStreamId);
+            }
+            case COMPRESS_TYPE_GZIP: {
+                byte[] values = Utils.gzipDecompress(msgBytes, 0, msgBytes.length);
+                return transformMessageObjs(context, inLongTopic, MessageObjs.parseFrom(values), inlongGroupId,
+                        inlongStreamId);
+            }
+            default:
+                throw new IllegalArgumentException("Unknown compress type:" + compressType);
+        }
+    }
+
+    /**
+     * transform MessageObjs to SortSdkMessage
+     *
+     * @param messageObjs {@link MessageObjs}
+     * @return {@link List< InLongMessage >}
+     */
+    private List<InLongMessage> transformMessageObjs(ClientContext context, InLongTopic inLongTopic,
+            MessageObjs messageObjs, String inlongGroupId,
+            String inlongStreamId) {
+        List<InLongMessage> inLongMessages = new ArrayList<>();
+        for (MessageObj messageObj : messageObjs.getMsgsList()) {
+            List<MapFieldEntry> mapFieldEntries = messageObj.getParamsList();
+            Map<String, String> headers = new HashMap<>();
+            for (MapFieldEntry mapFieldEntry : mapFieldEntries) {

Review comment:
       yes mapFieldEntries maybe be null




-- 
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: commits-unsubscribe@inlong.apache.org

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



[GitHub] [incubator-inlong] wardlican commented on a change in pull request #2575: [INLONG-2382][Sort-sdk] Support Pulsar consumer of PB compression cache message protocol

Posted by GitBox <gi...@apache.org>.
wardlican commented on a change in pull request #2575:
URL: https://github.com/apache/incubator-inlong/pull/2575#discussion_r810813406



##########
File path: inlong-sdk/sort-sdk/pom.xml
##########
@@ -76,13 +76,32 @@
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <plugin.compile.version>3.8.1</plugin.compile.version>
+        <pulsar.version>2.7.2</pulsar.version>

Review comment:
       ok i will improve it to 2.8.1




-- 
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: commits-unsubscribe@inlong.apache.org

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



[GitHub] [incubator-inlong] luchunliang commented on a change in pull request #2575: [INLONG-2382][Sort-sdk] Support Pulsar consumer of PB compression cache message protocol

Posted by GitBox <gi...@apache.org>.
luchunliang commented on a change in pull request #2575:
URL: https://github.com/apache/incubator-inlong/pull/2575#discussion_r810493947



##########
File path: inlong-sdk/sort-sdk/pom.xml
##########
@@ -113,15 +132,9 @@
         </dependency>
 
         <dependency>
-            <groupId>org.apache.inlong</groupId>
-            <artifactId>inlong-common</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.inlong</groupId>
-            <artifactId>tubemq-client</artifactId>
-            <version>${project.version}</version>
+            <groupId>org.xerial.snappy</groupId>
+            <artifactId>snappy-java</artifactId>
+            <version>1.1.7.3</version>

Review comment:
       Artifact version information need to move to "properties".




-- 
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: commits-unsubscribe@inlong.apache.org

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



[GitHub] [incubator-inlong] dockerzhang commented on pull request #2575: [INLONG-2382][Sort-sdk] Support Pulsar consumer of PB compression cache message protocol

Posted by GitBox <gi...@apache.org>.
dockerzhang commented on pull request #2575:
URL: https://github.com/apache/incubator-inlong/pull/2575#issuecomment-1045715923


   @luchunliang PTAL


-- 
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: commits-unsubscribe@inlong.apache.org

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



[GitHub] [incubator-inlong] luchunliang commented on a change in pull request #2575: [INLONG-2382][Sort-sdk] Support Pulsar consumer of PB compression cache message protocol

Posted by GitBox <gi...@apache.org>.
luchunliang commented on a change in pull request #2575:
URL: https://github.com/apache/incubator-inlong/pull/2575#discussion_r810475683



##########
File path: inlong-sdk/sort-sdk/pom.xml
##########
@@ -76,13 +76,32 @@
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <plugin.compile.version>3.8.1</plugin.compile.version>
+        <pulsar.version>2.7.2</pulsar.version>

Review comment:
       The newest version of pulsar client is 2.8.1

##########
File path: inlong-sdk/sort-sdk/src/main/java/org/apache/inlong/sdk/sort/impl/decode/MessageDeserializer.java
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.inlong.sdk.sort.impl.decode;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.inlong.sdk.commons.protocol.ProxySdk.MapFieldEntry;
+import org.apache.inlong.sdk.commons.protocol.ProxySdk.MessageObj;
+import org.apache.inlong.sdk.commons.protocol.ProxySdk.MessageObjs;
+import org.apache.inlong.sdk.sort.api.ClientContext;
+import org.apache.inlong.sdk.sort.api.Deserializer;
+import org.apache.inlong.sdk.sort.entity.InLongMessage;
+import org.apache.inlong.sdk.sort.entity.InLongTopic;
+import org.apache.inlong.sdk.sort.util.Utils;
+
+public class MessageDeserializer implements Deserializer {
+
+    private static final int MESSAGE_VERSION_NONE = 0;
+    private static final int MESSAGE_VERSION_PB = 1;
+    private static final int COMPRESS_TYPE_NONE = 0;
+    private static final int COMPRESS_TYPE_GZIP = 1;
+    private static final int COMPRESS_TYPE_SNAPPY = 2;
+    private static final String VERSION_KEY = "version";
+    private static final String COMPRESS_TYPE_KEY = "compressType";
+    private static final String MSG_TIME_KEY = "msgTime";
+    private static final String SOURCE_IP_KEY = "sourceIp";
+    private static final String INLONG_GROUPID_KEY = "inlongGroupId";
+    private static final String INLONG_STREAMID_KEY = "inlongStreamId";
+
+    public MessageDeserializer() {
+    }
+
+    @Override
+    public List<InLongMessage> deserialize(ClientContext context, InLongTopic inLongTopic, Map<String, String> headers,
+            byte[] data) throws Exception {
+
+        //1. version
+        int version = Integer.parseInt(headers.getOrDefault(VERSION_KEY, "0"));
+        switch (version) {
+            case MESSAGE_VERSION_NONE: {
+                return decode(context, inLongTopic, data, headers);
+            }
+            case MESSAGE_VERSION_PB: {
+                return decodePB(context, inLongTopic, data, headers);
+            }
+            default:
+                throw new IllegalArgumentException("Unknown version type:" + version);
+        }
+    }
+
+    private List<InLongMessage> decode(ClientContext context, InLongTopic inLongTopic, byte[] msgBytes,
+            Map<String, String> headers) {
+        long msgTime = Long.parseLong(headers.getOrDefault(MSG_TIME_KEY, "0"));
+        String sourceIp = headers.getOrDefault(SOURCE_IP_KEY, "");
+        String inlongGroupId = headers.getOrDefault(INLONG_GROUPID_KEY, "");
+        String inlongStreamId = headers.getOrDefault(INLONG_STREAMID_KEY, "");
+        context.getStatManager()
+                .getStatistics(context.getConfig().getSortTaskId(),
+                        inLongTopic.getInLongCluster().getClusterId(), inLongTopic.getTopic())
+                .addDecompressionConsumeSize(msgBytes.length);
+        return Collections
+                .singletonList(new InLongMessage(inlongGroupId, inlongStreamId, msgTime, sourceIp, msgBytes, headers));
+    }
+
+    /**
+     * uncompress and decode byte[]
+     *
+     * @param msgBytes byte[]
+     * @return {@link MessageObjs}
+     */
+    private List<InLongMessage> decodePB(ClientContext context, InLongTopic inLongTopic, byte[] msgBytes,
+            Map<String, String> headers) throws IOException {
+        int compressType = Integer.parseInt(headers.getOrDefault(COMPRESS_TYPE_KEY, "0"));
+        String inlongGroupId = headers.getOrDefault(INLONG_GROUPID_KEY, "");
+        String inlongStreamId = headers.getOrDefault(INLONG_STREAMID_KEY, "");
+        switch (compressType) {
+            case COMPRESS_TYPE_NONE: {
+                return transformMessageObjs(context, inLongTopic, MessageObjs.parseFrom(msgBytes), inlongGroupId,
+                        inlongStreamId);
+            }
+            case COMPRESS_TYPE_SNAPPY: {
+                byte[] values = Utils.snappyDecompress(msgBytes, 0, msgBytes.length);
+                return transformMessageObjs(context, inLongTopic, MessageObjs.parseFrom(values), inlongGroupId,
+                        inlongStreamId);
+            }
+            case COMPRESS_TYPE_GZIP: {
+                byte[] values = Utils.gzipDecompress(msgBytes, 0, msgBytes.length);
+                return transformMessageObjs(context, inLongTopic, MessageObjs.parseFrom(values), inlongGroupId,
+                        inlongStreamId);
+            }
+            default:
+                throw new IllegalArgumentException("Unknown compress type:" + compressType);
+        }
+    }
+
+    /**
+     * transform MessageObjs to SortSdkMessage
+     *
+     * @param messageObjs {@link MessageObjs}
+     * @return {@link List< InLongMessage >}
+     */
+    private List<InLongMessage> transformMessageObjs(ClientContext context, InLongTopic inLongTopic,
+            MessageObjs messageObjs, String inlongGroupId,
+            String inlongStreamId) {
+        List<InLongMessage> inLongMessages = new ArrayList<>();
+        for (MessageObj messageObj : messageObjs.getMsgsList()) {
+            List<MapFieldEntry> mapFieldEntries = messageObj.getParamsList();
+            Map<String, String> headers = new HashMap<>();
+            for (MapFieldEntry mapFieldEntry : mapFieldEntries) {

Review comment:
       mapFieldEntries maybe be null.




-- 
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: commits-unsubscribe@inlong.apache.org

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



[GitHub] [incubator-inlong] wardlican commented on a change in pull request #2575: [INLONG-2382][Sort-sdk] Support Pulsar consumer of PB compression cache message protocol

Posted by GitBox <gi...@apache.org>.
wardlican commented on a change in pull request #2575:
URL: https://github.com/apache/incubator-inlong/pull/2575#discussion_r810809631



##########
File path: inlong-sdk/sort-sdk/pom.xml
##########
@@ -113,15 +132,9 @@
         </dependency>
 
         <dependency>
-            <groupId>org.apache.inlong</groupId>
-            <artifactId>inlong-common</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.inlong</groupId>
-            <artifactId>tubemq-client</artifactId>
-            <version>${project.version}</version>
+            <groupId>org.xerial.snappy</groupId>
+            <artifactId>snappy-java</artifactId>
+            <version>1.1.7.3</version>

Review comment:
       ok




-- 
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: commits-unsubscribe@inlong.apache.org

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