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/14 02:41:26 UTC

[GitHub] [incubator-inlong] wardlican commented on a change in pull request #2442: [INLONG-2380] DataProxy support Kafka sink of PB compression cache message protocol.

wardlican commented on a change in pull request #2442:
URL: https://github.com/apache/incubator-inlong/pull/2442#discussion_r805465769



##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/dispatch/DispatchManager.java
##########
@@ -0,0 +1,160 @@
+/**
+ * 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.dataproxy.dispatch;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.flume.Context;
+import org.apache.inlong.sdk.commons.protocol.ProxyEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DispatchManager
+ */
+public class DispatchManager {
+
+    public static final Logger LOG = LoggerFactory.getLogger(DispatchManager.class);
+    public static final String KEY_DISPATCH_TIMEOUT = "dispatchTimeout";
+    public static final String KEY_DISPATCH_MAX_PACKCOUNT = "dispatchMaxPackCount";
+    public static final String KEY_DISPATCH_MAX_PACKSIZE = "dispatchMaxPackSize";
+    public static final long DEFAULT_DISPATCH_TIMEOUT = 2000;
+    public static final long DEFAULT_DISPATCH_MAX_PACKCOUNT = 256;
+    public static final long DEFAULT_DISPATCH_MAX_PACKSIZE = 327680;
+    public static final long MINUTE_MS = 60L * 1000;
+
+    private LinkedBlockingQueue<DispatchProfile> dispatchQueue;
+    private final long dispatchTimeout;
+    private final long maxPackCount;
+    private final long maxPackSize;
+    private ConcurrentHashMap<String, DispatchProfile> profileCache = new ConcurrentHashMap<>();
+    //
+    private AtomicBoolean needOutputOvertimeData = new AtomicBoolean(false);
+
+    /**
+     * Constructor
+     * 
+     * @param context
+     * @param dispatchQueue
+     */
+    public DispatchManager(Context context, LinkedBlockingQueue<DispatchProfile> dispatchQueue) {
+        this.dispatchQueue = dispatchQueue;
+        this.dispatchTimeout = context.getLong(KEY_DISPATCH_TIMEOUT, DEFAULT_DISPATCH_TIMEOUT);
+        this.maxPackCount = context.getLong(KEY_DISPATCH_MAX_PACKCOUNT, DEFAULT_DISPATCH_MAX_PACKCOUNT);
+        this.maxPackSize = context.getLong(KEY_DISPATCH_MAX_PACKSIZE, DEFAULT_DISPATCH_MAX_PACKSIZE);
+    }
+
+    /**
+     * addEvent
+     * 
+     * @param event
+     */
+    public void addEvent(ProxyEvent event) {
+        if (needOutputOvertimeData.get()) {
+            this.outputOvertimeData();
+            this.needOutputOvertimeData.set(false);
+        }
+        // parse
+        String eventUid = event.getUid();
+        long dispatchTime = event.getMsgTime() - event.getMsgTime() % MINUTE_MS;
+        String dispatchKey = eventUid + "." + dispatchTime;
+        //

Review comment:
       Delete empty comments

##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/dispatch/DispatchManager.java
##########
@@ -0,0 +1,160 @@
+/**
+ * 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.dataproxy.dispatch;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.flume.Context;
+import org.apache.inlong.sdk.commons.protocol.ProxyEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DispatchManager
+ */
+public class DispatchManager {
+
+    public static final Logger LOG = LoggerFactory.getLogger(DispatchManager.class);
+    public static final String KEY_DISPATCH_TIMEOUT = "dispatchTimeout";
+    public static final String KEY_DISPATCH_MAX_PACKCOUNT = "dispatchMaxPackCount";
+    public static final String KEY_DISPATCH_MAX_PACKSIZE = "dispatchMaxPackSize";
+    public static final long DEFAULT_DISPATCH_TIMEOUT = 2000;
+    public static final long DEFAULT_DISPATCH_MAX_PACKCOUNT = 256;
+    public static final long DEFAULT_DISPATCH_MAX_PACKSIZE = 327680;
+    public static final long MINUTE_MS = 60L * 1000;
+
+    private LinkedBlockingQueue<DispatchProfile> dispatchQueue;
+    private final long dispatchTimeout;
+    private final long maxPackCount;
+    private final long maxPackSize;
+    private ConcurrentHashMap<String, DispatchProfile> profileCache = new ConcurrentHashMap<>();
+    //
+    private AtomicBoolean needOutputOvertimeData = new AtomicBoolean(false);
+
+    /**
+     * Constructor
+     * 
+     * @param context
+     * @param dispatchQueue
+     */
+    public DispatchManager(Context context, LinkedBlockingQueue<DispatchProfile> dispatchQueue) {
+        this.dispatchQueue = dispatchQueue;
+        this.dispatchTimeout = context.getLong(KEY_DISPATCH_TIMEOUT, DEFAULT_DISPATCH_TIMEOUT);
+        this.maxPackCount = context.getLong(KEY_DISPATCH_MAX_PACKCOUNT, DEFAULT_DISPATCH_MAX_PACKCOUNT);
+        this.maxPackSize = context.getLong(KEY_DISPATCH_MAX_PACKSIZE, DEFAULT_DISPATCH_MAX_PACKSIZE);
+    }
+
+    /**
+     * addEvent
+     * 
+     * @param event
+     */
+    public void addEvent(ProxyEvent event) {
+        if (needOutputOvertimeData.get()) {
+            this.outputOvertimeData();
+            this.needOutputOvertimeData.set(false);
+        }
+        // parse
+        String eventUid = event.getUid();
+        long dispatchTime = event.getMsgTime() - event.getMsgTime() % MINUTE_MS;
+        String dispatchKey = eventUid + "." + dispatchTime;
+        //
+        DispatchProfile dispatchProfile = this.profileCache.get(dispatchKey);
+        if (dispatchProfile == null) {
+            dispatchProfile = new DispatchProfile(eventUid, event.getInlongGroupId(), event.getInlongStreamId(),
+                    dispatchTime);
+            this.profileCache.put(dispatchKey, dispatchProfile);
+        }
+        //

Review comment:
       ditto

##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/dispatch/DispatchProfile.java
##########
@@ -0,0 +1,174 @@
+/**
+ * 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.dataproxy.dispatch;
+
+import java.util.ArrayList;
+import java.util.List;
+

Review comment:
       Delete empty line

##########
File path: inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/sink/SinkContext.java
##########
@@ -0,0 +1,190 @@
+/**
+ * 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.dataproxy.sink;
+
+import java.util.Date;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.apache.flume.Channel;
+import org.apache.flume.Context;
+import org.apache.inlong.commons.config.metrics.MetricRegister;
+import org.apache.inlong.dataproxy.config.holder.CommonPropertiesHolder;
+import org.apache.inlong.dataproxy.metrics.DataProxyMetricItemSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SinkContext
+ */
+public class SinkContext {
+
+    public static final Logger LOG = LoggerFactory.getLogger(SinkContext.class);
+
+    public static final String KEY_MAX_THREADS = "maxThreads";
+    public static final String KEY_PROCESSINTERVAL = "processInterval";
+    public static final String KEY_RELOADINTERVAL = "reloadInterval";
+
+    protected final String clusterId;
+    protected final String sinkName;
+    protected final Context sinkContext;
+
+    protected final Channel channel;
+    //

Review comment:
       ditto




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