A method and system for cross-database query of microservices based on blockchain

By designing smart contracts on the blockchain and utilizing the network-wide consensus mechanism, the problems of data inconsistency and synchronization delay in cross-border query of microservices are solved, real-time synchronization and secure storage of data are realized, and data credibility and performance are improved. , and simplifies access to new nodes and management of abnormal nodes.

CN114490791BActive Publication Date: 2024-12-06中睿信数字技术有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210104576.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-28
Publication Date
2024-12-06
Estimated Expiration
2042-01-28

AI Technical Summary

Technical Problem

The existing data synchronization solution has data inconsistency, abnormal node perception delay, difficulty in accessing new nodes, and synchronization delay and insecurity in off-site computer rooms in microservices cross-store queries.

Method used

Using blockchain technology for real-time data synchronization, design smart contracts to realize automated synchronization and secure storage of data on the blockchain, use the blockchain's entire network consensus mechanism to ensure data consistency and security, and use microservices The historical data synchronization is automatically completed during node deployment.

Benefits of technology

It improves the trustworthiness and security of data, reduces business impact, improves capacity and performance, and realizes timely perception and elimination of abnormal nodes, simplifying the access process of new nodes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114490791B_ABST
    Figure CN114490791B_ABST
Patent Text Reader

Abstract

The present invention provides a method and system for cross-database query of microservices based on blockchain, and the method comprises: step 1: designing a smart contract according to a database table that needs to be associated, and deploying the smart contract on the blockchain based on a WeBase platform; step 2: when a computer room needs to perform an update operation on commodity data, based on corresponding update request information and commodity data to be updated, sending a transaction request to a control terminal of the blockchain; step 3: calling the smart contract, and executing a corresponding transaction on the blockchain according to a preset process; step 4: after reaching a transaction consensus based on the blockchain, storing the agreed state data; step 5: when a microservice needs to be associated with public business data for query, the microservice is associated with a database table synchronized to a local node of the blockchain, and data synchronization is automatically realized by adopting blockchain technology, thereby improving the credibility of the data and ensuring the security of the data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of blockchain technology, and in particular to a method and system for microservice cross-database query based on blockchain. Background Art

[0002] At present, the existing data synchronization table broadcast solution can basically realize the cross-database related query business of microservices, but the existing problems are also quite obvious. There are three specific pain points: 1. Based on the data synchronization mode, when the synchronization service is abnormal, it will cause inconsistent table data in different databases, affecting the final business; 2. It is impossible to perceive abnormal nodes in time; 3. It is not convenient to access new nodes; 4. For remote computer rooms, etc., synchronization has large delays and insecurity;

[0003] The present invention provides a method and system for cross-database query of microservices based on blockchain, which replaces the traditional microservice data synchronization or cross-database solution and uses the whole network consensus of blockchain to synchronize data in real time; through MySQL storage, distributed storage is realized, which can bring improvements in capacity and performance; when a new microservice node is deployed, the blockchain node can be automatically added to the blockchain network, and historical data synchronization can be automatically completed subsequently; the use of blockchain greatly improves data security. Summary of the invention

[0004] The present invention provides a method and system for microservice cross-database query based on blockchain, which is used to automatically realize data synchronization by adopting blockchain technology, thereby improving the credibility of data and ensuring the security of data.

[0005] The present invention provides a method for microservice cross-database query based on blockchain, comprising:

[0006] Step 1: Design smart contracts based on the database tables that need to be associated, and deploy them on the blockchain based on the WeBase platform;

[0007] Step 2: When the computer room needs to perform an update operation on the commodity data, a transaction request is sent to the control terminal of the blockchain based on the corresponding update request information and the commodity data to be updated;

[0008] Step 3: Call the corresponding smart contract and execute the corresponding transaction on the blockchain according to the preset process;

[0009] Step 4: After reaching a transaction consensus based on the blockchain, the agreed status data is stored;

[0010] Step 5: When the microservice needs to be associated with public business data for query, the microservice is associated with the database table synchronized to the local node by the blockchain.

[0011] In one possible implementation, step 1, before designing the smart contract, includes:

[0012] Step 1.1: Obtain the first minimum number of consensus nodes required by the blockchain;

[0013] Step 1.2: Based on the first number, determine the second number of computer rooms that serve as consensus institutions and the third number of startup nodes in each consensus institution, and use the nodes corresponding to other computer rooms that do not serve as consensus institutions as observation nodes to participate in block synchronization.

[0014] In one possible implementation, in step 1, before designing the smart contract, it also includes:

[0015] Step 1.4: Get relevant information of the blockchain node group configuration file;

[0016] Step 1.5: Modify the relevant information;

[0017] Step 1.6: Based on the modification results, confirm whether the blockchain's default node storage engine RocksDB has been changed to MySQL.

[0018] In one possible implementation, in step 2, based on the corresponding update request information and the commodity data to be updated, sending a transaction request to the control terminal of the blockchain includes:

[0019] Step 2.1: When the computer room needs to perform an update operation on the commodity data, the SDK interface provided by the WeBase platform is called, and the corresponding update request information is used as the first transaction request information;

[0020] Step 2.2: Using the commodity data to be updated as the second transaction request information;

[0021] Step 2.3: The WeBase platform sends the first transaction request information and the second transaction request information to the control terminal of the blockchain based on the protocol interface provided by the blockchain.

[0022] In one possible implementation, in step 3, the corresponding transaction is executed on the blockchain according to the preset process, specifically including:

[0023] Step 3.1: During the process of executing the first operation on the blockchain network, a first inspection is performed on the first operation according to an operation specification standard of the first operation;

[0024] Step 3.2: Obtaining an ideal result of the first operation based on an operation specification standard, and performing a second inspection on an actual operation result of the first operation based on the ideal result;

[0025] Step 3.3: Obtaining an expected result of the first operation based on the current operation standardization level, and performing a third inspection on the actual operation result of the first operation based on the expected result;

[0026] Step 3.4: Determine the eligibility of the first operation according to the first test result, the second test result and the third test result;

[0027] Step 3.5: When the eligibility satisfies the first condition, other operations except the first operation are performed in sequence based on the blockchain and according to a preset process;

[0028] Step 3.6: When the eligibility satisfies the second condition, a difference report corresponding to the first operation is obtained, and a correction plan corresponding to the difference report is retrieved for correction.

[0029] In one possible implementation, in step 4, before storing the agreed state data, the following steps are performed:

[0030] Obtaining historical consensus record information of all nodes in the blockchain, and using the historical consensus record information as content information to supplement the pre-built recognition model;

[0031] Acquire current position information of each node among all nodes, and determine current layout areas of all nodes based on the current position information;

[0032] Obtain the center position of the current layout area and the distance between the current position of each node and the center position, and use the center position as the center, the distance as the radius, and a preset direction and a preset starting position as the starting point to draw a circle toward each node;

[0033] When there is a first node at the center position, a first sorting number is set for the first node, and sorting numbers are set for other nodes except the first node according to the radius sizes corresponding to the remaining nodes, and a first sequence is generated in combination with the first sorting number;

[0034] Obtaining the arc line where multiple nodes with the same radius are located, and counting the order in which the nodes appear on the arc line according to the preset direction and starting from the preset starting position, and based on the order, updating the first order, generating a second order, and using it as the final order;

[0035] When the first node does not exist at the center position, obtain the second node corresponding to the minimum radius, set a first sorting number for the second node, and sort the remaining nodes in sequence to obtain the final order;

[0036] Control the recognition model to access all corresponding nodes in the last order, and obtain the time point when each node receives the transaction data and the corresponding transaction data information, and confirm whether the information to be determined of each node is consistent. If consistent, it is determined that the transaction consensus is reached;

[0037] If they are inconsistent, it is determined that no transaction consensus has been reached.

[0038] In a possible implementation, in step 4, after storing the agreed state data, the following is further included:

[0039] When a new microservice is expanded, a blockchain node is added, and data synchronization is automatically completed, maintaining the same data status as other nodes.

[0040] In a possible implementation, in step 4, after storing the agreed state data, the following is further included:

[0041] When a blockchain node tampers with data or engages in other abnormal behavior, the node whose ledger data is inconsistent with that of other blockchain nodes will be removed from the blockchain.

[0042] In one possible implementation, after removing nodes whose ledger data are inconsistent with other blockchain nodes from the blockchain, the following steps are performed:

[0043] Obtaining attribute information corresponding to the set tags of all nodes existing in the blockchain;

[0044] Obtain problem attribute information corresponding to the problem node information where data tampering or other abnormal behaviors have occurred, filter the attribute information based on the problem attribute information, and determine the effect of the blockchain on eliminating the problem nodes based on the filtering results.

[0045] The present invention provides a microservice cross-database query system based on blockchain, comprising:

[0046] Design module, which is used to design smart contracts according to the database tables associated as needed, and deploy them on the blockchain based on the WeBase platform;

[0047] A sending module, used for sending a transaction request to the control terminal of the blockchain based on the corresponding update request information and the commodity data to be updated when the computer room needs to perform an update operation on the commodity data;

[0048] The execution module is used to call the corresponding smart contract and execute the corresponding transaction on the blockchain according to the preset process;

[0049] The storage module is used to store the agreed status data after reaching a transaction consensus based on the blockchain;

[0050] The association module is used to associate the microservice with the database table synchronized to the local node of the blockchain when the microservice needs to be associated with the public business data for query.

[0051] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings.

[0052] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:

[0054] Figure 1 This is a flow chart of a microservice cross-database query based on a broadcast table in an embodiment of the present invention;

[0055] Figure 2 This is a flowchart of a microservice cross-database query based on blockchain in an embodiment of the present invention;

[0056] Figure 3 This is a flowchart of a method for cross-database query of microservices based on blockchain in an embodiment of the present invention;

[0057] Figure 4 This is a flow chart of sending a transaction request in an embodiment of the present invention;

[0058] Figure 5 This is a flow chart of executing a corresponding transaction on a blockchain according to a preset process in an embodiment of the present invention;

[0059] Figure 6 The present invention is a block diagram of a microservice cross-database query system based on blockchain in an embodiment of the present invention. DETAILED DESCRIPTION

[0060] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.

[0061] Traditional microservice table association query problems are mainly solved by using data synchronization tools to implement table broadcast or secondary association at the service level. The secondary association at the service level is mainly implemented by obtaining the required data through service calls, and returning it to the user after secondary association at the code level. This is very unfriendly for scenarios with large data volumes. For the corresponding table broadcast solution, in the business database, there are often some tables with small data volumes and low update frequency, but they are often needed for association queries. Broadcast tables have the following characteristics:

[0062] The data in the broadcast table is consistent in each shard;

[0063] Data insertion, updating, and deletion are performed once in each shard in real time;

[0064] Queries on broadcast tables are executed in only one shard;

[0065] Any table can be associated with a broadcast table.

[0066] Microservice blockchain underlying interaction flow chart:

[0067] The server in the Hangzhou data center is responsible for the product microservices and has a product microservice database. Through the WeBase management platform, the relevant data of the product microservices is deployed in the Hangzhou node in the blockchain according to the microservice data storage contract;

[0068] The server in the Shanghai data center is responsible for the payment microservice and has a payment microservice database. Through the WeBase management platform, the relevant data of the payment microservice is deployed in the Shanghai node in the blockchain according to the microservice data storage contract;

[0069] The Beijing data center server is responsible for the order microservice and has an order microservice database. Through the WeBase management platform, the relevant data of the order microservice is deployed in the Beijing node in the blockchain according to the microservice data storage contract;

[0070] When a new microservice is expanded, as long as the corresponding blockchain node is added, the previous historical data will be automatically synchronized based on the blockchain mechanism, and finally maintain the same data status as other nodes, and the relevant data of the new microservice will be deployed at the node of the corresponding area in the blockchain;

[0071] Among them, there is a connection between the Hangzhou node and the Shanghai node in the blockchain, there is a connection between the Shanghai node and the Beijing node, and there is a connection between the Beijing node and the new node.

[0072] Embodiment 1:

[0073] The embodiment of the present invention provides a method for cross-database query of microservices based on blockchain, such as Figure 3 As shown, including:

[0074] Step 1: Design smart contracts based on the database tables that need to be associated, and deploy them on the blockchain based on the WeBase platform;

[0075] Step 2: When the computer room needs to perform an update operation on the commodity data, a transaction request is sent to the control terminal of the blockchain based on the corresponding update request information and the commodity data to be updated;

[0076] Step 3: Call the corresponding smart contract and execute the corresponding transaction on the blockchain according to the preset process;

[0077] Step 4: After reaching a transaction consensus based on the blockchain, the agreed status data is stored;

[0078] Step 5: When the microservice needs to be associated with public business data for query, the microservice is associated with the database table synchronized to the local node by the blockchain.

[0079] In this embodiment, the smart contract can be simply understood as a piece of code written on the blockchain, which is event-driven, has a dynamic state, is recognized by multiple parties, and can automatically process information on the chain according to preset conditions. Once an event triggers a clause in the contract, the code will be automatically executed. The biggest advantage of smart contracts is that they use program algorithms to replace human arbitration and contract execution.

[0080] In this embodiment, the WeBase platform refers to the middleware platform built between the blockchain application and the FISCO BCOS node.

[0081] In this embodiment, the computer room may be any one of the computer rooms in Hangzhou, Shanghai, and Beijing.

[0082] In this embodiment, the update request information refers to update instruction information with letters, numbers or words, such as: KHGJ, KJI567, and the words "request update".

[0083] In this embodiment, the commodity data to be updated refers to data including commodity name, performance, quantity, etc. The commodities may be daily necessities, school supplies, maintenance supplies, experimental supplies, etc.

[0084] In this embodiment, the preset process refers to a process formed in the order of transaction verification, transaction broadcasting, transaction execution, and transaction consensus.

[0085] In this embodiment, the microservice may be any one or more of a user microservice, an order microservice, a product microservice, and a report statistics service.

[0086] The beneficial effects of the above technical solution are as follows: smart contracts are deployed on the blockchain, avoiding the risk of contract tampering, and are open and transparent on the blockchain, making it easy to view in a timely manner. Real-time data synchronization is performed with the help of the blockchain's full network consensus to avoid affecting the final business. Through distributed storage, capacity and performance improvements are brought about. When a new microservice node is deployed, it automatically connects to the blockchain network and automatically completes historical data synchronization. Abnormal nodes are also perceived in a timely manner to ensure data security.

[0087] Embodiment 2:

[0088] Based on Example 1, the embodiment of the present invention provides a method for cross-database query of microservices based on blockchain. In step 1, before designing a smart contract, the method includes:

[0089] Step 1.1: Obtain the first minimum number of consensus nodes required by the blockchain;

[0090] Step 1.2: Based on the first number, determine the second number of computer rooms that serve as consensus institutions and the third number of startup nodes in each consensus institution, and use the nodes corresponding to other computer rooms that do not serve as consensus institutions as observation nodes to participate in block synchronization.

[0091] In this embodiment, the first number is 4.

[0092] In this embodiment, the second number is 2.

[0093] In this embodiment, the third number is 2.

[0094] The beneficial effect of the above technical solution is: according to the minimum consensus node, the number of computer rooms serving as consensus organizations and the number of startup nodes in each consensus organization are limited to avoid too many nodes participating in the consensus and affecting the consensus efficiency.

[0095] Embodiment 3:

[0096] Based on Example 1, the embodiment of the present invention provides a method for cross-database query of microservices based on blockchain. In step 1, before designing the smart contract, it also includes:

[0097] Step 1.4: Get relevant information of the blockchain node group configuration file;

[0098] Step 1.5: Modify the relevant information;

[0099] Step 1.6: Based on the modification results, confirm whether the blockchain's default node storage engine RocksDB has been changed to MySQL.

[0100] In this embodiment, the blockchain node group configuration file is the configuration file group.1.ini.

[0101] In this embodiment, the relevant information includes information including database IP, database port, database account, database name, and database password.

[0102] In this embodiment, RocksDB refers to the default key-value database storage system of the blockchain.

[0103] In this embodiment, mysql refers to a relational database management system.

[0104] The beneficial effect of the above technical solution is: by confirming the modification results of the storage system, it is convenient to solve the problem of cross-database association query of microservices in a timely manner.

[0105] Embodiment 4:

[0106] Based on Example 1, the present invention provides a method for cross-database query of microservices based on blockchain, such as Figure 4 As shown, in step 2, based on the corresponding update request information and the commodity data to be updated, a transaction request is sent to the control terminal of the blockchain, including:

[0107] Step 2.1: When the computer room needs to perform an update operation on the commodity data, the SDK interface provided by the WeBase platform is called, and the corresponding update request information is used as the first transaction request information;

[0108] Step 2.2: Using the commodity data to be updated as the second transaction request information;

[0109] Step 2.3: The WeBase platform sends the first transaction request information and the second transaction request information to the control terminal of the blockchain based on the protocol interface provided by the blockchain.

[0110] The beneficial effect of the above technical solution is: by updating the request information and the commodity data to be updated, the corresponding transaction is determined so as to initiate a call to the smart contract, laying the foundation for the subsequent execution of transactions based on the smart contract.

[0111] Embodiment 5:

[0112] Based on Example 1, the present invention provides a method for cross-database query of microservices based on blockchain, such as Figure 5 As shown, in step 3, the corresponding transaction is executed in the blockchain according to the preset process, specifically including:

[0113] Step 3.1: During the process of executing the first operation on the blockchain network, a first inspection is performed on the first operation according to an operation specification standard of the first operation;

[0114] Step 3.2: Obtaining an ideal result of the first operation based on an operation specification standard, and performing a second inspection on an actual operation result of the first operation based on the ideal result;

[0115] Step 3.3: Obtaining an expected result of the first operation based on the current operation standardization level, and performing a third inspection on the actual operation result of the first operation based on the expected result;

[0116] Step 3.4: Determine the eligibility of the first operation according to the first test result, the second test result and the third test result;

[0117] Step 3.5: When the eligibility satisfies the first condition, other operations except the first operation are performed in sequence based on the blockchain and according to a preset process;

[0118] Step 3.6: When the eligibility satisfies the second condition, a difference report corresponding to the first operation is obtained, and a correction plan corresponding to the difference report is retrieved for correction.

[0119] In this embodiment, the first operation is a transaction verification operation.

[0120] In this embodiment, the operation specification standard is formed by the requirement information corresponding to the control based on each operation program.

[0121] In this embodiment, the first check refers to checking the execution process of the first operation according to the operation requirement corresponding to the first operation.

[0122] In this embodiment, the ideal result refers to the result generated by executing the first operation according to the operation specification standard.

[0123] In this embodiment, the second inspection refers to comparing the actual operation result with the ideal result to determine the deviation between them.

[0124] In this embodiment, the expected result refers to the result that should be produced when the first operation is executed according to the current operation standardization level, wherein the current operation standardization level can be: non-standard, generally standard, and very standard.

[0125] In this embodiment, the third inspection refers to comparing the actual operation result with the expected result to determine the deviation between them.

[0126] In this embodiment, qualification refers to the sum of three product results: the product result of the first test result and the corresponding first influence weight value, the product result of the second test result and the corresponding second influence weight value, and the product result of the third test result and the corresponding third influence weight value.

[0127] In this embodiment, the first condition refers to achieving a preset qualification.

[0128] In this embodiment, other operations refer to transaction broadcast, transaction execution, and transaction consensus.

[0129] In this embodiment, the second condition refers to failure to meet the preset eligibility.

[0130] In this embodiment, the difference report refers to a report including information such as the name of the difference object and the degree of difference.

[0131] In this embodiment, the correction scheme refers to a scheme including difference correction measures formulated for each difference object and the corresponding difference degree, and information such as the difference correction degree.

[0132] The beneficial effects of the above technical solution are: through three tests, accurate qualification determination results are ensured, further ensuring that each operation can be carried out accurately and efficiently, thereby improving the efficiency of transaction consensus.

[0133] Embodiment 6:

[0134] Based on Example 1, the embodiment of the present invention provides a method for cross-database query of microservices based on blockchain. In step 4, before storing the consistent state data, the method includes:

[0135] Obtaining historical consensus record information of all nodes in the blockchain, and using the historical consensus record information as content information to supplement the pre-built recognition model;

[0136] Acquire current position information of each node among all nodes, and determine current layout areas of all nodes based on the current position information;

[0137] Obtain the center position of the current layout area and the distance between the current position of each node and the center position, and use the center position as the center, the distance as the radius, and a preset direction and a preset starting position as the starting point to draw a circle toward each node;

[0138] When there is a first node at the center position, a first sorting number is set for the first node, and sorting numbers are set for other nodes except the first node according to the radius sizes corresponding to the remaining nodes, and a first sequence is generated in combination with the first sorting number;

[0139] Obtaining the arc line where multiple nodes with the same radius are located, and counting the order in which the nodes appear on the arc line according to the preset direction and starting from the preset starting position, and based on the order, updating the first order, generating a second order, and using it as the final order;

[0140] When the first node does not exist at the center position, obtain the second node corresponding to the minimum radius, set a first sorting number for the second node, and sort the remaining nodes in sequence to obtain the final order;

[0141] Control the recognition model to access all corresponding nodes in the last order, and obtain the time point when each node receives the transaction data and the corresponding transaction data information, and confirm whether the information to be determined of each node is consistent. If consistent, it is determined that the transaction consensus is reached;

[0142] If they are inconsistent, it is determined that no transaction consensus has been reached.

[0143] In this embodiment, the historical consensus record information refers to a record including information such as the consensus status corresponding to the historical transaction consensus of each node, the time when the consensus was reached, and the business data of the node that reached the consensus.

[0144] In this embodiment, the current location information refers to the relative location information of each node based on the layout area of ​​the blockchain.

[0145] In this embodiment, the current layout area refers to the area where all nodes are located, that is, the layout area of ​​the blockchain.

[0146] In this embodiment, the preset direction refers to a clockwise direction or a counterclockwise direction.

[0147] In this embodiment, the preset starting position refers to the position of any node.

[0148] In this embodiment, the circle drawing operation refers to expressing multiple nodes with the same distance from the center position in the form of arc lines, and placing the remaining nodes separately on the corresponding arc lines.

[0149] In this embodiment, the first order refers to the order obtained by sorting the nodes according to the distance between the nodes and the first node, which may or may not include the case where the sorting numbers are the same.

[0150] In this embodiment, updating the first sequence means reordering the corresponding nodes with the same sequence number in the first sequence according to the order in which they appear on the arc line, and integrating the reordered order and the order of other nodes except the nodes with the same sequence number;

[0151] For example: set the sorting number of the first node to 1, there is one node at the first distance from the center, which is the third node, and the sorting number is set to 2, there are three nodes at the second distance from the center, which are the fourth node, the fifth node, and the sixth node, and the sorting numbers are set to 3, 3, 3, there is one node at the third distance from the center, which is the seventh node, and the sorting number is set to 4, and in a clockwise direction, starting from the position of the fourth node, the order of appearance of the fourth node, the fifth node, and the sixth node is counted, and the order is: fourth node>sixth node>fifth node, among which the fourth node appears the earliest, so the sorting numbers of the fourth node, the fifth node, and the sixth node are adjusted to 4, 6, and 5, and the sorting number of the node corresponding to the third distance is adjusted to 7.

[0152] In this embodiment, the second order is adjusted according to the rule that a node has a sequence number, and all are different.

[0153] The beneficial effects of the above technical solution are: adjusting the sorting number set for the node to ensure that the recognition model identifies each node in an orderly manner, avoiding repeated recognition, saving time, and accurately determining whether a transaction consensus is reached by identifying the consensus situation of each node. When problems are found, they are eliminated in time to reduce the impact on consensus efficiency.

[0154] Embodiment 7:

[0155] Based on Example 1, the embodiment of the present invention provides a method for cross-database query of microservices based on blockchain. In step 4, after storing the agreed state data, it also includes:

[0156] When a new microservice is expanded, a blockchain node is added, and data synchronization is automatically completed, maintaining the same data status as other nodes.

[0157] In this embodiment, the data state refers to a modification state or a normal state.

[0158] The beneficial effect of the above technical solution is: based on the blockchain access mode, it is possible to synchronize historical data while deploying new blockchain nodes for new microservices.

[0159] Embodiment 8:

[0160] Based on Example 1, the embodiment of the present invention provides a method for cross-database query of microservices based on blockchain. In step 4, after storing the agreed state data, it also includes:

[0161] When a blockchain node tampers with data or engages in other abnormal behavior, the node whose ledger data is inconsistent with that of other blockchain nodes will be removed from the blockchain.

[0162] In this embodiment, other abnormal behavior may be data loss.

[0163] The beneficial effects of the above technical solution are: abnormal nodes can be detected in a timely manner through the consensus mechanism of the blockchain, and consensus can be eliminated in a timely manner to reduce the impact on consensus efficiency.

[0164] Embodiment 9:

[0165] Based on Example 8, the embodiment of the present invention provides a method for cross-database query of microservices based on blockchain, after removing nodes whose ledger data are inconsistent with other blockchain nodes from the blockchain, including:

[0166] Obtaining attribute information corresponding to the set tags of all nodes existing in the blockchain;

[0167] Obtain problem attribute information corresponding to the problem node information where data tampering or other abnormal behaviors have occurred, filter the attribute information based on the problem attribute information, and determine the effect of the blockchain on eliminating the problem nodes based on the filtering results.

[0168] In this embodiment, the attribute information refers to information such as the size, amount, data type, and data access time of the data stored on the node.

[0169] In this embodiment, the problem attribute information refers to information such as the size of the data stored corresponding to the problem node, the amount of data, the data type, the time when the data problem occurred, and the type of problem data.

[0170] In this embodiment, screening refers to comparing the attribute information with the problem attribute information to confirm whether the problem node still exists.

[0171] The beneficial effects of the above technical solution are: based on the screening of problem nodes, the elimination effect can be truly understood to ensure that the problem nodes can be accurately eliminated to avoid affecting the transaction consensus.

[0172] Embodiment 10:

[0173] The embodiment of the present invention provides a microservice cross-database query system based on blockchain, such as Figure 6 As shown, including:

[0174] Design module, which is used to design smart contracts according to the database tables associated as needed, and deploy them on the blockchain based on the WeBase platform;

[0175] A sending module, used for sending a transaction request to the control terminal of the blockchain based on the corresponding update request information and the commodity data to be updated when the computer room needs to perform an update operation on the commodity data;

[0176] The execution module is used to call the corresponding smart contract and execute the corresponding transaction on the blockchain according to the preset process;

[0177] The storage module is used to store the agreed status data after reaching a transaction consensus based on the blockchain;

[0178] The association module is used to associate the microservice with the database table synchronized to the local node of the blockchain when the microservice needs to be associated with the public business data for query.

[0179] The beneficial effects of the above technical solution are as follows: smart contracts are deployed on the blockchain, avoiding the risk of contract tampering, and are open and transparent on the blockchain, making it easy to view in a timely manner. Real-time data synchronization is performed with the help of the blockchain's full network consensus to avoid affecting the final business. Through distributed storage, capacity and performance improvements are brought about. When a new microservice node is deployed, it automatically connects to the blockchain network and automatically completes historical data synchronization. Abnormal nodes are also perceived in a timely manner to ensure data security.

[0180] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A method for cross-database query of microservices based on blockchain, characterized in that: include: Step 1: Design smart contracts based on the database tables that need to be associated, and deploy them on the blockchain based on the WeBase platform; Step 2: When the computer room needs to perform an update operation on the commodity data, a transaction request is sent to the control terminal of the blockchain based on the corresponding update request information and the commodity data to be updated; Step 3: Call the corresponding smart contract and execute the corresponding transaction on the blockchain according to the preset process; Step 4: After reaching a transaction consensus based on the blockchain, the agreed status data is stored; Step 5: When the microservice needs to be associated with public business data for query, the microservice is associated with the database table synchronized to the local node by the blockchain; In step 4, before storing the agreed state data, the following steps are performed: Obtaining historical consensus record information of all nodes in the blockchain, and using the historical consensus record information as content information to supplement the pre-built recognition model; Acquire current position information of each node among all nodes, and determine current layout areas of all nodes based on the current position information; Obtain the center position of the current layout area and the distance between the current position of each node and the center position, and use the center position as the center, the distance as the radius, and a preset direction and a preset starting position as the starting point to draw a circle toward each node; When there is a first node at the center position, a first sorting number is set for the first node, and sorting numbers are set for other nodes except the first node according to the radius sizes corresponding to the remaining nodes, and a first sequence is generated in combination with the first sorting number; Obtaining the arc line where multiple nodes with the same radius are located, and counting the order in which the nodes appear on the arc line according to the preset direction and starting from the preset starting position, and based on the order, updating the first order, generating a second order, and using it as the final order; When the first node does not exist at the center position, obtain the second node corresponding to the minimum radius, set a first sorting number for the second node, and sort the remaining nodes in sequence to obtain the final order; Control the recognition model to access all corresponding nodes in the last order, and obtain the time point when each node receives the transaction data and the corresponding transaction data information, and confirm whether the information to be determined of each node is consistent. If consistent, it is determined that the transaction consensus is reached; If they are inconsistent, it is determined that no transaction consensus has been reached.

2. According to a method for cross-database query of microservices based on blockchain according to claim 1, it is characterized in that: In step 1, before designing the smart contract, include: Step 1.1: Obtain the first minimum number of consensus nodes required by the blockchain; Step 1.2: Based on the first number, determine the second number of computer rooms that serve as consensus institutions and the third number of startup nodes in each consensus institution, and use the nodes corresponding to other computer rooms that do not serve as consensus institutions as observation nodes to participate in block synchronization.

3. According to a method for cross-database query of microservices based on blockchain according to claim 1, it is characterized in that: In step 1, before designing the smart contract, it also includes: Step 1.4: Get relevant information of the blockchain node group configuration file; Step 1.5: Modify the relevant information; Step 1.6: Based on the modification results, confirm whether the blockchain's default node storage engine RocksDB has been changed to MySQL.

4. According to a method for cross-database query of microservices based on blockchain in claim 1, it is characterized in that: In step 2, based on the corresponding update request information and the commodity data to be updated, a transaction request is sent to the control terminal of the blockchain, including: Step 2.1: When the computer room needs to perform an update operation on the commodity data, the SDK interface provided by the WeBase platform is called, and the corresponding update request information is used as the first transaction request information; Step 2.2: Using the commodity data to be updated as the second transaction request information; Step 2.3: The WeBase platform sends the first transaction request information and the second transaction request information to the control terminal of the blockchain based on the protocol interface provided by the blockchain.

5. According to a method for cross-database query of microservices based on blockchain according to claim 1, it is characterized in that: In step 3, the corresponding transaction is executed on the blockchain according to the preset process, including: Step 3.1: During the process of executing the first operation on the blockchain, a first inspection is performed on the first operation according to an operation specification standard of the first operation; Step 3.2: Obtaining an ideal result of the first operation based on an operation specification standard, and performing a second inspection on an actual operation result of the first operation based on the ideal result; Step 3.3: Obtaining an expected result of the first operation based on the current operation standardization level, and performing a third inspection on the actual operation result of the first operation based on the expected result; Step 3.4: Determine the eligibility of the first operation according to the first test result, the second test result and the third test result; Step 3.5: When the eligibility satisfies the first condition, other operations except the first operation are performed in sequence based on the blockchain and according to a preset process; Step 3.6: When the eligibility satisfies the second condition, a difference report corresponding to the first operation is obtained, and a correction plan corresponding to the difference report is retrieved for correction.

6. According to a method for cross-database query of microservices based on blockchain in claim 1, it is characterized in that: In step 4, after the agreed state data is stored, the following steps are also included: When a new microservice is expanded, a blockchain node is added, and data synchronization is automatically completed, maintaining the same data status as other nodes.

7. According to a method for cross-database query of microservices based on blockchain in claim 1, it is characterized in that: In step 4, after the agreed state data is stored, the following steps are also included: When a blockchain node tampers with data or engages in other abnormal behavior, the node whose ledger data is inconsistent with that of other blockchain nodes will be removed from the blockchain.

8. According to a method for cross-database query of microservices based on blockchain according to claim 7, it is characterized in that: After removing nodes whose ledger data are inconsistent with other blockchain nodes from the blockchain, including: Obtaining attribute information corresponding to the set tags of all nodes existing in the blockchain; Obtain problem attribute information corresponding to the problem node information where data tampering or other abnormal behaviors have occurred, filter the attribute information based on the problem attribute information, and determine the effect of the blockchain on eliminating the problem nodes based on the filtering results.

9. A microservice cross-database query system based on blockchain, characterized in that: include: Design module, which is used to design smart contracts according to the database tables associated as needed, and deploy them on the blockchain based on the WeBase platform; A sending module, used for sending a transaction request to the control terminal of the blockchain based on the corresponding update request information and the commodity data to be updated when the computer room needs to perform an update operation on the commodity data; The execution module is used to call the corresponding smart contract and execute the corresponding transaction on the blockchain according to the preset process; The storage module is used to store the agreed status data after reaching a transaction consensus based on the blockchain; An association module, used to associate the microservice with the database table synchronized to the local node by the blockchain when the microservice needs to be associated with the public business data for query; Before storing the agreed state data, it includes: Obtaining historical consensus record information of all nodes in the blockchain, and using the historical consensus record information as content information to supplement the pre-built recognition model; Acquire current position information of each node among all nodes, and determine current layout areas of all nodes based on the current position information; Obtain the center position of the current layout area and the distance between the current position of each node and the center position, and use the center position as the center, the distance as the radius, and a preset direction and a preset starting position as the starting point to draw a circle toward each node; When there is a first node at the center position, a first sorting number is set for the first node, and sorting numbers are set for other nodes except the first node according to the radius sizes corresponding to the remaining nodes, and a first sequence is generated in combination with the first sorting number; Obtaining the arc line where multiple nodes with the same radius are located, and counting the order in which the nodes appear on the arc line according to the preset direction and starting from the preset starting position, and based on the order, updating the first order, generating a second order, and using it as the final order; When the first node does not exist at the center position, obtain the second node corresponding to the minimum radius, set a first sorting number for the second node, and sort the remaining nodes in sequence to obtain the final order; Control the recognition model to access all corresponding nodes in the last order, and obtain the time point when each node receives the transaction data and the corresponding transaction data information, and confirm whether the information to be determined of each node is consistent. If consistent, it is determined that the transaction consensus is reached; If they are inconsistent, it is determined that no transaction consensus has been reached.