Method for processing sequence values in database cluster, medium and computer device
By establishing a target cache on the host in the database cluster to receive and manage sequence value request requests from the standby host, the problem of standby update behavior being unable to be transferred is solved, thereby improving the performance of the database cluster and the uniqueness and integrity of sequence values.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CETC JINCANG (BEIJING) TECH CO LTD
- Filing Date
- 2023-11-13
- Publication Date
- 2026-06-05
AI Technical Summary
In a database read-write separation cluster, the update behavior of the standby machine when using sequence values cannot be effectively transferred to the master machine, resulting in unclear functionality and performance degradation.
A target cache is established in the host machine to receive sequence value request requests from the standby machine and return sequence segments within a set range, ensuring that the standby machine only performs query operations, while the host machine is responsible for updating and managing the sequence values.
The functional division of the primary and backup servers was clearly defined, which improved the query performance of the backup servers. Furthermore, the unified management of sequence values by the primary server ensured the overall performance of the database cluster and the uniqueness and integrity of the sequence values.
Smart Images

Figure CN117453770B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of databases, and in particular to a method, medium, and computer device for processing sequence values in a database cluster. Background Technology
[0002] In a current read / write splitting cluster, the ideal scenario is that the standby machine can only perform query operations, while the primary machine performs update operations. However, in the actual process of using sequence values on the standby machine, using the next value of the sequence is an update operation. Therefore, to ensure the functionality of the standby machine, this update operation needs to be transferred to the primary machine. Summary of the Invention
[0003] In view of the above problems, the present invention proposes a method, medium and computer device for processing sequence values in a database cluster that overcomes or at least partially solves the above problems.
[0004] One object of the present invention is to more clearly define the functions of the main unit and the backup unit.
[0005] A further objective of this invention is to improve the performance of database clusters.
[0006] A further objective of this invention is to ensure the uniqueness and integrity of sequence values between the primary and backup machines.
[0007] Specifically, the present invention provides a method for processing sequence values in a database cluster, comprising:
[0008] Build a target cache based on sequence values on the host of the database cluster;
[0009] The host receives sequence value request requests from the standby machines in the database cluster.
[0010] The target cache requests the return of the corresponding sequence segment based on the sequence value. The sequence segment includes a set range of sequence values.
[0011] Optionally, the step of establishing a target cache based on sequence values on the hosts of the database cluster includes:
[0012] The host receives a sequence value creation instruction.
[0013] The host generates a sequence value based on the sequence value creation instruction and stores it in the target cache.
[0014] Optionally, after the step of generating a sequence value in the host according to the sequence value creation instruction and storing it in the target cache, the method further includes:
[0015] Update the sequence value in the target cache based on the operation log in the host.
[0016] Optionally, the step of updating the sequence value in the target cache based on the operation log in the host includes:
[0017] Determine the most recently used target sequence value in the target cache based on the operation log;
[0018] The increment is determined based on the sequence value creation instruction;
[0019] The target sequence value is updated based on the increment.
[0020] Optionally, after the step of requesting the return of the corresponding sequence segment based on the sequence value in the target cache, the following may be included:
[0021] Invoke the standby unit to receive the sequence value query request;
[0022] Retrieve the target sequence value from the sequence segment based on the sequence value query request.
[0023] Optionally, the step of retrieving the target sequence value from the sequence segment based on the sequence value query request includes:
[0024] Determine whether the target sequence value exists in the sequence segment;
[0025] If not, a sequence value request is sent to the host.
[0026] Optionally, after the step of determining whether the target sequence value exists in the sequence segment, the method further includes:
[0027] If the target sequence value exists in the sequence segment, perform a query operation on the standby machine based on the target sequence value.
[0028] Optionally, the step of requesting the return of the corresponding sequence segment based on the sequence value in the target cache includes:
[0029] The starting value of the sequence segment is determined based on the sequence value request;
[0030] Extract a sequence of values within a preset range from the starting value in the target cache as a sequence segment;
[0031] Return the sequence segment to the standby machine.
[0032] According to another aspect of the present invention, a machine-readable storage medium is also provided, on which a machine-executable program is stored, which, when executed by a processor, implements the method for processing sequence values in a database cluster as described above.
[0033] According to another aspect of the present invention, a computer device is also provided, including a memory, a processor, and a machine-executable program stored in the memory and running on the processor, wherein the processor executes the machine-executable program to implement the processing method for sequence values in a database cluster as described above.
[0034] The method for processing sequence values in a database cluster according to the present invention establishes a target cache based on sequence values in the host of the database cluster beforehand. Then, the host receives sequence value request requests from standby machines in the database cluster, and returns the corresponding sequence segment in the target cache based on the sequence value request request. The sequence segment includes sequence values within a defined range. This method transfers the update behavior of sequence values, which originally belonged to the standby machines in the database cluster, to the host, allowing the standby machines to only perform query operations. This improves the query performance of the standby machines and more clearly defines the functions of the host and standby machines, thereby improving the overall performance of the database.
[0035] Furthermore, in the solution of this invention, after the standby machine receives a sequence value query request, it retrieves the target sequence value from the sequence segment according to the query request. If the target sequence value is not found in the sequence segment of the standby machine, it actively sends a sequence value request to the host machine. This method ensures that only querying occurs on the standby machine, and that all standby machines request sequence values from the host machine, thus guaranteeing the uniqueness and integrity of sequence values within the database cluster through the host machine.
[0036] The above and other objects, advantages and features of the present invention will become more apparent to those skilled in the art from the following detailed description of specific embodiments of the invention in conjunction with the accompanying drawings. Attached Figure Description
[0037] The following sections will describe some specific embodiments of the invention in detail by way of example and not limitation, with reference to the accompanying drawings. The same reference numerals in the drawings denote the same or similar parts or portions. Those skilled in the art should understand that these drawings are not necessarily drawn to scale. In the drawings:
[0038] Figure 1 This is a flowchart illustrating a method for processing sequence values in a database cluster according to an embodiment of the present invention;
[0039] Figure 2 This is a schematic diagram of the host operation flow of a method for processing sequence values in a database cluster according to another embodiment of the present invention;
[0040] Figure 3 This is a schematic diagram of the standby operation process of a method for processing sequence values in a database cluster according to another embodiment of the present invention;
[0041] Figure 4This is a schematic diagram of a machine-readable storage medium in a method for processing sequence values in a database cluster according to an embodiment of the present invention; and
[0042] Figure 5 This is a schematic diagram of a computer device in a method for processing sequence values in a database cluster according to an embodiment of the present invention. Detailed Implementation
[0043] Those skilled in the art should understand that the embodiments described below are merely a part of the embodiments of the present invention, and not all of the embodiments of the present invention. These partial embodiments are intended to explain the technical principles of the present invention and are not intended to limit the scope of protection of the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by those skilled in the art without creative effort should still fall within the scope of protection of the present invention.
[0044] A database cluster is a concept that combines multiple database instances (nodes) into a single system. The goal of a database cluster is to improve the performance, availability, and scalability of a database system. In a database cluster, each database instance (node) can run independently and has its own computing and storage resources. These nodes are connected via a network to form a logical cluster. Nodes achieve data consistency and reliability through data sharing and collaborative work. Typically, a database cluster has one primary server and multiple backup servers. The primary server, with higher performance, is generally used for write operations such as insert, delete, and update operations, while the backup servers support query operations by synchronizing data with the primary server, thus achieving read-write separation. However, for sequence values, the backup server needs to retrieve the next value during a query process, which is actually an update process for the sequence value. Therefore, to strictly distinguish the functions of the primary and backup servers, a method is needed to transfer the sequence value update process to the higher-performance primary server, while the backup servers are only used for queries, thereby improving the overall performance of the database.
[0045] Figure 1 This is a flowchart illustrating a method for processing sequence values in a database cluster according to an embodiment of the present invention. In this embodiment, the process generally includes:
[0046] Step S101: Establish a target cache on the host of the database cluster based on the sequence value. In this embodiment, the sequence value is a user-created database object that generates a unique integer. An optional example is creating a primary key value that must be unique for each row and can then be incremented or decremented based on a set value. In this step, a target cache is established on the host to store the sequence values generated by the host.
[0047] Step S102: The host receives a sequence value request from the standby machine in the database cluster. In this embodiment, when the standby machine needs insufficient sequence values to support subsequent queries during data retrieval, the standby machine will request sequence values from the host. Those skilled in the art can set the specific form and content of the sequence value request according to the actual situation.
[0048] Step S103: Return the corresponding sequence segment in the target cache according to the sequence value request. In this step, after the host receives the sequence value request, it returns the sequence values within a set range following the sequence value corresponding to this standby machine as a sequence segment to the standby machine for use.
[0049] This method can transfer the update of sequence values, which originally belonged to the standby machine in the database cluster, to the primary machine. This allows the standby machine to only perform query operations, thereby improving the query performance of the standby machine and more clearly defining the functions of the primary and standby machines, thus improving the overall performance of the database.
[0050] In some optional embodiments, the step of establishing a target cache based on a sequence value on the host of the database cluster generally includes: receiving a sequence value creation instruction from the host; generating a sequence value on the host according to the sequence value creation instruction; and storing the sequence value in the target cache. In this step, the sequence value creation instruction generally includes information such as the start value, maximum value, and increment of the sequence value. The host then creates the sequence value according to the information in the sequence value creation instruction and stores the created sequence value in the target cache. An optional sequence value creation instruction may be:
[0051] create sequence sequence_name
[0052] start with n1
[0053] increment by n2
[0054] maxvalue n3|no maxvalue
[0055] minvalue n4|no minvalue
[0056] cache n5|no cache
[0057] cycle|no cycle
[0058] order|no order
[0059] Where, sequence_name represents the sequence name; start with n1 means that the first sequence value generated is n1; increase by n2 means that the increment of the sequence value each time is n2; maxvalue n3 means that the upper limit of the sequence value is n3, and no maxvalue can also be used to indicate that the sequence value has no upper limit;
[0060] In some optional embodiments, after the step of generating a sequence value in the host according to the sequence value creation instruction and storing it in the target cache, the method may further include: updating the sequence value in the target cache according to the operation log in the host. The operation log (or binary log) is a log file that records all change operations in the database, containing detailed information about insert, update, and delete operations performed on the database. In this step, since the host is generally responsible for update operations in the database cluster, and the operation log is also updated on the host, updating the sequence value in the host according to the operation log ensures the consistency of the sequence value throughout the entire database cluster.
[0061] The steps for updating the sequence value in the target cache based on the operation log in the host generally include: determining the most recently used target sequence value in the target cache based on the operation log; determining the increment based on the sequence value creation instruction; and updating the target sequence value based on the increment.
[0062] In some alternative embodiments, after the step of requesting the return of the corresponding sequence segment in the target cache based on the sequence value, the process generally includes: calling the standby machine to receive the sequence value query request; and retrieving the target sequence value from the sequence segment based on the sequence value query request. The sequence value query request can be initiated by the database cluster after receiving a database query request, parsing the content of the database query request to obtain the sequence value corresponding to the content to be queried, and then querying it in the sequence segment of the standby machine. For example, when the database is performing batch data reading, after the standby machine reads one piece of data, it automatically obtains the sequence value corresponding to the next piece of data. At this time, obtaining the next sequence value is the target sequence value in the sequence value query request. Then, the standby machine checks in its sequence segment whether the next sequence value exists; if it exists, the next sequence value is retrieved and the query operation is performed. Those skilled in the art can set the form and content of the sequence value query request according to the actual situation.
[0063] In this embodiment, the step of obtaining the target sequence value from the sequence segment according to the sequence value query request generally includes: determining whether the target sequence value exists in the sequence segment; if not, sending a sequence value request to the host. In this step, when the standby machine queries the sequence segment, if the target sequence value does not exist in the sequence segment, it controls the standby machine to send a sequence value request to the host, thereby updating the sequence segment in the standby machine.
[0064] After determining whether the target sequence value exists in the sequence segment, the process can generally include: if the target sequence value exists in the sequence segment, performing a query operation on the standby machine based on the target sequence value.
[0065] In this embodiment, the step of returning the corresponding sequence segment in the target cache according to the sequence value request generally includes: determining the starting value of the sequence segment according to the sequence value request; extracting a preset range of sequence values from the starting value in the target cache as the sequence segment; and returning the sequence segment to the standby machine. Those skilled in the art can set the range of the sequence segment according to the actual situation of the database.
[0066] This method allows for a clearer definition of the roles of the primary and standby servers in a database cluster. Updates are delegated to the higher-performing primary server, while the standby servers are only responsible for queries. Furthermore, all standby servers dynamically request sequence segments from the primary server, enabling the primary server to control the uniformity and integrity of sequence values and ensure that sequence values are not duplicated, thereby improving database performance.
[0067] Figure 2 This is a schematic diagram of the host operation flow of a method for processing sequence values in a database cluster according to another embodiment of the present invention. In some optional embodiments, this flow generally includes:
[0068] Step S201: The host receives a sequence value creation instruction. In this step, the sequence value creation instruction generally includes information such as the starting value, maximum value, and increment of the sequence value. The host then creates the sequence value according to the information in the sequence value creation instruction and stores the created sequence value in the target cache.
[0069] Step S202: Generate a sequence value in the host according to the sequence value creation instruction and store it in the target cache. In some optional embodiments, the sequence value creation instruction may be:
[0070] create sequence sequence_name
[0071] start with n1
[0072] increment by n2
[0073] maxvalue n3|no maxvalue
[0074] minvalue n4|no minvalue
[0075] cache n5|no cache
[0076] cycle|no cycle
[0077] order|no order
[0078] Where, sequence_name represents the sequence name; start with n1 means that the first sequence value generated is n1; increase by n2 means that the increment of the sequence value each time is n2; maxvalue n3 means that the upper limit of the sequence value is n3, and no maxvalue can also be used to indicate that the sequence value has no upper limit;
[0079] Step S203: Update the sequence value in the target cache according to the operation log in the host. In this embodiment, the operation log (or binary log) is a log file that records all change operations in the database, containing detailed information about insert, update, and delete operations performed on the database. In this step, since the host is generally responsible for update operations in the database cluster, and the operation log is also updated on the host, updating the sequence value in the host according to the operation log ensures the consistency of the sequence value throughout the entire database cluster.
[0080] Step S204: The host receives a sequence value request from the standby machine in the database cluster. In this embodiment, when the standby machine needs insufficient sequence values to support subsequent queries during data retrieval, the standby machine will request sequence values from the host. Those skilled in the art can set the specific form and content of the sequence value request according to the actual situation.
[0081] Step S205: Determine the starting value of the sequence segment based on the sequence value request.
[0082] Step S206: Extract a sequence of values within a preset range from the starting value in the target cache as a sequence segment. Those skilled in the art can set the size of the preset range according to the actual situation of the database.
[0083] Step S207: Return the sequence segment to the standby machine.
[0084] The above method allows for a clearer definition of the roles of the primary and standby servers in the database cluster. Updates are delegated to the higher-performing primary server, which uniformly creates and updates sequence values. Subsequently, the primary server returns the corresponding sequence segments based on requests from the standby server. This ensures that sequence values are not duplicated throughout the database cluster, guaranteeing their uniformity and integrity, thereby improving the overall performance of the database cluster.
[0085] Figure 3This is a schematic diagram of the standby operation flow of a method for processing sequence values in a database cluster according to another embodiment of the present invention. In some optional embodiments, this flow generally includes:
[0086] Step S301: Invoke the standby machine to receive the sequence value query request. In this embodiment, the sequence value query request can be obtained by the database cluster parsing the content of the database query request to obtain the sequence value corresponding to the content to be queried after receiving the database query request, and then querying it in the sequence segment of the standby machine. For example, when the database is performing batch data reading, after the standby machine reads one piece of data, it will automatically obtain the sequence value corresponding to the next piece of data, and then query whether the next sequence value exists in the sequence segment of the standby machine. If it exists, the next sequence value is retrieved and the query operation is performed. Those skilled in the art can set the form and content of the sequence value query request according to the actual situation.
[0087] Step S302: Determine whether the target sequence value exists in the sequence segment. In this step, the sequence segment is a range of sequence values obtained by the standby machine from the master machine. Those skilled in the art can set the range of the sequence segment according to the actual situation of the database.
[0088] Step S303: If the determination in step S302 is yes, a query operation is performed on the standby machine based on the target sequence value. In this step, if the determination in step S302 is yes, it means that the target sequence value exists in the current sequence segment of the standby machine, and then the target sequence value is obtained and a query operation is performed on the standby machine.
[0089] Step S304: If the determination in step S302 is negative, a sequence value request is sent to the host. In this step, if the determination in step S302 is negative, it means that the target sequence value does not exist in the sequence segment. Therefore, the standby machine is controlled to send a sequence value request to the host, thereby updating the sequence segment in the standby machine to satisfy the query.
[0090] This method allows for a clearer definition of the roles of the primary and standby machines in a database cluster. It controls standby machines to be responsible only for queries, and all standby machines dynamically request sequence segments from the primary machine. This ensures the consistency and integrity of sequence values across different standby machines, thereby improving database performance.
[0091] This embodiment also provides a machine-readable storage medium and a computer device. Figure 4 This is a schematic diagram of a machine-readable storage medium 401 according to an embodiment of the present invention. Figure 5 This is a schematic diagram of a computer device 503 according to an embodiment of the present invention.
[0092] The machine-readable storage medium 401 stores a machine-executable program 402 thereon, which, when executed by a processor, implements the method for processing sequence values in the database cluster of any of the above embodiments.
[0093] Computer device 503 may include memory 501, processor 502 and machine-executable program 402 stored on memory 501 and running on processor 502, and when processor 502 executes machine-executable program 402, it implements the method for processing sequence values in database cluster of any of the above embodiments.
[0094] It should be noted that the logic and / or steps represented in the flowchart or otherwise described herein, such as updating sequence values, may be specifically implemented in any machine-readable storage medium for use by, or in conjunction with, an instruction execution system, apparatus or device (such as a computer-based system, a processor-based system or other system that can fetch and execute instructions from, an instruction execution system, apparatus or device).
[0095] For the purposes of this embodiment, the machine-readable storage medium 401 can be any means capable of containing, storing, communicating, propagating, or transmitting a program for use by or in conjunction with an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of the machine-readable storage medium 401 include: an electrical connection (electronic device) having one or more wires, a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, the machine-readable storage medium 401 can even be paper or other suitable media on which the program can be printed, since the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in a computer memory.
[0096] It should be understood that various parts of the present invention can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system.
[0097] Computer device 503 can be, for example, a server, desktop computer, laptop computer, tablet computer, or smartphone. In some examples, computer device 503 can be a cloud computing node. Computer device 503 can be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, program modules can include routines, programs, object programs, components, logic, data structures, etc., that perform specific tasks or implement specific abstract data types. Computer device 503 can be implemented in a distributed cloud computing environment where tasks are performed by remote processing devices linked via a communication network. In a distributed cloud computing environment, program modules can reside on local or remote computing system storage media, including storage devices.
[0098] Computer device 503 may include a processor 502 adapted to execute stored instructions and a memory 501 that provides temporary storage space for the operation of said instructions during operation. The processor 502 may be a single-core processor, a multi-core processor, a computing cluster, or any other configuration. The memory 501 may include random access memory (RAM), read-only memory, flash memory, or any other suitable storage system.
[0099] The processor 502 can be connected via a system interconnect (e.g., PCI, PCI-Express, etc.) to an I / O interface (input / output interface) suitable for connecting the computer device 503 to one or more I / O devices (input / output devices). I / O devices may include, for example, a keyboard and indicating devices, where indicating devices may include a touchpad or touchscreen, etc. I / O devices may be built into the computer device 503 or may be external devices connected to the computing device.
[0100] The processor 502 may also be linked via a system interconnect to a display interface suitable for connecting the computer device 503 to a display device. The display device may include a display screen as a built-in component of the computer device 503. The display device may also include an external computer monitor, television, or projector connected to the computer device 503. Furthermore, a network interface controller (NIC) may be adapted to connect the computer device 503 to a network via a system interconnect. In some embodiments, the NIC may use any suitable interface or protocol (such as an Internet Minicomputer System Interface) to transmit data. The network may be a cellular network, a radio network, a wide area network (WAN), a local area network (LAN), or the Internet, etc. Remote devices may connect to the computing device via the network.
[0101] The flowchart provided in this embodiment is not intended to indicate that the operations of the method will be performed in any particular order, or that all operations of the method are included in every case. Furthermore, the method may include additional operations. Within the scope of the technical concept provided by the method in this embodiment, additional variations can be made to the above method.
[0102] Therefore, those skilled in the art should recognize that although numerous exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications conforming to the principles of the present invention can be directly determined or derived from the disclosure of the present invention without departing from the spirit and scope of the invention. Thus, the scope of the present invention should be understood and construed as covering all such other variations or modifications.
Claims
1. A method for processing sequence values in a database cluster, comprising: A target cache is established on the host of the database cluster based on the sequence value; The host receives a sequence value request from the standby machine in the database cluster. The target cache requests the return of the corresponding sequence segment based on the sequence value, and the sequence segment includes a sequence value within a set range; The standby unit is invoked to receive the sequence value query request; Determine whether the target sequence value exists in the sequence segment; If not, then send the sequence value request to the host; If the target sequence value exists in the sequence segment, a query operation is performed on the standby machine based on the target sequence value.
2. The method for processing sequence values in a database cluster according to claim 1, wherein, The step of establishing a target cache based on the sequence value in the host of the database cluster includes: The host is invoked to receive a sequence value creation instruction; The host generates a sequence value according to the sequence value creation instruction and stores it in the target cache.
3. The method for processing sequence values in a database cluster according to claim 2, wherein, The step of generating a sequence value in the host according to the sequence value creation instruction and storing it in the target cache further includes: The sequence value in the target cache is updated according to the operation log in the host.
4. The method for processing sequence values in a database cluster according to claim 3, wherein, The step of updating the sequence value in the target cache according to the operation log in the host includes: The most recently used target sequence value in the target cache is determined based on the operation log; The increment is determined based on the sequence value creation instruction; The target sequence value is updated according to the increment.
5. The method for processing sequence values in a database cluster according to claim 1, wherein, The step of requesting the return of the corresponding sequence segment in the target cache based on the sequence value includes: The starting value of the sequence segment is determined according to the sequence value request; The sequence segment is obtained by extracting a sequence of values within a preset range from the starting value in the target cache. The sequence segment is returned to the standby machine.
6. A machine-readable storage medium having a machine-executable program stored thereon, wherein the machine-executable program, when executed by a processor, implements the method for processing sequence values in a database cluster according to any one of claims 1 to 5.
7. A computer device comprising a memory, a processor, and a machine-executable program stored in the memory and running on the processor, wherein the processor, when executing the machine-executable program, implements the method for processing sequence values in a database cluster according to any one of claims 1 to 5.