Data communication method and device
Receive access requests through the data permission server, establish a connection with the high-availability database node, and determine the access type matching based on the cluster information. This solves the problem that the ORM framework does not support high availability, enables business services to access the high-availability database, and improves efficiency. stability.
Patent Information
- Application Number
- CN202310333200.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-30
- Publication Date
- 2024-10-01
AI Technical Summary
In a production environment, the diversity of business service usage causes ORM frameworks in some languages to not support high availability of databases, which in turn affects the communication between business services and high-availability databases.
The data permission server receives the access request from the terminal device, establishes a connection with the high-availability database node, receives cluster information, determines whether the access type supported by the database node matches the business access type, and controls the terminal device to communicate with the target database node until match.
It enables business services to access high-availability database nodes, improving the stability of business services without relying on whether the ORM framework of business services supports high availability of the database.
Smart Images

Figure CN118733649A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a data communication method and device. Background Art
[0002] With the development of the project, more and more business services now use data permission services for static permission control. Among them, the proportion of services that use data permission services to control data permission for the database Postgres is relatively large. The stand-alone Postgres gradually fails to meet the demand for business service stability. There is a strong demand to support high availability of the database to improve the stability of business services.
[0003] In the related art, if the Object Relational Mapping (ORM) framework of the business service supports high availability of the database, the high availability function of the database provided by the ORM framework is used to implement communication between the business service and the high availability database provided by the ORM framework.
[0004] However, in a production environment, business services use a variety of languages. The ORM frameworks of business services in some languages do not support high availability of databases. Therefore, whether business services can communicate with high-availability databases depends on whether the ORM framework of business services supports high availability of databases. Summary of the invention
[0005] In view of the problems existing in the prior art, an embodiment of the present invention provides a data communication method and device.
[0006] The present invention provides a data communication method, which is applied to a data authority server; the method comprises:
[0007] Receiving an access request sent by a terminal device corresponding to a target service; the access request is used to request access to a highly available database node;
[0008] Receiving cluster information sent by a target database node in a database cluster; the cluster information is sent by the target database node when a connection between the data authority server and the target database node established based on the access request is successful; the target database node has a high availability function;
[0009] When determining that the target access type of the target service accessing the database node is a write type or a read-write type, determining whether the access type supported by the target database node matches the target access type based on the cluster information;
[0010] When the access type matches the target access type, the terminal device is controlled to communicate with the target database node based on the target service.
[0011] According to a data communication method provided by the present invention, the method further includes:
[0012] When the access type does not match the target access type, new cluster information sent by the new target database node in the database cluster is received, until it is determined based on the new cluster information that the access type supported by the new target database node matches the target access type, and the terminal device is controlled to communicate with the new target database node based on the target business; the new cluster information is sent by the new target database node when the connection between the data authority server and the new target database node is successfully established; the new target database node has a high availability function.
[0013] According to a data communication method provided by the present invention, the determining, based on the cluster information, whether the access type supported by the target database node matches the target access type comprises:
[0014] When it is determined that the cluster information includes a preset field, obtaining a field value of the preset field; the preset field is used to indicate an access type supported by the target database node;
[0015] It is determined based on the field value whether the access type supported by the target database node matches the target access type.
[0016] According to a data communication method provided by the present invention, the determining, based on the field value, whether the access type supported by the target database node matches the target access type comprises:
[0017] When the target access type is a write type and the field value is a first field value, determining that the access type supported by the target database node matches the target access type; the first field value is used to indicate that the access type supported by the target database node is a read-write type;
[0018] When the target access type is a write type and the field value is a second field value, it is determined that the access type supported by the target database node does not match the target access type; the second field value is used to indicate that the access type supported by the target database node is a read type.
[0019] According to a data communication method provided by the present invention, the method further includes:
[0020] When the target access type is a read-write type and the field value is the first field value, determining that the access type supported by the target database node matches the target access type;
[0021] When the target access type is a read-write type and the field value is the second field value, it is determined that the access type supported by the target database node does not match the target access type.
[0022] According to a data communication method provided by the present invention, the method further includes:
[0023] When it is determined that the cluster information does not include the preset field, sending a target statement to the target database node; the target statement is used to query the access type supported by the target database node;
[0024] Receive a target field value sent by the target database, where the target field value is a field value corresponding to an access type supported by a target database node queried by the target statement;
[0025] A determination is made based on the target field value whether an access type supported by the target database node matches the target access type.
[0026] According to a data communication method provided by the present invention, before receiving an access request sent by a terminal device corresponding to a target service, the method further includes:
[0027] A connection is established between the terminal device and the data authority server based on the Internet Protocol IP address of the data authority server.
[0028] The present invention also provides a data communication device, the device comprising:
[0029] A first receiving unit, configured to receive an access request sent by a terminal device corresponding to a target service; the access request is used to request access to a highly available database node;
[0030] A second receiving unit is used to receive cluster information sent by a target database node in the database cluster; the cluster information is sent by the target database node when the connection between the data authority server and the target database node established based on the access request is successful; the target database node has a high availability function;
[0031] a determining unit, configured to determine, when determining that a target access type of the target service accessing the database node is a write type or a read-write type, whether an access type supported by the target database node matches the target access type based on the cluster information;
[0032] A first control unit is used to control the terminal device to communicate with the target database node based on the target service when the access type matches the target access type.
[0033] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the above-mentioned data communication methods is implemented.
[0034] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the data communication method described in any one of the above is implemented.
[0035] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned data communication methods.
[0036] The data communication method and device provided by the present invention, when the data authority server receives an access request for accessing a highly available database node sent by a terminal device corresponding to a target business, the data authority server establishes a connection between the data authority server and a target database node with a highly available function in a database cluster, and when the connection is successful, the data authority server receives cluster information sent by the target database node, and when it is determined based on the cluster information that the access type supported by the target database node matches the target access type of the target business accessing the database node, the terminal device is controlled to communicate with the target database node based on the target business, thereby realizing the target business's access to the highly available target database node. It can be seen that the present invention can determine whether the access type supported by the target database node matches the target access type of the target business accessing the database node through the deployed data authority server, and when matching, realize the target business's access to the highly available target database node, without relying on whether the ORM framework of the target business supports the high availability of the database. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0038] Figure 1 It is one of the flow charts of the data communication method provided by the present invention;
[0039] Figure 2 This is the second flow chart of the data communication method provided by the present invention;
[0040] Figure 3 This is the third flow chart of the data communication method provided by the present invention;
[0041] Figure 4 It is an interactive flow chart of the data communication method provided by the present invention;
[0042] Figure 5 is a schematic diagram of the structure of a data communication device provided by an embodiment of the present invention;
[0043] Figure 6 It is a schematic diagram of the physical structure of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0045] Combine the following Figure 1-Figure 4 The data communication method of the present invention is described.
[0046] Figure 1 It is one of the flow charts of the data communication method provided by the embodiment of the present invention, which is applied to the data authority server, such as Figure 1 As shown, the data communication method includes the following steps:
[0047] Step 101: Receive an access request sent by a terminal device corresponding to a target service; the access request is used to request access to a highly available database node.
[0048] The target business runs on the terminal device, and the target business can be an event management business, an asset management business, or any other business that needs to access the database node. A highly available database node is a hot standby node, which is a logical node stored in a hot standby group and is used to replace a failed database node.
[0049] For example, when the target business requires the database node to support high availability, the high availability function of the database node can be configured for the target business in advance on the data authority server, that is, the configuration of the database node can be modified on the data authority server. In this way, when the target business needs to use a highly available database node, the terminal device running the target business is triggered to send an access request to the data authority server for access to the highly available database node; taking the target business as an event management business as an example, when an event occurs, the data about the event needs to be recorded in the database node, and at this time, the terminal device can be triggered to send an access request to the data authority server for access to the highly available database node.
[0050] It should be noted that the language type of the data permission server can be Java, Go or Rust, etc., and the present invention is not limited to this.
[0051] Step 102, receiving cluster information sent by a target database node in a database cluster; the cluster information is sent by the target database node when a connection between the data authority server and the target database node is successfully established based on the access request; the target database node has a high availability function.
[0052] Each database node in the database cluster may be Postgres, etc. When the database node is Postgres, the database cluster may be constructed based on the pg_auto_failover function of Postgres.
[0053] For example, when the data authority server receives an access request sent by a terminal device, it parses the access request and determines that the terminal device needs to access a highly available database node. At this time, based on the IP address of any target database node with high availability in the database cluster, a connection is established between the data authority server and the target database node. When the connection between the data authority server and the target database node is successfully established, the target database node returns the cluster information to the data authority server, that is, the data authority server receives the cluster information sent by the target database node.
[0054] It should be noted that the specific steps for establishing a connection between a data authority server and a target database node may be as follows: the data authority server sends a startup package to the target database node; upon receiving the startup package, the target database node returns a random number for password encryption to the data authority server; the data authority server encrypts the plain text based on the random number to obtain the ciphertext, and sends the ciphertext to the target database node; the target database node verifies the password of the ciphertext; if the verification is successful, a successful connection with the data authority server is established.
[0055] Step 103: When it is determined that the target access type of the target service accessing the database node is a write type or a read-write type, determine based on the cluster information whether the access type supported by the target database node matches the target access type.
[0056] For example, when the data permission server receives an access request sent by a terminal device corresponding to the target business, it can also determine the target access type of the target business to access the database node. When the target access type is a write type or a read-write type, it parses the cluster information, and determines based on the parsed cluster information whether the access type supported by the target database node matches the target access type, that is, determines whether the target database node can meet the needs of the target business.
[0057] It should be noted that when it is determined that the target access type for the target business to access the database node is a read type, there is no need to determine whether the access type supported by the target database node matches the target access type based on the cluster information. The terminal device can be directly controlled to communicate with any target database node in the database cluster based on the target business. The reason is that database nodes are of two types: read-only type and read-write type. Regardless of the type, they can meet the needs of the target business.
[0058] Step 104: When the access type matches the target access type, control the terminal device to communicate with the target database node based on the target service.
[0059] For example, when it is determined based on the parsed cluster information that the access type supported by the target database node matches the target access type, it means that the target database node can meet the needs of the target business. At this time, communication between the terminal device running the target business and the target database node can be established through the data authority server; taking the target business as event management business as an example, the terminal device can write data related to the event management business into the target database node through the data authority server.
[0060] The data communication method provided by the present invention is that when the data authority server receives an access request for accessing a highly available database node sent by a terminal device corresponding to a target business, the data authority server establishes a connection between the data authority server and a target database node with a highly available function in a database cluster. When the connection is successful, the data authority server receives cluster information sent by the target database node. When it is determined based on the cluster information that the access type supported by the target database node matches the target access type of the target business accessing the database node, the terminal device is controlled to communicate with the target database node based on the target business, thereby realizing the target business's access to the highly available target database node. It can be seen that the present invention can determine whether the access type supported by the target database node matches the target access type of the target business accessing the database node through the deployed data authority server, and when matching, realize the target business's access to the highly available target database node, without relying on whether the ORM framework of the target business supports the high availability of the database, and is also independent of the language used by the target business.
[0061] In one embodiment, Figure 2 FIG. 2 is a flow chart of a data communication method provided by an embodiment of the present invention. Figure 2 As shown, the data communication method also includes the following steps:
[0062] Step 105: When the access type does not match the target access type, new cluster information sent by the new target database node in the database cluster is received, until it is determined based on the new cluster information that the access type supported by the new target database node matches the target access type, and then the terminal device is controlled to communicate with the new target database node based on the target business; the new cluster information is sent by the new target database node when a connection is successfully established between the data authority server and the new target database node; the new target database node has a high availability function.
[0063] For example, when it is determined based on the parsed cluster information that the access type supported by the target database node does not match the target access type, it means that the target database node cannot meet the needs of the target business. At this time, the data authority server establishes a connection between the data authority server and the new target database node based on the IP address of the new target database node (a node other than the above-mentioned target database node) with high availability function in the database cluster. When the connection between the data authority server and the new target database node is successfully established, new cluster information sent by the new target database node is received. This cycle is repeated until it is determined based on the new cluster information that the access type supported by the new target database node matches the target access type, which means that the new target database node can meet the needs of the target business. At this time, communication between the terminal device running the target business and the new target database node can be established through the data authority server.
[0064] The data communication method provided by the embodiment of the present invention, when it is determined based on the parsed cluster information that the access type supported by the target database node does not match the target access type, continues to establish a connection with a new target database node in the database cluster until the access type supported by the new target database node matches the target access type of the target business, thereby ensuring that the target business can normally access the database node with high availability, thereby improving the stability of the target business operation.
[0065] In one embodiment, in the above step 103, determining whether the access type supported by the target database node matches the target access type based on the cluster information may be implemented in the following manner:
[0066] When it is determined that the cluster information includes a preset field, obtaining a field value of the preset field; the preset field is used to indicate an access type supported by the target database node;
[0067] It is determined based on the field value whether the access type supported by the target database node matches the target access type.
[0068] For example, when the data permission server receives the cluster information sent by the target database node, it parses the cluster information to determine whether the cluster information includes a preset field. For example, the preset field may be in_hot_standby. When it is determined that the cluster information includes the preset field, it indicates that the cluster information contains the access type supported by the target database node. At this time, the field value of the preset field is obtained, and the access type specifically supported by the target database node is determined based on the field value of the preset field, and then it is determined whether the access type specifically supported by the target database node matches the target access type of the target business.
[0069] The data communication method provided by the embodiment of the present invention can determine the access type specifically supported by the target database node based on the field value of the preset field included in the cluster information, so as to facilitate the data permission server to match the database node that meets the requirements for the target business and ensure the stability of the target business operation.
[0070] In one embodiment, the above-mentioned determination based on the field value whether the access type supported by the target database node matches the target access type may be specifically implemented in the following manner:
[0071] When the target access type is a write type and the field value is a first field value, determining that the access type supported by the target database node matches the target access type; the first field value is used to indicate that the access type supported by the target database node is a read-write type;
[0072] When the target access type is a write type and the field value is a second field value, it is determined that the access type supported by the target database node does not match the target access type; the second field value is used to indicate that the access type supported by the target database node is a read type.
[0073] For example, when the data permission server determines that the target access type that the target business needs to access the target database node is a write type, and the field value of the preset field in the cluster information is the first field value indicating that the access type supported by the target database node is a read-write type, since the read-write type supported by the target database node can meet the write type required by the target business, it is determined that the access type supported by the target database node matches the target access type. For example, the preset field is in_hot_standby, and the first field value is "off", and "off" is used to indicate that the access type supported by the target database node is a read-write type.
[0074] When the data authority server determines that the target access type that the target business needs to access the target database node is a write type, and the field value of the preset field in the cluster information is the second field value indicating that the access type supported by the target database node is a read type, since the read type supported by the target database node cannot meet the write type required by the target business, it is determined that the access type supported by the target database node does not match the target access type, and the connection between the data authority server and the target database node is disconnected. For example, the preset field is in_hot_standby, and the second field value is "on". "On" is used to indicate that the access type supported by the target database node is a read type, and does not support a write type.
[0075] The data communication method provided by the embodiment of the present invention can determine whether the access type supported by the target database node matches the write type based on the field value of the preset field in the cluster information when the target access type required by the target business is a write type, thereby facilitating the data permission server to match a database node with a write type for the target business and ensuring the stability of the target business operation.
[0076] In one embodiment, the above-mentioned determination based on the field value whether the access type supported by the target database node matches the target access type may be specifically implemented in the following manner:
[0077] When the target access type is a read-write type and the field value is the first field value, determining that the access type supported by the target database node matches the target access type;
[0078] When the target access type is a read-write type and the field value is the second field value, it is determined that the access type supported by the target database node does not match the target access type.
[0079] Among them, the read-write type refers to the read type and the write type.
[0080] For example, when the data permission server determines that the target access type that the target business needs to access the target database node is a read-write type, and the field value of the preset field in the cluster information is a first field value indicating that the access type supported by the target database node is a read-write type, since the read-write type supported by the target database node can meet the read-write type required by the target business, it is determined that the access type supported by the target database node matches the target access type.
[0081] When the data authority server determines that the target access type that the target business needs to access the target database node is a read-write type, and the field value of the preset field in the cluster information is a second field value indicating that the access type supported by the target database node is a read type, since the read type supported by the target database node cannot meet the read-write type required by the target business, it is determined that the access type supported by the target database node does not match the target access type. At this time, the connection between the data authority server and the target database node is disconnected.
[0082] The data communication method provided by the embodiment of the present invention can determine whether the access type supported by the target database node matches the read-write type based on the field value of the preset field in the cluster information when the target access type required by the target business is a read-write type, so as to facilitate the data permission server to match the target business with a database node with a read-write type, thereby ensuring the stability of the target business operation.
[0083] In one embodiment, in the above step 103, determining whether the access type supported by the target database node matches the target access type based on the cluster information may be implemented in the following manner:
[0084] When it is determined that the cluster information does not include the preset field, sending a target statement to the target database node; the target statement is used to query the access type supported by the target database node;
[0085] Receive a target field value sent by the target database, where the target field value is a field value corresponding to an access type supported by a target database node queried by the target statement;
[0086] A determination is made based on the target field value whether an access type supported by the target database node matches the target access type.
[0087] For example, when the data permission server determines that the cluster information does not include a preset field, it may consider that the version of the target database node is lower. In this case, the data permission server may send a target statement to the target database node for querying the access type supported by the target database node. For example, the target statement may be "SHOWtransaction_read_only`SQL". When the target database node receives the target statement, it returns the corresponding target field value to the data permission server based on the access type supported by the target data set node itself, and then determines whether the access type supported by the target database node matches the target access type required by the target business based on the target field value returned by the target database node.
[0088] Based on the target field value returned by the target database node, determine whether the access type supported by the target database node matches the target access type required by the target business. This can be achieved in the following ways:
[0089] When the target access type is a write type and the target field value is a first field value, it is determined that the access type supported by the target database node matches the target access type; the first field value is used to indicate that the access type supported by the target database node is a read-write type; when the target access type is a write type and the target field value is a second field value, it is determined that the access type supported by the target database node does not match the target access type; the second field value is used to indicate that the access type supported by the target database node is a read type.
[0090] When the target access type is a read-write type and the target field value is the first field value, it is determined that the access type supported by the target database node matches the target access type; when the target access type is a read-write type and the target field value is the second field value, it is determined that the access type supported by the target database node does not match the target access type.
[0091] The data communication method provided by an embodiment of the present invention can, when it is determined that the cluster information does not include a preset field for indicating the access type supported by the target database node, send a target statement to the target database node to query the access type supported by the target database node through the data authority server, and then determine whether the access type supported by the target database node matches the target access type required by the target business based on the target field value returned by the target database node, thereby realizing the process of the data authority server obtaining supported access types from database nodes of different versions, ensuring full utilization of high-availability database nodes of different versions in the database cluster.
[0092] In one embodiment, Figure 3 FIG. 3 is a flow chart of a data communication method provided by an embodiment of the present invention. Figure 3 As shown, before the above step 101, the data communication method further includes the following steps:
[0093] Step 106: Establish a connection between the terminal device and the data authority server based on the Internet Protocol IP address of the data authority server.
[0094] For example, the terminal device can establish a connection with the data authority server based on the Internet Protocol (IP) address of the data authority server, so that the target business running on the terminal device can communicate with the database node with high availability in the cluster database through the data authority server.
[0095] The data communication method provided by the embodiment of the present invention enables a terminal device running a target business to establish a connection with a data authority server based on the IP address of the data authority server, thereby facilitating subsequent communication with a database node with high availability capabilities through the data authority server, thereby realizing the proxy function of the data authority server.
[0096] Figure 4 is an interactive flow chart of a data communication method provided by an embodiment of the present invention, such as Figure 4 As shown, the data communication method is applied to a terminal device, a data authority server and a database cluster, and includes the following steps:
[0097] Step 401: The terminal device establishes a connection between the terminal device and the data authority server based on the Internet Protocol IP address of the data authority server.
[0098] Step 402: The data authority server receives an access request sent by a terminal device corresponding to the target service.
[0099] The access request is used to request access to a highly available database node.
[0100] Step 403: The data authority server establishes a connection between the data authority server and the target database node based on the access request.
[0101] Step 404: When the connection between the data authority server and the target database node established based on the access request is successful, the target database node in the database cluster sends cluster information to the data authority server.
[0102] It should be noted that, based on the different results of determining whether the cluster information includes a preset field, the following execution steps are also different. When it is determined that the cluster information includes a preset field, steps 405, 409 and 410 are executed; when it is determined that the cluster information does not include a preset field, steps 406 to 410 are executed.
[0103] Step 405: When the data permission server determines that the target access type of the target business accessing the database node is a write type or a read-write type, and determines that the cluster information includes a preset field, it obtains the field value of the preset field, and determines whether the access type supported by the target database node matches the target access type based on the field value.
[0104] Step 406: When the data authority server determines that the target access type of the target business accessing the database node is a write type or a read-write type and determines that the cluster information does not include the preset field, the data authority server sends a target statement to the target database node.
[0105] The target statement is used to query the access type supported by the target database node.
[0106] Step 407: The data authority server receives the target field value sent by the target database, where the target field value is the field value corresponding to the access type supported by the target database node queried by the target statement.
[0107] Step 408: The data authority server determines whether the access type supported by the target database node matches the target access type based on the target field value.
[0108] It should be noted that the following execution steps are different depending on the determination result of whether the access type matches the target access type. When the access type matches the target access type, step 409 is executed; when the access type does not match the target access type, step 410 is executed.
[0109] Step 409: When the access type matches the target access type, control the terminal device to communicate with the target database node based on the target service.
[0110] Step 410: When the access type does not match the target access type, new cluster information sent by a new target database node in the database cluster is received, until it is determined based on the new cluster information that the access type supported by the new target database node matches the target access type, and then the terminal device is controlled to communicate with the new target database node based on the target service.
[0111] The new cluster information is sent by the new target database node when a connection is successfully established between the data authority server and the new target database node.
[0112] The new target database node has a high availability function.
[0113] The data communication device provided by the present invention is described below. The data communication device described below and the data communication method described above can be referenced to each other.
[0114] Figure 5 is a schematic diagram of the structure of a data communication device provided by an embodiment of the present invention, such as Figure 5 As shown, the data communication device 500 includes a first receiving unit 501, a second receiving unit 502, a determining unit 503 and a first control unit 504; wherein:
[0115] The first receiving unit 501 is used to receive an access request sent by a terminal device corresponding to a target service; the access request is used to request access to a highly available database node;
[0116] The second receiving unit 502 is used to receive cluster information sent by a target database node in the database cluster; the cluster information is sent by the target database node when the connection between the data authority server and the target database node established based on the access request is successful; the target database node has a high availability function;
[0117] A determination unit 503 is configured to determine, when determining that a target access type of the target service accessing the database node is a write type or a read-write type, whether an access type supported by the target database node matches the target access type based on the cluster information;
[0118] The first control unit 504 is configured to control the terminal device to communicate with the target database node based on the target service when the access type matches the target access type.
[0119] The data communication device provided by the present invention, when the data authority server receives an access request for accessing a highly available database node sent by a terminal device corresponding to a target business, establishes a connection between the data authority server and a target database node with a highly available function in a database cluster, and when the connection is successful, receives cluster information sent by the target database node, and when it is determined based on the cluster information that the access type supported by the target database node matches the target access type of the target business accessing the database node, controls the terminal device to communicate with the target database node based on the target business, thereby realizing the target business's access to the highly available target database node. It can be seen that the present invention can determine whether the access type supported by the target database node matches the target access type of the target business accessing the database node through the deployed data authority server, and when matching, realizes the target business's access to the highly available target database node, without relying on whether the ORM framework of the target business supports the high availability of the database.
[0120] Based on any of the above embodiments, the data communication device 500 further includes:
[0121] A second control unit is used to receive new cluster information sent by a new target database node in the database cluster when the access type does not match the target access type, until it is determined based on the new cluster information that the access type supported by the new target database node matches the target access type, and then control the terminal device to communicate with the new target database node based on the target business; the new cluster information is sent by the new target database node when a connection is successfully established between the data authority server and the new target database node; the new target database node has a high availability function.
[0122] Based on any of the foregoing embodiments, the determining unit 503 is specifically configured to:
[0123] When it is determined that the cluster information includes a preset field, obtaining a field value of the preset field; the preset field is used to indicate an access type supported by the target database node;
[0124] It is determined based on the field value whether the access type supported by the target database node matches the target access type.
[0125] Based on any of the foregoing embodiments, the determining unit 503 is further specifically configured to:
[0126] When the target access type is a write type and the field value is a first field value, determining that the access type supported by the target database node matches the target access type; the first field value is used to indicate that the access type supported by the target database node is a read-write type;
[0127] When the target access type is a write type and the field value is a second field value, it is determined that the access type supported by the target database node does not match the target access type; the second field value is used to indicate that the access type supported by the target database node is a read type.
[0128] Based on any of the foregoing embodiments, the determining unit 503 is further specifically configured to:
[0129] When the target access type is a read-write type and the field value is the first field value, determining that the access type supported by the target database node matches the target access type;
[0130] When the target access type is a read-write type and the field value is the second field value, it is determined that the access type supported by the target database node does not match the target access type.
[0131] Based on any of the foregoing embodiments, the determining unit 503 is further specifically configured to:
[0132] When it is determined that the cluster information does not include the preset field, sending a target statement to the target database node; the target statement is used to query the access type supported by the target database node;
[0133] Receive a target field value sent by the target database, where the target field value is a field value corresponding to an access type supported by a target database node queried by the target statement;
[0134] A determination is made based on the target field value whether an access type supported by the target database node matches the target access type.
[0135] Based on any of the above embodiments, the data communication device 500 further includes:
[0136] An establishing unit is used to establish a connection between the terminal device and the data authority server based on the Internet Protocol IP address of the data authority server.
[0137] Figure 6 is a schematic diagram of the physical structure of an electronic device provided by an embodiment of the present invention, such as Figure 6 As shown, the electronic device may include: a processor 610, a communication interface 620, a memory 630 and a communication bus 640, wherein the processor 610, the communication interface 620 and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call the logic instructions in the memory 630 to execute the data communication method, which includes: receiving an access request sent by a terminal device corresponding to a target service; the access request is used to request access to a highly available database node;
[0138] Receiving cluster information sent by a target database node in a database cluster; the cluster information is sent by the target database node when a connection between the data authority server and the target database node established based on the access request is successful; the target database node has a high availability function;
[0139] When determining that the target access type of the target service accessing the database node is a write type or a read-write type, determining whether the access type supported by the target database node matches the target access type based on the cluster information;
[0140] When the access type matches the target access type, the terminal device is controlled to communicate with the target database node based on the target service.
[0141] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0142] On the other hand, the present invention further provides a computer program product, the computer program product includes a computer program, the computer program can be stored on a non-transitory computer-readable storage medium, when the computer program is executed by a processor, the computer can execute the data communication method provided by the above methods, the method comprising: receiving an access request sent by a terminal device corresponding to a target service; the access request is used to request access to a highly available database node;
[0143] Receiving cluster information sent by a target database node in a database cluster; the cluster information is sent by the target database node when a connection between the data authority server and the target database node established based on the access request is successful; the target database node has a high availability function;
[0144] When determining that the target access type of the target service accessing the database node is a write type or a read-write type, determining whether the access type supported by the target database node matches the target access type based on the cluster information;
[0145] When the access type matches the target access type, the terminal device is controlled to communicate with the target database node based on the target service.
[0146] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the computer program is executed by a processor to execute the data communication method provided by the above methods, the method comprising: receiving an access request sent by a terminal device corresponding to a target service; the access request is used to request access to a highly available database node;
[0147] Receiving cluster information sent by a target database node in a database cluster; the cluster information is sent by the target database node when a connection between the data authority server and the target database node established based on the access request is successful; the target database node has a high availability function;
[0148] When determining that the target access type of the target service accessing the database node is a write type or a read-write type, determining whether the access type supported by the target database node matches the target access type based on the cluster information;
[0149] When the access type matches the target access type, the terminal device is controlled to communicate with the target database node based on the target service.
[0150] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0151] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0152] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A data communication method, characterized in that: Applied to the data authority server; the method comprises: Receiving an access request sent by a terminal device corresponding to a target service; the access request is used to request access to a highly available database node; Receiving cluster information sent by a target database node in a database cluster; the cluster information is sent by the target database node when a connection between the data authority server and the target database node established based on the access request is successful; the target database node has a high availability function; When determining that the target access type of the target service accessing the database node is a write type or a read-write type, determining whether the access type supported by the target database node matches the target access type based on the cluster information; When the access type matches the target access type, the terminal device is controlled to communicate with the target database node based on the target service.
2. The data communication method according to claim 1, characterized in that: The method further comprises: When the access type does not match the target access type, new cluster information sent by the new target database node in the database cluster is received, until it is determined based on the new cluster information that the access type supported by the new target database node matches the target access type, and the terminal device is controlled to communicate with the new target database node based on the target business; the new cluster information is sent by the new target database node when the connection between the data authority server and the new target database node is successfully established; the new target database node has a high availability function.
3. The data communication method according to claim 1, characterized in that: The determining, based on the cluster information, whether the access type supported by the target database node matches the target access type includes: When it is determined that the cluster information includes a preset field, obtaining a field value of the preset field; the preset field is used to indicate an access type supported by the target database node; It is determined based on the field value whether the access type supported by the target database node matches the target access type.
4. The data communication method according to claim 3, characterized in that: The determining, based on the field value, whether the access type supported by the target database node matches the target access type includes: When the target access type is a write type and the field value is a first field value, determining that the access type supported by the target database node matches the target access type; the first field value is used to indicate that the access type supported by the target database node is a read-write type; When the target access type is a write type and the field value is a second field value, it is determined that the access type supported by the target database node does not match the target access type; the second field value is used to indicate that the access type supported by the target database node is a read type.
5. The data communication method according to claim 4, characterized in that: The method further comprises: When the target access type is a read-write type and the field value is the first field value, determining that the access type supported by the target database node matches the target access type; When the target access type is a read-write type and the field value is the second field value, it is determined that the access type supported by the target database node does not match the target access type.
6. The data communication method according to claim 3, characterized in that: The method further comprises: When it is determined that the cluster information does not include the preset field, sending a target statement to the target database node; the target statement is used to query the access type supported by the target database node; Receive a target field value sent by the target database, where the target field value is a field value corresponding to an access type supported by a target database node queried by the target statement; A determination is made based on the target field value whether an access type supported by the target database node matches the target access type.
7. The data communication method according to any one of claims 1 to 6, characterized in that: Before receiving the access request sent by the terminal device corresponding to the target service, the method further includes: A connection is established between the terminal device and the data authority server based on the Internet Protocol IP address of the data authority server.
8. A data communication device, characterized in that: The device comprises: A first receiving unit, configured to receive an access request sent by a terminal device corresponding to a target service; the access request is used to request access to a highly available database node; A second receiving unit is used to receive cluster information sent by a target database node in the database cluster; the cluster information is sent by the target database node when the connection between the data authority server and the target database node established based on the access request is successful; the target database node has a high availability function; a determining unit, configured to determine, when determining that a target access type of the target service accessing the database node is a write type or a read-write type, whether an access type supported by the target database node matches the target access type based on the cluster information; A first control unit is used to control the terminal device to communicate with the target database node based on the target service when the access type matches the target access type.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the data communication method according to any one of claims 1 to 7 is implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the data communication method according to any one of claims 1 to 7 is implemented.
11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the data communication method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Method and system for read-write splitting database
CN102622427A
Comprehensive method for host-standby / cluster application based on PostgreSQL database
CN105224637A
Method and server side device for authorizing content access request
CN109120636A
Database access method, system and device and storage medium
CN111367983A
Database access control method and device, database main system and electronic equipment
CN111783042A
