A multi-database routing method and system

By using unique identification information and preset strings to redetermine the database in a multi-database environment, the problems of poor processing capabilities of single databases and uneven routing of multiple databases are solved, and business processing capabilities and query efficiency are improved.

CN114490564BActive Publication Date: 2025-04-11NETSUNION CLEARING CORP
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202011166055.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-10-27
Publication Date
2025-04-11
Estimated Expiration
2040-10-27

AI Technical Summary

Technical Problem

In the prior art, single database business processing capabilities are poor, and the routing is uneven when a faulty database occurs in multiple databases, and the query efficiency is low.

Method used

A multi-database routing method is provided, by receiving transaction requests with unique identification information, determining the target database, and when the database fails, the database is re-determined using the identification information and preset strings until a normal database is found.

Benefits of technology

It solves the problem of uneven traffic in the faulty database, ensures that transaction requests can find a normal available database, and improves business processing capabilities and query efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114490564B_ABST
    Figure CN114490564B_ABST
Patent Text Reader

Abstract

The present invention discloses a multi-database routing method and system, the method comprising: receiving a transaction request carrying first identification information corresponding to a transaction operation; determining a first database according to the first identification information; in the case of a failure of the first database, re-determining the first database according to the first identification information and a preset character string until the re-determined first database is normal; in the case of a normal first database, determining the first database as a target database, and storing the transaction operation result corresponding to the transaction request in the target database. The present invention ensures the uniqueness of the information and thus the uniqueness of the matching process by receiving a request with unique first identification information; solves the technical problem of evenly or quasi-evenly distributing the traffic of a failed database to the remaining normal databases, solves the problem of uneven routing, and improves the business processing capability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data storage, and in particular to a multi-database routing method and system. Background Art

[0002] The acquiring institution initiates a transaction request, which is routed through the acquiring channel and forwarded to the transaction service. After business processing, the transaction service selects an available database for transaction storage operations. The account channel forwards the transaction request to the account institution after signing and other processing. However, with the continuous increase in business transaction volume, a single database can no longer support the current business volume, has poor business processing capabilities, and cannot provide highly available services. In the case of multiple databases, once a database failure occurs in the existing routing method, it will cause problems such as uneven routing and low query efficiency. Summary of the invention

[0003] In view of this, an embodiment of the present invention provides a multi-database routing method and system to solve the problems of poor business processing capability of a single database, uneven routing when a faulty database occurs in multiple databases, and low query efficiency in the prior art.

[0004] In order to achieve the above object, the present invention provides the following technical solutions:

[0005] In a first aspect, an embodiment of the present invention provides a multi-database routing method, comprising the following steps: receiving a transaction request, the transaction request carrying first identification information corresponding to a transaction operation; determining a first database according to the first identification information; in the event of a failure of the first database, redetermining the first database according to the first identification information and a preset character string until the redetermined first database is normal; in the event that the first database is normal, determining the first database as a target database, and storing a transaction operation result corresponding to the transaction request in the target database.

[0006] In one embodiment, determining the first database according to the first identification information includes: calculating a first Hash value of the first identification information; calculating a remainder of dividing the first Hash value by the total number of databases, and determining the first database according to the remainder.

[0007] In one embodiment, the redetermining the first database based on the first identification information and the preset character string includes: generating second identification information based on the first identification information and the preset character string; calculating a second hash value of the second identification information, and determining the second database based on the remainder of dividing the second hash value by the total number of databases; judging whether the second database is faulty, and updating the number of executions, wherein the number of executions is used to reflect the number of judgments for judging whether the second database is faulty; in the case of a fault in the second database, if the number of executions is less than a preset threshold, re-executing the above steps until the redetermined second database is normal or the number of executions reaches the preset threshold; in the case of a fault in the second database, determining the second database as the redetermined first database.

[0008] In one embodiment, the multi-database routing method provided by the embodiment of the present invention further includes the following steps: when the number of executions reaches the preset threshold, generating third identification information according to the remainder of dividing the second hash value by the total number of databases and a preset value; determining a third database according to the third identification information, and judging whether the third database is faulty; when the third database is faulty, re-executing the above steps until the re-determined third database is normal; when the third database is normal, determining the third database as the re-determined first database.

[0009] In one embodiment, the multi-database routing method further includes the following steps: determining an available database list according to an operating status of each database, wherein the operating status includes fault or normal; after determining the first database according to the first identification information, the method further includes: judging whether the first database exists in the available database list; if the first database exists in the available database list, determining that the first database is normal; if the first database does not exist in the available database list, determining that the first database is faulty.

[0010] In one embodiment, the multi-database routing method further includes the following steps: recording a mapping relationship between the first identification information and a target database where the transaction operation result is actually stored; receiving a transaction query request, the transaction query request carrying the first identification information; performing a transaction query based on the mapping relationship and the first identification information to obtain a query result.

[0011] In a second aspect, an embodiment of the present invention provides a multi-database routing system, comprising the following modules: a receiving module, used to receive a transaction request, the transaction request carrying unique identification information of a transaction operation; a first processing module, used to determine a first database according to the unique identification information; a second processing module, used to, in the event that the first database fails, redetermine the first database according to the unique identification information and a preset character string until the redetermined first database is normal; a third processing module, used to, in the event that the first database is normal, determine the first database as a target database, and store the transaction operation result corresponding to the transaction request in the target database.

[0012] In a third aspect, an embodiment of the present invention provides an electronic device, comprising: at least one processor, and a memory communicatively connected to the at least one processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor executes the multi-database routing method of the first aspect of the embodiment of the present invention.

[0013] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the multi-database routing method of the first aspect of the embodiment of the present invention.

[0014] At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects:

[0015] The multi-database routing method and system provided by the present invention ensure the uniqueness of information and thus the uniqueness of the matching process by receiving a request with unique first identification information; use the first identification information to match the first database where the transaction operation information needs to be stored, and in the event of a failure of the first database, use the first identification information and a preset character string to redetermine the first database until the redetermined first database is normal, determine the first database as the target database, and store the transaction operation result corresponding to the transaction request in the target database; solve the technical problem of evenly or quasi-evenly distributing the traffic of the failed database to the remaining normal databases, and solve the problem of uneven routing; at the same time, ensure that a transaction can find a normal and available database, and the implementation method is simple, thereby improving the business processing capability. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0017] Figure 1 A flowchart of a specific example of the interaction process of various services in the acquiring process provided by an embodiment of the present invention;

[0018] Figure 2 A flowchart of a specific example of a multi-database routing method provided by an embodiment of the present invention;

[0019] Figure 3 A flowchart of a specific example of redetermining a first database provided by an embodiment of the present invention;

[0020] Figure 4 A module composition diagram of a multi-database routing system provided by an embodiment of the present invention;

[0021] Figure 5 A composition diagram of a specific example of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0022] The technical solution of the present invention will be described clearly and completely below in conjunction with the accompanying drawings. Obviously, the described embodiments are only 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.

[0023] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.

[0024] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, it can also be the internal connection of two components, it can be a wireless connection, or it can be a wired connection. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0025] In addition, the technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0026] Example 1

[0027] The embodiment of the present invention provides a multi-database routing method, which mainly implements a routing solution in the case of multiple databases, and how to more easily implement the uniform routing of the database when a database failure occurs, and can quickly locate the database where the data is located when querying the data in each database, reduce unnecessary queries, and improve the efficiency of database operation. Routing in the embodiment of the present invention refers to the process in which a router receives a data packet from one interface, directs it according to the destination address of the data packet, and forwards it to another interface. The main difference between routing and bridging is that bridging occurs at the second layer (data link layer) of the OSI reference model, while routing occurs at the third layer (network layer). This difference causes the two to use different information in the process of transmitting information, thereby completing their tasks in different ways.

[0028] Taking the UnionPay barcode acquiring as an example, the interaction between various services in the acquiring process is explained. Figure 1 As shown in the figure, the acquiring institution initiates a transaction request, which is routed through the acquiring channel and forwarded to the transaction service. After business processing, the transaction service selects an available database for transaction storage operations. The transaction service forwards the transaction request to the account channel, and the account channel forwards the transaction request to the account institution after signing and other processing. With the continuous increase in the transaction volume of NetsUnion, a single database can no longer support the current business volume and cannot provide high-availability services. Against this background, NetsUnion uses multiple databases to solve the single database problem, improve business processing capabilities, and achieve high-availability services.

[0029] like Figure 2 As shown, the multi-database routing method of the embodiment of the present invention includes the following steps:

[0030] Step S1: receiving a transaction request, where the transaction request carries first identification information corresponding to a transaction operation.

[0031] In the embodiment of the present invention, the received transaction request carries the unique first identification information of the transaction operation, so as to facilitate routing the transaction request and matching the corresponding transaction service. For example, in general, the transaction request carries the first identification information of the transaction operation, which generally includes three elements of the transaction service: address, protocol format and protocol name. The network interface can be accessed through the address, and the address includes the following elements: IP address, service port, service protocol (TCP, UDP, etc.); the protocol format refers to which fields the protocol has, which is determined after negotiation between the interface provider and the protocol caller; the protocol name or protocol type, because on the same service listening port, multiple interfaces may be provided to the caller at the same time, and the protocol type (name) is needed to distinguish different network interfaces; the transaction institution number + order number can also be used as the first identification, and then the first identification is used to match the first database that the transaction operation needs to fall into. It should be noted that in the embodiment of the present invention, the unique first identification information contained in the transaction request is only illustrated by example, and in actual applications, it can also be other ways, which are set and adjusted according to actual system requirements, and the present invention is not limited to this.

[0032] Step S3: Determine the first database according to the first identification information.

[0033] In the embodiment of the present invention, a matching first database is searched according to the first identification information. Prior to this, it is necessary to perform a database ID assignment operation on each database, and assign IDs to multiple databases in sequence, for example, assigning database IDs as 00, 01, 02, 03...mn. After obtaining the matching first database, it is necessary to determine whether this database is a faulty database, wherein the fault may be a database transaction fault (referring to a transaction not running to a normal termination point during its operation, such as incorrect input data, calculation overflow, application error, parallel transaction deadlock, etc.), a system fault (referring to a normal operation of the entire system being stopped due to some reason, causing all running transactions to be stopped). The running transactions are terminated in an abnormal way, such as operating system failure, operator error, system CPU failure, system power failure, etc.) or medium failure (referring to hardware failure that causes partial or complete loss of data stored in external memory, such as hard disk damage, head collision, instantaneous strong magnetic field interference, etc.), or the database cannot perform data operations during the maintenance stage, because if a database has a failure or is in the maintenance stage, this database cannot perform corresponding data operations. At this time, after receiving the transaction request, the faulty database needs to be excluded in the process of selecting data to be stored in the database, and at the same time, it is also necessary to consider that the process of data storage can ensure that each database can distribute traffic as evenly as possible. That is, after receiving the transaction request, the transaction service operation is not performed immediately, but it is necessary to first determine whether the database is faulty. It should be noted that the failure condition of the database in the embodiment of the present invention can be adjusted accordingly according to the requirements of the security and accuracy of the actual system, and the method for detecting database failure is also adaptively adjusted according to the failure condition, wherein the assignment of the database ID is also set according to the actual situation, and the present invention is not limited to this.

[0034] Step S5: in the case of a failure of the first database, the first database is re-determined according to the first identification information and a preset character string until the re-determined first database is normal.

[0035] In the embodiment of the present invention, if the first database fails, it means that the transaction operation cannot fall into the first database at this time, which means that the problem of uniform storage of operation data in the database needs to be considered at this time, and the first database needs to be re-determined according to the first identification information and the preset string until the first database is re-determined to be normal, so as to solve the technical problem of how to evenly or quasi-evenly distribute the traffic of the faulty database to the remaining available databases except the faulty database, so as not to make all the relevant data of the transaction operation fall into a fixed database, causing an avalanche effect and uneven routing. It should be noted that the uniform storage mentioned in the embodiment of the present invention is only a relative state, not an absolute uniformity, and the present invention is not limited to this.

[0036] Step S7: when the first database is normal, the first database is determined as the target database, and the transaction operation result corresponding to the transaction request is stored in the target database.

[0037] The multi-database routing method provided by the present invention ensures the uniqueness of information and thus the uniqueness of the matching process by receiving a request with unique first identification information; uses the first identification information to match the first database where the transaction operation information needs to be stored, and in the event of a failure of the first database, uses the first identification information and a preset character string to redetermine the first database until the redetermined first database is normal, determines the first database as the target database, and stores the transaction operation result corresponding to the transaction request in the target database; solves the technical problem of evenly or quasi-evenly distributing the traffic of the failed database to the remaining normal databases, and solves the problem of uneven routing; at the same time, ensures that a transaction can find a normal and available database, and the implementation method is simple, thereby improving the business processing capability.

[0038] In a specific embodiment, determining the first database according to the first identification information includes the following steps:

[0039] Step S31: Calculate a first hash value of the first identification information.

[0040] In the embodiment of the present invention, the first identification information of the transaction operation carried by the transaction request is hashed to obtain the first hash value, wherein the first identification information is hashed using a hash algorithm. What the hash algorithm needs to do is to generate a fixed-length data for a data of any size as its mapping. The so-called mapping is a one-to-one correspondence. A reliable hash algorithm must meet three points: the first is security. Given data M, it is easy to calculate the hash value X, while given hash value X cannot calculate M, or the hash algorithm should be a one-way algorithm; the second is uniqueness. Two different data must have different hashes. The third is fixed length. Given a hash algorithm, no matter how large the input data is, the output length is fixed, and for different hash algorithms, the more hash bits, the higher the security level.

[0041] In practical applications, there are many kinds of hash algorithms, such as md5, sha256, etc., but they can be generally divided into two categories, one is ordinary hash, and the other is encrypted hash; currently MD5 can only be used as ordinary hash for data verification; the difference between encrypted hash and ordinary hash is security, and only hash algorithms with high security can be used as encrypted hash. Generally speaking, the more secure the hash algorithm, the slower the processing speed, so it is not suitable to use encrypted hash to replace ordinary hash in all occasions.

[0042] It should be noted that the selection of the hash algorithm in the embodiment of the present invention is based on actual security and system processor performance, and the specific selection of the hash function is also adjusted according to actual needs, and the present invention is not limited to this.

[0043] Step S33: Calculate the remainder of dividing the first hash value by the total number of databases, and determine the first database according to the remainder.

[0044] In an embodiment of the present invention, after obtaining the first hash value, the remainder of dividing the first hash value by the total number of databases is calculated, and the total number of databases includes normal databases and faulty databases; after obtaining the remainder, the remainder is used to match each database, for example, if the remainder is 02, then according to the IDs of multiple databases, the database with the corresponding database ID of 02 is matched, and the first database is obtained according to the matching result (the database with the database ID of 02). After obtaining the first database, it is necessary to determine whether the first database is faulty. If the first database is a faulty database, it is necessary to recalculate and match. If the first database is not a faulty database, the transaction operation can be directly placed in the first database.

[0045] In a specific embodiment, if Figure 3 As shown, re-determining the first database according to the first identification information and the preset character string includes the following steps:

[0046] Step S10: Generate second identification information according to the first identification information and a preset character string.

[0047] In an embodiment of the present invention, the process of generating the second identification information based on the first identification information and the preset character string is a process of a salting algorithm. The basic idea of ​​the salting algorithm is that when the user provides a password for the first time (usually when registering), the system automatically adds some "condiments" (i.e., the preset character string in the embodiment of the present invention) to the password, and then hashes it to ensure the security of the data. The first identification information is added with the preset character string to obtain the second identification information, and the second identification information is matched with the first database using the second identification information. It should be noted that the preset character string in the embodiment of the present invention is set and adjusted according to actual security requirements, and is an arbitrary fixed character string, such as a barcode added to the first key, or any other arbitrary character string. This is only used as an example, and the present invention is not limited to this.

[0048] Step S20: Calculate the second hash value of the second identification information, and determine the second database according to the remainder of dividing the second hash value by the total number of databases. In an embodiment of the present invention, the second identification information is hashed to obtain a second hash value, the remainder of dividing the second hash value by the total number of databases is calculated, and the remainder is used to match each database, and the second database is determined according to the matching result. It should be noted that in the process of using a hash algorithm to take a hash value from the second identification information, the same algorithm as the algorithm for calculating the first hash value can be selected, or an algorithm different from the algorithm for calculating the first hash value can be selected, and the selection is made according to actual needs, and the present invention is not limited to this.

[0049] Step S30: determine whether the second database is faulty, and update the execution count, where the execution count is used to reflect the number of determinations for determining whether the second database is faulty.

[0050] Step S40: In the case of a fault in the second database, if the number of executions is less than a preset threshold, the above step S10 is re-executed until it is determined again that the second database is normal or the number of executions reaches the preset threshold.

[0051] If the second database found is also a faulty database, and the updated execution times are less than the preset threshold, the second identification information at this time needs to be re-determined as the first identification information, and the above-mentioned preset string (such as barcode) is added again, that is, the second identification information is further added with the above-mentioned preset string and then the matching is repeated until the database found is an available database and the process is terminated. If the execution times reach a certain preset threshold, it means that an available database has not been found after multiple cycles, for example, if an available database has not been found after 5 cycles, then the preset string will no longer be added, the cycle is terminated, and other algorithms will be selected for matching.

[0052] It should be noted that the preset threshold is freely defined. The embodiment of the present invention only illustrates that the preset threshold is 5. In actual applications, it can be any customized value, which is determined according to the actual performance of the system. The present invention is not limited to this.

[0053] Step S50: when the redetermined second database is normal, the second database is determined as the redetermined first database.

[0054] Step S60: When the number of executions reaches a preset threshold, the third identification information is generated according to the remainder of the second hash value divided by the total number of databases and the preset value. In the embodiment of the present invention, if the number of executions reaches the preset threshold, the identification information needs to be re-determined, and the third identification information is generated according to the remainder of the second hash value divided by the total number of databases and the preset value. Specifically, the remainder of the second hash value divided by the total number of databases is reduced by the preset value each time, and is reduced in sequence, that is, the above-determined remainder is reduced by any one of 1 or n digits, and is reduced in sequence to obtain the third identification information; that is, for example, the second identification information is reduced by 1 to obtain the third identification information, and then the third identification information is matched with each database ID, and the third database is obtained according to the matching result. If the third target database fails, the third identification information is continued to be reduced by 1, and this process is repeated until it is determined that the third database is normal, and an available target database is selected.

[0055] Step S70: Determine the third database according to the third identification information, and determine whether the third database is faulty. In the embodiment of the present invention, after the third identification information is determined, the database is matched according to the third identification information, and the third database is determined according to the matching result, wherein the matching method is the same as the matching method of the first database, and the third identification information is matched with the database ID, which will not be described in detail here.

[0056] Step S80: In the case of a failure of the third database, re-execute the above step S60 until the third database is re-determined to be normal. In the embodiment of the present invention, if the third database is still faulty, the current third identification information is re-determined as the second hash value, and then the process returns to step S60, that is, the third identification information is re-generated based on the remainder of the second hash value divided by the total number of databases and the preset value, the identification information is re-determined, and then the database is matched.

[0057] Step S90: when the third database is normal, determine the third database as the re-determined first database.

[0058] In a specific embodiment, the multi-database routing method provided by the embodiment of the present invention further includes the following steps:

[0059] Step S01: Determine a list of available databases according to the operating status of each database, where the operating status includes failure or normal.

[0060] In an embodiment of the present invention, after a faulty database is detected, it is marked as a faulty database, and its operating state is updated to a faulty state. After the database is detected as a normal database, its operating state is marked as a normal state, and a list of available databases is maintained in the memory. In the detection process again and again, the operating state of the database is continuously updated. For example, a re-detection can be set at a preset interval to determine whether the current faulty / normal database is still faulty / normal. If there is a change, the corresponding operating state is changed. It is also possible to determine the corresponding database failure for each database, and use certain specific information to determine whether the database is in a transaction failure, system failure or medium failure, etc. Once a database is determined to be faulty, it is deleted from the list of available databases, and then the unavailable database is judged for a period of time, and the repaired database is added to the list of available databases.

[0061] In the process of updating the list of available databases, a topological relationship can also be established to a certain extent, that is, a topological relationship between the database operation state and the list of available databases is established. Once the database operation state changes, the topological relationship also needs to change. The reconstruction of the topological relationship should be synchronized with the update of the database operation state. It should be noted that the embodiment of the present invention only illustrates the process of updating the list of available databases. In actual applications, other updating methods can also be selected, and the present invention is not limited thereto.

[0062] After determining the first database according to the first identification information, the multi-database routing method further includes:

[0063] Step S301: Determine whether the first database exists in the available database list. In the embodiment of the present invention, after obtaining the first database, determine whether the first database is in the available database list maintained in the system memory, and according to the available database list in the current state, determine that the database in the current available database list is an available normal database.

[0064] Step S303: if the first database exists in the list of available databases, determine that the first database is normal.

[0065] Step S305: if the first database does not exist in the list of available databases, determine that the first database fails.

[0066] In a specific embodiment, the multi-database routing method provided by the embodiment of the present invention further includes the following steps:

[0067] Step S011: Record the mapping relationship between the first identification information and the target database where the transaction operation results are actually stored. In the embodiment of the present invention, in order to avoid some invalid queries in the subsequent data query process, after the transaction storage database corresponding to each identification information is determined, the mapping relationship between the first identification information and the target database where the transaction operation results are actually stored is recorded.

[0068] Step S021: receiving a transaction query request, the transaction query request carrying first identification information. In an embodiment of the present invention, a transaction query request carrying first identification information known to the transaction request is received.

[0069] Step S031: Perform transaction query according to the mapping relationship and the first identification information to obtain the query result.

[0070] In the embodiment of the present invention, when the first identification information carried in the transaction is used for querying, the corresponding transaction database can be found according to the above-mentioned process of falling into the database, but some invalid queries will be caused. In order to avoid invalid queries, a redis component is added to store the mapping relationship between the first identification information and the actual database, which greatly reduces the invalid queries of the database. Among them, redis supports a variety of data structures, such as string (string), list (bidirectional linked list), dict (hash table), set (set), zset (sorted set), hyperloglog (cardinality estimation); supports persistence operations, and can persist aof and rdb data to disk, so as to perform operations such as data backup or data recovery, which is a better means to prevent data loss; supports single-threaded requests, all commands are executed serially, and data consistency issues do not need to be considered in concurrent situations. It should be noted that the embodiment of the present invention only illustrates the example of adding a redis component to store the mapping relationship between the first identification information and the actual database. In practical applications, other components such as mongodb can also be selected, and the present invention is not limited to this.

[0071] The multi-database routing method provided by the present invention ensures the uniqueness of information and thus the uniqueness of the matching process by receiving a request with unique first identification information; uses the first identification information to match the first database where the transaction operation information needs to be stored; in the case of a failure of the first database, uses the first identification information and a preset string to redetermine the first database until the redetermined first database is normal, determines the first data as the target database, and stores the transaction operation result corresponding to the transaction request in the target database; solves the technical problem of distributing the flow of the failed database to the remaining normal databases on an average or similar average basis, and solves the problem of uneven routing; at the same time, ensures that a transaction can find a normal and available database, and the implementation method is simple, improving the business processing capability. At the same time, by adding a redis component, invalid queries of the database are greatly reduced, and query efficiency is improved.

[0072] Example 2

[0073] The embodiment of the present invention provides a multi-database routing system, such as Figure 4 As shown, including:

[0074] The receiving module 1 is used to receive a transaction request, which carries unique identification information of the transaction operation. This module executes the method described in step S1 of embodiment 1, which will not be described in detail here.

[0075] The first processing module 3 is used to determine the first database according to the unique identification information; this module executes the method described in step S3 of embodiment 1, which will not be described in detail here.

[0076] The second processing module 5 is used to redetermine the first database according to the unique identification information and the preset character string when the first database fails, until the redetermined first database is normal; this module executes the method described in step S5 of embodiment 1, which will not be repeated here.

[0077] The third processing module 7 is used to determine the first database as the target database when the first database is normal, and store the transaction operation result corresponding to the transaction request in the target database; this module executes the method described in step S7 of embodiment 1, which will not be repeated here.

[0078] The multi-database routing system provided by the present invention ensures the uniqueness of information and thus the uniqueness of the matching process by receiving a request with unique first identification information; uses the first identification information to match the first database where the transaction operation information needs to be stored; in the case of a failure of the first database, uses the first identification information and a preset string to redetermine the first database until the redetermined first database is normal, determines the first data as the target database, and stores the transaction operation result corresponding to the transaction request in the target database; solves the technical problem of distributing the flow of the failed database to the remaining normal databases on an average or similar average basis, and solves the problem of uneven routing; at the same time, ensures that a transaction can find a normal and available database, and the implementation method is simple, improving the business processing capability. At the same time, by adding the redis component, the invalid queries of the database are greatly reduced, and the query efficiency is improved.

[0079] Example 3

[0080] An embodiment of the present invention provides an electronic device, such as Figure 5 As shown, it includes: at least one processor 401, such as a CPU (Central Processing Unit), at least one communication interface 403, a memory 404, and at least one communication bus 402. Among them, the communication bus 402 is used to realize the connection and communication between these components. Among them, the communication interface 403 may include a display screen (Display), a keyboard (Keyboard), and the optional communication interface 403 may also include a standard wired interface and a wireless interface. The memory 404 may be a high-speed RAM memory (Ramdom Access Memory, volatile random access memory) or a non-volatile memory (non-volatile memory), such as at least one disk memory. The memory 404 may also be at least one storage device located away from the aforementioned processor 401. Among them, the processor 401 can execute the multi-database routing method of embodiment 1. A set of program codes are stored in the memory 404, and the processor 401 calls the program code stored in the memory 404 to execute the multi-database routing method of embodiment 1.

[0081] The communication bus 402 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The communication bus 402 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5The fact that only one line is used in the diagram does not mean that there is only one bus or only one type of bus.

[0082] Among them, the memory 404 may include a volatile memory (English: volatile memory), such as a random access memory (English: random-access memory, abbreviated: RAM); the memory may also include a non-volatile memory (English: non-volatile memory), such as a flash memory (English: flash memory), a hard disk drive (English: hard disk drive, abbreviated: HDD) or a solid-state drive (English: solid-state drive, abbreviated: SSD); the memory 404 may also include a combination of the above types of memory.

[0083] The processor 401 may be a central processing unit (CPU), a network processor (NP), or a combination of a CPU and a NP.

[0084] The processor 401 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0085] Optionally, the memory 404 is also used to store program instructions. The processor 401 can call the program instructions to implement the multi-database routing method in the embodiment 1 of the present application.

[0086] The embodiment of the present invention further provides a computer-readable storage medium, on which computer-executable instructions are stored, and the computer-executable instructions can execute the multi-database routing method of embodiment 1. The storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above-mentioned types of memory.

[0087] Obviously, the above embodiments are merely examples for the purpose of clear explanation, and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived from these are still within the scope of protection of the invention.

Claims

1. A multi-database routing method, characterized in that: include: receiving a transaction request, wherein the transaction request carries first identification information corresponding to the transaction operation; determining a first database according to the first identification information; In the case that the first database fails, the first database is re-determined according to the first identification information and the preset character string until the re-determined first database is normal, wherein the re-determining the first database according to the first identification information and the preset character string includes: Generate second identification information according to the first identification information and the preset character string; Calculate a second Hash value of the second identification information, and determine a second database according to a remainder obtained by dividing the second Hash value by the total number of databases; Determine whether the second database is faulty, and update the execution count, where the execution count is used to reflect the number of determinations for determining whether the second database is faulty; In the case of a failure of the second database, if the execution times are less than a preset threshold, the above steps are executed again until it is determined that the second database is normal or the execution times reach the preset threshold; In a case where the redetermined second database is normal, determining the second database as the redetermined first database; When the number of executions reaches the preset threshold, generating third identification information according to a remainder of dividing the second hash value by the total number of databases and a preset value; Determine a third database according to the third identification information, and judge whether the third database is faulty; In the case of a failure of the third database, re-execute the above steps until it is determined that the third database is normal; In a case where the third database is normal, determining the third database as the re-determined first database; In the case that the first database is normal, the first database is determined as a target database, and the transaction operation result corresponding to the transaction request is stored in the target database.

2. The multi-database routing method according to claim 1, characterized in that: The determining the first database according to the first identification information includes: Calculate a first Hash value of the first identification information; A remainder obtained by dividing the first hash value by the total number of databases is calculated, and a first database is determined according to the remainder.

3. The multi-database routing method according to claim 1, characterized in that: The method further comprises: Determine a list of available databases according to the operating status of each database, wherein the operating status includes failure or normal; After determining the first database according to the first identification information, the method further includes: Determine whether the first database exists in the available database list; In a case where the first database exists in the available database list, determining that the first database is normal; In a case where the first database does not exist in the available database list, it is determined that the first database is faulty.

4. The multi-database routing method according to claim 1, characterized in that: Also includes: Recording a mapping relationship between the first identification information and a target database where the transaction operation result is actually stored; receiving a transaction query request, wherein the transaction query request carries the first identification information; A transaction query is performed according to the mapping relationship and the first identification information to obtain a query result.

5. A multi-database routing system, characterized in that: include: A receiving module, configured to receive a transaction request, wherein the transaction request carries first identification information of a transaction operation; A first processing module, configured to determine a first database according to the first identification information; The second processing module is configured to, in the case where the first database fails, redetermine the first database according to the first identification information and a preset character string until the redetermined first database is normal, wherein the redetermining the first database according to the first identification information and the preset character string comprises: Generate second identification information according to the first identification information and the preset character string; Calculate a second Hash value of the second identification information, and determine a second database according to a remainder obtained by dividing the second Hash value by the total number of databases; Determine whether the second database is faulty, and update the execution count, where the execution count is used to reflect the number of determinations for determining whether the second database is faulty; In the case of a failure of the second database, if the execution times are less than a preset threshold, the above steps are executed again until it is determined that the second database is normal or the execution times reach the preset threshold; In a case where the re-determined second database is normal, determining the second database as the re-determined first database; When the number of executions reaches the preset threshold, generating third identification information according to a remainder of dividing the second hash value by the total number of databases and a preset value; Determine a third database according to the third identification information, and judge whether the third database is faulty; In the case of a failure of the third database, re-execute the above steps until it is determined that the third database is normal; In a case where the third database is normal, determining the third database as the re-determined first database; The third processing module is configured to determine the first database as a target database when the first database is normal, and store the transaction operation result corresponding to the transaction request in the target database.

6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the multi-database routing method according to any one of claims 1 to 4 is implemented.

7. An electronic device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the multi-database routing method according to any one of claims 1 to 4 by executing the computer instructions.

Citation Information

Patent Citations

  • Database determination method and device and transaction processing system

    CN110717827A