You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2021/08/29 08:00:31 UTC

[GitHub] [rocketmq-externals] lizhiboo opened a new pull request #800: Rocketmq connector sink for hudi

lizhiboo opened a new pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800


   Support rocketmq connector sink to hudi.
   welcome to contribute together.


-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] duhenglucky merged pull request #800: [ISSUE #801]Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
duhenglucky merged pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800


   


-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] odbozhou commented on a change in pull request #800: Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
odbozhou commented on a change in pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800#discussion_r698207363



##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/config/CloneUtils.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.rocketmq.connect.hudi.config;
+
+import java.io.*;
+
+public class CloneUtils {
+    @SuppressWarnings("unchecked")
+    public static <T extends Serializable> T clone(T obj) {
+        T clonedObj = null;
+        try {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ObjectOutputStream oos = new ObjectOutputStream(baos);
+            oos.writeObject(obj);
+            oos.close();
+
+            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+            ObjectInputStream ois = new ObjectInputStream(bais);
+            clonedObj = (T) ois.readObject();
+            ois.close();
+        } catch (Exception e) {
+            e.printStackTrace();

Review comment:
       At least print the log, otherwise the exception will be swallowed

##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/connector/HudiSinkTask.java
##########
@@ -0,0 +1,124 @@
+
+/*
+ * 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.rocketmq.connect.hudi.connector;
+
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.common.QueueMetaData;
+import io.openmessaging.connector.api.data.SinkDataEntry;
+import io.openmessaging.connector.api.sink.SinkTask;
+import org.apache.rocketmq.connect.hudi.config.HudiConnectConfig;
+import org.apache.rocketmq.connect.hudi.config.ConfigUtil;
+import org.apache.rocketmq.connect.hudi.sink.Updater;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+
+/**
+ * In the naming, we are using database for "keyspaces" and table for "columnFamily"
+ * This is because we kind of want the abstract data source to be aligned with SQL databases
+ */
+public class HudiSinkTask extends SinkTask {
+    private static final Logger log = LoggerFactory.getLogger(HudiSinkTask.class);
+
+    private HudiConnectConfig hudiConnectConfig;
+    private Updater updater;
+    private BlockingQueue<Updater> tableQueue = new LinkedBlockingQueue<Updater>();
+
+    public HudiSinkTask() {
+        this.hudiConnectConfig = new HudiConnectConfig();
+    }
+
+    @Override
+    public void put(Collection<SinkDataEntry> sinkDataEntries) {
+        try {
+            if (tableQueue.size() > 1) {
+                updater = tableQueue.poll(1000, TimeUnit.MILLISECONDS);
+            } else {
+                updater = tableQueue.peek();
+            }
+            log.info("Hudi Sink Task trying to put()");
+            for (SinkDataEntry record : sinkDataEntries) {
+                log.info("Hudi Sink Task trying to call updater.push()");
+                Boolean isSuccess = updater.push(record);
+                if (!isSuccess) {
+                    log.error("push data error, record:{}", record);
+                }
+            }
+        } catch (Exception e) {
+            log.error("put sinkDataEntries error, {}", e);
+        }
+    }
+
+    @Override
+    public void commit(Map<QueueMetaData, Long> map) {
+
+    }
+
+    /**
+     * Remember always close the CqlSession according to
+     * https://docs.datastax.com/en/developer/java-driver/4.5/manual/core/
+     * @param props
+     */
+    @Override
+    public void start(KeyValue props) {
+        try {
+            ConfigUtil.load(props, this.hudiConnectConfig);
+            log.info("init data source success");
+        } catch (Exception e) {
+            log.error("Cannot start Hudi Sink Task because of configuration error{}", e);
+        }
+        try {
+            Updater updater = new Updater(hudiConnectConfig);
+            updater.start();
+            tableQueue.add(updater);
+        } catch (Exception e) {
+            log.error("fail to start updater{}", e);
+        }
+
+
+    }
+
+    @Override
+    public void stop() {
+        try {
+            for(Updater updater : tableQueue) {
+                updater.start();

Review comment:
       start ?

##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/connector/HudiSinkConnector.java
##########
@@ -0,0 +1,232 @@
+
+/*
+ * 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.rocketmq.connect.hudi.connector;
+
+
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.Task;
+import io.openmessaging.connector.api.sink.SinkConnector;
+import io.openmessaging.internal.DefaultKeyValue;
+import org.apache.commons.lang3.concurrent.BasicThreadFactory;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.protocol.route.BrokerData;
+import org.apache.rocketmq.common.protocol.route.QueueData;
+import org.apache.rocketmq.common.protocol.route.TopicRouteData;
+import org.apache.rocketmq.connect.hudi.config.*;
+import org.apache.rocketmq.remoting.RPCHook;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+
+public class HudiSinkConnector extends SinkConnector{
+    private static final Logger log = LoggerFactory.getLogger(HudiSinkConnector.class);
+    private volatile boolean configValid = false;
+    private ScheduledExecutorService executor;
+    private HashMap<String, Set<TaskTopicInfo>> topicRouteMap;
+
+    private DefaultMQAdminExt srcMQAdminExt;
+    private SinkConnectConfig sinkConnectConfig;
+
+    private volatile boolean adminStarted;
+
+    private ScheduledFuture<?> listenerHandle;
+    public static String HUDI_CONNECTOR_ADMIN_PREFIX = "HUDI-CONNECTOR-ADMIN";
+    public static final String PREFIX = "hudi";
+
+    public HudiSinkConnector() {
+        topicRouteMap = new HashMap<>();
+        sinkConnectConfig = new SinkConnectConfig();
+        executor = Executors.newSingleThreadScheduledExecutor(new BasicThreadFactory.Builder().namingPattern("HudiFSinkConnector-SinkWatcher-%d").daemon(true).build());
+    }
+
+    private synchronized void startMQAdminTools() {
+        if (!configValid || adminStarted) {
+            return;
+        }
+        RPCHook rpcHook = null;
+        this.srcMQAdminExt = new DefaultMQAdminExt(rpcHook);
+        this.srcMQAdminExt.setNamesrvAddr(this.sinkConnectConfig.getSrcNamesrvs());
+        this.srcMQAdminExt.setAdminExtGroup(Utils.createGroupName(HUDI_CONNECTOR_ADMIN_PREFIX));
+        this.srcMQAdminExt.setInstanceName(Utils.createInstanceName(this.sinkConnectConfig.getSrcNamesrvs()));
+
+        try {
+            log.info("Trying to start srcMQAdminExt");
+            this.srcMQAdminExt.start();
+            log.info("RocketMQ srcMQAdminExt started");
+
+        } catch (MQClientException e) {
+            log.error("Hudi Sink Task start failed for `srcMQAdminExt` exception.", e);
+        }
+
+        adminStarted = true;
+    }
+
+    @Override
+    public String verifyAndSetConfig(KeyValue config) {
+        for (String requestKey : HudiConnectConfig.REQUEST_CONFIG) {
+            if (!config.containsKey(requestKey)) {
+                return "Request config key: " + requestKey;
+            }
+        }
+        try {
+            this.sinkConnectConfig.validate(config);
+        } catch (IllegalArgumentException e) {
+            return e.getMessage();
+        }
+        this.configValid = true;
+
+        return "";
+    }
+
+    @Override
+    public void start() {
+        startMQAdminTools();
+        startListener();
+    }
+
+    public void startListener() {

Review comment:
       What is the function of the startListener method?
   
   

##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/connector/HudiSinkConnector.java
##########
@@ -0,0 +1,232 @@
+
+/*
+ * 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.rocketmq.connect.hudi.connector;
+
+
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.Task;
+import io.openmessaging.connector.api.sink.SinkConnector;
+import io.openmessaging.internal.DefaultKeyValue;
+import org.apache.commons.lang3.concurrent.BasicThreadFactory;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.protocol.route.BrokerData;
+import org.apache.rocketmq.common.protocol.route.QueueData;
+import org.apache.rocketmq.common.protocol.route.TopicRouteData;
+import org.apache.rocketmq.connect.hudi.config.*;
+import org.apache.rocketmq.remoting.RPCHook;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+
+public class HudiSinkConnector extends SinkConnector{
+    private static final Logger log = LoggerFactory.getLogger(HudiSinkConnector.class);
+    private volatile boolean configValid = false;
+    private ScheduledExecutorService executor;
+    private HashMap<String, Set<TaskTopicInfo>> topicRouteMap;
+
+    private DefaultMQAdminExt srcMQAdminExt;
+    private SinkConnectConfig sinkConnectConfig;
+
+    private volatile boolean adminStarted;
+
+    private ScheduledFuture<?> listenerHandle;
+    public static String HUDI_CONNECTOR_ADMIN_PREFIX = "HUDI-CONNECTOR-ADMIN";
+    public static final String PREFIX = "hudi";
+
+    public HudiSinkConnector() {
+        topicRouteMap = new HashMap<>();
+        sinkConnectConfig = new SinkConnectConfig();
+        executor = Executors.newSingleThreadScheduledExecutor(new BasicThreadFactory.Builder().namingPattern("HudiFSinkConnector-SinkWatcher-%d").daemon(true).build());
+    }
+
+    private synchronized void startMQAdminTools() {

Review comment:
       What is the function of the startMQAdminTools method?

##########
File path: rocketmq-connect-hudi/src/main/java/example/avro/User.java
##########
@@ -0,0 +1,501 @@
+package example.avro; /**
+ * Autogenerated by Avro
+ *
+ * DO NOT EDIT DIRECTLY
+ */
+
+import org.apache.avro.message.BinaryMessageDecoder;
+import org.apache.avro.message.BinaryMessageEncoder;
+import org.apache.avro.message.SchemaStore;
+import org.apache.avro.specific.SpecificData;
+import org.apache.avro.util.Utf8;
+
+@org.apache.avro.specific.AvroGenerated
+public class User extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {

Review comment:
       Is this file necessary? If it is a necessary class, please modify the package name and include the apache license

##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/connector/HudiSinkConnector.java
##########
@@ -0,0 +1,232 @@
+
+/*
+ * 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.rocketmq.connect.hudi.connector;
+
+
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.Task;
+import io.openmessaging.connector.api.sink.SinkConnector;
+import io.openmessaging.internal.DefaultKeyValue;
+import org.apache.commons.lang3.concurrent.BasicThreadFactory;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.protocol.route.BrokerData;
+import org.apache.rocketmq.common.protocol.route.QueueData;
+import org.apache.rocketmq.common.protocol.route.TopicRouteData;
+import org.apache.rocketmq.connect.hudi.config.*;
+import org.apache.rocketmq.remoting.RPCHook;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+
+public class HudiSinkConnector extends SinkConnector{
+    private static final Logger log = LoggerFactory.getLogger(HudiSinkConnector.class);
+    private volatile boolean configValid = false;
+    private ScheduledExecutorService executor;
+    private HashMap<String, Set<TaskTopicInfo>> topicRouteMap;
+
+    private DefaultMQAdminExt srcMQAdminExt;
+    private SinkConnectConfig sinkConnectConfig;
+
+    private volatile boolean adminStarted;
+
+    private ScheduledFuture<?> listenerHandle;
+    public static String HUDI_CONNECTOR_ADMIN_PREFIX = "HUDI-CONNECTOR-ADMIN";
+    public static final String PREFIX = "hudi";
+
+    public HudiSinkConnector() {
+        topicRouteMap = new HashMap<>();
+        sinkConnectConfig = new SinkConnectConfig();
+        executor = Executors.newSingleThreadScheduledExecutor(new BasicThreadFactory.Builder().namingPattern("HudiFSinkConnector-SinkWatcher-%d").daemon(true).build());
+    }
+
+    private synchronized void startMQAdminTools() {
+        if (!configValid || adminStarted) {
+            return;
+        }
+        RPCHook rpcHook = null;
+        this.srcMQAdminExt = new DefaultMQAdminExt(rpcHook);
+        this.srcMQAdminExt.setNamesrvAddr(this.sinkConnectConfig.getSrcNamesrvs());
+        this.srcMQAdminExt.setAdminExtGroup(Utils.createGroupName(HUDI_CONNECTOR_ADMIN_PREFIX));
+        this.srcMQAdminExt.setInstanceName(Utils.createInstanceName(this.sinkConnectConfig.getSrcNamesrvs()));
+
+        try {
+            log.info("Trying to start srcMQAdminExt");
+            this.srcMQAdminExt.start();
+            log.info("RocketMQ srcMQAdminExt started");
+
+        } catch (MQClientException e) {
+            log.error("Hudi Sink Task start failed for `srcMQAdminExt` exception.", e);
+        }
+
+        adminStarted = true;
+    }
+
+    @Override
+    public String verifyAndSetConfig(KeyValue config) {
+        for (String requestKey : HudiConnectConfig.REQUEST_CONFIG) {
+            if (!config.containsKey(requestKey)) {
+                return "Request config key: " + requestKey;
+            }
+        }
+        try {
+            this.sinkConnectConfig.validate(config);
+        } catch (IllegalArgumentException e) {
+            return e.getMessage();
+        }
+        this.configValid = true;
+
+        return "";
+    }
+
+    @Override
+    public void start() {
+        startMQAdminTools();
+        startListener();
+    }
+
+    public void startListener() {
+        listenerHandle = executor.scheduleAtFixedRate(new Runnable() {
+            boolean first = true;
+            HashMap<String, Set<TaskTopicInfo>> origin = null;
+
+            @Override
+            public void run() {
+                buildRoute();
+                if (first) {
+                    origin = CloneUtils.clone(topicRouteMap);
+                    first = false;
+                }
+                if (!compare(origin, topicRouteMap)) {
+                    context.requestTaskReconfiguration();
+                    origin = CloneUtils.clone(topicRouteMap);
+                }
+            }
+        }, sinkConnectConfig.getRefreshInterval(), sinkConnectConfig.getRefreshInterval(), TimeUnit.SECONDS);
+    }
+
+    public boolean compare(Map<String, Set<TaskTopicInfo>> origin, Map<String, Set<TaskTopicInfo>> updated) {
+        if (origin.size() != updated.size()) {
+            return false;
+        }
+        for (Map.Entry<String, Set<TaskTopicInfo>> entry : origin.entrySet()) {
+            if (!updated.containsKey(entry.getKey())) {
+                return false;
+            }
+            Set<TaskTopicInfo> originTasks = entry.getValue();
+            Set<TaskTopicInfo> updateTasks = updated.get(entry.getKey());
+            if (originTasks.size() != updateTasks.size()) {
+                return false;
+            }
+
+            if (!originTasks.containsAll(updateTasks)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    public void buildRoute() {

Review comment:
       What is the function of the buildRoute method?
   
   

##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/connector/HudiSinkTask.java
##########
@@ -0,0 +1,124 @@
+
+/*
+ * 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.rocketmq.connect.hudi.connector;
+
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.common.QueueMetaData;
+import io.openmessaging.connector.api.data.SinkDataEntry;
+import io.openmessaging.connector.api.sink.SinkTask;
+import org.apache.rocketmq.connect.hudi.config.HudiConnectConfig;
+import org.apache.rocketmq.connect.hudi.config.ConfigUtil;
+import org.apache.rocketmq.connect.hudi.sink.Updater;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+
+/**
+ * In the naming, we are using database for "keyspaces" and table for "columnFamily"
+ * This is because we kind of want the abstract data source to be aligned with SQL databases
+ */
+public class HudiSinkTask extends SinkTask {
+    private static final Logger log = LoggerFactory.getLogger(HudiSinkTask.class);
+
+    private HudiConnectConfig hudiConnectConfig;
+    private Updater updater;
+    private BlockingQueue<Updater> tableQueue = new LinkedBlockingQueue<Updater>();
+
+    public HudiSinkTask() {
+        this.hudiConnectConfig = new HudiConnectConfig();
+    }
+
+    @Override
+    public void put(Collection<SinkDataEntry> sinkDataEntries) {
+        try {
+            if (tableQueue.size() > 1) {
+                updater = tableQueue.poll(1000, TimeUnit.MILLISECONDS);

Review comment:
       Sink starts with only one updater, why should a blocking queue be introduced?




-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] ltamber commented on a change in pull request #800: Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
ltamber commented on a change in pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800#discussion_r698116971



##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/config/CloneUtils.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.rocketmq.connect.hudi.config;
+
+import java.io.*;

Review comment:
       import * is not recommended.




-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] ltamber commented on a change in pull request #800: Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
ltamber commented on a change in pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800#discussion_r698117521



##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/connector/HudiSinkConnector.java
##########
@@ -0,0 +1,232 @@
+
+/*
+ * 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.rocketmq.connect.hudi.connector;
+
+
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.Task;
+import io.openmessaging.connector.api.sink.SinkConnector;
+import io.openmessaging.internal.DefaultKeyValue;
+import org.apache.commons.lang3.concurrent.BasicThreadFactory;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.protocol.route.BrokerData;
+import org.apache.rocketmq.common.protocol.route.QueueData;
+import org.apache.rocketmq.common.protocol.route.TopicRouteData;
+import org.apache.rocketmq.connect.hudi.config.*;
+import org.apache.rocketmq.remoting.RPCHook;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;

Review comment:
       import * is not recommended




-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] lizhiboo commented on a change in pull request #800: [ISSUE #801]Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
lizhiboo commented on a change in pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800#discussion_r704183604



##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/connector/HudiSinkTask.java
##########
@@ -0,0 +1,124 @@
+
+/*
+ * 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.rocketmq.connect.hudi.connector;
+
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.common.QueueMetaData;
+import io.openmessaging.connector.api.data.SinkDataEntry;
+import io.openmessaging.connector.api.sink.SinkTask;
+import org.apache.rocketmq.connect.hudi.config.HudiConnectConfig;
+import org.apache.rocketmq.connect.hudi.config.ConfigUtil;
+import org.apache.rocketmq.connect.hudi.sink.Updater;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+
+/**
+ * In the naming, we are using database for "keyspaces" and table for "columnFamily"
+ * This is because we kind of want the abstract data source to be aligned with SQL databases
+ */
+public class HudiSinkTask extends SinkTask {
+    private static final Logger log = LoggerFactory.getLogger(HudiSinkTask.class);
+
+    private HudiConnectConfig hudiConnectConfig;
+    private Updater updater;
+    private BlockingQueue<Updater> tableQueue = new LinkedBlockingQueue<Updater>();
+
+    public HudiSinkTask() {
+        this.hudiConnectConfig = new HudiConnectConfig();
+    }
+
+    @Override
+    public void put(Collection<SinkDataEntry> sinkDataEntries) {
+        try {
+            if (tableQueue.size() > 1) {
+                updater = tableQueue.poll(1000, TimeUnit.MILLISECONDS);

Review comment:
       done




-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] odbozhou commented on pull request #800: Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
odbozhou commented on pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800#issuecomment-908075911


   Submit an issue, this pr is associated with this issue


-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] duhenglucky commented on a change in pull request #800: [ISSUE #801]Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
duhenglucky commented on a change in pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800#discussion_r702831452



##########
File path: rocketmq-connect/rocketmq-connect-runtime/src/main/java/org/apache/rocketmq/connect/runtime/connectorwrapper/WorkerSinkTask.java
##########
@@ -21,15 +21,10 @@
 import io.openmessaging.KeyValue;
 import io.openmessaging.connector.api.PositionStorageReader;
 import io.openmessaging.connector.api.common.QueueMetaData;
-import io.openmessaging.connector.api.data.Converter;
-import io.openmessaging.connector.api.data.DataEntryBuilder;
-import io.openmessaging.connector.api.data.EntryType;
-import io.openmessaging.connector.api.data.Field;
-import io.openmessaging.connector.api.data.Schema;
-import io.openmessaging.connector.api.data.SinkDataEntry;
-import io.openmessaging.connector.api.data.SourceDataEntry;
+import io.openmessaging.connector.api.data.*;

Review comment:
       It is not recommended to use * for imports




-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] lizhiboo commented on a change in pull request #800: [ISSUE #801]Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
lizhiboo commented on a change in pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800#discussion_r704181662



##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/config/CloneUtils.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.rocketmq.connect.hudi.config;
+
+import java.io.*;

Review comment:
       done

##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/connector/HudiSinkConnector.java
##########
@@ -0,0 +1,232 @@
+
+/*
+ * 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.rocketmq.connect.hudi.connector;
+
+
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.Task;
+import io.openmessaging.connector.api.sink.SinkConnector;
+import io.openmessaging.internal.DefaultKeyValue;
+import org.apache.commons.lang3.concurrent.BasicThreadFactory;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.protocol.route.BrokerData;
+import org.apache.rocketmq.common.protocol.route.QueueData;
+import org.apache.rocketmq.common.protocol.route.TopicRouteData;
+import org.apache.rocketmq.connect.hudi.config.*;
+import org.apache.rocketmq.remoting.RPCHook;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;

Review comment:
       done




-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] lizhiboo commented on a change in pull request #800: [ISSUE #801]Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
lizhiboo commented on a change in pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800#discussion_r704184406



##########
File path: rocketmq-connect/rocketmq-connect-runtime/src/main/resources/connect.conf
##########
@@ -13,11 +13,16 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 
+workerId=DEFAULT_WORKER_1
+storePathRootDir=/Users/osgoo/Downloads/storeRoot
+
 ## Http port for user to access REST API
-httpPort=8081
+httpPort=8082
 
 # Rocketmq namesrvAddr
 namesrvAddr=localhost:9876
 
 # Source or sink connector jar file dir,The default value is rocketmq-connect-sample
-pluginPaths=/usr/local/connector-plugins
+pluginPaths=/Users/osgoo/Downloads/connector-plugins

Review comment:
       changed

##########
File path: rocketmq-connect/rocketmq-connect-runtime/src/main/java/org/apache/rocketmq/connect/runtime/connectorwrapper/WorkerSinkTask.java
##########
@@ -21,15 +21,10 @@
 import io.openmessaging.KeyValue;
 import io.openmessaging.connector.api.PositionStorageReader;
 import io.openmessaging.connector.api.common.QueueMetaData;
-import io.openmessaging.connector.api.data.Converter;
-import io.openmessaging.connector.api.data.DataEntryBuilder;
-import io.openmessaging.connector.api.data.EntryType;
-import io.openmessaging.connector.api.data.Field;
-import io.openmessaging.connector.api.data.Schema;
-import io.openmessaging.connector.api.data.SinkDataEntry;
-import io.openmessaging.connector.api.data.SourceDataEntry;
+import io.openmessaging.connector.api.data.*;

Review comment:
       done




-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] odbozhou commented on a change in pull request #800: [ISSUE #801]Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
odbozhou commented on a change in pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800#discussion_r703212129



##########
File path: rocketmq-connect/rocketmq-connect-runtime/src/main/resources/connect.conf
##########
@@ -13,11 +13,16 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 
+workerId=DEFAULT_WORKER_1
+storePathRootDir=/Users/osgoo/Downloads/storeRoot
+
 ## Http port for user to access REST API
-httpPort=8081
+httpPort=8082
 
 # Rocketmq namesrvAddr
 namesrvAddr=localhost:9876
 
 # Source or sink connector jar file dir,The default value is rocketmq-connect-sample
-pluginPaths=/usr/local/connector-plugins
+pluginPaths=/Users/osgoo/Downloads/connector-plugins

Review comment:
       Personal directory ?

##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/strategy/TaskDivideByQueueStrategy.java
##########
@@ -0,0 +1,64 @@
+package org.apache.rocketmq.connect.hudi.strategy;
+
+import com.alibaba.fastjson.JSONObject;
+import io.openmessaging.KeyValue;
+import io.openmessaging.internal.DefaultKeyValue;
+import org.apache.rocketmq.common.message.MessageQueue;
+import org.apache.rocketmq.connect.hudi.config.HudiConnectConfig;
+
+import java.util.*;
+
+import static org.apache.rocketmq.connect.hudi.config.HudiConnectConfig.*;
+
+/**
+ * @author osgoo

Review comment:
       please remove author info

##########
File path: rocketmq-connect/rocketmq-connect-runtime/src/main/java/org/apache/rocketmq/connect/runtime/ConnectStartup.java
##########
@@ -48,6 +48,7 @@
 
     public static void main(String[] args) {
 
+        args = new String[] {"-c", "/Users/osgoo/Documents/workspace/lizhiboo/rocketmq-externals/rocketmq-connect/rocketmq-connect-runtime/target/distribution/conf/connect.conf"};

Review comment:
       please remove test code

##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/strategy/TaskDivideStrategyFactory.java
##########
@@ -0,0 +1,11 @@
+package org.apache.rocketmq.connect.hudi.strategy;
+
+/**
+ * @author osgoo

Review comment:
       please remove author info

##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/strategy/ITaskDivideStrategy.java
##########
@@ -0,0 +1,13 @@
+package org.apache.rocketmq.connect.hudi.strategy;
+
+import io.openmessaging.KeyValue;
+
+import java.util.List;
+
+/**
+ * @author osgoo

Review comment:
       please remove author info

##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/connector/HudiSinkConnector.java
##########
@@ -0,0 +1,248 @@
+
+/*
+ * 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.rocketmq.connect.hudi.connector;
+
+
+import com.alibaba.fastjson.JSONObject;
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.Task;
+import io.openmessaging.connector.api.sink.SinkConnector;
+import io.openmessaging.internal.DefaultKeyValue;
+import org.apache.commons.lang3.concurrent.BasicThreadFactory;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.message.MessageQueue;
+import org.apache.rocketmq.common.protocol.route.BrokerData;
+import org.apache.rocketmq.common.protocol.route.QueueData;
+import org.apache.rocketmq.common.protocol.route.TopicRouteData;
+import org.apache.rocketmq.connect.hudi.config.*;
+import org.apache.rocketmq.connect.hudi.strategy.ITaskDivideStrategy;
+import org.apache.rocketmq.connect.hudi.strategy.TaskDivideStrategyFactory;
+import org.apache.rocketmq.remoting.RPCHook;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.ArrayList;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+
+public class HudiSinkConnector extends SinkConnector{
+    private static final Logger log = LoggerFactory.getLogger(HudiSinkConnector.class);
+    private volatile boolean configValid = false;
+    private ScheduledExecutorService executor;
+    private HashMap<String, Set<MessageQueue>> topicRouteMap;
+
+    private DefaultMQAdminExt srcMQAdminExt;
+    private SinkConnectConfig sinkConnectConfig;
+
+    private volatile boolean adminStarted;
+
+    private ScheduledFuture<?> listenerHandle;
+    public static String HUDI_CONNECTOR_ADMIN_PREFIX = "HUDI-CONNECTOR-ADMIN";
+    public static final String PREFIX = "hudi";
+
+    public HudiSinkConnector() {
+        topicRouteMap = new HashMap<>();
+        sinkConnectConfig = new SinkConnectConfig();
+        executor = Executors.newSingleThreadScheduledExecutor(new BasicThreadFactory.Builder().namingPattern("HudiFSinkConnector-SinkWatcher-%d").daemon(true).build());
+    }
+
+    private synchronized void startMQAdminTools() {
+        if (!configValid || adminStarted) {
+            return;
+        }
+        RPCHook rpcHook = null;
+        this.srcMQAdminExt = new DefaultMQAdminExt(rpcHook);
+        this.srcMQAdminExt.setNamesrvAddr(this.sinkConnectConfig.getSrcNamesrvs());
+        this.srcMQAdminExt.setAdminExtGroup(Utils.createGroupName(HUDI_CONNECTOR_ADMIN_PREFIX));
+        this.srcMQAdminExt.setInstanceName(Utils.createInstanceName(this.sinkConnectConfig.getSrcNamesrvs()));
+
+        try {
+            log.info("Trying to start srcMQAdminExt");
+            this.srcMQAdminExt.start();
+            log.info("RocketMQ srcMQAdminExt started");
+
+        } catch (MQClientException e) {
+            log.error("Hudi Sink Task start failed for `srcMQAdminExt` exception.", e);
+        }
+
+        adminStarted = true;
+    }
+
+    @Override
+    public String verifyAndSetConfig(KeyValue config) {
+        for (String requestKey : HudiConnectConfig.REQUEST_CONFIG) {
+            if (!config.containsKey(requestKey)) {
+                return "Request config key: " + requestKey;
+            }
+        }
+        try {
+            this.sinkConnectConfig.validate(config);
+        } catch (IllegalArgumentException e) {
+            return e.getMessage();
+        }
+        this.configValid = true;
+
+        return "";
+    }
+
+    @Override
+    public void start() {
+        startMQAdminTools();
+        startListener();
+    }
+
+    public void startListener() {
+        listenerHandle = executor.scheduleAtFixedRate(new Runnable() {
+            boolean first = true;
+            HashMap<String, Set<MessageQueue>> origin = null;
+
+            @Override
+            public void run() {
+                buildRoute();
+                if (first) {
+                    origin = CloneUtils.clone(topicRouteMap);
+                    first = false;
+                }
+                if (!compare(origin, topicRouteMap)) {
+                    context.requestTaskReconfiguration();
+                    origin = CloneUtils.clone(topicRouteMap);
+                }
+            }
+        }, sinkConnectConfig.getRefreshInterval(), sinkConnectConfig.getRefreshInterval(), TimeUnit.SECONDS);
+    }
+
+    public boolean compare(Map<String, Set<MessageQueue>> origin, Map<String, Set<MessageQueue>> updated) {
+        if (origin.size() != updated.size()) {
+            return false;
+        }
+        for (Map.Entry<String, Set<MessageQueue>> entry : origin.entrySet()) {
+            if (!updated.containsKey(entry.getKey())) {
+                return false;
+            }
+            Set<MessageQueue> originTasks = entry.getValue();
+            Set<MessageQueue> updateTasks = updated.get(entry.getKey());
+            if (originTasks.size() != updateTasks.size()) {
+                return false;
+            }
+
+            if (!originTasks.containsAll(updateTasks)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    public void buildRoute() {
+        String srcCluster = this.sinkConnectConfig.getSrcCluster();
+        try {
+            for (String topic : this.sinkConnectConfig.getWhiteList()) {
+
+                // different from BrokerData with cluster field, which can ensure the brokerData is from expected cluster.
+                // QueueData use brokerName as unique info on cluster of rocketmq. so when we want to get QueueData of
+                // expected cluster, we should get brokerNames of expected cluster, and then filter queueDatas.
+                List<BrokerData> brokerList = Utils.examineBrokerData(this.srcMQAdminExt, topic, srcCluster);
+                Set<String> brokerNameSet = new HashSet<String>();
+                for (BrokerData b : brokerList) {
+                    brokerNameSet.add(b.getBrokerName());
+                }
+
+                TopicRouteData topicRouteData = srcMQAdminExt.examineTopicRouteInfo(topic);
+                if (!topicRouteMap.containsKey(topic)) {
+                    topicRouteMap.put(topic, new HashSet<>(16));
+                }
+                for (QueueData qd : topicRouteData.getQueueDatas()) {
+                    if (brokerNameSet.contains(qd.getBrokerName())) {
+                        for (int i = 0; i < qd.getReadQueueNums(); i++) {
+                            MessageQueue taskTopicInfo = new MessageQueue(topic, qd.getBrokerName(), i);
+                            topicRouteMap.get(topic).add(taskTopicInfo);
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("Fetch topic list error.", e);
+        } finally {

Review comment:
       if finally unuse ,please remove

##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/connector/HudiSinkConnector.java
##########
@@ -0,0 +1,248 @@
+
+/*
+ * 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.rocketmq.connect.hudi.connector;
+
+
+import com.alibaba.fastjson.JSONObject;
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.Task;
+import io.openmessaging.connector.api.sink.SinkConnector;
+import io.openmessaging.internal.DefaultKeyValue;
+import org.apache.commons.lang3.concurrent.BasicThreadFactory;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.message.MessageQueue;
+import org.apache.rocketmq.common.protocol.route.BrokerData;
+import org.apache.rocketmq.common.protocol.route.QueueData;
+import org.apache.rocketmq.common.protocol.route.TopicRouteData;
+import org.apache.rocketmq.connect.hudi.config.*;
+import org.apache.rocketmq.connect.hudi.strategy.ITaskDivideStrategy;
+import org.apache.rocketmq.connect.hudi.strategy.TaskDivideStrategyFactory;
+import org.apache.rocketmq.remoting.RPCHook;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.ArrayList;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+
+public class HudiSinkConnector extends SinkConnector{
+    private static final Logger log = LoggerFactory.getLogger(HudiSinkConnector.class);
+    private volatile boolean configValid = false;
+    private ScheduledExecutorService executor;
+    private HashMap<String, Set<MessageQueue>> topicRouteMap;
+
+    private DefaultMQAdminExt srcMQAdminExt;
+    private SinkConnectConfig sinkConnectConfig;
+
+    private volatile boolean adminStarted;
+
+    private ScheduledFuture<?> listenerHandle;
+    public static String HUDI_CONNECTOR_ADMIN_PREFIX = "HUDI-CONNECTOR-ADMIN";
+    public static final String PREFIX = "hudi";
+
+    public HudiSinkConnector() {
+        topicRouteMap = new HashMap<>();
+        sinkConnectConfig = new SinkConnectConfig();
+        executor = Executors.newSingleThreadScheduledExecutor(new BasicThreadFactory.Builder().namingPattern("HudiFSinkConnector-SinkWatcher-%d").daemon(true).build());
+    }
+
+    private synchronized void startMQAdminTools() {
+        if (!configValid || adminStarted) {
+            return;
+        }
+        RPCHook rpcHook = null;
+        this.srcMQAdminExt = new DefaultMQAdminExt(rpcHook);
+        this.srcMQAdminExt.setNamesrvAddr(this.sinkConnectConfig.getSrcNamesrvs());
+        this.srcMQAdminExt.setAdminExtGroup(Utils.createGroupName(HUDI_CONNECTOR_ADMIN_PREFIX));
+        this.srcMQAdminExt.setInstanceName(Utils.createInstanceName(this.sinkConnectConfig.getSrcNamesrvs()));
+
+        try {
+            log.info("Trying to start srcMQAdminExt");
+            this.srcMQAdminExt.start();
+            log.info("RocketMQ srcMQAdminExt started");
+
+        } catch (MQClientException e) {
+            log.error("Hudi Sink Task start failed for `srcMQAdminExt` exception.", e);
+        }
+
+        adminStarted = true;
+    }
+
+    @Override
+    public String verifyAndSetConfig(KeyValue config) {
+        for (String requestKey : HudiConnectConfig.REQUEST_CONFIG) {
+            if (!config.containsKey(requestKey)) {
+                return "Request config key: " + requestKey;
+            }
+        }
+        try {
+            this.sinkConnectConfig.validate(config);
+        } catch (IllegalArgumentException e) {
+            return e.getMessage();
+        }
+        this.configValid = true;
+
+        return "";
+    }
+
+    @Override
+    public void start() {
+        startMQAdminTools();
+        startListener();
+    }
+
+    public void startListener() {
+        listenerHandle = executor.scheduleAtFixedRate(new Runnable() {
+            boolean first = true;
+            HashMap<String, Set<MessageQueue>> origin = null;
+
+            @Override
+            public void run() {
+                buildRoute();
+                if (first) {
+                    origin = CloneUtils.clone(topicRouteMap);
+                    first = false;
+                }
+                if (!compare(origin, topicRouteMap)) {
+                    context.requestTaskReconfiguration();
+                    origin = CloneUtils.clone(topicRouteMap);
+                }
+            }
+        }, sinkConnectConfig.getRefreshInterval(), sinkConnectConfig.getRefreshInterval(), TimeUnit.SECONDS);
+    }
+
+    public boolean compare(Map<String, Set<MessageQueue>> origin, Map<String, Set<MessageQueue>> updated) {
+        if (origin.size() != updated.size()) {
+            return false;
+        }
+        for (Map.Entry<String, Set<MessageQueue>> entry : origin.entrySet()) {
+            if (!updated.containsKey(entry.getKey())) {
+                return false;
+            }
+            Set<MessageQueue> originTasks = entry.getValue();
+            Set<MessageQueue> updateTasks = updated.get(entry.getKey());
+            if (originTasks.size() != updateTasks.size()) {
+                return false;
+            }
+
+            if (!originTasks.containsAll(updateTasks)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    public void buildRoute() {
+        String srcCluster = this.sinkConnectConfig.getSrcCluster();
+        try {
+            for (String topic : this.sinkConnectConfig.getWhiteList()) {
+
+                // different from BrokerData with cluster field, which can ensure the brokerData is from expected cluster.
+                // QueueData use brokerName as unique info on cluster of rocketmq. so when we want to get QueueData of
+                // expected cluster, we should get brokerNames of expected cluster, and then filter queueDatas.
+                List<BrokerData> brokerList = Utils.examineBrokerData(this.srcMQAdminExt, topic, srcCluster);
+                Set<String> brokerNameSet = new HashSet<String>();
+                for (BrokerData b : brokerList) {
+                    brokerNameSet.add(b.getBrokerName());
+                }
+
+                TopicRouteData topicRouteData = srcMQAdminExt.examineTopicRouteInfo(topic);
+                if (!topicRouteMap.containsKey(topic)) {
+                    topicRouteMap.put(topic, new HashSet<>(16));
+                }
+                for (QueueData qd : topicRouteData.getQueueDatas()) {
+                    if (brokerNameSet.contains(qd.getBrokerName())) {
+                        for (int i = 0; i < qd.getReadQueueNums(); i++) {
+                            MessageQueue taskTopicInfo = new MessageQueue(topic, qd.getBrokerName(), i);
+                            topicRouteMap.get(topic).add(taskTopicInfo);
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("Fetch topic list error.", e);
+        } finally {
+            // srcMQAdminExt.shutdown();
+        }
+    }
+
+
+    /**
+     * We need to reason why we don't call srcMQAdminExt.shutdown() here, and why
+     * it can be applied to srcMQAdminExt
+     */
+    @Override
+    public void stop() {
+        listenerHandle.cancel(true);
+        // srcMQAdminExt.shutdown();

Review comment:
       remove unused code




-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] lizhiboo commented on pull request #800: [ISSUE #801]Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
lizhiboo commented on pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800#issuecomment-915041130


   > Pom can add maven-checkstyle-plugin to unify the code style
   
   added


-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] lizhiboo commented on a change in pull request #800: [ISSUE #801]Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
lizhiboo commented on a change in pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800#discussion_r704187632



##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/config/CloneUtils.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.rocketmq.connect.hudi.config;
+
+import java.io.*;
+
+public class CloneUtils {
+    @SuppressWarnings("unchecked")
+    public static <T extends Serializable> T clone(T obj) {
+        T clonedObj = null;
+        try {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ObjectOutputStream oos = new ObjectOutputStream(baos);
+            oos.writeObject(obj);
+            oos.close();
+
+            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+            ObjectInputStream ois = new ObjectInputStream(bais);
+            clonedObj = (T) ois.readObject();
+            ois.close();
+        } catch (Exception e) {
+            e.printStackTrace();

Review comment:
       done




-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] lizhiboo commented on a change in pull request #800: [ISSUE #801]Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
lizhiboo commented on a change in pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800#discussion_r704184752



##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/connector/HudiSinkConnector.java
##########
@@ -0,0 +1,248 @@
+
+/*
+ * 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.rocketmq.connect.hudi.connector;
+
+
+import com.alibaba.fastjson.JSONObject;
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.Task;
+import io.openmessaging.connector.api.sink.SinkConnector;
+import io.openmessaging.internal.DefaultKeyValue;
+import org.apache.commons.lang3.concurrent.BasicThreadFactory;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.message.MessageQueue;
+import org.apache.rocketmq.common.protocol.route.BrokerData;
+import org.apache.rocketmq.common.protocol.route.QueueData;
+import org.apache.rocketmq.common.protocol.route.TopicRouteData;
+import org.apache.rocketmq.connect.hudi.config.*;
+import org.apache.rocketmq.connect.hudi.strategy.ITaskDivideStrategy;
+import org.apache.rocketmq.connect.hudi.strategy.TaskDivideStrategyFactory;
+import org.apache.rocketmq.remoting.RPCHook;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.ArrayList;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+
+public class HudiSinkConnector extends SinkConnector{
+    private static final Logger log = LoggerFactory.getLogger(HudiSinkConnector.class);
+    private volatile boolean configValid = false;
+    private ScheduledExecutorService executor;
+    private HashMap<String, Set<MessageQueue>> topicRouteMap;
+
+    private DefaultMQAdminExt srcMQAdminExt;
+    private SinkConnectConfig sinkConnectConfig;
+
+    private volatile boolean adminStarted;
+
+    private ScheduledFuture<?> listenerHandle;
+    public static String HUDI_CONNECTOR_ADMIN_PREFIX = "HUDI-CONNECTOR-ADMIN";
+    public static final String PREFIX = "hudi";
+
+    public HudiSinkConnector() {
+        topicRouteMap = new HashMap<>();
+        sinkConnectConfig = new SinkConnectConfig();
+        executor = Executors.newSingleThreadScheduledExecutor(new BasicThreadFactory.Builder().namingPattern("HudiFSinkConnector-SinkWatcher-%d").daemon(true).build());
+    }
+
+    private synchronized void startMQAdminTools() {
+        if (!configValid || adminStarted) {
+            return;
+        }
+        RPCHook rpcHook = null;
+        this.srcMQAdminExt = new DefaultMQAdminExt(rpcHook);
+        this.srcMQAdminExt.setNamesrvAddr(this.sinkConnectConfig.getSrcNamesrvs());
+        this.srcMQAdminExt.setAdminExtGroup(Utils.createGroupName(HUDI_CONNECTOR_ADMIN_PREFIX));
+        this.srcMQAdminExt.setInstanceName(Utils.createInstanceName(this.sinkConnectConfig.getSrcNamesrvs()));
+
+        try {
+            log.info("Trying to start srcMQAdminExt");
+            this.srcMQAdminExt.start();
+            log.info("RocketMQ srcMQAdminExt started");
+
+        } catch (MQClientException e) {
+            log.error("Hudi Sink Task start failed for `srcMQAdminExt` exception.", e);
+        }
+
+        adminStarted = true;
+    }
+
+    @Override
+    public String verifyAndSetConfig(KeyValue config) {
+        for (String requestKey : HudiConnectConfig.REQUEST_CONFIG) {
+            if (!config.containsKey(requestKey)) {
+                return "Request config key: " + requestKey;
+            }
+        }
+        try {
+            this.sinkConnectConfig.validate(config);
+        } catch (IllegalArgumentException e) {
+            return e.getMessage();
+        }
+        this.configValid = true;
+
+        return "";
+    }
+
+    @Override
+    public void start() {
+        startMQAdminTools();
+        startListener();
+    }
+
+    public void startListener() {
+        listenerHandle = executor.scheduleAtFixedRate(new Runnable() {
+            boolean first = true;
+            HashMap<String, Set<MessageQueue>> origin = null;
+
+            @Override
+            public void run() {
+                buildRoute();
+                if (first) {
+                    origin = CloneUtils.clone(topicRouteMap);
+                    first = false;
+                }
+                if (!compare(origin, topicRouteMap)) {
+                    context.requestTaskReconfiguration();
+                    origin = CloneUtils.clone(topicRouteMap);
+                }
+            }
+        }, sinkConnectConfig.getRefreshInterval(), sinkConnectConfig.getRefreshInterval(), TimeUnit.SECONDS);
+    }
+
+    public boolean compare(Map<String, Set<MessageQueue>> origin, Map<String, Set<MessageQueue>> updated) {
+        if (origin.size() != updated.size()) {
+            return false;
+        }
+        for (Map.Entry<String, Set<MessageQueue>> entry : origin.entrySet()) {
+            if (!updated.containsKey(entry.getKey())) {
+                return false;
+            }
+            Set<MessageQueue> originTasks = entry.getValue();
+            Set<MessageQueue> updateTasks = updated.get(entry.getKey());
+            if (originTasks.size() != updateTasks.size()) {
+                return false;
+            }
+
+            if (!originTasks.containsAll(updateTasks)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    public void buildRoute() {
+        String srcCluster = this.sinkConnectConfig.getSrcCluster();
+        try {
+            for (String topic : this.sinkConnectConfig.getWhiteList()) {
+
+                // different from BrokerData with cluster field, which can ensure the brokerData is from expected cluster.
+                // QueueData use brokerName as unique info on cluster of rocketmq. so when we want to get QueueData of
+                // expected cluster, we should get brokerNames of expected cluster, and then filter queueDatas.
+                List<BrokerData> brokerList = Utils.examineBrokerData(this.srcMQAdminExt, topic, srcCluster);
+                Set<String> brokerNameSet = new HashSet<String>();
+                for (BrokerData b : brokerList) {
+                    brokerNameSet.add(b.getBrokerName());
+                }
+
+                TopicRouteData topicRouteData = srcMQAdminExt.examineTopicRouteInfo(topic);
+                if (!topicRouteMap.containsKey(topic)) {
+                    topicRouteMap.put(topic, new HashSet<>(16));
+                }
+                for (QueueData qd : topicRouteData.getQueueDatas()) {
+                    if (brokerNameSet.contains(qd.getBrokerName())) {
+                        for (int i = 0; i < qd.getReadQueueNums(); i++) {
+                            MessageQueue taskTopicInfo = new MessageQueue(topic, qd.getBrokerName(), i);
+                            topicRouteMap.get(topic).add(taskTopicInfo);
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("Fetch topic list error.", e);
+        } finally {

Review comment:
       changed

##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/connector/HudiSinkConnector.java
##########
@@ -0,0 +1,248 @@
+
+/*
+ * 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.rocketmq.connect.hudi.connector;
+
+
+import com.alibaba.fastjson.JSONObject;
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.Task;
+import io.openmessaging.connector.api.sink.SinkConnector;
+import io.openmessaging.internal.DefaultKeyValue;
+import org.apache.commons.lang3.concurrent.BasicThreadFactory;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.message.MessageQueue;
+import org.apache.rocketmq.common.protocol.route.BrokerData;
+import org.apache.rocketmq.common.protocol.route.QueueData;
+import org.apache.rocketmq.common.protocol.route.TopicRouteData;
+import org.apache.rocketmq.connect.hudi.config.*;
+import org.apache.rocketmq.connect.hudi.strategy.ITaskDivideStrategy;
+import org.apache.rocketmq.connect.hudi.strategy.TaskDivideStrategyFactory;
+import org.apache.rocketmq.remoting.RPCHook;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.ArrayList;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+
+public class HudiSinkConnector extends SinkConnector{
+    private static final Logger log = LoggerFactory.getLogger(HudiSinkConnector.class);
+    private volatile boolean configValid = false;
+    private ScheduledExecutorService executor;
+    private HashMap<String, Set<MessageQueue>> topicRouteMap;
+
+    private DefaultMQAdminExt srcMQAdminExt;
+    private SinkConnectConfig sinkConnectConfig;
+
+    private volatile boolean adminStarted;
+
+    private ScheduledFuture<?> listenerHandle;
+    public static String HUDI_CONNECTOR_ADMIN_PREFIX = "HUDI-CONNECTOR-ADMIN";
+    public static final String PREFIX = "hudi";
+
+    public HudiSinkConnector() {
+        topicRouteMap = new HashMap<>();
+        sinkConnectConfig = new SinkConnectConfig();
+        executor = Executors.newSingleThreadScheduledExecutor(new BasicThreadFactory.Builder().namingPattern("HudiFSinkConnector-SinkWatcher-%d").daemon(true).build());
+    }
+
+    private synchronized void startMQAdminTools() {
+        if (!configValid || adminStarted) {
+            return;
+        }
+        RPCHook rpcHook = null;
+        this.srcMQAdminExt = new DefaultMQAdminExt(rpcHook);
+        this.srcMQAdminExt.setNamesrvAddr(this.sinkConnectConfig.getSrcNamesrvs());
+        this.srcMQAdminExt.setAdminExtGroup(Utils.createGroupName(HUDI_CONNECTOR_ADMIN_PREFIX));
+        this.srcMQAdminExt.setInstanceName(Utils.createInstanceName(this.sinkConnectConfig.getSrcNamesrvs()));
+
+        try {
+            log.info("Trying to start srcMQAdminExt");
+            this.srcMQAdminExt.start();
+            log.info("RocketMQ srcMQAdminExt started");
+
+        } catch (MQClientException e) {
+            log.error("Hudi Sink Task start failed for `srcMQAdminExt` exception.", e);
+        }
+
+        adminStarted = true;
+    }
+
+    @Override
+    public String verifyAndSetConfig(KeyValue config) {
+        for (String requestKey : HudiConnectConfig.REQUEST_CONFIG) {
+            if (!config.containsKey(requestKey)) {
+                return "Request config key: " + requestKey;
+            }
+        }
+        try {
+            this.sinkConnectConfig.validate(config);
+        } catch (IllegalArgumentException e) {
+            return e.getMessage();
+        }
+        this.configValid = true;
+
+        return "";
+    }
+
+    @Override
+    public void start() {
+        startMQAdminTools();
+        startListener();
+    }
+
+    public void startListener() {
+        listenerHandle = executor.scheduleAtFixedRate(new Runnable() {
+            boolean first = true;
+            HashMap<String, Set<MessageQueue>> origin = null;
+
+            @Override
+            public void run() {
+                buildRoute();
+                if (first) {
+                    origin = CloneUtils.clone(topicRouteMap);
+                    first = false;
+                }
+                if (!compare(origin, topicRouteMap)) {
+                    context.requestTaskReconfiguration();
+                    origin = CloneUtils.clone(topicRouteMap);
+                }
+            }
+        }, sinkConnectConfig.getRefreshInterval(), sinkConnectConfig.getRefreshInterval(), TimeUnit.SECONDS);
+    }
+
+    public boolean compare(Map<String, Set<MessageQueue>> origin, Map<String, Set<MessageQueue>> updated) {
+        if (origin.size() != updated.size()) {
+            return false;
+        }
+        for (Map.Entry<String, Set<MessageQueue>> entry : origin.entrySet()) {
+            if (!updated.containsKey(entry.getKey())) {
+                return false;
+            }
+            Set<MessageQueue> originTasks = entry.getValue();
+            Set<MessageQueue> updateTasks = updated.get(entry.getKey());
+            if (originTasks.size() != updateTasks.size()) {
+                return false;
+            }
+
+            if (!originTasks.containsAll(updateTasks)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    public void buildRoute() {
+        String srcCluster = this.sinkConnectConfig.getSrcCluster();
+        try {
+            for (String topic : this.sinkConnectConfig.getWhiteList()) {
+
+                // different from BrokerData with cluster field, which can ensure the brokerData is from expected cluster.
+                // QueueData use brokerName as unique info on cluster of rocketmq. so when we want to get QueueData of
+                // expected cluster, we should get brokerNames of expected cluster, and then filter queueDatas.
+                List<BrokerData> brokerList = Utils.examineBrokerData(this.srcMQAdminExt, topic, srcCluster);
+                Set<String> brokerNameSet = new HashSet<String>();
+                for (BrokerData b : brokerList) {
+                    brokerNameSet.add(b.getBrokerName());
+                }
+
+                TopicRouteData topicRouteData = srcMQAdminExt.examineTopicRouteInfo(topic);
+                if (!topicRouteMap.containsKey(topic)) {
+                    topicRouteMap.put(topic, new HashSet<>(16));
+                }
+                for (QueueData qd : topicRouteData.getQueueDatas()) {
+                    if (brokerNameSet.contains(qd.getBrokerName())) {
+                        for (int i = 0; i < qd.getReadQueueNums(); i++) {
+                            MessageQueue taskTopicInfo = new MessageQueue(topic, qd.getBrokerName(), i);
+                            topicRouteMap.get(topic).add(taskTopicInfo);
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("Fetch topic list error.", e);
+        } finally {
+            // srcMQAdminExt.shutdown();
+        }
+    }
+
+
+    /**
+     * We need to reason why we don't call srcMQAdminExt.shutdown() here, and why
+     * it can be applied to srcMQAdminExt
+     */
+    @Override
+    public void stop() {
+        listenerHandle.cancel(true);
+        // srcMQAdminExt.shutdown();

Review comment:
       done

##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/strategy/ITaskDivideStrategy.java
##########
@@ -0,0 +1,13 @@
+package org.apache.rocketmq.connect.hudi.strategy;
+
+import io.openmessaging.KeyValue;
+
+import java.util.List;
+
+/**
+ * @author osgoo

Review comment:
       done

##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/strategy/TaskDivideByQueueStrategy.java
##########
@@ -0,0 +1,64 @@
+package org.apache.rocketmq.connect.hudi.strategy;
+
+import com.alibaba.fastjson.JSONObject;
+import io.openmessaging.KeyValue;
+import io.openmessaging.internal.DefaultKeyValue;
+import org.apache.rocketmq.common.message.MessageQueue;
+import org.apache.rocketmq.connect.hudi.config.HudiConnectConfig;
+
+import java.util.*;
+
+import static org.apache.rocketmq.connect.hudi.config.HudiConnectConfig.*;
+
+/**
+ * @author osgoo

Review comment:
       done

##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/strategy/TaskDivideStrategyFactory.java
##########
@@ -0,0 +1,11 @@
+package org.apache.rocketmq.connect.hudi.strategy;
+
+/**
+ * @author osgoo

Review comment:
       done

##########
File path: rocketmq-connect/rocketmq-connect-runtime/src/main/java/org/apache/rocketmq/connect/runtime/ConnectStartup.java
##########
@@ -48,6 +48,7 @@
 
     public static void main(String[] args) {
 
+        args = new String[] {"-c", "/Users/osgoo/Documents/workspace/lizhiboo/rocketmq-externals/rocketmq-connect/rocketmq-connect-runtime/target/distribution/conf/connect.conf"};

Review comment:
       done




-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] lizhiboo edited a comment on pull request #800: Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
lizhiboo edited a comment on pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800#issuecomment-908185971


   issue refer #801 


-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] lizhiboo commented on a change in pull request #800: [ISSUE #801]Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
lizhiboo commented on a change in pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800#discussion_r704183935



##########
File path: rocketmq-connect-hudi/src/main/java/org/apache/rocketmq/connect/hudi/connector/HudiSinkTask.java
##########
@@ -0,0 +1,124 @@
+
+/*
+ * 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.rocketmq.connect.hudi.connector;
+
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.common.QueueMetaData;
+import io.openmessaging.connector.api.data.SinkDataEntry;
+import io.openmessaging.connector.api.sink.SinkTask;
+import org.apache.rocketmq.connect.hudi.config.HudiConnectConfig;
+import org.apache.rocketmq.connect.hudi.config.ConfigUtil;
+import org.apache.rocketmq.connect.hudi.sink.Updater;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+
+/**
+ * In the naming, we are using database for "keyspaces" and table for "columnFamily"
+ * This is because we kind of want the abstract data source to be aligned with SQL databases
+ */
+public class HudiSinkTask extends SinkTask {
+    private static final Logger log = LoggerFactory.getLogger(HudiSinkTask.class);
+
+    private HudiConnectConfig hudiConnectConfig;
+    private Updater updater;
+    private BlockingQueue<Updater> tableQueue = new LinkedBlockingQueue<Updater>();
+
+    public HudiSinkTask() {
+        this.hudiConnectConfig = new HudiConnectConfig();
+    }
+
+    @Override
+    public void put(Collection<SinkDataEntry> sinkDataEntries) {
+        try {
+            if (tableQueue.size() > 1) {
+                updater = tableQueue.poll(1000, TimeUnit.MILLISECONDS);
+            } else {
+                updater = tableQueue.peek();
+            }
+            log.info("Hudi Sink Task trying to put()");
+            for (SinkDataEntry record : sinkDataEntries) {
+                log.info("Hudi Sink Task trying to call updater.push()");
+                Boolean isSuccess = updater.push(record);
+                if (!isSuccess) {
+                    log.error("push data error, record:{}", record);
+                }
+            }
+        } catch (Exception e) {
+            log.error("put sinkDataEntries error, {}", e);
+        }
+    }
+
+    @Override
+    public void commit(Map<QueueMetaData, Long> map) {
+
+    }
+
+    /**
+     * Remember always close the CqlSession according to
+     * https://docs.datastax.com/en/developer/java-driver/4.5/manual/core/
+     * @param props
+     */
+    @Override
+    public void start(KeyValue props) {
+        try {
+            ConfigUtil.load(props, this.hudiConnectConfig);
+            log.info("init data source success");
+        } catch (Exception e) {
+            log.error("Cannot start Hudi Sink Task because of configuration error{}", e);
+        }
+        try {
+            Updater updater = new Updater(hudiConnectConfig);
+            updater.start();
+            tableQueue.add(updater);
+        } catch (Exception e) {
+            log.error("fail to start updater{}", e);
+        }
+
+
+    }
+
+    @Override
+    public void stop() {
+        try {
+            for(Updater updater : tableQueue) {
+                updater.start();

Review comment:
       done

##########
File path: rocketmq-connect-hudi/src/main/java/example/avro/User.java
##########
@@ -0,0 +1,501 @@
+package example.avro; /**
+ * Autogenerated by Avro
+ *
+ * DO NOT EDIT DIRECTLY
+ */
+
+import org.apache.avro.message.BinaryMessageDecoder;
+import org.apache.avro.message.BinaryMessageEncoder;
+import org.apache.avro.message.SchemaStore;
+import org.apache.avro.specific.SpecificData;
+import org.apache.avro.util.Utf8;
+
+@org.apache.avro.specific.AvroGenerated
+public class User extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {

Review comment:
       removed




-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] lizhiboo commented on pull request #800: Rocketmq connector sink for hudi

Posted by GitBox <gi...@apache.org>.
lizhiboo commented on pull request #800:
URL: https://github.com/apache/rocketmq-externals/pull/800#issuecomment-908185971


   #801 


-- 
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: dev-unsubscribe@rocketmq.apache.org

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