Consume Hologres binlog data with Flink
This topic describes how to use Realtime Compute for Apache Flink to consume Hologres binlog data in real time.
Usage notes
Before consuming Hologres binlog data, note the following:
You can consume binlog data only from Hologres V0.9 or later. You can configure an engine whitelist only for Hologres V1.3.21 or later. If you enable a whitelist on an instance that runs a version earlier than Hologres V1.3.21, binlog consumption fails. If your instance version is earlier than required, you can Obtain online support for Hologres for assistance.
Hologres supports the binlog feature at the table level for row-oriented tables and column-oriented tables. Starting from Hologres V1.1, row-column hybrid storage tables are also supported. After you enable the binlog feature, column-oriented tables theoretically have higher overhead than row-oriented tables. Therefore, for scenarios with frequent data updates, we recommend that you enable the binlog feature for row-oriented tables.
For more information about binlog support and how to enable and configure this feature, see Subscribe to Hologres binlogs.
Only Realtime Compute for Apache Flink provided by Alibaba Cloud supports consuming Hologres binlog data. In HoloHub mode, consuming Hologres binlog data with Flink supports only simple data types. Starting with Flink VVR 6.0.3, you can consume Hologres binlog data in JDBC mode. Compared with HoloHub mode, JDBC mode supports more data types. For more information, see Data type mappings between Blink/Flink and Hologres. This mode requires additional permissions. For details, see Permissions.
You cannot consume binlog data from a parent partitioned table.
Hologres V2.0 offers limited support for HoloHub mode. Starting from V2.1, HoloHub mode is deprecated and fully replaced by JDBC mode. Before you upgrade your Hologres instance, refer to Switch from HoloHub mode to JDBC mode to check your Flink jobs that currently use HoloHub mode, upgrade your Flink VVR jobs accordingly, and then upgrade your Hologres instance.
Permissions
Unlike HoloHub mode, JDBC mode supports custom Hologres accounts when you use Realtime Compute for Apache Flink to consume Hologres binlog data.
To consume Hologres binlog data in HoloHub mode, your Flink job requires read and write permissions on the table.
To consume Hologres binlog data in JDBC mode, the following prerequisites apply: For more information, see Consume binlog data by using JDBC.
The
hg_binlogextension is created. This extension is created by default in Hologres V2.0 and later.The user is a superuser of the instance, or has both owner permissions on the target table and replication role permissions for the instance.
Consume binlog data with Flink
Realtime Compute for Apache Flink that uses VVR 2.4 or later supports real-time consumption of binlog data by using the Hologres Connector. The following sections describe how to use this feature.
Source table DDL in non-CDC mode
In this mode, the binlog data consumed by the Source is passed to downstream nodes as regular Flink data. This means all data is treated as data of the Insert type, and you can choose how to process data of a specific hg_binlog_event_type type based on your business requirements. After binlog is enabled for a Hologres table, you can use the following DDL for a source table (in non-CDC mode) in Flink to consume the binlog in real time.
create table test_message_src_binlog_table(
hg_binlog_lsn BIGINT,
hg_binlog_event_type BIGINT,
hg_binlog_timestamp_us BIGINT,
id INTEGER,
title VARCHAR,
body VARCHAR
) with (
'connector'='hologres',
'dbname'='<yourDbname>',
'tablename'='<yourTablename>',
'username'='<yourAccessID>',
'password'='<yourAccessSecret>',
'endpoint'='<yourEndpoint>',
'binlog' = 'true',
'binlogMaxRetryTimes' = '10',
'binlogRetryIntervalMs' = '500',
'binlogBatchReadSize' = '100'
);The three
binlogxxxparameters are binlog system fields. Their names and types are fixed and cannot be modified.Other fields correspond to your user-defined fields and must be in all lowercase.
Source table DDL in CDC mode
In this mode, the Source consumes binlog data and automatically sets the correct Flink RowKind type (INSERT, DELETE, UPDATE_BEFORE, or UPDATE_AFTER) for each row based on the hg_binlog_event_type. This enables mirror synchronization of table data, similar to the CDC feature in MySQL and PostgreSQL.
Hologres binlog source tables in CDC mode do not currently support watermark definitions. If you need to perform window aggregation, you can use a non-windowing approach. For more information, see How do I implement minute-level aggregation when CDC source tables do not support window functions?.
After you enable the binlog feature for a Hologres table, you can use the following DDL in Flink to create a source table to consume binlog data in real time in CDC mode.
create table test_message_src_binlog_table(
id INTEGER,
title VARCHAR,
body VARCHAR
) with (
'connector'='hologres',
'dbname'='<yourDbname>',
'tablename'='<yourTablename>',
'username'='<yourAccessID>',
'password'='<yourAccessSecret>',
'endpoint'='<yourEndpoint>',
'binlog' = 'true',
'cdcMode' = 'true',
'binlogMaxRetryTimes' = '10',
'binlogRetryIntervalMs' = '500',
'binlogBatchReadSize' = '100'
);Source table for full and incremental data
Starting from VVR engine 1.13-vvr-4.0.13 and Hologres V0.10, the Hologres binlog CDC source table supports integrated consumption of full and incremental data. This method first reads the historical full data from the database and then smoothly transitions to reading incremental data from the binlog. For more information, see Hologres real-time data warehouse.
Binlog source table in JDBC mode
Starting with Flink VVR 6.0.3, you can consume Hologres binlog data in JDBC mode. Compared with HoloHub mode, JDBC mode supports more data types and custom accounts. For more information about how to use JDBC mode, see Hologres real-time data warehouse.
Switch from HoloHub mode to JDBC mode
Hologres began phasing out HoloHub mode in V2.0. If you need to upgrade your Hologres instance, you must switch your jobs from HoloHub mode to JDBC mode as described below.
Upgrade to V2.1
Before you upgrade your Hologres instance to V2.1, choose one of the following solutions to check your Flink jobs and Hologres instance to ensure the jobs run as expected.
(Solution 1) (Recommended) Upgrade your Flink VVR version to 8.0.7 or later. Flink automatically switches from HoloHub mode to JDBC mode.
(Solution 2) Upgrade your Flink VVR to a version between 6.0.7 and 8.0.5. Add the parameter
'sdkMode'='jdbc'to the source table and restart the job. You must also grant the user one of the following permission sets. After you confirm that the job runs properly, you can upgrade the Hologres instance.(Option 1) superuser permissions on the instance.
(Option 2) owner permissions on the target table, the CREATE DATABASE permission, and replication role permissions for the instance.
(Solution 3) (Not recommended) Upgrade the Flink VVR version to 8.0.6. Flink automatically switches from HoloHub mode to JDBC mode. However, VVR 8.0.6 has a known defect that may cause job deployment to time out if a dimension table contains too many fields. For more information, see Hologres Connector Release Notes.
(Optional) If you have many Flink VVR jobs, use the following instructions to identify which jobs and tables require an upgrade.
Upgrade to V2.0
(Solution 1) (Recommended) Upgrade your Flink VVR version to 8.0.6 or later. Flink automatically switches from HoloHub mode to JDBC mode. However, VVR 8.0.6 has a known defect that may cause job deployment to time out if a dimension table contains too many fields. For more information, see Hologres Connector Release Notes. We recommend that you upgrade to VVR 8.0.7.
(Solution 2) Upgrade your Flink VVR version to 8.0.4 or 8.0.5 and restart the Flink job. You must also grant the user one of the following permission sets. After you confirm that the job runs properly, you can upgrade the Hologres instance.
(Option 1) superuser permissions on the instance.
(Option 2) owner permissions on the target table, the CREATE DATABASE permission, and replication role permissions for the instance.
(Solution 3) Upgrade your Flink VVR version to a version between 6.0.7 and 8.0.3. Flink continues to use HoloHub mode to consume binlog data.
If you have many Flink VVR jobs that consume Hologres binlog data, you can use the following method to identify the jobs and tables that need to be upgraded.
This tool can obtain information only for the following types of jobs:
SQL jobs that use DDL to define tables.
Catalog jobs that use hints to specify parameters.
The tool does not support obtaining information for JAR jobs or Catalog tables that do not have hint parameters.
Download the open-source tool find-incompatible-flink-jobs-1.0-SNAPSHOT-jar-with-dependencies.jar.
On a local command line, navigate to the open-source tool's directory and run the following command to view all jobs and tables that require an upgrade.
NoteTo run the following command, you must have a Java environment installed, with JDK 8 or later.
java -cp find-incompatible-flink-jobs-1.0-SNAPSHOT-jar-with-dependencies.jar com.alibaba.hologres.FindIncompatibleFlinkJobs <region> <url> <AccessKeyID> <AccessKeySecret> <binlog/rpc> # Example java -cp find-incompatible-flink-jobs-1.0-SNAPSHOT-jar-with-dependencies.jar com.alibaba.hologres.FindIncompatibleFlinkJobs Beijing https://vvp.console.aliyun.com/web/xxxxxx/en/#/workspaces/xxxx/namespaces/xxxx/operations/stream/xxxx my-access-key-id my-access-key-secret binlogThe following table describes the parameters.
Parameter
Description
region
The region where your Realtime Compute for Apache Flink workspace is located. For a list of valid values, see the Region values table.
url
The URL of any job in the target Realtime Compute for Apache Flink workspace.
AccessKey ID
The AccessKey ID for an account that has permission to access the Realtime Compute for Apache Flink workspace.
AccessKey secret
The AccessKey secret for an account that has permission to access the Realtime Compute for Apache Flink workspace.
binlog/rpc
The type of job content to check. Valid values:
binlog: Checks all Hologres binlog source tables in all jobs within the workspace.rpc: Checks all dimension tables or result tables that userpcmode in all jobs within the workspace.
The following code provides a sample result.
dwd_xxx nx not a running job, skip dwd_st xxx not a running job, skip dwd_xxx a not a running job, skip dia xxx not a hologres job, skip dwd_tr xxx ail not sql job, skip --- The following are Hologres binlog source tables that are on a version earlier than 8.0.5 and do not have sdkmode = jdbc set --- deploymentName version tableName ads_xxx xxx vvr-6.0.7-flink-1.15 adsdb.ads_xxx xxx xxx catalog xxx vvr-8.0.1-flink-1.17 odsdb.ods_xxx nts xxx vvr-8.0.1-flink-1.17 dwsdb.dws_xxx tag xxx s vvr-8.0.1-flink-1.17 odsdb.ods_xxx ers