Transaction identification processing method, device and electronic equipment

Through circular linked lists and master-slave server communication, the problem of repeated and incremental transaction identification in the distributed database system is solved, efficient and reliable transaction identification management is achieved, and the client's demand for continuously increasing transaction identification is met and the system's high level is improved. Availability.

CN112231069BActive Publication Date: 2024-12-27BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011100032.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-10-14
Publication Date
2024-12-27
Estimated Expiration
2040-10-14

AI Technical Summary

Technical Problem

In a distributed database system, duplication is easily caused when using the database auto-increment primary key to obtain transaction identifiers, which cannot meet the continuous incremental requirements of global transaction identifiers.

Method used

The transaction identification queue is implemented using a circular linked list, and multiple transaction identifications are stored in advance, and the transaction identification is continuously incremented and high availability through master-slave server communication and log backup.

Benefits of technology

It realizes the continuous increase in transaction identifiers by the client, improves the acquisition efficiency, reduces the frequency of log generation, and ensures that the slave server can continue to provide incremental transaction identifiers when the master server is down, improving the high availability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112231069B_ABST
    Figure CN112231069B_ABST
Patent Text Reader

Abstract

The present invention provides a method, device and electronic device for processing transaction identifiers, and relates to the field of computer technology. The method includes receiving a request from a client to obtain a transaction identifier; reading the transaction identifier currently pointed to by a queue pointer from a preset first queue, and moving the queue pointer according to a preset step length so that the queue pointer points to the next transaction identifier in the first queue; the first queue pre-stores a plurality of sequentially increasing transaction identifiers; and returning the read transaction identifier to the client. The embodiment of the present invention generates a plurality of sequentially increasing transaction identifiers in advance and stores them in a queue. When a request to obtain a transaction identifier from a client is received, the transaction identifiers are read from the queue in sequence and returned to the client, thereby realizing a continuous increase in the transaction identifier provided to the client. This method can meet the client's demand for a continuously increasing transaction identifier.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device and electronic equipment for processing transaction identification. Background Art

[0002] The database auto-increment primary key means that the value of the id field is set to auto-increment when designing the table. In this way, when inserting a row of data, there is no need to specify the id, but it is automatically filled in according to the id value of the previous field plus 1. For example, in the MySQL database, the sql statement AUTO_INCREMENT can be used to enable auto-increment assignment for a specific field. By using the auto-increment id as the primary key, the atomicity of the field can be guaranteed.

[0003] In a distributed database system, distributed transactions need to be uniquely identified. If each server node in the system independently obtains the transaction identifier using the database's auto-increment primary key, many duplicate transaction identifiers will be generated, which will fail to meet the requirement for continuous increment of the global transaction identifier. Summary of the invention

[0004] In view of this, an object of the present invention is to provide a method, device and electronic device for processing a transaction identifier, which can meet the client's demand for a continuously increasing transaction identifier.

[0005] In a first aspect, an embodiment of the present invention provides a method for processing a transaction identifier, comprising: receiving a request from a client for obtaining a transaction identifier; reading the transaction identifier currently pointed to by a queue pointer from a preset first queue, and moving the queue pointer according to a preset step size so that the queue pointer points to the next transaction identifier in the first queue; a plurality of sequentially increasing transaction identifiers are pre-stored in the first queue; and the read transaction identifier is returned to the client.

[0006] In a preferred embodiment of the present invention, the first queue is implemented using a circular linked list, which is composed of at least two doubly linked lists.

[0007] In a preferred embodiment of the present invention, a first transaction identifier set is pre-stored in the double linked list currently being read, and the transaction identifiers in the first transaction identifier set are incremented in sequence; the above method further includes: when the number of unread transaction identifiers in the first transaction identifier set is lower than a preset threshold, triggering generation of a second transaction identifier set; the transaction identifiers in the second transaction identifier set are incremented in sequence, and the minimum transaction identifier in the second transaction identifier set is greater than the maximum transaction identifier in the first transaction identifier set; and storing the second transaction identifier set in a next double linked list sequentially associated with the double linked list currently being read.

[0008] In a preferred embodiment of the present invention, the above method is applied to a master server, and the master server is communicatively connected to a preset slave server, and the method further includes: when any transaction identifier set is stored in the first queue, a log is generated; the content of the log includes the maximum transaction identifier in the transaction identifier set; the log is sent to the slave server, so that the slave server generates a third transaction identifier set when receiving the log, and stores the third transaction identifier set in a second queue preset on the slave server; the transaction identifiers in the third transaction identifier set are incremented sequentially, and the minimum transaction identifier in the third transaction identifier set is greater than the maximum transaction identifier in the transaction identifier set.

[0009] In a preferred embodiment of the present invention, the method further comprises: when the master server is down, triggering the slave server to read the transaction identifier in the second queue to respond to the client's request for obtaining the transaction identifier.

[0010] In a preferred embodiment of the present invention, the step of reading the transaction identifier currently pointed to by the queue pointer includes: reading the transaction identifier currently pointed to by the queue pointer through a first thread; wherein the transaction identifiers in the first queue are all generated through a second thread.

[0011] In a second aspect, an embodiment of the present invention further provides a transaction identifier processing device, comprising: a transaction identifier acquisition request receiving module, used to receive a client's acquisition request for a transaction identifier; a transaction identifier reading module, used to read the transaction identifier currently pointed to by a queue pointer from a preset first queue, and move the queue pointer according to a preset step size so that the queue pointer points to the next transaction identifier in the first queue; a plurality of sequentially increasing transaction identifiers are pre-stored in the first queue; and a transaction identifier returning module, used to return the read transaction identifier to the client.

[0012] In a preferred embodiment of the present invention, the first queue is implemented using a circular linked list, which is composed of at least two double linked lists.

[0013] In a third aspect, an embodiment of the present invention further provides an electronic device, which includes a processor and a memory, wherein the memory stores computer executable instructions that can be executed by the processor, and the processor executes the computer executable instructions to implement the above-mentioned transaction identification processing method.

[0014] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the above-mentioned transaction identification processing method.

[0015] The embodiments of the present invention bring the following beneficial effects:

[0016] The embodiment of the present invention provides a method, device and electronic device for processing a transaction identifier, which first receives a request from a client to obtain a transaction identifier; then reads the transaction identifier currently pointed to by a queue pointer from a preset first queue, and moves the queue pointer according to a preset step length so that the queue pointer points to the next transaction identifier in the first queue; the first queue pre-stores a plurality of sequentially increasing transaction identifiers; and then returns the read transaction identifier to the client. In this method, by pre-generating a plurality of sequentially increasing transaction identifiers and storing them in a queue, when a transaction identifier acquisition request from a client is received, the transaction identifiers are read from the queue in sequence and returned to the client, thereby realizing a continuous increase in the transaction identifier provided to the client. This method can meet the client's demand for a continuously increasing transaction identifier.

[0017] In addition, the present application also stores the transaction identifier in the memory by means of a circular linked list, so that the transaction identifier can be read more quickly to respond to the client's request. Moreover, by generating a transaction identifier set with a certain number of transaction identifiers at one time, and then reading the transaction identifiers therein in sequence, and only generating corresponding logs when the transaction identifier set is generated, compared with the method in the prior art of generating transaction identifiers immediately when there is a demand and generating corresponding logs, the method in the present application reduces the frequency of log generation, and the efficiency of obtaining transaction identifiers is also higher. Furthermore, the present application also sets a master-slave server, and backs up the log generated by the master server to the slave server, so that the slave server pre-generates a transaction identifier set that is still continuously increasing compared to the transaction identifier in the master server, so that in the case of a master server crash, the slave server can continue to provide the client with continuously increasing transaction identifiers, thereby increasing the high availability of the system.

[0018] Other features and advantages of the present disclosure will be set forth in the following description, or some features and advantages may be inferred or unambiguously determined from the description, or may be learned by implementing the above-mentioned technology of the present disclosure.

[0019] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0021] Figure 1A flowchart of a method for processing a transaction identifier provided by an embodiment of the present invention;

[0022] Figure 2 A schematic diagram of a flow chart of a method for dynamically storing a transaction identifier in a queue provided by an embodiment of the present invention;

[0023] Figure 3 A schematic diagram of a communication process between a master and slave server in a transaction identification process provided by an embodiment of the present invention;

[0024] Figure 4 A schematic diagram of the structure of a transaction identification processing device provided by an embodiment of the present invention;

[0025] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.

[0026] Icons: 41 - transaction identifier acquisition request receiving module; 42 - transaction identifier reading module; 43 - transaction identifier returning module; 51 - processor; 52 - memory; 53 - bus; 54 - communication interface. DETAILED DESCRIPTION

[0027] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0028] Considering that obtaining transaction identifiers by means of a database auto-increment primary key cannot meet the problem that the demand for continuous increment of transaction identifiers in a distributed database system is not met, an embodiment of the present invention provides a transaction identifier processing method, device, and electronic device, which can be applied to various application scenarios where transaction identifiers need to be obtained. To facilitate understanding of this embodiment, a transaction identifier processing method disclosed in an embodiment of the present invention is first introduced in detail.

[0029] See also Figure 1 , which is a flow chart of a method for processing a transaction identifier provided by an embodiment of the present invention, comprising Figure 1 It can be seen that the method comprises the following steps:

[0030] Step S102: receiving a request from the client for obtaining a transaction identifier.

[0031] Here, a transaction refers to a sequence of reading and writing to a database. In the process of transaction processing, the transaction manager is usually responsible for generating transactions and assigning transaction identifiers to them. The transaction identifier is the number of a committed transaction, and in a distributed database system, a global transaction identifier (GTID) is required. The global transaction identifier is a globally unique number and is required to be continuously incremented.

[0032] In addition, the client is also the user end, which is a program corresponding to the server and provides local services to customers. In actual operation, the transaction identification processing method in this embodiment can be run in a distributed database system, for example, running on each server node in a distributed system; and the method can also be run in other non-distributed systems to provide incremental transaction identification services, and its application scenario is not limited here.

[0033] In actual operation, when the client needs to process a new transaction, it sends a request to the server to obtain the transaction identifier.

[0034] Step S104: read the transaction identifier currently pointed to by the queue pointer from the preset first queue, and move the queue pointer according to the preset step length so that the queue pointer points to the next transaction identifier in the first queue; the first queue pre-stores a plurality of sequentially increasing transaction identifiers.

[0035] In this embodiment, a plurality of sequentially increasing transaction identifiers are pre-generated and pre-stored in a preset first queue, wherein the first queue is a special first-in-first-out linear table that only allows deletion operations at the front end of the table and insertion operations at the rear end of the table. Here, "first" is only used for the purpose of distinguishing descriptions and cannot be understood as indicating or implying relative importance.

[0036] When receiving a request from the client for obtaining a transaction identifier, the server reads the transaction identifier currently pointed to by the queue pointer from the first queue, wherein the read transaction identifier is used as the target transaction identifier for responding to the current client request.

[0037] After reading a transaction identifier, the queue pointer is automatically moved according to the preset step size so that the queue pointer points to the next transaction identifier in the first queue. In this way, when a request to obtain the next transaction identifier is received, the above-mentioned "next transaction identifier" pointed to by the read queue pointer can be read accordingly, thereby realizing sequential reading of the transaction identifiers stored in the first queue and providing them to the client.

[0038] Step S106: Return the read transaction identifier to the client.

[0039] Through the aforementioned steps S102 to S104, the transaction identifier is read from the first queue, and here, the read transaction identifier is returned to the client.

[0040] Thus, according to the above-mentioned transaction identifier processing method, since multiple transaction identifiers (which may be 10,000, 100,000, etc.) that increase in sequence are stored in advance in the first queue, when a transaction identifier request is received, the transaction identifier can be read sequentially from the first queue, so that the transaction identifier read and returned to the client satisfies monotonically increasing, unique and non-repeating. Compared with the existing transaction identifier processing method (the database self-increment primary key method), the prior art generates transaction identifiers immediately when there is a demand, generates in real time and returns in real time, and cannot meet the demand for continuous increase of global transaction identifiers in distributed systems. The above-mentioned method of the present application can efficiently provide distributed systems with continuously increasing transaction identifiers to meet their demand for global transaction identifiers.

[0041] A method for processing a transaction identifier provided by an embodiment of the present invention first receives a request from a client to obtain a transaction identifier; then reads the transaction identifier currently pointed to by a queue pointer from a preset first queue, and moves the queue pointer according to a preset step length so that the queue pointer points to the next transaction identifier in the first queue; the first queue pre-stores a plurality of sequentially increasing transaction identifiers; and then returns the read transaction identifier to the client. In this method, by pre-generating a plurality of sequentially increasing transaction identifiers and storing them in a queue, when a transaction identifier acquisition request from a client is received, the transaction identifiers are read from the queue in order and returned to the client, thereby realizing a continuous increase in the transaction identifier provided to the client. This method can meet the client's demand for a continuously increasing transaction identifier.

[0042] In actual operation, the client's continuous demand for transaction identifiers requires the server to continuously provide transaction identifiers that meet the requirements. Figure 1 On the basis of the transaction identifier processing method shown, this embodiment introduces in detail how to dynamically store transaction identifiers that meet the requirements in the first queue, so as to continuously provide the client with transaction identifiers that meet the requirements.

[0043] This embodiment provides another method for processing a transaction identifier, wherein the method includes the following steps 11-13:

[0044] (11) receiving a request from a client for obtaining a transaction identifier;

[0045] (12) reading a transaction identifier currently pointed to by a queue pointer from a preset first queue, and moving the queue pointer according to a preset step length so that the queue pointer points to a next transaction identifier in the first queue; wherein the first queue is implemented by a circular linked list, and the circular linked list is composed of at least two double linked lists; and a first transaction identifier set is pre-stored in the double linked list currently being read, and the transaction identifiers in the first transaction identifier set are incremented in sequence;

[0046] (13) The read transaction identifier is returned to the client.

[0047] In this embodiment, the first queue is implemented by a circular linked list, and the circular linked list is composed of at least two double linked lists. Here, each data node of the double linked list has two pointers, which point to the direct successor and the direct predecessor respectively. Therefore, starting from any node in the double linked list, its predecessor node and successor node can be easily accessed. In addition, the circular linked list is a chain storage structure, and the pointer field of the last node in the linked list points to the head node, and the entire linked list forms a ring. The circular linked list realizes the reuse of storage space without adding additional storage capacity.

[0048] like Figure 2 As shown, it is a flowchart of a method for dynamically storing transaction identifiers in a queue. Figure 2 In the transaction identification processing method of this embodiment, how to dynamically store the transaction identification in the first queue is shown. Figure 2 It can be seen that the method comprises the following steps:

[0049] Step S202: When the number of unread transaction identifiers in the first transaction identifier set is lower than a preset threshold, a second transaction identifier set is triggered to be generated; the transaction identifiers in the second transaction identifier set are incremented in sequence, and the minimum transaction identifier in the second transaction identifier set is greater than the maximum transaction identifier in the first transaction identifier set.

[0050] In actual operation, the threshold can be set to a specific number, such as 500; or the threshold can be set to the ratio of unread transaction identifiers to the total number of transaction identifiers in the first transaction identifier set, such as 20%. Assuming that the first transaction identifier set contains 10,000 transaction identifiers, when the remaining unread transaction identifiers are 2,000, the generation of the second transaction identifier set is triggered.

[0051] For the above-mentioned second transaction identification set, the transaction identifications in the second transaction identification set are increased in sequence, and the minimum transaction identification in the second transaction identification set is greater than the maximum transaction identification in the first transaction identification set. For example, assuming that the transaction identifications in the first transaction identification set are 1 to 10000, the transaction identifications in the second transaction identification set can be 10001 to 20000, so that each transaction identification set as a whole also satisfies the sequential increase of transaction identifications.

[0052] In one possible implementation, two threads may be set on the server, one of which is used to read the transaction identifier and the other thread is used to generate the transaction identifier. For example, the transaction identifier currently pointed to by the queue pointer of the first queue is read by the first thread, and the transaction identifier is generated by the second thread and stored in the first queue. In this way, the efficiency of the overall transaction identifier processing can be improved in an asynchronous manner.

[0053] Step S204: storing the second transaction identifier set in the next doubly linked list sequentially associated with the doubly linked list currently being read.

[0054] Here, the multiple double linked lists in the circular linked list queue are connected head to tail to form a cycle. After the second transaction identification set is generated, the second transaction identification set is stored in the next double linked list sequentially associated with the currently read double linked list.

[0055] For the first queue, after all the transaction identifiers in the currently read double linked list are read, the queue pointer points to the head of the next double linked list sequentially associated with the currently read double linked list, so that the transaction identifiers in the next double linked list can continue to be read, thereby realizing continuous reading of transaction identifiers.

[0056] In at least one possible implementation, the association between the linked lists in the circular linked list can be dynamically implemented. For example, assuming that the circular linked list includes a double linked list A and a double linked list B, the double linked list A is the linked list currently being read, which contains 10,000 incremental transaction identifiers 1 to 10,000. When there are 2,000 unread transaction identifiers remaining in the double linked list A, another 10,000 transaction identifiers 10,001 to 20,000 are triggered to be generated and stored in the double linked list B. At this time, the double linked list A and the double linked list B are associated. If the association is successful, the state of the largest node in the double linked list A (that is, the node corresponding to the transaction identifier 10,000) is modified, and isLastOne is changed from "true" to "false", thereby realizing the series connection of the two linked lists. After reading the transaction identifier in the double linked list A, the queue pointer continues to point to the head of the double linked list B to read the transaction identifier in the double linked list B. If the doubly linked list A and the doubly linked list B are not successfully associated, the state of the largest node in the doubly linked list A (that is, the node corresponding to the transaction ID 10000), isLastOne, still remains "true".

[0057] The transaction identifier processing method provided in this embodiment realizes dynamically storing the transaction identifiers that meet the requirements in the above-mentioned first queue by means of a circular linked list, so that monotonically increasing transaction identifiers can be continuously provided to the client, and the transaction identifiers are stored in the memory by means of a circular linked list, so that the transaction identifiers can be read more quickly to respond to the client's request.

[0058] In order to alleviate the problem of reducing the high availability of the transaction identification processing service due to downtime, this embodiment Figure 1 Based on the transaction identifier processing method shown, another transaction identifier processing method is introduced. The method is applied to a master server, and the master server is communicatively connected to a preset slave server. In this method, based on the above steps S102 to S106, the communication between the master and slave servers is further introduced.

[0059] See also Figure 3 , which is a schematic diagram of the communication process between the master and slave servers in transaction identification processing. Figure 3 It can be seen that it includes the following steps:

[0060] Step S302: when any transaction identifier set is stored in the first queue, a log is generated; the content of the log includes the maximum transaction identifier in the transaction identifier set.

[0061] In this embodiment, after the transaction identifier set is generated, when the transaction identifier set is stored in the first queue, a corresponding log is generated, wherein the content of the log includes the maximum transaction identifier in the transaction identifier set.

[0062] For example, assuming that the first transaction identifier set includes 10,000 transaction identifiers 1 to 10,000, when the first transaction identifier set is stored in the first queue, a log is generated, and the log includes the maximum transaction identifier in the current first queue as 10,000. Similarly, when other transaction identifier sets are subsequently generated, a log is also generated accordingly, and the maximum transaction identifier in the transaction identifier set (that is, the maximum transaction identifier in the current queue) is recorded in the log.

[0063] Step S304: Send the log to the slave server so that the slave server generates a third transaction identifier set when receiving the log, and stores the third transaction identifier set in a second queue preset on the slave server; the transaction identifiers in the third transaction identifier set are incremented sequentially, and the minimum transaction identifier in the third transaction identifier set is greater than the maximum transaction identifier in the above transaction identifier set.

[0064] The master server sends the generated log to the slave server immediately, so that the slave server can know the current maximum transaction identifier in the first queue of the master service.

[0065] Among them, a second queue is preset in the slave server, and its working principle can refer to the first queue in the master service, and the relevant content can refer to the corresponding part in the aforementioned embodiment. Specifically, after receiving the log, the slave server triggers the generation of a third transaction identification set, and stores the third transaction identification set in the second queue preset on the slave server.

[0066] Here, the transaction identifiers in the third transaction identifier set are incremented in sequence, and the minimum transaction identifier in the third transaction identifier set is greater than the maximum transaction identifier in the transaction identifier set (i.e., in the first queue). For example, assuming that the maximum transaction identifier recorded in the log is 10000, it indicates that the current maximum transaction identifier in the first queue of the master server is 10000. At this time, the minimum transaction identifier in the transaction identifier set generated by the slave server is greater than 10000, for example, it can start from 10001.

[0067] In this embodiment, when the master server is down, the slave server is triggered to read the transaction identifier in the second queue to respond to the client's request for obtaining the transaction identifier. In this way, since the transaction identifiers in the second queue in the slave server increase in sequence and continue to increase relative to the maximum transaction identifier in the master server, the client's demand for continuously increasing transaction identifiers can continue to be met.

[0068] The transaction identification processing method provided in this embodiment generates a transaction identification set with a certain number of transaction identifications at one time, reads the transaction identifications therein in sequence, and generates corresponding logs only when the transaction identification set is generated. Compared with the method of generating transaction identifications and generating corresponding logs in real time when there is a demand in the prior art, the method in this application reduces the frequency of log generation and is more efficient in obtaining transaction identifications. Furthermore, this application also sets up a master-slave server and backs up the logs generated by the master server to the slave server, so that the slave server pre-generates a transaction identification set that is still continuously increasing compared to the transaction identification in the master server, so that when the master server is down, the slave server can continue to provide the client with continuously increasing transaction identifications, thereby increasing the high availability of the system.

[0069] In order to more clearly understand the transaction identification processing method provided by the present invention, this embodiment also introduces an application example of the transaction identification processing method. The steps of the method are as follows.

[0070] (1) Set the transaction identifier of the distributed sequence to an unsigned long integer, that is, unsigned long, occupying 8 bytes, with a starting value of 1 and a step length of 10000, that is, the transaction identifier is 1 to 10000;

[0071] (2) Using a lock-free queue to store the transaction identifiers 1 to 10,000, four queues are set, denoted as QA, QB, QC, and QD, and the capacity of each queue is 10,000 transaction identifiers;

[0072] (3) Start two threads, one of which is responsible for generating 10,000 transaction representations each time, denoted as production thread A; the other thread is responsible for reading the lock-free queue and issuing transaction identifiers in response to replies, denoted as consumption thread B; consumption thread B defines a queue pointer p, which points to a value in the queue and is initially empty;

[0073] (4) Production thread A generates 10,000 numbers (i.e., transaction identifiers), i.e., 1 to 10,000, and stores them in queue QA. It also generates a log with the content of 10,000. The isLastOne of the node corresponding to transaction identifier 10,000 (the last node, i.e., the largest node) is changed to true. The log is sent to the standby node. After the standby node responds (indicating that the standby node has received the data), the pointer p of consumer thread B executes the head of the queue of QA, i.e., 1.

[0074] (5) After receiving the request, consumer thread B reads out 1, and pointer p executes the second value of QA, which is 2, and sends out transaction identifier 1;

[0075] (6) When production thread A reads the sequence id pointed to by pointer p of consumer thread B>8000 (that is, when the transaction identifier in the queue has reached 80%), production thread A generates 10,000 numbers, such as 10001-20000, and stores them in queue QB, and generates a log with the content of 20000 (the maximum value of the current queue); and sends the log to the standby node. After the standby node responds (indicating that the standby node has received it), it associates QA with QB, and changes the isLastOne of the node corresponding to the transaction identifier 10000 in QA to false;

[0076] (7) If an abnormal situation occurs, for example, QB has not yet been associated with QA, then the isLastOne of QA's largest nodes is true. At this time, consumer thread B waits and dispatches when isLastOne is false.

[0077] (8) The four queues are used in turn, and no memory is released. QC and QD are used like QB. When QD is used, it means that QA has been used up and can be reused.

[0078] (9) Workflow of the standby node: if the maximum transaction ID in the log sent by the primary node is 10000, the generated starting value is 10001, that is, 10001 to 20000. The generation process is the same as that of the primary node. In this way, it is ensured that the standby node is always one step larger than the primary node, that is, 10000.

[0079] (10) When the master node crashes, the backup node becomes the master node. When the master node crashes, if the sequence of the master node is 7890, the range of the master node distributed transaction identifier is 1 to 10000, and the range of the backup node distributed transaction identifier is 10001 to 20000, then the distributed transaction identifier read from the queue of the slave node is 10001 (the transaction identifier changes from 7890 to 10001, a part is lost in the middle, but the increment is guaranteed), thus ensuring that the distributed transaction identifier is incremented and unique.

[0080] Corresponds to Figure 1 The transaction identification processing method shown in , the embodiment of the present invention also provides a transaction identification processing device, see Figure 4 , which is a schematic diagram of the structure of a transaction identification processing device. Figure 4 It can be seen that the device includes a transaction identifier acquisition request receiving module 41, a transaction identifier reading module 42 and a transaction identifier returning module 43 which are connected in sequence, wherein the functions of each module are as follows:

[0081] The transaction identifier acquisition request receiving module 41 is used to receive a request from a client to acquire a transaction identifier;

[0082] The transaction identifier reading module 42 is used to read the transaction identifier currently pointed to by the queue pointer from the preset first queue, and move the queue pointer according to the preset step length so that the queue pointer points to the next transaction identifier in the first queue; the first queue pre-stores a plurality of sequentially increasing transaction identifiers;

[0083] The transaction identifier returning module 43 is used to return the read transaction identifier to the client.

[0084] A transaction identifier processing device provided by an embodiment of the present invention first receives a request from a client to obtain a transaction identifier; then reads the transaction identifier currently pointed to by a queue pointer from a preset first queue, and moves the queue pointer according to a preset step length so that the queue pointer points to the next transaction identifier in the first queue; the first queue pre-stores a plurality of sequentially increasing transaction identifiers; and then returns the read transaction identifier to the client. In the device, a plurality of sequentially increasing transaction identifiers are pre-generated and stored in a queue. When a transaction identifier acquisition request from a client is received, the transaction identifiers are read from the queue in sequence and returned to the client, thereby realizing a continuous increase in the transaction identifier provided to the client. This method can meet the client's demand for a continuously increasing transaction identifier.

[0085] In one possible implementation manner, the first queue is implemented using a circular linked list, and the circular linked list is composed of at least two doubly linked lists.

[0086] In another possible implementation, a first transaction identifier set is pre-stored in the double linked list currently being read, and the transaction identifiers in the first transaction identifier set are incremented in sequence; the above-mentioned device further includes: a transaction identifier set generation module, which is used to trigger the generation of a second transaction identifier set when the number of unread transaction identifiers in the first transaction identifier set is lower than a preset threshold; the transaction identifiers in the second transaction identifier set are incremented in sequence, and the minimum transaction identifier in the second transaction identifier set is greater than the maximum transaction identifier in the first transaction identifier set; and a transaction identifier set storage module, which is used to store the second transaction identifier set in a next double linked list sequentially associated with the double linked list currently being read.

[0087] In another possible implementation, the above-mentioned device is applied to a master server, and the master server is communicatively connected to a preset slave server, and the device also includes: a log generation module, which is used to generate a log when any transaction identifier set is stored in the first queue; the content of the log includes the maximum transaction identifier in the transaction identifier set; a log sending module, which is used to send the log to the slave server, so that the slave server generates a third transaction identifier set when receiving the log, and stores the third transaction identifier set in a second queue preset on the slave server; the transaction identifiers in the third transaction identifier set are incremented sequentially, and the minimum transaction identifier in the third transaction identifier set is greater than the maximum transaction identifier in the transaction identifier set.

[0088] In another possible implementation, the apparatus further includes: a trigger module, configured to trigger the slave server to read the transaction identifier in the second queue when the master server is down, so as to respond to the client's request for obtaining the transaction identifier.

[0089] In another possible implementation, the transaction identifier reading module 42 is further configured to: read, through a first thread, a transaction identifier currently pointed to by a queue pointer; wherein the transaction identifiers in the first queue are all generated through a second thread.

[0090] The transaction identifier processing device provided in the embodiment of the present invention has the same implementation principle and technical effects as those of the aforementioned transaction identifier processing method embodiment. For the sake of brief description, for parts not mentioned in the embodiment of the transaction identifier processing device, reference may be made to the corresponding contents in the aforementioned transaction identifier processing method embodiment.

[0091] The embodiment of the present invention further provides an electronic device, such as Figure 5 As shown, it is a schematic diagram of the structure of the electronic device, wherein the electronic device includes a processor 51 and a memory 52, the memory 52 stores machine executable instructions that can be executed by the processor 51, and the processor 51 executes the machine executable instructions to implement the above-mentioned transaction identification processing method.

[0092] exist Figure 5 In the illustrated embodiment, the electronic device further includes a bus 53 and a communication interface 54 , wherein the processor 51 , the communication interface 54 and the memory 52 are connected via the bus.

[0093] The memory 52 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 54 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0094] The processor 51 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 51. The above processor 51 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in the embodiments of the present invention can be directly embodied as a hardware decoding processor to execute, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor 51 reads the information in the memory 52 and completes the steps of the transaction identification processing method of the above embodiment in combination with its hardware.

[0095] An embodiment of the present invention also provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the above-mentioned transaction identification processing method. The specific implementation can be referred to the aforementioned method embodiment, which will not be repeated here.

[0096] The transaction identifier processing method, transaction identifier processing device and electronic device computer program product provided in the embodiments of the present invention include a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the transaction identifier processing method described in the previous method embodiment. The specific implementation can be found in the method embodiment, which will not be repeated here.

[0097] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

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

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

[0100] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A method for processing a transaction identifier, characterized in that: include: Receive a request from a client for obtaining a transaction identifier; wherein the request is a transaction identifier acquisition request sent by the client to a server when the client needs to process a new transaction; Reading a transaction identifier currently pointed to by a queue pointer from a preset first queue, and moving the queue pointer according to a preset step length so that the queue pointer points to a next transaction identifier in the first queue; a plurality of sequentially increasing transaction identifiers are pre-stored in the first queue; wherein the transaction identifiers are pre-generated multiple sequentially increasing transaction identifiers, and the multiple sequentially increasing transaction identifiers are pre-stored in the preset first queue; The read transaction identifier is returned to the client.

2. The method for processing a transaction identifier according to claim 1, characterized in that: The first queue is implemented by using a circular linked list, and the circular linked list is composed of at least two double linked lists.

3. The method for processing a transaction identifier according to claim 2, characterized in that: A first transaction identifier set is pre-stored in the currently read double linked list, and the transaction identifiers in the first transaction identifier set are incremented in sequence; the method further includes: When the number of unread transaction identifiers in the first transaction identifier set is lower than a preset threshold, generating a second transaction identifier set is triggered; the transaction identifiers in the second transaction identifier set are incremented in sequence, and the minimum transaction identifier in the second transaction identifier set is greater than the maximum transaction identifier in the first transaction identifier set; The second transaction identifier set is stored in a next doubly linked list sequentially associated with the doubly linked list currently being read.

4. The method for processing a transaction identifier according to claim 3, characterized in that: The method is applied to a master server, and the master server is communicatively connected with a preset slave server, and the method further comprises: When any transaction identifier set is stored in the first queue, a log is generated; the content of the log includes the maximum transaction identifier in the transaction identifier set; The log is sent to the slave server, so that the slave server generates a third transaction identifier set when receiving the log, and stores the third transaction identifier set in a second queue preset on the slave server; the transaction identifiers in the third transaction identifier set are increased in sequence, and the minimum transaction identifier in the third transaction identifier set is greater than the maximum transaction identifier in the transaction identifier set.

5. The method for processing a transaction identifier according to claim 4, characterized in that: The method further comprises: When the master server is down, the slave server is triggered to read the transaction identifier in the second queue to respond to the client's request for obtaining the transaction identifier.

6. The method for processing a transaction identifier according to claim 1, characterized in that: The step of reading the transaction identifier currently pointed to by the queue pointer comprises: The transaction identifier currently pointed to by the queue pointer is read through the first thread; wherein the transaction identifiers in the first queue are all generated through the second thread.

7. A transaction identification processing device, characterized in that: include: A transaction identifier acquisition request receiving module, used to receive a request from a client to acquire a transaction identifier; wherein the acquisition request is a transaction identifier acquisition request sent by the client to the server when the client needs to process a new transaction; A transaction identifier reading module, used to read the transaction identifier currently pointed to by the queue pointer from a preset first queue, and move the queue pointer according to a preset step length so that the queue pointer points to the next transaction identifier in the first queue; a plurality of sequentially increasing transaction identifiers are pre-stored in the first queue, wherein the transaction identifiers are pre-generated multiple sequentially increasing transaction identifiers, and the multiple sequentially increasing transaction identifiers are pre-stored in the preset first queue; The transaction identifier returning module is used to return the read transaction identifier to the client.

8. The transaction identification processing device according to claim 7, characterized in that: The first queue is implemented by using a circular linked list, and the circular linked list is composed of at least two double linked lists.

9. An electronic device, characterized in that: The electronic device includes a processor and a memory, the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the transaction identification processing method described in any one of claims 1 to 6.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the transaction identification processing method according to any one of claims 1 to 6.