CN112231069A - Transaction identifier processing method and device and electronic equipment - Google Patents
Transaction identifier processing method and device and electronic equipment Download PDFInfo
- Publication number
- CN112231069A CN112231069A CN202011100032.0A CN202011100032A CN112231069A CN 112231069 A CN112231069 A CN 112231069A CN 202011100032 A CN202011100032 A CN 202011100032A CN 112231069 A CN112231069 A CN 112231069A
- Authority
- CN
- China
- Prior art keywords
- transaction
- transaction identifier
- queue
- identifier
- client
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000003672 processing method Methods 0.000 title description 20
- 238000000034 method Methods 0.000 claims abstract description 57
- 230000006854 communication Effects 0.000 description 10
- 238000004891 communication Methods 0.000 description 8
- 238000010586 diagram Methods 0.000 description 6
- 238000004519 manufacturing process Methods 0.000 description 5
- 230000008569 process Effects 0.000 description 4
- 230000001960 triggered effect Effects 0.000 description 3
- 230000006870 function Effects 0.000 description 2
- 230000002159 abnormal effect Effects 0.000 description 1
- 230000002567 autonomic effect Effects 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000002457 bidirectional effect Effects 0.000 description 1
- 238000004590 computer program Methods 0.000 description 1
- 125000004122 cyclic group Chemical group 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000000802 evaporation-induced self-assembly Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000004044 response Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/466—Transaction processing
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention provides a method and a device for processing a transaction identifier and electronic equipment, and relates to the technical field of computers, wherein the method comprises the steps of receiving an acquisition request of a client for the transaction identifier; reading the transaction identifier currently pointed by the queue pointer from a preset first queue, and moving the queue pointer according to a preset step length so as to enable the queue pointer to point to the next transaction identifier in the first queue; a plurality of transaction identifiers which are sequentially increased are stored in the first queue in advance; and returning the read transaction identification to the client. The embodiment of the invention generates a plurality of transaction identifiers which are sequentially increased in advance and stores the transaction identifiers in the queue, and when a transaction identifier acquisition request of the client is received, the transaction identifiers are sequentially read from the queue and returned to the client, so that the transaction identifiers provided for the client are continuously increased.
Description
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for processing a transaction identifier, and an electronic device.
Background
The database autonomic key is to set the value of the id field to a self-increment form when designing a table, so that when a row of data is inserted, the id is not required to be specified, and the data is automatically added by 1 to be filled according to the id value of the previous field. For example, in a MySQL database, a selfjoin value may be enabled for a particular field by the sql statement AUTO _ INCREMENT, and by using the selfjoin id as the primary key, the atomicity of the field can be guaranteed.
In a distributed database system, a distributed transaction needs to be uniquely identified, and if each server node in the system independently acquires the transaction identifier in a database self-increment key mode, a plurality of repeated transaction identifiers are generated, so that the requirement of continuous increment of the global transaction identifier cannot be met.
Disclosure of Invention
In view of this, the present invention provides a method, an apparatus and an electronic device for processing a transaction identifier, which can meet a requirement of a client on a continuously increasing transaction identifier.
In a first aspect, an embodiment of the present invention provides a method for processing a transaction identifier, where the method includes: receiving an acquisition request of a client for a transaction identifier; reading the transaction identifier currently pointed by the queue pointer from a preset first queue, and moving the queue pointer according to a preset step length so as to enable the queue pointer to point to the next transaction identifier in the first queue; a plurality of transaction identifiers which are sequentially increased are stored in the first queue in advance; and returning the read transaction identification to the client.
In a preferred embodiment of the present invention, 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.
In a preferred embodiment of the present invention, a first transaction identifier set is pre-stored in a currently read double-linked list, and transaction identifiers in the first transaction identifier set are sequentially incremented; the method further comprises the following steps: when the number of the unread transaction identifiers in the first transaction identifier set is lower than a preset threshold value, triggering to generate a second transaction identifier set; the transaction identifiers in the second transaction identifier set are sequentially increased in size, and the minimum transaction identifier in the second transaction identifier set is larger than the maximum transaction identifier in the first transaction identifier set; the second transaction identification set is stored in a next double-linked list that is sequentially associated with the currently read double-linked list.
In a preferred embodiment of the present invention, the method is applied to a master server, and the master server is in communication connection with a preset slave server, and the method further includes: when any transaction identification set is stored in the first queue, generating a log; the content of the log comprises the largest transaction identity in the set of transaction identities; sending the log to the slave server, so that the slave server generates a third transaction identification set when receiving the log, and storing the third transaction identification set into a second queue preset on the slave server; the transaction identifiers in the third transaction identifier set are sequentially increased, and the minimum transaction identifier in the third transaction identifier set is larger than the maximum transaction identifier in the transaction identifier set.
In a preferred embodiment of the present invention, the method further includes: and when the main server is down, triggering the slave server to read the transaction identifier in the second queue so as to respond to the acquisition request of the client for the transaction identifier.
In a preferred embodiment of the present invention, the step of reading the transaction identifier currently pointed to by the queue pointer includes: reading a transaction identifier currently pointed by a queue pointer through a first thread; and generating transaction identifications in the first queue through the second thread.
In a second aspect, an embodiment of the present invention further provides a device for processing a transaction identifier, where the device includes: the transaction identifier acquisition request receiving module is used for receiving an acquisition request of a client for the transaction identifier; the transaction identifier reading module is used for reading the transaction identifier currently pointed by the queue pointer from a preset first queue and moving the queue pointer according to a preset step length so as to enable the queue pointer to point to the next transaction identifier in the first queue; a plurality of transaction identifiers which are sequentially increased are stored in the first queue in advance; and the transaction identifier returning module is used for returning the read transaction identifier to the client.
In a preferred embodiment of the present invention, 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.
In a third aspect, an embodiment of the present invention further provides an electronic device, where the electronic device includes a processor and a memory, where the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the processing method for the transaction identifier.
In a fourth aspect, the embodiments of the present invention also provide a computer-readable storage medium, which stores computer-executable instructions, and when the computer-executable instructions are called and executed by a processor, the computer-executable instructions cause the processor to implement the processing method of the transaction identifier.
The embodiment of the invention has the following beneficial effects:
the embodiment of the invention provides a method, a device and electronic equipment for processing transaction identifiers, which comprises the steps of firstly receiving an acquisition request of a client for the transaction identifiers; then, reading the transaction identifier currently pointed by the queue pointer from a preset first queue, and moving the queue pointer according to a preset step length so as to enable the queue pointer to point to the next transaction identifier in the first queue; a plurality of transaction identifiers which are sequentially increased are stored in the first queue in advance; and returning the read transaction identifier to the client. In the method, a plurality of transaction identifiers which are sequentially increased are generated in advance and stored in the queue, when a transaction identifier acquisition request of the client is received, the transaction identifiers are sequentially read from the queue and returned to the client, so that the transaction identifiers provided for the client are continuously increased, and the method can meet the requirement of the client on the continuously increased transaction identifiers.
In addition, the transaction identifier is stored in the memory in a circular linked list mode, so that the transaction identifier can be read more quickly to respond to the request of the client. In addition, a certain number of transaction identifier sets are generated at one time, the transaction identifiers in the transaction identifier sets are sequentially read, and only corresponding logs are generated when the transaction identifier sets are generated. In addition, the master server and the slave server are arranged, and the log generated by the master server is backed up to the slave server, so that the slave server generates a transaction identifier set which is continuously increased compared with the transaction identifier in the master server in advance, the slave server can still continuously provide the continuously increased transaction identifier for the client under the condition that the master server is down, and the high availability of the system is increased.
Additional features and advantages of the disclosure will be set forth in the description which follows, or in part may be learned by the practice of the above-described techniques of the disclosure, or may be learned by practice of the disclosure.
In order to make the aforementioned objects, features and advantages of the present disclosure more comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings can be obtained by those skilled in the art without creative efforts.
Fig. 1 is a schematic flowchart of a transaction identifier processing method according to an embodiment of the present invention;
fig. 2 is a flowchart illustrating a method for dynamically storing a transaction identifier in a queue according to an embodiment of the present invention;
fig. 3 is a schematic diagram of a communication process between a master server and a slave server in transaction identifier processing according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a transaction identifier processing apparatus according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Icon: 41-a transaction identification acquisition request receiving module; 42-transaction identification reading module; 43-transaction identity return module; 51-a processor; 52-a memory; 53-bus; 54-communication interface.
Detailed Description
To make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In consideration of the problem that the requirement for continuous incremental increase of the transaction identifier in the distributed database system cannot be met by acquiring the transaction identifier in a database self-increment key mode, the method, the device and the electronic equipment for processing the transaction identifier provided by the embodiment of the invention can be applied to various application scenes needing to acquire the transaction identifier. For the convenience of understanding the embodiment, a detailed description is first given to a method for processing a transaction identifier disclosed in the embodiment of the present invention.
Referring to fig. 1, a flow chart of a method for processing a transaction identifier according to an embodiment of the present invention is shown, and as can be seen from fig. 1, the method includes the following steps:
step S102: and receiving an acquisition request of the client for the transaction identifier.
Here, a transaction refers to a sequence of reading and writing to a database, and during the transaction process, a transaction manager is generally responsible for generating and assigning a transaction identifier to the transaction. The Transaction ID is a number for a committed Transaction, and a Global Transaction ID (GTID) is required in the distributed database system, and is a globally unique number that is required to be incremented continuously.
In addition, the client is also a user end, which is a program corresponding to the server and providing local services for the client. In practical operation, the processing method of the transaction identifier in this embodiment may be executed in a distributed database system, for example, executed in each server node in the distributed database system; moreover, the method may also be operated in other non-distributed systems, and is used for providing a service of incremental transaction identification, and an application scenario thereof is not limited herein.
In actual operation, when a client needs to process a new transaction, a transaction identifier acquisition request is sent to a server.
Step S104: reading the transaction identifier currently pointed by the queue pointer from a preset first queue, and moving the queue pointer according to a preset step length so as to enable the queue pointer to point to the next transaction identifier in the first queue; the first queue stores a plurality of transaction identifiers which are sequentially increased in advance.
In this embodiment, a plurality of sequentially increasing transaction identifiers are generated in advance, and are stored in a preset first queue in advance, where the first queue is a special first-in first-out linear table, and allows only a delete operation to be performed at the front end (front) of the table, and an insert operation to be performed at the back end (rear) of the table. Here, "first" is used only for the purpose of distinguishing the description, and is not to be construed as indicating or implying relative importance.
When receiving an acquisition request of the client for the transaction identifier, the server reads the transaction identifier currently pointed by the queue pointer from the first queue, wherein the read transaction identifier is used as a target transaction identifier for responding to the current client request.
After reading a transaction identifier, automatically moving the queue pointer according to a preset step length to enable the queue pointer to point to a next transaction identifier in the first queue, so that when receiving a next transaction identifier acquisition request, the next transaction identifier pointed by the queue pointer can be correspondingly read, thereby realizing that the transaction identifiers stored in the first queue are sequentially read and provided for a client.
Step S106: and returning the read transaction identification to the client.
Through the foregoing steps S102 to S104, the transaction identifier is read from the first queue, and here, the read transaction identifier is returned to the client.
Thus, according to the above transaction identifier processing method, since a plurality of transaction identifiers (which may be 1 ten thousand, 10 ten thousand, or the like) that sequentially increment are stored in the first queue in advance, when a transaction identifier request is received, the transaction identifiers can be sequentially read from the first queue, so that the transaction identifiers read and returned to the client satisfy monotonic increment, and are unique and not repeated. Compared with the existing transaction identifier processing method (a mode of a database self-increment key), the transaction identifier is generated immediately when the transaction identifier is needed in the prior art, the real-time return is generated in real time, and the requirement of continuous increment of the global transaction identifier in the distributed system cannot be met.
The embodiment of the invention provides a processing method of transaction identification, which comprises the steps of firstly receiving an acquisition request of a client aiming at the transaction identification; then, reading the transaction identifier currently pointed by the queue pointer from a preset first queue, and moving the queue pointer according to a preset step length so as to enable the queue pointer to point to the next transaction identifier in the first queue; a plurality of transaction identifiers which are sequentially increased are stored in the first queue in advance; and returning the read transaction identifier to the client. In the method, a plurality of transaction identifiers which are sequentially increased are generated in advance and stored in the queue, when a transaction identifier acquisition request of the client is received, the transaction identifiers are sequentially read from the queue and returned to the client, so that the transaction identifiers provided for the client are continuously increased, and the method can meet the requirement of the client on the continuously increased transaction identifiers.
In actual operation, the client needs the transaction identifier continuously, and the server is required to provide the transaction identifier meeting the requirement continuously, so that on the basis of the processing method of the transaction identifier shown in fig. 1, this embodiment details how to dynamically store the transaction identifier meeting the requirement in the first queue, so as to provide the transaction identifier meeting the requirement continuously for the client.
The embodiment provides another transaction identifier processing method, wherein the method comprises the following steps 11-13:
(11) receiving an acquisition request of a client for a transaction identifier;
(12) reading the transaction identifier currently pointed by the queue pointer from a preset first queue, and moving the queue pointer according to a preset step length so as to enable the queue pointer to point to the next transaction identifier in the first queue; wherein, the first queue is realized by adopting a circular linked list, and the circular linked list is composed of at least two double linked lists; 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 sequentially increased in number;
(13) and returning the read transaction identification to the client.
In this embodiment, 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, where each data node of the double linked list has two pointers pointing to direct successors and direct predecessors, respectively, so that starting from any node in the bidirectional linked list, it is convenient to access its predecessor node and successor node. And, the circular linked list is a kind of chain storage structure, the pointer field of the last node in the linked list points to the head node, the whole linked list forms a ring. The cyclic linked list realizes the repeated use of the storage space without adding extra storage capacity.
Fig. 2 is a schematic flow chart of a method for dynamically storing a transaction identifier in a queue, and fig. 2 illustrates how, in the method for processing a transaction identifier according to this embodiment, a transaction identifier is dynamically stored in the first queue, as can be seen from fig. 2, the method includes the following steps:
step S202: when the number of the unread transaction identifiers in the first transaction identifier set is lower than a preset threshold value, triggering to generate a second transaction identifier set; the transaction identifiers in the second transaction identifier set are sequentially increased, and the minimum transaction identifier in the second transaction identifier set is larger than the maximum transaction identifier in the first transaction identifier set.
In practical operation, the threshold may be set to a specific number, for example, 500; the threshold may also be set as a proportion of the unread transaction id to the total number of transaction ids in the first transaction id set, for example, 20%. Assuming that 10000 transaction identifiers are contained in the first transaction identifier set, when the number of the remaining unread transaction identifiers is 2000, the generation of the second transaction identifier set is triggered.
For the second transaction identifier set, the transaction identifiers in the second transaction identifier set are sequentially increased, and the minimum transaction identifier in the second transaction identifier set is greater than the maximum transaction identifier in the first transaction identifier set. For example, assuming that the transaction identifiers in the first transaction identifier set are 1-10000, the transaction identifiers in the second transaction identifier set may be 10001-20000, so that the transaction identifiers in the transaction identifier sets are sequentially increased.
In one possible implementation, two threads may be set at the server, where one thread 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. Therefore, the efficiency of the whole transaction identification processing can be improved in an asynchronous mode.
Step S204: the second transaction identification set is stored in a next double-linked list that is sequentially associated with the currently read double-linked list.
Here, the multiple doubly linked lists in the circular linked list queue are connected end to form a loop. After generating the second transaction identification set, the second transaction identification set is stored in a next double-linked list that is sequentially associated with the currently read double-linked list.
For the first queue, after the transaction identifiers in the currently read double-linked list are all 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 be continuously read, and the transaction identifiers can be continuously read.
In at least one possible implementation manner, the association between the linked lists in the above circular linked list may be dynamically implemented, for example, assuming that the circular linked list includes a double linked list a and a double linked list B, where the double linked list a is a currently read linked list and includes 10000 transaction identifiers 1 to 10000 in increments, and when 2000 unread transaction identifiers remain in the double linked list a, another 10000 transaction identifiers 10001 to 20000 are triggered and generated to be 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 isLastOne is modified from 'true' to 'false' by modifying the state of the maximum node (namely, the node corresponding to the transaction identifier 10000) in the double linked list A, so that the two linked lists are connected in series, and after the transaction identifier in the double linked list A is read, the queue pointer continuously points to the head in the double linked list B to read the transaction identifier in the double linked list B. If the double-linked list A and the double-linked list B are not successfully associated, the state of the maximum node (namely the node corresponding to the transaction identifier 10000) in the double-linked list A is still maintained as "true".
The method for processing the transaction identifier provided in this embodiment achieves that the transaction identifier meeting the requirement is dynamically stored in the first queue in a circular linked list manner, so that the transaction identifier that monotonically increases can be continuously provided for the client, and the transaction identifier is stored in the memory in a circular linked list manner, so that the transaction identifier can be read more quickly to respond to the request of the client.
In order to alleviate the problem of reducing the high availability of the transaction identifier processing service due to downtime, the present embodiment introduces another transaction identifier processing method based on the transaction identifier processing method shown in fig. 1, where the method is applied to a master server and the master server is communicatively connected to a preset slave server, and the method further introduces communication between the master server and the slave server based on the steps S102 to S106 included above.
Referring to fig. 3, a schematic diagram of a communication process between a master server and a slave server in transaction identification processing is shown, and as can be seen from fig. 3, the communication process includes the following steps:
step S302: when any transaction identification set is stored in the first queue, generating a log; the contents of the log include the largest transaction identification in the set of transaction identifications.
In this embodiment, after generating the transaction identifier set, when the transaction identifier set is stored in the first queue, a corresponding log is generated, where the content of the log includes a maximum transaction identifier in the transaction identifier set.
For example, assuming that the generated first transaction identifier set includes 1 ten thousand transaction identifiers 1 to 10000, when the first transaction identifier set is stored in the first queue, a log is generated, where the log includes the current maximum transaction identifier in the first queue as 10000. Similarly, when other transaction identifier sets are subsequently generated, a log is correspondingly generated, 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.
Step S304: sending the log to the slave server, so that the slave server generates a third transaction identification set when receiving the log, and storing the third transaction identification set into a second queue preset on the slave server; the transaction identifiers in the third transaction identifier set are sequentially increased, and the minimum transaction identifier in the third transaction identifier set is larger than the maximum transaction identifier in the transaction identifier set.
The master server sends the generated log to the slave server in real time, so that the slave server can acquire the current maximum transaction identifier in the first queue of the master service.
The second queue is preset in the slave server, and the working principle of the second queue can refer to the first queue in the master service, and related contents refer to corresponding parts in the foregoing embodiments. Specifically, after receiving the log, the slave server triggers generation of a third transaction identifier set, and stores the third transaction identifier set in a second queue preset on the slave server.
Here, the transaction identifiers in the third transaction identifier set are sequentially incremented, 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 id recorded in the log is 10000, which indicates that the current maximum transaction id in the first queue of the primary server is 10000, at this time, the minimum transaction id in the transaction id set generated from the server is greater than 10000, which may be, for example, 10001.
In this embodiment, when the master server goes down, the slave server is triggered to read the transaction identifier in the second queue, so as to respond to the request of the client for acquiring the transaction identifier. In this way, the transaction identifiers in the second queue in the slave service are sequentially increased and are continuously increased relative to the maximum transaction identifier in the master server, so that the requirement of the client on the continuously increased transaction identifiers can be continuously met.
In the method for processing the transaction identifier provided in this embodiment, a certain number of transaction identifier sets are generated at one time, the transaction identifiers therein are sequentially read, and only when the transaction identifier sets are generated, corresponding logs are generated. In addition, the master server and the slave server are arranged, and the log generated by the master server is backed up to the slave server, so that the slave server generates a transaction identifier set which is continuously increased compared with the transaction identifier in the master server in advance, the slave server can still continuously provide the continuously increased transaction identifier for the client under the condition that the master server is down, and the high availability of the system is increased.
In order to more clearly understand the transaction identifier processing method provided by the present invention, this embodiment also introduces an application example of the transaction identifier processing method, and the steps of the method are as follows.
(1) Setting the transaction identifier of the distributed sequence to be unsigned long integer, namely: the unscented long occupies 8 bytes, the initial value is 1, the step length is 10000, namely the transaction identifier is 1-10000;
(2) storing the transaction identifications 1-10000 by adopting a lock-free queue, wherein four queues are set and respectively marked as QA, QB, QC and QD, and the capacity of the transaction identification in each queue is 1 ten thousand;
(3) starting two threads, wherein one thread is responsible for generating 10000 transaction representations each time and is marked as a production thread A; one thread is responsible for reading the lock-free queue, responding to the response, namely issuing the transaction identifier, and recording as a consumption thread B; the consumption thread B defines a queue pointer p which points to a certain value in the queue and is empty initially;
(4) the production thread A generates 10000 numbers (namely transaction identifiers), namely 1-10000, stores the numbers in a queue QA, generates a log, and the content of the log is 10000, wherein the isLastOne of the node corresponding to the transaction identifier 10000 (the last node, namely the maximum node) is modified to true; sending the log to the standby node, and after the standby node responds (indicating that the standby node has received), the pointer p of the consumer thread B executes the head of the queue of QA, namely 1;
(5) after receiving the request, the consumer thread B reads 1, and the pointer p executes the second value of QA, namely 2, and dispatches the transaction identifier 1;
(6) when the production thread A reads a sequence id >8000 pointed by a pointer p of the consumer thread B (namely, after the usage amount of the transaction identifier in the queue reaches 80%), the production thread A generates 10000 numbers, such as 10001-20000, stores the numbers in the queue QB, and generates a log, wherein the content of the log is 20000 (the maximum value of the current queue); sending the log to a standby node, associating QA with QB after the standby node responds (indicating that the standby node has received the log), and modifying isLastOne of the node corresponding to the transaction identifier 10000 in QA into false;
(7) if an abnormal condition occurs, for example, QB is not associated with QA, the node isLastOne with the maximum QA is true, at the moment, the consumer thread B waits, and dispatch is performed when isLastOne is false;
(8) the four queues are used in turn, so that the release of a memory cannot be involved, QC and QD are used like QB, and when QD is used, QA is completely used and can be repeatedly used;
(9) in the working process of the standby node, if the maximum transaction identifier in the log sent by the main node is 10000 after the production thread A receives the log, the generated initial value is 10001, namely 10001-20000, and the generation process is the same as that of the main node, so that the standby node is ensured to be one step length larger than the main node forever, namely 10000;
(10) and when the main node is down, the standby node becomes the main node. In the downtime, if the sequence of the main node is 7890, the range of the main node distributed transaction identifier is 1-10000, and the range of the standby node distributed transaction identifier is 10001-20000, the distributed transaction identifier read from the queue of the node is 10001 (the transaction identifier is changed from 7890 to 10001, a part is lost in the middle, but increment is guaranteed), so that increment and uniqueness of the distributed transaction identifier are guaranteed.
Corresponding to the transaction identifier processing method shown in fig. 1, an embodiment of the present invention further provides a transaction identifier processing apparatus, see fig. 4, which is a schematic structural diagram of the transaction identifier processing apparatus, as can be seen from fig. 4, the apparatus includes a transaction identifier obtaining request receiving module 41, a transaction identifier reading module 42, and a transaction identifier returning module 43, which are connected in sequence, where functions of each module are as follows:
a transaction identifier obtaining request receiving module 41, configured to receive a obtaining request of a client for a transaction identifier;
a transaction identifier reading module 42, configured to read, from a preset first queue, a transaction identifier currently pointed to by a queue pointer, and move 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 transaction identifiers which are sequentially increased are stored in the first queue in advance;
and a transaction identifier returning module 43, configured to return the read transaction identifier to the client.
The embodiment of the invention provides a processing device of transaction identifiers, which firstly receives an acquisition request of a client for the transaction identifiers; then, reading the transaction identifier currently pointed by the queue pointer from a preset first queue, and moving the queue pointer according to a preset step length so as to enable the queue pointer to point to the next transaction identifier in the first queue; a plurality of transaction identifiers which are sequentially increased are stored in the first queue in advance; and returning the read transaction identifier to the client. In the device, a plurality of transaction identifiers which are sequentially increased are generated in advance and stored in a queue, when a transaction identifier acquisition request of a client is received, the transaction identifiers are sequentially read from the queue and returned to the client, so that the transaction identifiers provided for the client are continuously increased, and the requirement of the client on the continuously increased transaction identifiers can be met.
In one possible implementation manner, 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.
In another possible implementation manner, a first transaction identifier set is pre-stored in a currently read double-linked list, and transaction identifiers in the first transaction identifier set are sequentially increased in number; the above-mentioned device still includes: the transaction identifier set generation module is used for triggering and generating a second transaction identifier set when the number of the unread transaction identifiers in the first transaction identifier set is lower than a preset threshold value; the transaction identifiers in the second transaction identifier set are sequentially increased in size, and the minimum transaction identifier in the second transaction identifier set is larger than the maximum transaction identifier in the first transaction identifier set; and the transaction identifier set storage module is used for storing the second transaction identifier set into the next double-linked list which is sequentially associated with the currently read double-linked list.
In another possible embodiment, the above apparatus is applied to a master server, and the master server is in communication connection with a preset slave server, and the apparatus further includes: the log generation module is used for generating a log when any transaction identification set is stored in the first queue; the content of the log comprises the largest transaction identity in the set of transaction identities; the log sending module is used for sending 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 into a second queue preset on the slave server; the transaction identifiers in the third transaction identifier set are sequentially increased, and the minimum transaction identifier in the third transaction identifier set is larger than the maximum transaction identifier in the transaction identifier set.
In another possible embodiment, the above apparatus further comprises: and the triggering module is used for triggering the slave server to read the transaction identifier in the second queue when the master server is down so as to respond to the acquisition request of the client for the transaction identifier.
In another possible implementation, the transaction identifier reading module 42 is further configured to: reading a transaction identifier currently pointed by a queue pointer through a first thread; and generating transaction identifications in the first queue through the second thread.
The implementation principle and the generated technical effect of the processing apparatus for transaction identifier provided in the embodiment of the present invention are the same as those of the aforementioned embodiment of the processing method for transaction identifier, and for brief description, reference may be made to the corresponding content in the aforementioned embodiment of the processing method for transaction identifier where no part of the embodiment of the processing apparatus for transaction identifier is mentioned.
An embodiment of the present invention further provides an electronic device, as shown in fig. 5, which is a schematic structural diagram of the electronic device, where the electronic device includes a processor 51 and a memory 52, the memory 52 stores machine executable instructions capable of being executed by the processor 51, and the processor 51 executes the machine executable instructions to implement the processing method of the transaction identifier.
In the embodiment shown in fig. 5, the electronic device further comprises a bus 53 and a communication interface 54, wherein the processor 51, the communication interface 54 and the memory 52 are connected by the bus.
The Memory 52 may include a high-speed Random Access Memory (RAM) and may also include a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. The communication connection between the network element of the system 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, a wide area network, a local network, a metropolitan area network, and the like can be used. The bus may be an ISA bus, PCI bus, EISA bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one double-headed arrow is shown in FIG. 5, but this does not indicate only one bus or one type of bus.
The processor 51 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 51. The Processor 51 may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the device 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 Gate or transistor logic devices, discrete hardware components. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present invention may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. 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 foregoing embodiment in combination with the hardware thereof.
An embodiment of the present invention further provides a machine-readable storage medium, where the machine-readable storage medium stores machine-executable instructions, and when the machine-executable instructions are called and executed by a processor, the machine-executable instructions cause the processor to implement the method for processing the transaction identifier, and specific implementation may refer to the foregoing method embodiment, and is not described herein again.
The method for processing a transaction identifier, the apparatus for processing a transaction identifier, and the computer program product of the electronic device provided in the embodiments of the present invention include a computer-readable storage medium storing a program code, where instructions included in the program code may be used to execute the method for processing a transaction identifier described in the foregoing method embodiments, and specific implementations may refer to the method embodiments and are not described herein again.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
In addition, in the description of the embodiments of the present invention, unless otherwise explicitly specified or limited, the terms "mounted," "connected," and "connected" are to be construed broadly, e.g., as meaning either a fixed connection, a removable connection, or an integral connection; can be mechanically or electrically connected; they may be connected directly or indirectly through intervening media, or they may be interconnected between two elements. The specific meanings of the above terms in the present invention can be understood in specific cases to those skilled in the art.
In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicate orientations or positional relationships based on the orientations or positional relationships shown in the drawings, and are only for convenience of description and simplicity of description, but do not indicate or imply that the device or element being referred to must have a particular orientation, be constructed and operated in a particular orientation, and thus, should not be construed as limiting the present invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance.
Finally, it should be noted that: the above-mentioned embodiments are only specific embodiments of the present invention, which are used for illustrating the technical solutions of the present invention and not for limiting the same, and the protection scope of the present invention is not limited thereto, although the present invention is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive the technical solutions described in the foregoing embodiments or equivalent substitutes for some technical features within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present invention, and they should be construed as being included therein. Therefore, the protection scope of the present invention shall be subject to the protection scope of the appended claims.
Claims (10)
1. A method for processing transaction identifier, comprising:
receiving an acquisition request of a client for a transaction identifier;
reading a transaction identifier currently pointed by a queue pointer from a preset first queue, and moving the queue pointer according to a preset step length so as to enable the queue pointer to point to a next transaction identifier in the first queue; a plurality of transaction identifiers which are sequentially increased are stored in the first queue in advance;
and returning the read transaction identifier to the client.
2. The method of claim 1, wherein 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 according to claim 2, wherein a first transaction identifier set is pre-stored in a currently read doubly linked list, and the transaction identifiers in the first transaction identifier set are sequentially incremented; the method further comprises the following steps:
when the number of the unread transaction identifications in the first transaction identification set is lower than a preset threshold value, triggering to generate a second transaction identification set; the transaction identifiers in the second transaction identifier set are sequentially increased in size, and the minimum transaction identifier in the second transaction identifier set is larger than the maximum transaction identifier in the first transaction identifier set;
and storing the second transaction identification set in a next double-linked list which is sequentially associated with the currently read double-linked list.
4. The method for processing the transaction identifier according to claim 3, wherein the method is applied to a master server, and the master server is communicatively connected to a preset slave server, the method further comprising:
when any transaction identification set is stored in the first queue, generating a log; the content of the log comprises the largest transaction identifier in the transaction identifier set;
sending the log to the slave server, so that the slave server generates a third transaction identification set when receiving the log, and storing the third transaction identification set in a second queue preset on the slave server; and the transaction identifications in the third transaction identification set are sequentially increased in an increasing manner, and the minimum transaction identification in the third transaction identification set is larger than the maximum transaction identification in the transaction identification set.
5. The method for processing transaction identifier according to claim 4, wherein the method further comprises:
and when the main server is down, triggering the slave server to read the transaction identifier in the second queue so as to respond to the request of the client for acquiring the transaction identifier.
6. The method for processing transaction id as claimed in claim 1, wherein the step of reading the transaction id currently pointed to by the queue pointer comprises:
reading a transaction identifier currently pointed by a queue pointer through a first thread; and generating transaction identifications in the first queue through a second thread.
7. An apparatus for processing transaction identifier, comprising:
the transaction identifier acquisition request receiving module is used for receiving an acquisition request of a client for the transaction identifier;
the transaction identifier reading module is used for reading the transaction identifier currently pointed by the queue pointer from a preset first queue, and moving the queue pointer according to a preset step length so as to enable the queue pointer to point to the next transaction identifier in the first queue; a plurality of transaction identifiers which are sequentially increased are stored in the first queue in advance;
and the transaction identifier returning module is used for returning the read transaction identifier to the client.
8. The apparatus for processing transaction identifier as claimed in claim 7, wherein said first queue is implemented by using a circular linked list, and said circular linked list is composed of at least two double linked lists.
9. An electronic device, comprising a processor and a memory, the memory storing computer-executable instructions executable by the processor, the processor executing the computer-executable instructions to implement the method of processing a transaction identifier of any of claims 1 to 6.
10. A computer-readable storage medium having stored thereon computer-executable instructions which, when invoked and executed by a processor, cause the processor to implement the method of processing a transaction identity of any of claims 1 to 6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011100032.0A CN112231069A (en) | 2020-10-14 | 2020-10-14 | Transaction identifier processing method and device and electronic equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011100032.0A CN112231069A (en) | 2020-10-14 | 2020-10-14 | Transaction identifier processing method and device and electronic equipment |
Publications (1)
Publication Number | Publication Date |
---|---|
CN112231069A true CN112231069A (en) | 2021-01-15 |
Family
ID=74112930
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202011100032.0A Pending CN112231069A (en) | 2020-10-14 | 2020-10-14 | Transaction identifier processing method and device and electronic equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112231069A (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113254483A (en) * | 2021-06-03 | 2021-08-13 | 北京金山云网络技术有限公司 | Request processing method and device, electronic equipment and storage medium |
CN113472736A (en) * | 2021-05-14 | 2021-10-01 | 山东英信计算机技术有限公司 | Method, device, equipment and readable medium for internal and external network data transmission |
CN114020662A (en) * | 2021-11-02 | 2022-02-08 | 上海兆芯集成电路有限公司 | Bridge module, data transmission system and data transmission method |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101216783A (en) * | 2007-12-29 | 2008-07-09 | 中国建设银行股份有限公司 | Process for optimizing ordering processing for multiple affairs |
US20150199415A1 (en) * | 2014-01-16 | 2015-07-16 | International Business Machines Corporation | Parallel transaction messages for database replication |
US20160344834A1 (en) * | 2015-05-20 | 2016-11-24 | SanDisk Technologies, Inc. | Transaction log acceleration |
WO2017041638A1 (en) * | 2015-09-08 | 2017-03-16 | 阿里巴巴集团控股有限公司 | Log data processing method and device |
CN108804545A (en) * | 2018-05-18 | 2018-11-13 | 深圳市彬讯科技有限公司 | Distributed globally unique ID generation methods and equipment |
CN110019112A (en) * | 2017-08-25 | 2019-07-16 | 阿里巴巴集团控股有限公司 | Data transactions method, apparatus and electronic equipment |
-
2020
- 2020-10-14 CN CN202011100032.0A patent/CN112231069A/en active Pending
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101216783A (en) * | 2007-12-29 | 2008-07-09 | 中国建设银行股份有限公司 | Process for optimizing ordering processing for multiple affairs |
US20150199415A1 (en) * | 2014-01-16 | 2015-07-16 | International Business Machines Corporation | Parallel transaction messages for database replication |
US20160344834A1 (en) * | 2015-05-20 | 2016-11-24 | SanDisk Technologies, Inc. | Transaction log acceleration |
WO2017041638A1 (en) * | 2015-09-08 | 2017-03-16 | 阿里巴巴集团控股有限公司 | Log data processing method and device |
CN110019112A (en) * | 2017-08-25 | 2019-07-16 | 阿里巴巴集团控股有限公司 | Data transactions method, apparatus and electronic equipment |
CN108804545A (en) * | 2018-05-18 | 2018-11-13 | 深圳市彬讯科技有限公司 | Distributed globally unique ID generation methods and equipment |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113472736A (en) * | 2021-05-14 | 2021-10-01 | 山东英信计算机技术有限公司 | Method, device, equipment and readable medium for internal and external network data transmission |
CN113472736B (en) * | 2021-05-14 | 2023-06-02 | 山东英信计算机技术有限公司 | Method, device, equipment and readable medium for transmitting data of internal and external networks |
CN113254483A (en) * | 2021-06-03 | 2021-08-13 | 北京金山云网络技术有限公司 | Request processing method and device, electronic equipment and storage medium |
CN113254483B (en) * | 2021-06-03 | 2021-11-09 | 北京金山云网络技术有限公司 | Request processing method and device, electronic equipment and storage medium |
CN114020662A (en) * | 2021-11-02 | 2022-02-08 | 上海兆芯集成电路有限公司 | Bridge module, data transmission system and data transmission method |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112231069A (en) | Transaction identifier processing method and device and electronic equipment | |
CN107315761B (en) | Data updating method, data query method and device | |
US9767019B2 (en) | Pauseless garbage collector write barrier | |
CN107608860B (en) | Method, device and equipment for classified storage of error logs | |
EP3565219A1 (en) | Service execution method and device | |
CN107451853B (en) | Method, device and system for real-time red packet distribution and storage medium | |
CN107222555B (en) | Message processing method and device | |
CN111722918A (en) | Service identification code generation method and device, storage medium and electronic equipment | |
CN112131005A (en) | Resource adjustment strategy determination method and device | |
CN113778652A (en) | Task scheduling method and device, electronic equipment and storage medium | |
CN111008071A (en) | Task scheduling system, method and server | |
CN108399175B (en) | Data storage and query method and device | |
CN113422808B (en) | Internet of things platform HTTP information pushing method, system, device and medium | |
US20220188156A1 (en) | Method and apparatus for determining hardware usage, storage medium, and electronic device | |
CN109450977B (en) | Cache data pushing and updating method and device | |
CN113849320A (en) | Development method, control method and computing device | |
US11822961B2 (en) | Method and apparatus for data processing, server and storage medium | |
US10666575B2 (en) | Asymmetric co-operative queue management for messages | |
CN111359205B (en) | Operation method and device of cloud game, computer equipment and storage medium | |
CN112306827A (en) | Log collection device, method and computer readable storage medium | |
CN110333984B (en) | Interface abnormality detection method, device, server and system | |
CN112948501B (en) | Data analysis method, device and system | |
CN108121580B (en) | Method and device for realizing application program notification service | |
CN110046040B (en) | Distributed task processing method and system and storage medium | |
CN113268327A (en) | Transaction request processing method and device and electronic equipment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |