yuzelin commented on code in PR #1586: URL: https://github.com/apache/incubator-paimon/pull/1586#discussion_r1270312555
########## docs/content/maintenance/manage-consumers.md: ########## @@ -0,0 +1,73 @@ +--- +title: "Manage Consumers" +weight: 9 +type: docs +aliases: +- /maintenance/manage-consumers.html +--- +<!-- +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. +--> + +# Manage Consumers + +## Record Consumer + +You can add or reset a consumer with a given consumer ID and next snapshot ID. + +{{< hint info >}} +First, you need to stop the streaming task using this consumer ID, and then execute the record consumer action job. +{{< /hint >}} + +{{< tabs "record-consumer" >}} + +{{< tab "Flink" >}} + + Run the following command: + +```bash +<FLINK_HOME>/bin/flink run \ + /path/to/paimon-flink-action-{{< version >}}.jar \ + record-consumer \ + --warehouse <warehouse-path> \ + --database <database-name> \ + --table <table-name> \ + --consumer-id <consumer-id> \ + --snapshot <next-snapshot-id> \ Review Comment: How about renaming this argument to `--next-snapshot`? ########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/consumer/RecordConsumerAction.java: ########## @@ -0,0 +1,47 @@ +/* + * 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.paimon.flink.action.consumer; + +import org.apache.paimon.flink.action.TableActionBase; + +import java.util.Map; + +/** Record consumer action for Flink. */ +public class RecordConsumerAction extends TableActionBase { Review Comment: I think it's unnecessary to place this action to a new package folder. ########## paimon-e2e-tests/src/test/java/org/apache/paimon/tests/FlinkActionsE2eTest.java: ########## @@ -400,6 +400,79 @@ public void testCreateAndDeleteTag() throws Exception { checkResult(); } + @Test + public void testRecordConsumer() throws Exception { + String tableDdl = + "CREATE TABLE IF NOT EXISTS T (\n" + + " k INT,\n" + + " v STRING,\n" + + " PRIMARY KEY (k) NOT ENFORCED\n" + + ");\n"; + + String inserts = + "INSERT INTO T VALUES (1, 'Apache');\n" + + "INSERT INTO T VALUES (2, 'Flink');\n" + + "INSERT INTO T VALUES (3, 'Paimon');\n"; + + runSql("SET 'table.dml-sync' = 'true';\n" + inserts, catalogDdl, useCatalogCmd, tableDdl); + + runSql( + "SET 'execution.checkpointing.interval' = '5s';\n" + + "INSERT INTO result1 SELECT * FROM T /*+ OPTIONS('consumer-id'='myid') */;", + catalogDdl, + useCatalogCmd, + tableDdl, + createResultSink("result1", "k INT, v STRING")); + checkResult("1, Apache", "2, Flink", "3, Paimon"); + clearCurrentResults(); + + runSql( + "SET 'execution.runtime-mode' = 'batch';\n" + + "RESET 'execution.checkpointing.interval';\n" + + "INSERT INTO _consumers1 SELECT consumer_id, next_snapshot_id FROM T\\$consumers;", + catalogDdl, + useCatalogCmd, + tableDdl, + createResultSink("_consumers1", "consumer_id STRING, next_snapshot_id BIGINT")); + checkResult("myid, 4"); + clearCurrentResults(); + + // run reset consumer action job + Container.ExecResult execResult = + jobManager.execInContainer( + "bin/flink", + "run", + "-p", + "1", + "lib/paimon-flink-action.jar", + "record-consumer", + "--warehouse", + warehousePath, + "--database", + "default", + "--table", + "T", + "--consumer-id", + "myid", + "--snapshot", + "1"); + + LOG.info(execResult.getStdout()); + LOG.info(execResult.getStderr()); + + runSql( + "INSERT INTO _consumers2 SELECT consumer_id, next_snapshot_id FROM T\\$consumers;", + catalogDdl, + useCatalogCmd, + tableDdl, + createResultSink("_consumers2", "consumer_id STRING, next_snapshot_id BIGINT")); + + // The value of next_snapshot_id in the result is 4 instead of 1, + // because the streaming read task is running, and the consumer `myid` is reset again, + // overwriting the value written by the action job. + checkResult("myid, 4"); + } Review Comment: I think we can remove this test. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
