I have problem with kafka consumer using group.id....
# troubleshooting
h
I have problem with kafka consumer using group.id. I have created the table `CREATE TABLE `ODS_STMT_ENTRY``
()
WITH (
'connector' = 'kafka',
'topic' = 'ODS_STMT_ENTRY_FLINK',
'properties.bootstrap.servers' = 'dc1-dev-kkbro01.seauat.com.vn:9092',
'properties.group.id' = 'ACCT',
'scan.startup.mode' = 'latest-offset',
...
);
My topic
ODS_STMT_ENTRY_FLINK
has 3 partitions. Then run the two `select * from `ODS_STMT_ENTRY`` jobs in parallel. As a result, both read all received messages without division. I use flink 1.8, can anyone tell me how to handle it?
w
just curious, in which catalog is this table?
h
@Woohyuck Choi defaut_catalog
w
maybe you could share more info 🤔 I suspect: any chance the same table is declared in each job? because the default_catalog is persistent within a session? + I'm not quite certain how Flink controls Kafka offsets under the hood, but according to the Doc, it doesn't use the typical 'keep offsets within Kafka'. https://nightlies.apache.org/flink/flink-docs-release-1.18/docs/connectors/datastream/kafka/#consumer-offset-committing
h
@Woohyuck Choi I have read it but i don't know how to fix in flink sql
w
Sorry. If you want to read all the messages somehow divided, there are many ways you can deal with it. • per partition
Copy code
CREATE TABLE `ODS_STMT_ENTRY`
(
    ...
    `partition` BIGINT METADATA VIRTUAL,
    ...
)
WITH (
     'connector' = 'kafka',
     'topic' = 'ODS_STMT_ENTRY_FLINK',
     'properties.bootstrap.servers' = 'dc1-dev-kkbro01.seauat.com.vn:9092',
     'properties.group.id' = 'ACCT',
     'scan.startup.mode' = 'latest-offset',
  ...
);

-- job 1 reads from even partitions
INSERT INTO some_sinks AS
SELECT
    *
FROM
    `ODS_STMT_ENTRY`
WHERE
    `partition` % 2 = 0
;

-- job 2 reads from odd partitions
INSERT INTO some_sinks AS
SELECT
    *
FROM
    `ODS_STMT_ENTRY`
WHERE
    `partition` % 2 = 1
;
• per other columns • randomly (not quite useful), etc According to the docs and Stackoverflow, Flink commits offsets at checkpoint. (Flink doesn't use the good old subscribe API, but the assign API) Therefore what you tried first (having multiple consumers with the same group id) will not work as expected. Hope it helps.
h
@Woohyuck Choi I want to use group.id to increase the system's fault tolerance, not to read messages by partitions
m
I want to use group.id to increase the system's fault tolerance, not to read messages by partitions
Flink relies on its checkpoint/savepoint mechanism for fault tolerance, you can't use Kafka's group.id system for this
h
@Martijn Visser do you know why flink doesn't generate consumerID and ClientID?
m
Flink only commits offsets back when you have enabled checkpointing, and only for monitoring purposes.
h
Hi @Martijn Visser, I tested the checkpoint for fault tolerance in case a worker is lost. I want to ask about some checkpoint cases where work cannot be restored? For example, if the master is lost, can checkpoint/savepoint be met?
m
If a JobManager or one of the TaskManagers is lost, then all of the Flink job will restart (if you have a restart policy configured) from the checkpoint.
m
i am also facing the same issue when i run my flink job on multiple ec2 instances with same group.id. i want one kafka message to be processed only once but it is getting processed multiple times exactly equal to the no of instances on which the job is running. checkpoint interval on job is 1 min with EXACTLY_ONCE semantics. any ideas/suggestions to mitigate this behaviour ?