flink-cdc icon indicating copy to clipboard operation
flink-cdc copied to clipboard

MySqlStreamingChangeEventSource stoped reading Incremental binlog

Open cdjincan opened this issue 4 years ago • 6 comments

Describe the bug I use flink cdc to meet my business needs, but when I submit the program to the production environment, the new binlog cannot be connected to flink. The specific taskmanager log is as follows

Environment :

  • Flink version : 1.13.2
  • Flink CDC version: 2.0.2
  • Database and version: mysql 5.7

To Reproduce Steps to reproduce the behavior:

  1. Thes test data :
  2. The test code :
  3. The error :

image

Additional Description If applicable, add screenshots to help explain your problem.

cdjincan avatar Dec 18 '21 05:12 cdjincan

create table saas_dsorderdb_sale_order_dim( id BIGINT, --主键id batch_no STRING, order_no STRING, customer_id BIGINT, tenant_id BIGINT, store_id BIGINT, shop_code STRING, order_status BIGINT, biz_type BIGINT, real_pay_amount DECIMAL(10,2), total_point_amount DECIMAL(10,2), pay_time TIMESTAMP, pay_status BIGINT, updated_at TIMESTAMP, created_at TIMESTAMP, distribution_way BIGINT, primary key (id) NOT ENFORCED ) with( 'connector' = 'mysql-cdc', 'hostname' = '${parameterTools.get(MYSQL_HOSTNAME)}', 'port' = '${parameterTools.get(MYSQL_PORT)}', 'username' = '${parameterTools.get(MYSQL_USERNAME)}', 'password' = '${parameterTools.get(MYSQL_PASSWORD)}', 'database-name' = 'dsorderdb\d+', 'table-name' = 'order_sale\d+', 'scan.startup.mode' = 'initial', 'server-time-zone' = 'Asia/Shanghai' );

create table saas_mallorderdb_sale_order_dim( id BIGINT, --主键id batch_no STRING, order_no STRING, customer_id BIGINT, tenant_id BIGINT, store_id BIGINT, shop_code STRING, order_status BIGINT, biz_type BIGINT, real_pay_amount DECIMAL(10,2), total_point_amount DECIMAL(10,2), pay_time TIMESTAMP, pay_status BIGINT, logistics_status BIGINT, updated_at TIMESTAMP, created_at TIMESTAMP, distribution_way BIGINT, primary key (id) NOT ENFORCED ) with( 'connector' = 'mysql-cdc', 'hostname' = '${parameterTools.get(MYSQL_MALL_HOSTNAME)}', 'port' = '${parameterTools.get(MYSQL_PORT)}', 'username' = '${parameterTools.get(MYSQL_USERNAME)}', 'password' = '${parameterTools.get(MYSQL_PASSWORD)}', 'database-name' = 'mallorderdb\d+', 'table-name' = 'order_sale\d+', 'scan.startup.mode' = 'initial', 'server-time-zone' = 'Asia/Shanghai' )

create table saas_sink_order_day( tenant_id BIGINT, store_id BIGINT, shop_code STRING, biz_type BIGINT, cal_date STRING, pay_amount DECIMAL(10,2), pay_quantity BIGINT, cancel_amount DECIMAL(10,2), cancel_quantity BIGINT, delivery_completed BIGINT, delivery_canceled BIGINT, pickup_completed BIGINT, pickup_canceled BIGINT, PRIMARY KEY (tenant_id,store_id,shop_code,biz_type,cal_date) NOT ENFORCED ) with( 'connector' = 'jdbc', 'url' = 'jdbc:mysql://${parameterTools.get(MYSQL_HOSTNAME_MAINLIB)}:3306/saasreportdb', 'table-name' = 'homepage_order_survey', 'username' = '${parameterTools.get(MYSQL_USERNAME)}', 'password' = '${parameterTools.get(MYSQL_PASSWORD)}' );

INSERT INTO saas_sink_order_day SELECT tenant_id, store_id,shop_code, 2 AS biz_type, DATE_FORMAT(created_at,'yyyy-MM-dd') cal_date, SUM(IF(pay_status=3, real_pay_amount + total_point_amount, 0)) pay_amount, SUM(IF(pay_status=3, 1, 0)) pay_quantity, SUM(IF(order_status IN (1050,1060,1080,1081),real_pay_amount,0)) cancel_amount, SUM(IF(order_status IN (1050,1060,1080,1081),1,0)) cancel_quantity, SUM(IF(distribution_way=1 AND order_status= 1040,1,0)) delivery_completed, SUM(IF(distribution_way=1 AND order_status IN (1050,1060,1080,1081),1,0)) delivery_canceled, SUM(IF(distribution_way=2 AND order_status= 1040,1,0)) pickup_completed, SUM(IF(distribution_way=2 AND order_status IN (1050,1060,1080,1081),1,0)) pickup_canceled FROM saas_dsorderdb_sale_order_dim /*+ OPTIONS('server-id' = '3201-3210') / WHERE biz_type = 1 AND DATE_FORMAT(created_at,'yyyy-MM-dd') >= DATE_FORMAT(NOW(),'yyyy-MM-dd') GROUP BY tenant_id, store_id,shop_code,DATE_FORMAT(created_at,'yyyy-MM-dd') UNION ALL SELECT tenant_id, store_id,shop_code, biz_type, DATE_FORMAT(created_at,'yyyy-MM-dd') cal_date, SUM(IF(pay_status=3, real_pay_amount + total_point_amount, 0)) pay_amount, SUM(IF(pay_status=3, 1, 0)) pay_quantity, SUM(IF(order_status IN (1050,1060,1080,1081),real_pay_amount,0)) cancel_amount, SUM(IF(order_status IN (1050,1060,1080,1081),1,0)) cancel_quantity, SUM(IF(distribution_way=1 AND order_status= 1040,1,0)) delivery_completed, SUM(IF(distribution_way=1 AND order_status IN (1050,1060,1080,1081),1,0)) delivery_canceled, SUM(IF(distribution_way=2 AND order_status= 1040,1,0)) pickup_completed, SUM(IF(distribution_way=2 AND order_status IN (1050,1060,1080,1081),1,0)) pickup_canceled FROM saas_mallorderdb_sale_order_dim /+ OPTIONS('server-id' = '3211-3220') */ WHERE biz_type in (1,3) AND DATE_FORMAT(created_at,'yyyy-MM-dd') >= DATE_FORMAT(NOW(),'yyyy-MM-dd') GROUP BY tenant_id, store_id,shop_code,biz_type,DATE_FORMAT(created_at,'yyyy-MM-dd')

cdjincan avatar Dec 18 '21 06:12 cdjincan

The incremental data on the day of the task start can be read, but by the next day, one of the sources will not consume the latest binlog, but this situation only exists in the production environment, and the test environment is ok.

cdjincan avatar Dec 18 '21 06:12 cdjincan

image Stop receiving new binlogs on time the next day,how can i solve this problem? @leonardBang

cdjincan avatar Dec 18 '21 17:12 cdjincan

I have the same problem, did you solve it?

someorz avatar May 09 '23 03:05 someorz

private void listenForEventPackets() throws IOException {
        ByteArrayInputStream inputStream = channel.getInputStream();
        boolean completeShutdown = false;
        try {
            while (inputStream.peek() != -1) {
                int packetLength = inputStream.readInteger(3);
                inputStream.skip(1); // 1 byte for sequence
                int marker = inputStream.read();
                if (marker == 0xFF) {
                    ErrorPacket errorPacket = new ErrorPacket(inputStream.read(packetLength - 1));
                    throw new ServerException(errorPacket.getErrorMessage(), errorPacket.getErrorCode(),
                        errorPacket.getSqlState());
                }
                if (marker == 0xFE && !blocking) {
                    completeShutdown = true;
                    break;
                }
                Event event;
                try {
                    event = eventDeserializer.nextEvent(packetLength == MAX_PACKET_LENGTH ?
                        new ByteArrayInputStream(readPacketSplitInChunks(inputStream, packetLength - 1)) :
                        inputStream);
                    if (event == null) {
                        throw new EOFException();
                    }
                } catch (Exception e) {
                    Throwable cause = e instanceof EventDataDeserializationException ? e.getCause() : e;
                    if (cause instanceof EOFException || cause instanceof SocketException) {
                        throw e;
                    }
                    if (isConnected()) {
                        for (LifecycleListener lifecycleListener : lifecycleListeners) {
                            lifecycleListener.onEventDeserializationFailure(this, e);
                        }
                    }
                    continue;
                }
                if (isConnected()) {
                    eventLastSeen = System.currentTimeMillis();
                    updateGtidSet(event);
                    notifyEventListeners(event);
                    updateClientBinlogFilenameAndPosition(event);
                }
            }
        } catch (Exception e) {
            if (isConnected()) {
                for (LifecycleListener lifecycleListener : lifecycleListeners) {
                    lifecycleListener.onCommunicationFailure(this, e);
                }
            }
        } finally {
            if (isConnected()) {
                if (completeShutdown) {
                    disconnect(); // initiate complete shutdown sequence (which includes keep alive thread)
                } else {
                    disconnectChannel();
                }
            }
        }
    }

I think it is probably related to this code, read the file and return -1, then disconnect, cdc reconnects to the same file, or returns -1, just like this infinite loop

someorz avatar May 09 '23 04:05 someorz

Closing this issue because it was created before version 2.3.0 (2022-11-10). Please try the latest version of Flink CDC to see if the issue has been resolved. If the issue is still valid, kindly report it on Apache Jira under project Flink with component tag Flink CDC. Thank you!

PatrickRen avatar Feb 28 '24 15:02 PatrickRen