Method for enabling Flink to read and write Tdenine

By designing the Source and Sink modules in Flink, combined with the data structure converter, real-time data reading and writing between Flink and Tdengine is realized, which solves the problem of lack of data exchange capabilities in enterprise-level environments and provides multi-API support and dynamic expansion. capabilities, improving data processing efficiency and flexibility.

CN118535624AActive Publication Date: 2024-08-23ZHENGZHOU HENGDA INTELLIGENT CONTROL TECHNOLOGY CO LTD +1

Patent Information

Application Number
CN202410539385.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-30
Publication Date
2024-08-23
Estimated Expiration
2044-04-30

AI Technical Summary

Technical Problem

There is a lack of connector products that can provide data reading and writing capabilities between Flink and Tdengine in the enterprise-level Flink production environment, making it impossible to directly implement enterprise-level data exchange.

Method used

A method is designed, including the Source module and the Sink module. Data is read through the Source module and sent to the Flink data stream. The data structure converter of the public module is used to convert and process the data and store it in Tdengine to achieve real-time data reading. Writing ability, and supports Table API/Flink SQL and DataStream API, supports checkpoint and savepoint, and dynamically supports the expansion and contraction of Tdengine.

Benefits of technology

It realizes the real-time reading and writing capabilities of Tdengine in the enterprise-level Flink environment, supports multiple API interfaces and state recovery, dynamically adapts to the expansion changes of Tdengine, and improves the flexibility and efficiency of data processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118535624A
    Figure CN118535624A
Patent Text Reader

Abstract

The invention provides a method for enabling Flink to read and write Tdenine, comprising a Source module, a Sink module and a public module, the Source module reads data and sends the data to a data stream of the Flink, the public module provides a data structure converter and a Tdenine connector, the data structure converter performs conversion processing on the data in the data stream, and the Tdenine connector is connected with the Sink module. And carrying out batch processing on the converted data by the Sink, and storing the data which needs to be stored after the batch processing into the Tdenine. The method for enabling the Flink to read and write the Tdenine can be used in an enterprise-level Flink production environment, supports real-time source and sink, and simultaneously supports state recovery of a Table API (Application Program Interface) / Flink SQL (Structured Query Language), a DataStream API (Application Program Interface), a checkpoint and a savepoint, and the sink supports upsert and dynamically supports tdenine capacity expansion and shrinkage.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of big data processing and stream computing, and in particular to a method for enabling Flink to read and write Tdengine. Background Art

[0002] TDengine is a high-performance time series database focused on time series data processing, suitable for large-scale IoT and big data scenarios. Its design goal is to provide efficient time series data storage and query to meet the growing demand for time series data processing.

[0003] Currently, there is a lack of a connector product similar to flink-connector-kafka but for reading and writing Tdengine, which can be used in an enterprise-level Flink production environment. Currently, there is no product that directly provides enterprise-level data reading and writing capabilities between flink and tdengine. Summary of the invention

[0004] In view of the problem that there is currently no product that directly provides enterprise-level data reading and writing capabilities between Flink and tdengine, the present invention provides a method that can be used in an enterprise-level Flink production environment to enable Flink to read and write Tdengine.

[0005] The solution adopted by the present invention to solve its technical problem is: a method for allowing Flink to read and write Tdengine, including a Source module, a Sink module and a common module, reading data through the Source module and sending the data to the data stream of Flink, providing a data structure converter and a Tdengine connector through the common module, the data structure converter converts the data in the data stream, the converted data is batch processed by the Sink, and the data that needs to be stored after batch processing is stored in Tdengine.

[0006] Furthermore, a Table Source parsing factory is set in the Source module. The Table Source parsing factory includes a Table Source configuration manager, a Job Manager-data source task splitter, a Task Manager-data source scheduling factory, a Task Manager-data merge factory, and a Task Manager-data source reader. The Table Source configuration manager is used to initialize the Source module, which includes parsing the Flink table creation statement and extracting field parameters and table creation parameters, verifying basic connection parameters, constructing parameters related to the sharding processor, constructing parameters related to the data reader, and constructing other initialization configurations. The Job Manager-data source task splitter obtains the partition corresponding to the topic or pattern through a scheduled task, determines whether the topic list has changed, and notifies the TaskManager-data source scheduling factory of the changed topic. The Task Manager-data source scheduling factory determines whether there is a created fetcher, and calls the Tdengine SDK according to the fetcher to update the consumed topic list. The Task Manager-data source reader periodically obtains the data corresponding to the topic, merges the data obtained by multiple fetchers under the TaskManager into the data queue, and transforms the Tdengine data type into the Row data recognized by Flink through the data structure converter. Manager-data merge factory inserts the acquired data into Flink's data flow.

[0007] Furthermore, a Table Sink parsing factory is set in the Sink module. The Table Sink parsing factory includes a Table Sink configuration manager, a JDBC connection creator, a JDBC SQL pre-compiled parser, a data source → JDBC statement converter and a JDBC statement batch executor. The Table Sink configuration manager is used to initialize the Sink module, which includes parsing the Flink table creation statement and extracting field parameters and table creation parameters, verifying basic connection parameters, constructing parameters related to the sharding processor, constructing parameters related to the data reader, and constructing other initialization configurations. The JDBC connection creator checks whether the table structure of the table creation statement contains a primary key, and checks whether there is only one primary key and is of time type, and then initializes the database connection. The JDBC SQL pre-compiled parser is used to build an insert statement pre-compiled executor and a delete statement executor. When the data is output to the Sink in real time, the changelog type of the data is determined, the primary key of the data is obtained through the data structure converter, or the Flink data type is transformed into a data type recognized by Tdengine. The data source → JDBC statement converter is used to assemble into SQL statements, and according to the tag of the data Group the data and concatenate JDBC statements. The JDBC statement batch executor deletes the data or inserts the data into Tdengine.

[0008] Furthermore, the Job Manager-data source task splitter obtains the partition status of TdengineTopic Partition through the defined topic, and notifies the partition status to the data source reader in the TaskManager through Flink RPC communication, so that one JobManager can uniformly manage and split multiple TaskManager data source tasks.

[0009] Furthermore, Task Manager-data source reader obtains real-time data in the database by calling Tdengine SDK.

[0010] Beneficial effects of the present invention: The method provided by the present invention for enabling Flink to read and write Tdengine can support real-time sources and sinks, and also support Table API / Flink SQL and DataStream API.

[0011] The present invention also supports checkpoint and savepoint, and can restore the state, wherein the sink supports upsert, and dynamically supports tdengine expansion and contraction. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] Figure 1 It is a block diagram of the method of the present invention.

[0013] Figure 2 It is the Source side running frame view in the present invention.

[0014] Figure 3 This is a view of the Sink side operation frame in the present invention. DETAILED DESCRIPTION

[0015] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be described in detail below.

[0016] Example 1: The present invention provides an enterprise-level method for Flink to read and write Tdengine, which supports real-time source and sink, supports Table API / Flink SQL and DataStream API, as well as checkpoint and savepoint, and can restore state. The sink supports upsert, and the method dynamically supports tdengine expansion and contraction.

[0017] Specific as Figure 1 As shown in the figure, in Flink, the Source is responsible for reading data. The Source can continuously read data and send the data to the Flink data stream. After the data is read by the Source and sent to the data stream, various transformations, processing, and calculations can be performed on the data. These transformation operations can be implemented through Flink's APIs and functions, allowing users to flexibly process data.

[0018] The Sink writes data, and the receiver is responsible for writing the converted data to an external system or destination, such as a database, message queue, file system, etc. The receiver receives the converted data and sends it to the external system for storage or subsequent processing.

[0019] The present invention adopts the Tdengine connector and data structure converter of the public module. The Tdengine connector is provided by the SDK provided by Tdengine. The real-time data stream in Tdengine is obtained by data subscription through the SDK, and the submission of the offset of the most recently obtained message of the message subscription is triggered at the moment of checkpoint or savepoint.

[0020] As for the sink, the Tdengine data binding method is used to call the jdbc interface in each TaskManager in a timed or quantitative manner to insert and delete data.

[0021] Data structure converters are used to convert between Flink's internal data representation (such as Row) and data types supported by JDBC. It ensures that data can be correctly converted from Flink streams to rows in database tables and vice versa.

[0022] For Tdengine, it is mainly divided into two parts. One part is to convert the original records read from Tdengine into the internal data format of Flink Table, and the other part is to convert the original records of Flink Table according to the data type of Tdengine.

[0023] The Source side creates a Table Source parsing factory. Flink Connector provides an SPI-based extension mechanism, which can be used to extend a Tdengine Source connector parsing factory. In this factory, the names of the connector parameters in the Table, the required and optional parameters, and the corresponding parameter verification are mainly configured. In addition, a set of creation logic for creating a Tdengine Table Source configuration manager is customized through the Flink context.

[0024] The Table Source parsing factory includes the Table Source configuration manager, Job Manager-data source task splitter, Task Manager-data source scheduling factory, Task Manager-data merge factory and Task Manager-data source reader.

[0025] The role of the Table Source Configuration Manager is to define Flink's new Source architecture to better support asynchronous and pluggable Source implementations.

[0026] This module mainly provides the following functions: Asynchronous data source support; Pluggable Source implementation; Support Checkpoint and status; Event time support; Scalability.

[0027] For Tdengine, this module mainly provides the ability to construct data source scheduling factories and data source task splitters, which are used to save the state of the Source during checkpoints and restore the state when tasks are started. It can also dynamically divide data sources and support dynamic scaling and dynamic changes in data sources.

[0028] In the Flink environment, there can be multiple TaskManagers, and a TaskManager can have multiple slots, so it is necessary to define a data source task splitter. The Job Manager-data source task splitter is mainly responsible for managing and coordinating the sharding logic of the Source, and usually runs on the Flink JobManager. At startup, this module obtains the partitioning status of the Tdengine Topic Partition through the defined topic, and notifies the partitioning status to the data source reader in the TaskManager through FlinkRPC communication. In order to achieve the effect of unified management and splitting of the TaskManager data source task splitting by the JobManager.

[0029] Task Manager-Data Source Scheduling Factory works on a TaskManager in a single-threaded manner and manages multiple Fetcher (data source reader) instances in the TaskManager. Fetcher is mainly used to fetch data from the Source shards and provide it to Flink tasks for processing. By managing these Fetchers, this component serializes concurrent Fetcher operations and ensures continuous and efficient data processing.

[0030] The Task Manager-Data Merge Factory is used to merge the original records read from multiple data source readers in a single TaskManager and convert them into Flink's internal data format. It serves as a bridge between data reading and data processing to ensure the correct formatting and delivery of data.

[0031] Task Manager-Data Source Reader is responsible for reading data from a single shard. It runs in TaskManager and mainly calls Tdengine's SDK to obtain real-time data from the database. At the same time, because Flink saves the state through checkpoint, it is necessary to set tdengine to not automatically submit the consumption progress when consuming the topic. When Flink triggers the checkpoint, it is necessary to call the SDK's submission interface to save the consumption progress.

[0032] Create a Table Sink parsing factory on the Sink side. Flink Connector provides an SPI-based extension mechanism, which can be used to extend a Tdengine Sink connector parsing factory. In this factory, you mainly configure the name of the connector parameter in the Table, the required and optional parameters, and the corresponding parameter verification. It is particularly important to parse the relevant information of each field in the Table creation statement. In addition, you can customize a set of creation logic for creating a Tdengine Table Sink through the Flink context.

[0033] In the Tdengine environment, the sink is written to Tdengine via JDBC, so the first thing to do is to initialize all configurations related to the JDBC connection. The Tdengine Table Sink mainly configures the data stream data mode and the factory method of the sink runtime. For Tdengine, it supports all data stream data modes provided by Flink, including INSERT, UPDATE_BEFORE, UPDATE_AFTER, and DELETE.

[0034] The Table Sink parsing factory includes the Table Sink configuration manager, JDBC connection creator, JDBC SQL pre-compilation parser, data source → JDBC statement converter, and JDBC statement batch executor.

[0035] The JDBC connection creator is responsible for providing and managing JDBC connections. It encapsulates the logic of database connections to ensure that connections can be established and maintained efficiently. The implementation of this interface usually needs to consider the logic of connection pooling, connection verification, connection closing, etc., so that JDBC connections can be used efficiently in large-scale data processing.

[0036] As for Tdengine, since its SDK implements the general JDBC standard protocol, the way to create a connection is similar to that of ordinary JDBC, that is, it can be created together with the JDBC address, user name, password and other parameters.

[0037] The JDBC SQL precompiler parser is a package of prepared statements, which allows easier use of field names to set parameters for prepared statements. This makes it easier to write dynamic, field-sensitive SQL statements. This module is similar to the PreparedStatement in JDK, and can improve the running efficiency of the code by precompiling.

[0038] For Tdengine, the parameter binding function can not only bind data to common fields, but also to tag fields and table names. Therefore, in addition to providing set methods for common fields, the precompiled parser in the Flink connector also needs to provide set methods for tag fields and table names.

[0039] The data source → JDBC statement converter defines the format of how to write data to the JDBC data source. It is one of the basic formats used for data output in Flink, especially for writing data to relational databases.

[0040] As for Tdengine, although it shares the same JDBC standard protocol as ordinary relational databases, it has its own unique data structure, so special processing is required when constructing JDBC statements, such as how to set the subtable name and how to set the value of the tag field.

[0041] The JDBC statement batch executor is an interface for performing batch update operations. This component collects a batch of data records and executes them through JDBC at one time to improve data writing efficiency.

[0042] As for Tdengine, due to its characteristics as a time series database, the time series is the primary key, so the so-called update operation can be implemented according to the insertion logic, and based on the parameter binding function it provides, it also provides the ability to perform batch insertion. However, for deletion operations, Tdengine only supports the deletion of a single piece of data, so it is not meaningful to perform batch deletion on it. Therefore, the deletion operation is not performed in the batch executor. When encountering a piece of data that needs to be deleted, the deletion statement is executed to prevent a large number of deletion operations from being executed at a certain point in time, resulting in low execution efficiency.

[0043] like Figure 2 As shown in the figure, the operation process on the Source side includes: 1. Initialization, including parsing Flink table creation statements and extracting field parameters and table creation parameters, verifying basic connection parameters (including but not limited to whether they are required, parameter size, etc.), constructing parameters related to shard processors, constructing parameters related to data readers, and constructing other initialization configurations; 2. Get the partition corresponding to the topic or pattern through a scheduled task; 3. Compare the partitions obtained last time to see if there are any changes in the topic list: If there is no topic change, the scheduled task ends; If there is a topic change, all TaskManagers are notified via RPC; 4. Determine whether a fetcher has been created: If there is no fetcher in the current TaskManager, create a fetcher and construct a result queue after the data is merged, and start the fetcher asynchronously to consume the data; If there is already a fetcher in the current TaskManager, call the Tdengine SDK to update the list of consumed topics; 5. Get the data corresponding to the topic regularly; 6. The data obtained by multiple fetchers under the current TaskManager are merged into the data queue; 7. Use the data converter to transform the data type of Tdengine into Row data recognized by Flink; 8. Insert the acquired data into Flink’s data stream.

[0044] like Figure 3 As shown in the figure, the operation process on the Sink side includes: 1. Initialization, including parsing Flink table creation statements and extracting field parameters and table creation parameters, verifying basic connection parameters (including but not limited to whether they are required, parameter size, etc.), storing JDBC connection information for subsequent use, storing batch execution information for subsequent use, initializing batch insert executors, initializing batch delete executors, and constructing other initialization configurations; 2. Check whether the table structure of the table creation statement contains a primary key 2.1. If there is a primary key, check whether there is only one primary key of time type. If it does not meet the requirements, throw an exception and end directly; if the primary key check is OK, create a database connection; If there is no primary key, initialize the database connection; 2.3 Initialize the precompiled executor of the insert statement, that is, initialize PreparedStatement according to the parameter binding function of Tdengine SDK; 2.4 Initialize the executor of the delete statement, that is, construct the SQL script of a single delete statement. Since the parameter binding function of the Tdengine SDK does not support the delete function, only the Statement can be initialized; 2.5 When data is output to the Sink in real time, determine the changelog type of the data: If the data type of the data is DELETE or UPDATE_BEFORE, obtain the time primary key of the data and execute the delete operation of a single statement based on the primary key; If the data type of the data is INSERT or UPDATE_AFTER, parse the tag of the data and group it into the cache queue according to the tag; 2.6 Use the data type converter to transform the Flink data type into a data type that Tdengine can recognize; 2.7 When the time interval is reached, the data is grouped according to the tag, and the batch insertion function is performed through the SDK parameter binding function; 2.8 After the insertion is completed, clear the cache queue.

[0045] Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other implementation methods obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

Claims

1. A method for enabling Flink to read and write Tdengine, characterized in that: It includes Source module, Sink module and common module. Data is read through Source module and sent to Flink's data stream. Data structure converter and Tdengine connector are provided through common module. Data structure converter converts data in data stream. The converted data is batch processed by Sink, and the data that needs to be stored after batch processing is stored in Tdengine.

2. The method for enabling Flink to read and write Tdengine according to claim 1, characterized in that: Set up the Table Source parsing factory in the Source module. The Table Source parsing factory includes the Table Source configuration manager, JobManager-data source task splitter, Task Manager-data source scheduling factory, Task Manager-data merge factory and Task Manager-data source reader. The Table Source configuration manager is used to initialize the Source module. The initialization includes parsing the Flink table creation statement and extracting field parameters and table creation parameters, verifying basic connection parameters, constructing parameters related to the sharding processor, constructing parameters related to the data reader, and constructing other initialization configurations. The JobManager-data source task splitter obtains the partition corresponding to the topic or pattern through the scheduled task, determines whether the topic list has changed, and notifies the Task Manager-data source scheduling factory of the changed topic. The TaskManager-data source scheduling factory determines whether there is a created fetcher, and calls the Tdengine SDK according to the fetcher to update the consumed topic list. The Task Manager-data source reader obtains the data corresponding to the topic regularly, merges the data obtained by multiple fetchers under the TaskManager into the data queue, and transforms the Tdengine data type into the Row data recognized by Flink through the data structure converter. Task Manager-data merge factory inserts the acquired data into Flink's data flow.

3. The method for enabling Flink to read and write Tdengine according to claim 1, characterized in that: Set up the Table Sink parsing factory in the Sink module. The Table Sink parsing factory includes the Table Sink configuration manager, JDBC connection creator, JDBC SQL pre-compiled parser, data source → JDBC statement converter and JDBC statement batch executor. The Table Sink configuration manager is used to initialize the Sink module. The initialization includes parsing the Flink table creation statement and extracting field parameters and table creation parameters, verifying basic connection parameters, constructing parameters related to the sharding processor, constructing parameters related to the data reader, and constructing other initialization configurations. The JDBC connection creator checks whether the table structure of the table creation statement contains a primary key, and checks whether there is only one primary key and is of time type, and then initializes the database connection. The JDBC SQL pre-compiled parser is used to build an insert statement pre-compiled executor and a delete statement executor. When the data is output to the Sink in real time, the changelog type of the data is determined, the primary key of the data is obtained through the data structure converter, or the Flink data type is transformed into a data type recognized by Tdengine. The data source → JDBC statement converter is used to assemble into SQL statements and according to the data tag Group the data and concatenate JDBC statements. The JDBC statement batch executor deletes the data or inserts the data into Tdengine.

4. The method for enabling Flink to read and write Tdengine according to claim 2, characterized in that: The Job Manager-data source task splitter obtains the partitioning status of the Tdengine Topic Partition through the defined topic, and notifies the partitioning status to the data source reader in the TaskManager through Flink RPC communication, so that one JobManager can uniformly manage and split multiple TaskManager data source tasks.

5. The method for enabling Flink to read and write Tdengine according to claim 2, characterized in that: Task Manager-Data Source Reader obtains real-time data from the database by calling Tdengine SDK.

Citation Information

Patent Citations

  • Industrial production data real-time processing method and system based on Flink SQL engine

    CN112287007A

  • Method and system for connecting TDengine without installing client

    CN114785767A

  • Method for realizing metadata management based on Flink SQL (Structured Query Language)

    CN115114299A

  • Automatic configuration processing method and system for risk control index calculation development based on FlinkSQL

    CN115469941A

  • Monitoring platform and method based on TDengine, electronic equipment and storage medium

    CN116996420A

Cited By

  • Data processing method and device, electronic equipment and computer readable storage medium

    CN119211343A