Random number consistency guarantee method and device, computer equipment and storage medium
By deploying random number coordination services in a distributed database system, the consistency of random numbers in a distributed database system is solved, and the correctness of the system is improved and the consistency of random numbers and the consistency of the system is improved. reliability.
Patent Information
- Application Number
- CN202411344190.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-25
- Publication Date
- 2024-12-13
AI Technical Summary
In distributed database systems, the consistency of random numbers is difficult to ensure, resulting in data consistency and security issues. Especially in application scenarios that require strict random number consistency, such as cryptography and financial transactions, which may cause data inconsistency. and security vulnerabilities.
Deploy the random number coordination service on the proxy node of the distributed database system, receive the client's SQL statement and split it into substatements, and distribute it to the target data node. Generate public random numbers through the random number coordination service, and ensure that consistency.
By ensuring the consistency of random numbers in the distributed database system, the correctness and reliability of the system are improved, data inconsistency and security vulnerabilities caused by random numbers are avoided, and protection of security-related applications is enhanced.
Smart Images

Figure CN119127902A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a random number consistency assurance method, device, computer equipment and non-volatile computer-readable storage medium applied to a distributed database system. Background Art
[0002] At present, in distributed database systems, the consistency of random numbers is a key factor in ensuring the correctness and reliability of the system. Especially in application scenarios that require randomness, such as cryptography, financial transactions, online games, etc., the generation and use of random numbers must be consistent throughout the system. However, the characteristics of distributed database systems make it a challenge to generate and maintain consistent random numbers on different data nodes. That is, data consistency currently faces many challenges in distributed environments. For example, in the scenario of distributed locks, if the random numbers generated by different data nodes are inconsistent, it may cause multiple data nodes to simultaneously believe that they have obtained the lock, thereby causing data consistency problems; in security-related applications, such as the generation of encryption keys and the issuance of authentication tokens, the consistency of random numbers is even more important. If the random numbers generated by different data nodes are inconsistent, security vulnerabilities may be exposed, and attackers may exploit these vulnerabilities to attack. However, in distributed database systems, random numbers are often calculated independently on each data node. Due to factors such as network delays, node failures, and concurrent operations, the random numbers generated by different data nodes may be different. This difference poses a serious threat to application scenarios that require strict random number consistency.
[0003] Based on this, how to provide a random number consistency assurance method, device, computer equipment and non-volatile computer-readable storage medium applied to a distributed database system to ensure the consistency of random numbers in the distributed database system, and then ensure the correctness and reliability of the distributed database system, is a problem that needs to be urgently solved by technical personnel in this field. Summary of the invention
[0004] In view of the above-mentioned deficiencies in the prior art, the object of the present invention is to provide a random number consistency assurance method, apparatus, computer equipment and non-volatile computer-readable storage medium applied to a distributed database system, aiming to solve the problem of how to ensure the consistency of random numbers in a distributed database system.
[0005] In order to achieve the above object, the present invention adopts the following technical solutions:
[0006] A random number consistency guarantee method, wherein the method is applied to a distributed database system, and the method comprises:
[0007] Pre-deploy a random number coordination service on the proxy node of the distributed database system; wherein the random number coordination service is used to coordinate the random number generation process of each data node in the distributed database system;
[0008] The proxy node receives the SQL statement sent by the client, splits the SQL statement into multiple sub-statements, and distributes them to multiple target data nodes accordingly;
[0009] By executing the sub-statements received by each target data node, when any of the sub-statements has a requirement for random number generation, the corresponding target data node sends a random number generation request to the random number coordination service; wherein the number of the sub-statements having the requirement for random number generation is greater than or equal to two;
[0010] A public random number is generated according to the random number generation request received first by the random number coordination service, and the public random number is returned to all the target data nodes that have sent the random number generation request.
[0011] In a further technical solution, the random number consistency guarantee method, wherein, after generating a public random number according to the random number generation request received first by the random number coordination service and returning the public random number to all the target data nodes that have sent the random number generation request, further comprises:
[0012] After receiving the public random number, each of the target data nodes that has sent the random number generation request to the random number coordination service uses the received public random number for its corresponding application scenario and returns the corresponding generated application result to the proxy node.
[0013] In a further technical solution, the random number consistency guarantee method, wherein, after each of the target data nodes that have sent the random number generation request to the random number coordination service receives the public random number, uses the received public random number for its corresponding application scenario and returns the corresponding generated application result to the proxy node, further includes:
[0014] After the application results corresponding to all the target data nodes that have sent the random number generation request to the random number coordination service are returned to the proxy node, the target cache storing the public random number in the random number coordination service is cleared.
[0015] In a further technical solution, the random number consistency guarantee method, wherein the receiving of the SQL statement sent by the client through the proxy node and the splitting of the SQL statement into multiple sub-statements are distributed to multiple target data nodes accordingly, comprises:
[0016] Receive the SQL statement sent by the client through the proxy node, and parse the SQL statement;
[0017] According to the parsing result, the SQL statement is split into multiple sub-statements through the proxy node, and distributed to multiple target data nodes accordingly.
[0018] In a further technical solution, the random number consistency guarantee method, wherein each of the target data nodes executes the corresponding received sub-statements, and when any of the sub-statements has a random number generation requirement, the corresponding target data node sends a random number generation request to the random number coordination service; wherein the number of the sub-statements having a random number generation requirement is greater than or equal to two, includes:
[0019] Executing the sub-statement received corresponding to each target data node;
[0020] When any of the sub-statements has a requirement for random number generation, the corresponding target data node sends a random number generation request to the random number coordination service; wherein the number of the sub-statements with the requirement for random number generation is greater than or equal to two, and the random number generation request also includes a timestamp and a data node ID.
[0021] In a further technical solution, the random number consistency guarantee method, wherein the generating a public random number according to the random number generation request received first by the random number coordination service, and returning the public random number to all the target data nodes that have sent the random number generation request, comprises:
[0022] Receiving each of the random number generation requests through the random number coordination service;
[0023] Determining a request order of each of the random number generation requests according to the timestamp corresponding to each of the random number generation requests;
[0024] Based on the request order, a public random number is generated according to the random number generation request received first by the random number coordination service, and the public random number is returned to all the target data nodes that have sent the random number generation request.
[0025] In a further technical solution, the random number consistency guarantee method, wherein, based on the request order, a public random number is generated by the random number coordination service according to the random number generation request received first, and the public random number is returned to all the target data nodes that have sent the random number generation request, further comprising:
[0026] The public random number is stored in the target cache within the random number coordination service.
[0027] A random number consistency assurance device, which is applied to a distributed database system, and comprises:
[0028] A service deployment module, used to deploy a random number coordination service on a proxy node of the distributed database system in advance; wherein the random number coordination service is used to coordinate the random number generation process of each data node in the distributed database system;
[0029] A receiving and splitting module, used for receiving the SQL statement sent by the client through the proxy node, splitting the SQL statement into multiple sub-statements, and distributing them to multiple target data nodes accordingly;
[0030] An execution and sending module, used for executing the sub-statements received by each target data node, and when any of the sub-statements has a random number generation requirement, the corresponding target data node sends a random number generation request to the random number coordination service; wherein the number of the sub-statements having a random number generation requirement is greater than or equal to two;
[0031] The generation and return module is used to generate a public random number according to the random number generation request received first through the random number coordination service, and return the public random number to all the target data nodes that have sent the random number generation request.
[0032] A computer device, wherein the computer device comprises at least one processor; and
[0033] a memory communicatively connected to the at least one processor; wherein,
[0034] The memory stores a computer program that can be executed by the at least one processor. When the computer program is executed by the at least one processor, the random number consistency assurance method as described in any one of the above items can be implemented.
[0035] A non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by at least one processor, the random number consistency assurance method as described in any one of the above items can be implemented.
[0036] Compared with the prior art, the present invention provides a method, device, computer equipment and non-volatile computer-readable storage medium for ensuring the consistency of random numbers, wherein, applied to a distributed database system, the method includes: deploying a random number coordination service on the proxy node of the distributed database system in advance; wherein, the random number coordination service is used to coordinate the random number generation process of each data node in the distributed database system; receiving the SQL statement sent by the client through the proxy node, and splitting the SQL statement into multiple sub-statements, and correspondingly distributing them to multiple target data nodes; executing the sub-statements received by each target data node, when any of the sub-statements has a random number generation requirement, the corresponding target data node sends a random number generation request to the random number coordination service; wherein, the number of the sub-statements with random number generation requirements is greater than or equal to two; generating a public random number according to the random number generation request received first by the random number coordination service, and returning the public random number to all the target data nodes that have sent the random number generation request. In this way, the method of the present invention can ensure the consistency of random numbers in the distributed database system, thereby ensuring the correctness and reliability of the distributed database system. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0038] Figure 1 A flowchart of a random number consistency assurance method provided by an embodiment of the present invention.
[0039] Figure 2 Another flowchart of a random number consistency assurance method provided by an embodiment of the present invention.
[0040] Figure 3 A schematic diagram of functional modules of a random number consistency assurance device provided by an embodiment of the present invention.
[0041] Figure 4 A schematic diagram of the hardware structure of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0042] In order to make the purpose, technical solution and effect of the present invention clearer and more specific, the present invention is further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0043] In the description of the present invention, the terms "include", "including", "have", "contain", etc. are all open terms, which mean including but not limited to. The descriptions with reference to the terms "one embodiment", "a specific embodiment", "some embodiments", "for example", etc. mean that the specific features, structures or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures or characteristics described may be combined in a suitable manner in any one or more embodiments or examples. The order of steps involved in each embodiment is used to schematically illustrate the implementation of the present application, and the order of steps therein is not limited and can be appropriately adjusted as needed.
[0044] Various non-limiting embodiments of the present invention are described in detail below in conjunction with the accompanying drawings.
[0045] At present, in distributed database systems, the consistency of random numbers is a key factor in ensuring the correctness and reliability of the system. Especially in application scenarios that require randomness, such as cryptography, financial transactions, online games, etc., the generation and use of random numbers must be consistent throughout the system. However, the characteristics of distributed database systems make it a challenge to generate and maintain consistent random numbers on different data nodes. That is, data consistency currently faces many challenges in distributed environments. For example, in the scenario of distributed locks, if the random numbers generated by different data nodes are inconsistent, it may cause multiple data nodes to simultaneously believe that they have obtained the lock, thereby causing data consistency problems; in security-related applications, such as the generation of encryption keys and the issuance of authentication tokens, the consistency of random numbers is even more important. If the random numbers generated by different data nodes are inconsistent, security vulnerabilities may be exposed, and attackers may exploit these vulnerabilities to attack. However, in distributed database systems, random numbers are often calculated independently on each data node. Due to factors such as network delays, node failures, and concurrent operations, the random numbers generated by different data nodes may be different. This difference poses a serious threat to application scenarios that require strict random number consistency.
[0046] Based on this, how to provide a random number consistency assurance method, device, computer equipment and non-volatile computer-readable storage medium applied to a distributed database system to ensure the consistency of random numbers in the distributed database system, and then ensure the correctness and reliability of the distributed database system, is a problem that needs to be urgently solved by technical personnel in this field.
[0047] To solve the above problems, see Figure 1 The embodiment of the present invention provides a method for ensuring the consistency of random numbers, which is applied to a distributed database system and comprises the following steps:
[0048] S100, pre-deploy a random number coordination service on the proxy node of the distributed database system; wherein the random number coordination service is used to coordinate the random number generation process of each data node in the distributed database system;
[0049] S200, receiving an SQL statement sent by a client through the proxy node, splitting the SQL statement into multiple sub-statements, and distributing the sub-statements to multiple target data nodes accordingly;
[0050] S300, executing the sub-statements received by each target data node, when any of the sub-statements has a requirement for random number generation, the corresponding target data node sends a random number generation request to the random number coordination service; wherein the number of the sub-statements having a requirement for random number generation is greater than or equal to two;
[0051] S400: Generate a public random number according to the random number generation request received first through the random number coordination service, and return the public random number to all the target data nodes that have sent the random number generation request.
[0052] Further, the random number consistency guarantee method, wherein, in step S100, a random number coordination service is pre-deployed on the proxy node of the distributed database system; wherein, the random number coordination service is used to coordinate the random number generation process of each data node in the distributed database system;
[0053] In the specific implementation, in this embodiment, a random number coordination service is pre-deployed on the proxy node of the distributed database system; wherein the random number coordination service is used to coordinate the random number generation process of each data node in the distributed database system; wherein the specific implementation process is roughly as follows:
[0054] 1) Requirements analysis and design
[0055] Analyze the requirements for random number generation in distributed database systems, including the purpose of random numbers, the required level of randomness, the expected number of concurrent requests, etc.
[0056] Design the architecture of the random number coordination service, determine how the random number coordination service will interact with proxy nodes and data nodes, and how to ensure the consistency and security of random numbers;
[0057] 2) Service development and deployment
[0058] Develop random number coordination services to implement random number generation algorithms, request processing logic, cache management and other functions;
[0059] Deploy the developed random number coordination service to the proxy node; this may involve operations such as containerized deployment, configuration management, and service registration;
[0060] 3) Configure the proxy node
[0061] Configure the access interface of the random number coordination service on the proxy node to ensure that the data node can communicate with the random number coordination service through the network;
[0062] Configure the proxy node to recognize the random number generation requirements in SQL statements and forward the request to the random number coordination service;
[0063] 4) Data Node Integration
[0064] Modify or configure the data node so that it can send a request to the random number coordination service when it executes a SQL statement and detects the need for random number generation;
[0065] Ensure that the data node can process the response from the random number coordination service and apply the received random number to the current database operation;
[0066] 5) Testing and Optimization
[0067] Test the random number coordination service, including unit testing, integration testing, and performance testing, to ensure that the random number coordination service can run stably under different loads;
[0068] Optimize the random number coordination service based on the test results, which may include algorithm optimization, cache strategy adjustment, load balancing, etc.
[0069] Through the above process, the random number coordination service can be successfully deployed and run in the distributed database system, thereby ensuring that the random numbers generated on different data nodes in the subsequent processes are consistent, meeting the requirements of the distributed database system for random number consistency.
[0070] Furthermore, the random number consistency guarantee method, wherein the step S200, receiving the SQL statement sent by the client through the proxy node, and splitting the SQL statement into multiple sub-statements, and correspondingly distributing them to multiple target data nodes, specifically includes:
[0071] Receive the SQL statement sent by the client through the proxy node, and parse the SQL statement;
[0072] According to the parsing result, the SQL statement is split into multiple sub-statements through the proxy node, and distributed to multiple target data nodes accordingly.
[0073] In the specific implementation, in this embodiment, the SQL statement sent by the client is received by the proxy node, and the SQL statement is parsed; according to the parsing result, the SQL statement is split into multiple sub-statements by the proxy node, and distributed to multiple target data nodes accordingly; wherein the specific implementation process is roughly as follows:
[0074] 1) Receive SQL statements
[0075] The proxy node provides a network interface (such as HTTP API, database interface, etc.) to receive SQL statements sent by the client;
[0076] Ensure that the proxy nodes are able to handle concurrent requests from multiple clients and have adequate security measures such as authentication and authorization;
[0077] 2) Parsing SQL statements
[0078] The proxy node uses the built-in parser or third-party library to perform syntax and semantic analysis on the received SQL statements;
[0079] During the parsing process, the proxy node needs to identify the type of SQL statement (such as SELECT, INSERT, UPDATE, DELETE, etc.), the data table being operated, and the data partition or shard information involved;
[0080] 3) Generate an execution plan
[0081] Based on the parsing results, the proxy node generates one or more execution plans that detail how to execute SQL statements on the data nodes;
[0082] For complex queries, query optimization may be required, such as selecting the most appropriate index, rearranging the order of query operations, etc.
[0083] 4) Split SQL statements
[0084] If the SQL statement involves multiple data partitions or shards in a distributed database, the proxy node needs to split the original SQL statement into multiple sub-statements;
[0085] Each substatement targets a specific data partition or shard and can be executed independently;
[0086] 5)Distribution sub-statements
[0087] The proxy node distributes the generated sub-statements to the corresponding target data nodes for execution; this usually involves sending the sub-statements to the target data nodes via a network call;
[0088] Through the above process, the distributed database system can efficiently process the SQL statements sent by the client.
[0089] Further, the random number consistency guarantee method, wherein the step S300, through each of the target data nodes executing the corresponding received sub-statements, when any of the sub-statements has a random number generation requirement, the corresponding target data node sends a random number generation request to the random number coordination service; wherein the number of the sub-statements with random number generation requirements is greater than or equal to two, specifically includes:
[0090] Executing the sub-statement received corresponding to each target data node;
[0091] When any of the sub-statements has a requirement for random number generation, the corresponding target data node sends a random number generation request to the random number coordination service; wherein the number of the sub-statements with the requirement for random number generation is greater than or equal to two, and the random number generation request also includes a timestamp and a data node ID.
[0092] In the specific implementation, in this embodiment, each of the target data nodes executes the corresponding received sub-statements; when any of the sub-statements has a random number generation requirement, the corresponding target data node sends a random number generation request to the random number coordination service; wherein the number of the sub-statements with the random number generation requirement is greater than or equal to two, and the random number generation request also includes a timestamp and a data node ID; wherein the specific implementation process is roughly as follows:
[0093] 1) Execute substatement
[0094] Each target data node independently executes the sub-statements it receives; these sub-statements are split and distributed by the proxy node based on the original SQL statement, and each sub-statement targets a specific data partition or shard;
[0095] 2) Detecting random number requirements
[0096] During the execution of the substatement, the target data node detects the need for random number generation; this may be due to the SQL statement containing functions such as RAND() or RANDOM(), or the application logic requiring random numbers to perform specific functions;
[0097] 3) Send a random number generation request
[0098] Once the target data node detects the need for random number generation, it constructs a random number generation request containing a timestamp and data node ID and sends it to the random number coordination service; the timestamp is used to ensure the order of the request, and the data node ID is used to identify the source of the request;
[0099] Through the above process, sub-statements with random number generation requirements can be detected, and random number generation requests can be sent to the random number coordination service through the corresponding target data node.
[0100] Further, the random number consistency guarantee method, wherein the step S400, generating a public random number according to the random number generation request received first by the random number coordination service, and returning the public random number to all the target data nodes that have sent the random number generation request, specifically includes:
[0101] Receiving each of the random number generation requests through the random number coordination service;
[0102] Determining a request order of each of the random number generation requests according to the timestamp corresponding to each of the random number generation requests;
[0103] Based on the request order, a public random number is generated according to the random number generation request received first by the random number coordination service, and the public random number is returned to all the target data nodes that have sent the random number generation request.
[0104] Further, the random number consistency guarantee method, wherein, based on the request order, a public random number is generated by the random number coordination service according to the random number generation request received first, and the public random number is returned to all the target data nodes that have sent the random number generation request, further includes:
[0105] The public random number is stored in a target cache within the random number coordination service.
[0106] In specific implementation, in this embodiment, each random number generation request is received through the random number coordination service; the request order of each random number generation request is determined according to the timestamp corresponding to each random number generation request; based on the request order, a public random number is generated according to the random number generation request received first through the random number coordination service, and the public random number is returned to all the target data nodes that have sent the random number generation request; at the same time, the public random number is stored in the target cache in the random number coordination service; wherein the specific implementation process is roughly as follows:
[0107] 1) Receive a random number generation request
[0108] The random number coordination service opens a listening port or service endpoint to receive random number generation requests from the target data node;
[0109] Each request contains a data node ID and a timestamp to ensure the uniqueness and order of the request;
[0110] 2) Request order determination
[0111] After receiving the request, the random number coordination service checks the timestamp in the request and sorts the requests according to the timestamp;
[0112] If a service receives multiple requests that arrive almost simultaneously (within the precision of the timestamps), it can use first-come, first-served (FCFS) or other algorithms to determine the order of the requests;
[0113] 3) Generate public random numbers
[0114] The random number coordination service selects the first received request according to the determined request order and generates a public random number using a cryptographically secure random number generator;
[0115] This public random number needs to meet the randomness requirements of the distributed database system, such as sufficient entropy in cryptographic applications;
[0116] 4) Return a public random number
[0117] The random number coordination service sends the generated public random number back to all target data nodes that have sent requests through responses;
[0118] At the same time, the service will store the public random number and its related information (such as generation time, related data node ID, etc.) in the internal target cache for subsequent use or auditing;
[0119] Through the above process, the random number coordination service can ensure that the random numbers generated in the distributed database system are consistent and can be shared and used by all relevant data nodes.
[0120] For further information, see Figure 2 , the random number consistency guarantee method, wherein, after the step S400, generating a public random number according to the random number generation request received first by the random number coordination service, and returning the public random number to all the target data nodes that have sent the random number generation request, further comprises the steps of:
[0121] S500. After receiving the public random number, each of the target data nodes that has sent the random number generation request to the random number coordination service uses the received public random number for its corresponding application scenario and returns the corresponding generated application result to the proxy node.
[0122] For further information, see Figure 2 , the random number consistency guarantee method, wherein, in step S500, after each of the target data nodes that have sent the random number generation request to the random number coordination service receives the public random number, uses the received public random number for its corresponding application scenario and returns the corresponding generated application result to the proxy node, it also includes the steps of:
[0123] S600: After the application results corresponding to all the target data nodes that have sent the random number generation request to the random number coordination service are returned to the proxy node, the target cache storing the public random number in the random number coordination service is cleared.
[0124] In specific implementation, in this embodiment, after receiving the public random number, each of the target data nodes that have sent the random number generation request to the random number coordination service uses the received public random number for its corresponding application scenario, and returns the corresponding generated application result to the proxy node; after the application results corresponding to all the target data nodes that have sent the random number generation request to the random number coordination service are returned to the proxy node, the target cache storing the public random number in the random number coordination service is cleared; wherein, the specific implementation process is roughly as follows:
[0125] 1) Use public random numbers
[0126] After receiving the public random number sent by the random number coordination service, each target data node that has sent a random number generation request applies the received public random number to its own (each target data node that has sent a random number generation request) corresponding application scenario; this may include generating encryption keys, random sampling, simulating random events, etc.;
[0127] The target data node ensures that the public random number is used correctly in local operations to meet the randomness requirements of the transaction or operation;
[0128] 2) Generate application results
[0129] After applying the public random number, the target data node performs relevant database operations, such as insert, update, or query, and generates the corresponding application results;
[0130] These results may include randomly processed data records, transaction status, computational output, etc.
[0131] 3) Return application results to the proxy node
[0132] The target data node encapsulates the application result in a response message and sends it back to the proxy node; this may be achieved through a network call, message queue, or other communication mechanism;
[0133] The proxy node is responsible for receiving application results from all relevant target data nodes and performing necessary aggregation or processing;
[0134] 4) Aggregate and process application results
[0135] The proxy node waits for all relevant target data nodes to return the application results. Once all application results are received, the proxy node will perform aggregation processing, such as merging data, sorting, and deduplication.
[0136] The proxy node ensures that all application results have been processed correctly and is ready to return the final result to the client or perform further operations;
[0137] 5) Clear the cache in the random number coordination service
[0138] After the application results of all relevant target data nodes have been returned and processed, a cache clearing request can be sent to the random number coordination service;
[0139] After receiving the clearing request, the random number coordination service clears the target cache that stores the public random number and its related information to ensure that the public random number will not be misused by subsequent operations, that is, to ensure that the public random number is only used by the current SQL statement;
[0140] Through the above process, the distributed database system can not only ensure the consistency of random numbers among various data nodes, avoiding data inconsistency problems caused by inconsistent random numbers, but also clean up resources in time after the operation is completed, avoiding misuse of random numbers and potential security risks; of course, the random number coordination service in this embodiment can also provide other functions, such as persistent storage of random numbers, fault recovery, etc., to further improve the reliability of the distributed database system.
[0141] It can be seen from the above method embodiments that the random number consistency guarantee method provided by the present invention is applied to a distributed database system, and at least includes: deploying a random number coordination service on the proxy node of the distributed database system in advance; wherein the random number coordination service is used to coordinate the random number generation process of each data node in the distributed database system; receiving the SQL statement sent by the client through the proxy node, and splitting the SQL statement into multiple sub-statements, and then distributing them to multiple target data nodes accordingly; executing the sub-statements received by each target data node, when any of the sub-statements has a random number generation requirement, the corresponding target data node sends a random number generation request to the random number coordination service; wherein the number of the sub-statements with random number generation requirements is greater than or equal to two; generating a public random number according to the random number generation request received first by the random number coordination service, and returning the public random number to all the target data nodes that have sent the random number generation request; and so on. In this way, the method of the present invention can ensure the consistency of random numbers in the distributed database system, thereby ensuring the correctness and reliability of the distributed database system.
[0142] Specifically, the random number consistency assurance method provided by the embodiment of the present invention can at least achieve the following beneficial technical effects:
[0143] 1. The method of the present invention proposes a random number consistency guarantee method applied to a distributed database system, which can solve the data inconsistency problem caused by inconsistent random numbers;
[0144] 2. The method of the present invention introduces a random number coordination service to centrally manage and coordinate the random number generation process of each data node, thereby ensuring the consistency of global random numbers;
[0145] 3. The method of the present invention can be seamlessly integrated with a distributed database system without modifying the existing database architecture and application programs.
[0146] It should be understood that, although the present application provides method operation steps as described in the embodiments or flowcharts, more or less operation steps may be included based on conventional or non-creative labor, and these operation steps are not necessarily performed in sequence according to the embodiment or flowchart. The order of steps listed in the embodiment or flowchart is only one way of executing the order of many steps, and does not represent the only execution order. It should be noted that there is not necessarily a certain order between the above steps. A person of ordinary skill in the art can understand from the description of the embodiment of the present invention that in different embodiments, the above steps may have different execution orders, that is, they may be executed in parallel, or they may be executed in exchange, etc. Moreover, at least a part of the steps in the embodiment or flowchart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but may be executed at different times, and the execution order of these sub-steps or stages is not necessarily performed in sequence, but may be executed in turn, alternately or synchronously with other steps or at least a part of the sub-steps or stages of other steps.
[0147] Based on the above method embodiment, please refer to Figure 3 Another embodiment of the present invention further provides a random number consistency guarantee device, which is applied to a distributed database system and includes:
[0148] The service deployment module 11 is used to deploy a random number coordination service on the proxy node of the distributed database system in advance; wherein the random number coordination service is used to coordinate the random number generation process of each data node in the distributed database system;
[0149] The receiving and splitting module 12 is used to receive the SQL statement sent by the client through the proxy node, split the SQL statement into multiple sub-statements, and distribute them to multiple target data nodes accordingly;
[0150] The execution and sending module 13 is used to execute the sub-statements received by each target data node, and when any of the sub-statements has a random number generation requirement, the corresponding target data node sends a random number generation request to the random number coordination service; wherein the number of the sub-statements having a random number generation requirement is greater than or equal to two;
[0151] The generation and return module 14 is used to generate a public random number according to the random number generation request received first through the random number coordination service, and return the public random number to all the target data nodes that have sent the random number generation request.
[0152] Furthermore, in the random number consistency guarantee device, the receiving and splitting module 12 specifically includes:
[0153] A receiving unit, configured to receive an SQL statement sent by a client through the proxy node, and parse the SQL statement;
[0154] The splitting unit is used to split the SQL statement into multiple sub-statements through the proxy node according to the parsing result, and distribute them to multiple target data nodes accordingly.
[0155] Furthermore, in the random number consistency guarantee device, the execution and sending module 13 specifically includes:
[0156] An execution unit, configured to execute the sub-statement received corresponding to each target data node through each target data node;
[0157] A sending unit is used for sending a random number generation request to the random number coordination service by the corresponding target data node when any of the sub-statements has a random number generation requirement; wherein the number of the sub-statements with random number generation requirements is greater than or equal to two, and the random number generation request also includes a timestamp and a data node ID.
[0158] Furthermore, in the random number consistency guarantee device, the generation and return module 14 specifically includes:
[0159] A receiving unit, configured to receive each of the random number generation requests through the random number coordination service;
[0160] a determining unit, configured to determine a request order of each of the random number generation requests according to the timestamp corresponding to each of the random number generation requests;
[0161] A generating and returning unit is used to generate a public random number based on the request order and according to the random number generation request received first through the random number coordination service, and return the public random number to all the target data nodes that have sent the random number generation request.
[0162] Furthermore, in the random number consistency assurance device, the generating and returning unit is further used for:
[0163] The public random number is stored in a target cache within the random number coordination service.
[0164] Furthermore, the random number consistency assurance device further comprises:
[0165] The application module is used for each of the target data nodes that have sent the random number generation request to the random number coordination service to use the received public random number for its corresponding application scenario after receiving the public random number, and return the corresponding generated application result to the proxy node.
[0166] Furthermore, the random number consistency assurance device further comprises:
[0167] The clearing module is used to clear the target cache storing the public random number in the random number coordination service after the application results corresponding to all the target data nodes that have sent the random number generation request to the random number coordination service are returned to the proxy node.
[0168] The specific implementation process and effects of the device embodiment of the present invention can be found in the above method embodiment, which will not be described in detail here.
[0169] It can be seen from the above device embodiments that the random number consistency assurance device provided by the present invention is applied to a distributed database system and at least includes: a service deployment module, which is used to pre-deploy a random number coordination service on the proxy node of the distributed database system; wherein the random number coordination service is used to coordinate the random number generation process of each data node in the distributed database system; a receiving and splitting module, which is used to receive the SQL statement sent by the client through the proxy node, and after splitting the SQL statement into multiple sub-statements, distribute them to multiple target data nodes accordingly; an execution and sending module, which is used to execute the corresponding received sub-statements through each target data node, and when any of the sub-statements has a random number generation requirement, the corresponding target data node sends a random number generation request to the random number coordination service; wherein the number of the sub-statements with random number generation requirements is greater than or equal to two; a generation and return module, which is used to generate a public random number according to the random number generation request received first through the random number coordination service, and return the public random number to all the target data nodes that have sent the random number generation request; and so on. In this way, the apparatus of the present invention can ensure the consistency of random numbers in the distributed database system, thereby ensuring the correctness and reliability of the distributed database system.
[0170] Specifically, the random number consistency assurance device provided by the embodiment of the present invention can at least achieve the following beneficial technical effects:
[0171] 1. The device of the present invention proposes a random number consistency guarantee device applied to a distributed database system, which can solve the problem of data inconsistency caused by inconsistent random numbers;
[0172] 2. The device of the present invention introduces a random number coordination service to centrally manage and coordinate the random number generation process of each data node, thereby ensuring the consistency of global random numbers;
[0173] 3. The device of the present invention can be seamlessly integrated with a distributed database system without modifying the existing database architecture and application programs.
[0174] Based on the above method embodiment, please refer to Figure 4 Another embodiment of the present invention further provides a computer device, wherein the computer device 10 includes:
[0175] memory 120 and one or more processors 110, Figure 4 A processor 110 is used as an example for description. The processor 110 and the memory 120 may be connected via a communication bus or other means. Figure 4 The example of connection via a communication bus is taken as an example.
[0176] The processor 110 is used to complete various control logics of the computer device 10. It can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), a single-chip microcomputer, an ARM (Acorn RISC Machine) or other programmable logic device, a discrete gate or transistor logic, a discrete hardware component, or any combination of these components. In addition, the processor 110 can also be any traditional processor, microprocessor or state machine. The processor 110 can also be implemented as a combination of computing devices, for example, a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors combined with a DSP, or any other such configuration.
[0177] The memory 120, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as the computer program corresponding to the random number consistency assurance method in any of the above method embodiments of the present invention. The processor 110 executes various functional applications and data processing of the computer device 10 by running the non-volatile software programs, instructions and units stored in the memory 120, that is, implements the random number consistency assurance method in any of the above method embodiments.
[0178] The memory 120 may include a program storage area and a data storage area, wherein the program storage area may store an application required for operating the device or at least one function; the data storage area may store data created according to the use of the computer device 10, etc. In addition, the memory 120 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 120 may optionally include a memory remotely arranged relative to the processor 110, and these remote memories may be connected to the computer device 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0179] One or more units are stored in the memory 120, and when executed by one or more processors 110, the random number consistency guarantee method in any of the above method embodiments can be implemented, for example, the random number consistency guarantee method described above can be implemented. Figure 1 The method comprises steps S100 to S400.
[0180] Those skilled in the art will understand that Figure 4 The hardware structure diagram shown in the figure is only a schematic diagram of a partial structure related to the solution of the present invention, and does not constitute a limitation on the computer device to which the solution of the present invention is applied. The specific computer device may include more components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0181] Based on the above method embodiments, another embodiment of the present invention further provides a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by at least one processor, the random number consistency guarantee method in any of the above method embodiments can be implemented, for example, the random number consistency guarantee method described above can be implemented. Figure 1 The method comprises steps S100 to S400.
[0182] As an example, the non-volatile storage medium can include a read-only memory (ROM), a programmable ROM (PROM), an electrically programmable ROM (EPROM), an electrically erasable ROM (EEPROM), or a flash memory. Volatile memory can include a random access memory (RAM) as an external cache memory. By way of illustration and not limitation, RAM can be obtained in many forms such as synchronous RAM (SRAM), dynamic RAM, (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), Synch link DRAM (SLDRAM), and direct Rambus RAM (DRRAM). The disclosed memory components or memories of the operating environment described herein are intended to include one or more of these and / or any other suitable types of memory.
[0183] Based on the above method embodiments, another embodiment of the present invention further provides a computer program product, the computer program product includes a computer program stored on a non-volatile computer-readable storage medium, the computer program includes program instructions, when the program instructions are executed by a processor, the random number consistency guarantee method in any of the above method embodiments can be implemented, for example, the above described Figure 1 The method comprises steps S100 to S400.
[0184] The embodiments described above are merely illustrative, in which the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0185] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a general hardware platform, and of course can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can exist in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of each embodiment or some parts of the embodiment.
[0186] Conditional language such as "can," "can," "might," or "may," unless specifically stated otherwise or otherwise understood within the context as used, is generally intended to convey, among other things, that a particular embodiment can include (while other embodiments do not) a particular feature, element, and / or operation. Thus, such conditional language is also generally intended to imply that a feature, element, and / or operation is required for one or more embodiments anyway or that one or more embodiments must include logic for determining, with or without input or prompting, whether such features, elements, and / or operations are included or will be performed in any particular embodiment.
[0187] What has been described herein, in this specification and in the accompanying drawings includes an example of a random number consistency guarantee method, device, computer equipment and non-volatile computer-readable storage medium that can be provided for a distributed database system. Of course, it is not possible to describe every conceivable combination of elements and / or methods for the purpose of describing the various features of the present disclosure, but it can be recognized that many other combinations and permutations of the disclosed features are possible. Therefore, it is obvious that various modifications can be made to the present disclosure without departing from the scope or spirit of the present disclosure, but all these various modifications should belong to the scope of protection of the claims attached to the present invention. In addition, or in an alternative, other embodiments of the present disclosure may be obvious from consideration of the present specification and the accompanying drawings and from the practice of the present disclosure as presented herein. It is intended that the examples proposed in the present specification and the accompanying drawings are considered to be illustrative and not restrictive in all respects. Although specific terms are used herein, they are used in a general and descriptive sense and are not used for limiting purposes.
Claims
1. A method for ensuring random number consistency, characterized in that: Applied to a distributed database system, the method comprises: Pre-deploy a random number coordination service on the proxy node of the distributed database system; wherein the random number coordination service is used to coordinate the random number generation process of each data node in the distributed database system; The proxy node receives the SQL statement sent by the client, splits the SQL statement into multiple sub-statements, and distributes them to multiple target data nodes accordingly; By executing the sub-statements received by each target data node, when any of the sub-statements has a requirement for random number generation, the corresponding target data node sends a random number generation request to the random number coordination service; wherein the number of the sub-statements having the requirement for random number generation is greater than or equal to two; A public random number is generated according to the random number generation request received first by the random number coordination service, and the public random number is returned to all the target data nodes that have sent the random number generation request.
2. The random number consistency guarantee method according to claim 1, characterized in that: After generating a public random number according to the random number generation request received first by the random number coordination service and returning the public random number to all the target data nodes that have sent the random number generation request, the method further includes: After receiving the public random number, each of the target data nodes that has sent the random number generation request to the random number coordination service uses the received public random number for its corresponding application scenario and returns the corresponding generated application result to the proxy node.
3. The random number consistency guarantee method according to claim 2, characterized in that: After each of the target data nodes that has sent the random number generation request to the random number coordination service receives the public random number, it uses the received public random number for its corresponding application scenario and returns the corresponding generated application result to the proxy node, further comprising: After the application results corresponding to all the target data nodes that have sent the random number generation request to the random number coordination service are returned to the proxy node, the target cache storing the public random number in the random number coordination service is cleared.
4. The random number consistency guarantee method according to claim 3, characterized in that: The step of receiving the SQL statement sent by the client through the proxy node, splitting the SQL statement into multiple sub-statements, and distributing the sub-statements to multiple target data nodes accordingly includes: Receive the SQL statement sent by the client through the proxy node, and parse the SQL statement; According to the parsing result, the SQL statement is split into multiple sub-statements through the proxy node, and distributed to multiple target data nodes accordingly.
5. The random number consistency guarantee method according to claim 4, characterized in that: The executing of the corresponding received sub-statements by each of the target data nodes, when any of the sub-statements has a random number generation requirement, the corresponding target data node sends a random number generation request to the random number coordination service; wherein the number of the sub-statements having a random number generation requirement is greater than or equal to two, including: Executing the sub-statement received corresponding to each target data node; When any of the sub-statements has a requirement for random number generation, the corresponding target data node sends a random number generation request to the random number coordination service; wherein the number of the sub-statements with the requirement for random number generation is greater than or equal to two, and the random number generation request also includes a timestamp and a data node ID.
6. The random number consistency guarantee method according to claim 5, characterized in that: The generating a public random number according to the random number generation request received first by the random number coordination service, and returning the public random number to all the target data nodes that have sent the random number generation request, includes: Receiving each of the random number generation requests through the random number coordination service; Determining a request order of each of the random number generation requests according to the timestamp corresponding to each of the random number generation requests; Based on the request order, a public random number is generated according to the random number generation request received first by the random number coordination service, and the public random number is returned to all the target data nodes that have sent the random number generation request.
7. The random number consistency guarantee method according to claim 6, characterized in that: The method further comprises: generating a public random number based on the request order, using the random number coordination service according to the random number generation request received first, and returning the public random number to all the target data nodes that have sent the random number generation request, and: The public random number is stored in the target cache within the random number coordination service.
8. A random number consistency assurance device, characterized in that: Applied to a distributed database system, the device comprises: A service deployment module, used to deploy a random number coordination service on a proxy node of the distributed database system in advance; wherein the random number coordination service is used to coordinate the random number generation process of each data node in the distributed database system; A receiving and splitting module, used for receiving the SQL statement sent by the client through the proxy node, splitting the SQL statement into multiple sub-statements, and distributing them to multiple target data nodes accordingly; An execution and sending module, used for executing the sub-statements received by each target data node, and when any of the sub-statements has a random number generation requirement, the corresponding target data node sends a random number generation request to the random number coordination service; wherein the number of the sub-statements having a random number generation requirement is greater than or equal to two; The generation and return module is used to generate a public random number according to the random number generation request received first through the random number coordination service, and return the public random number to all the target data nodes that have sent the random number generation request.
9. A computer device, characterized in that: The computer device comprises at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor. When the computer program is executed by the at least one processor, the random number consistency assurance method as described in any one of claims 1 to 7 can be implemented.
10. A non-volatile computer-readable storage medium, characterized in that: The non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by at least one processor, the random number consistency assurance method according to any one of claims 1 to 7 can be implemented.
