CN117112585B - Self-increment ID allocation method and device, electronic equipment and readable storage medium - Google Patents

Self-increment ID allocation method and device, electronic equipment and readable storage medium Download PDF

Info

Publication number
CN117112585B
CN117112585B CN202311094319.0A CN202311094319A CN117112585B CN 117112585 B CN117112585 B CN 117112585B CN 202311094319 A CN202311094319 A CN 202311094319A CN 117112585 B CN117112585 B CN 117112585B
Authority
CN
China
Prior art keywords
self
increment
transaction
node
data table
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.)
Active
Application number
CN202311094319.0A
Other languages
Chinese (zh)
Other versions
CN117112585A (en
Inventor
熊亮春
谢腾进
刘奇
黄东旭
崔秋
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Pingkai Star Beijing Technology Co ltd
Original Assignee
Pingkai Star Beijing Technology Co ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Pingkai Star Beijing Technology Co ltd filed Critical Pingkai Star Beijing Technology Co ltd
Priority to CN202311094319.0A priority Critical patent/CN117112585B/en
Publication of CN117112585A publication Critical patent/CN117112585A/en
Application granted granted Critical
Publication of CN117112585B publication Critical patent/CN117112585B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2308Concurrency control
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/466Transaction processing

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the application provides a self-increment ID allocation method, a self-increment ID allocation device, electronic equipment and a readable storage medium, and relates to the technical field of databases. The method comprises the following steps: acquiring a first transaction to be submitted, wherein the first transaction aims at least one target data table; the data records in each data row of the target data table are provided with a first self-increment ID; the first transaction comprises at least one data record to be inserted, which corresponds to each target data table; in response to pre-submitting the first transaction to the corresponding second node, for each target data table, an application request is sent to a third node corresponding to the target data table, the application request being for requesting that the number of first self-increment IDs be allocated for the target data table. In the embodiment of the application, the request allocation request is applied once to allocate the first self-increment ID for all the data records to be inserted aiming at the target data table, instead of allocating one first self-increment ID for one data record to be inserted at a time, and the allocation of the self-increment ID is carried out by taking the data table as a unit, so that the allocation efficiency can be improved.

Description

Self-increment ID allocation method and device, electronic equipment and readable storage medium
Technical Field
The application relates to the technical field of databases, in particular to a self-increment ID allocation method, a self-increment ID allocation device, electronic equipment and a readable storage medium.
Background
The self-increasing column of the database refers to a column which is provided in the data table and is automatically allocated with monotonically increasing numerical values, the self-increasing column is applicable to integer types and is commonly used for a primary key or an ID field, and when each data record is added in the data table, numerical values are not required to be set for the field corresponding to the self-increasing column in the data record, and the numerical values of the field corresponding to the self-increasing column are automatically generated and are unique.
When the ID is allocated for the self-increment list, the most strict requirement is to continuously and monotonically increment the ID by taking a transaction (namely a database transaction) as a unit under the premise of ensuring the performance, namely one transaction is locked at a time, when the transaction is submitted, the ID is allocated for each data record related to the transaction in turn, the requirement is relatively easy to realize in a traditional single database, can also be realized in a distributed database, a central database is selected from at least two database nodes of the distributed database, and the ID is allocated by the central database.
Whether the database is a stand-alone database or a distributed database, the ID is allocated to the transaction on one database node, so that each data record related to each transaction can be allocated with continuous monotonically increasing ID, however, the mode can only lock one transaction at a time, and can only allocate ID for one data record in one transaction at a time, namely, the whole process is to allocate ID for each data record in each transaction in series, the allocation efficiency is lower, and a larger allocation bottleneck is brought.
Disclosure of Invention
The embodiment of the application provides a self-increment ID allocation method, a self-increment ID allocation device, electronic equipment, a computer readable storage medium and a computer program product, which are used for solving the technical problems in the background technology.
According to a first aspect of an embodiment of the present application, there is provided a self-increment ID allocation method, applied to a first node of a node cluster of a distributed database, the method including:
Acquiring a first transaction to be submitted, the first transaction aiming at least one target data table; the data records in each data row of the target data table are provided with a first self-increment ID; the first transaction comprises at least one data record to be inserted, which corresponds to each target data table; each target data table is stored in at least one second node in the node cluster;
Responsive to pre-committing the first transaction to a corresponding second node, for each target data table, determining a third node from the second nodes corresponding to the target data table; the third node is the first node storing the target data table in the at least one second node; the third node records a first target self-increment ID; the first target self-increment ID is the maximum value of the first self-increment ID of each data line in the target data table;
For each target data table, sending an application request to a third node corresponding to the target data table, wherein the application request comprises a transaction identifier of the first transaction and the number of data records to be inserted corresponding to the target data table; the request is for requesting allocation of the number of first self-increment IDs to the target data table.
According to a second aspect of the embodiment of the present application, there is provided a self-increment ID allocation method, applied to a third node in a node cluster of a distributed database, where the third node is a first node storing a target data table in at least one second node; the target data table is stored in at least one second node in the node cluster; the third node records a first target self-increment ID; the data records in each data row of the target data table are provided with a first self-increment ID; the first target self-increment ID is the maximum value of the first self-increment ID of the data record in the target data table;
The method comprises the following steps:
Receiving an application request sent by a first node, wherein the application request comprises a transaction identifier of a first transaction and the number of data records to be inserted corresponding to the target data table; the application request is used for requesting the target data table aiming at the first transaction characterized by the transaction identification to be allocated with the first self-increment ID of the quantity; the application request is generated by the first node in response to pre-submission of a first transaction to be submitted, wherein the first transaction comprises at least one data record to be inserted corresponding to the target data table;
If the target data table is determined to be inserted into the at least one data record to be inserted without overflowing, taking the first target self-increasing ID as a starting value of the first self-increasing ID of the at least one data record to be inserted;
Sending an allocation indication message to each second node corresponding to the target data table, wherein the allocation indication message comprises a transaction identifier of the first transaction and a start value of the first self-increment ID; the allocation indication message is used for indicating that the first self-increment ID is allocated to at least one data record to be inserted contained in the first transaction based on the initial value of the first self-increment ID.
According to a third aspect of the embodiment of the present application, there is provided a self-increment ID allocation method, applied to any one second node of a distributed database node cluster, where the second node stores a target data table; the data records in each data row of the target data table are provided with a first self-increment ID;
The method comprises the following steps:
storing a transaction identification of a first transaction, at least one data record to be inserted for the target data table contained in the first transaction, and a second self-increment ID of each data record to be inserted in response to pre-commit of the first transaction by the first node; wherein the second self-increment ID is a self-increment ID allocated to each data record to be inserted in the first transaction;
Receiving an allocation indication message sent by a third node, wherein the allocation indication message comprises a transaction identifier of the first transaction and a start value of the first self-increment ID; the allocation indication message is used for indicating that the first self-increment ID is allocated to at least one data record to be inserted contained in the first transaction based on the initial value of the first self-increment ID;
Determining a first self-increment ID of each data record to be inserted based on a start value of the first self-increment ID and a second self-increment ID of each data record to be inserted contained in the transaction identifier in response to the allocation indication message; and/or
Determining a pre-commit time of a pre-committed first transaction, storing a transaction identifier of the first transaction, a start value of the first self-increment ID, the number of at least one data record to be inserted for the target data table in the first transaction and the pre-commit time as a synchronous set to be set in advance, so that when a background of the distributed database periodically accesses the second node, the background asynchronously reads the synchronous set, and determining a first self-increment ID of each data record to be inserted and informing the second node;
inserting at least one new data row into the target data table, wherein each new data row comprises a data record to be inserted and a first self-increment ID corresponding to the data record to be inserted;
if it is determined that all data records to be inserted for the target data table in the first transaction are inserted into the target data table, the first transaction is committed.
According to a fourth aspect of the embodiment of the present application, there is provided a self-increment ID allocation method, applied to a background of a distributed database, the method including:
Periodically accessing each second node in the cluster of nodes of the distributed database; the second node stores a target data table, and data records in each data row of the target data table are provided with a first self-increment ID; the second node also stores the transaction identification of each pre-committed first transaction, at least one data record to be inserted in the target data table, and a second self-increment ID of each data record to be inserted;
Reading the synchronous set of each second node for the second node in the current period; the synchronization set comprises at least one record to be synchronized, wherein each record to be synchronized comprises a transaction identifier of a first transaction, a starting value of the first self-increment ID and a pre-submitting time of the first transaction;
Determining the transaction identifier of each first transaction in the previous period at the pre-submitting moment from the synchronous set, and determining at least one data record to be inserted corresponding to the transaction identifier and the second self-increment ID of each data record to be inserted;
For each data record to be inserted, determining a first self-increment ID of each data record to be inserted based on a start value of a first self-increment ID corresponding to the transaction identifier of the first transaction and a second self-increment ID of the data record to be inserted;
the second node is informed of the first self-increment ID of each data record to be inserted.
According to a fifth aspect of an embodiment of the present application, there is provided a self-ID allocation apparatus, applied to a first node of a node cluster of a distributed database, the apparatus including:
A first acquisition module, configured to acquire a first transaction to be committed, where the first transaction is directed to at least one target data table; the data records in each data row of the target data table are provided with a first self-increment ID; the first transaction comprises at least one data record to be inserted, which corresponds to each target data table; each target data table is stored in at least one second node in the node cluster;
a first determining module, configured to determine, for each target data table, a third node from the second nodes corresponding to the target data table in response to pre-submitting the first transaction to the corresponding second nodes; the third node is the first node storing the target data table in the at least one second node; the third node records a first target self-increment ID; the first target self-increment ID is the maximum value of the first self-increment ID of each data line in the target data table;
The first sending module is used for sending an application request to a third node corresponding to each target data table, wherein the application request comprises a transaction identifier of the first transaction and the number of data records to be inserted corresponding to the target data table; the request is for requesting allocation of the number of first self-increment IDs to the target data table.
According to a sixth aspect of the embodiment of the present application, there is provided a self-ID allocation apparatus, which is applied to a third node in a node cluster of a distributed database, where the third node is a first node storing a target data table in at least one second node; the target data table is stored in at least one second node in the node cluster; the third node records a first target self-increment ID; the data records in each data row of the target data table are provided with a first self-increment ID; the first target self-increment ID is the maximum value of the first self-increment ID of the data record in the target data table;
The device comprises:
The first receiving module is used for receiving an application request sent by the first node, wherein the application request comprises a transaction identifier of a first transaction and the number of data records to be inserted corresponding to the target data table; the application request is used for requesting the target data table aiming at the first transaction characterized by the transaction identification to be allocated with the first self-increment ID of the quantity; the application request is generated by the first node in response to pre-submission of a first transaction to be submitted, wherein the first transaction comprises at least one data record to be inserted corresponding to the target data table;
The initial value determining module is configured to, if it is determined that the target data table does not overflow after being inserted into the at least one data record to be inserted, take the first target self-increasing ID as an initial value of the first self-increasing ID of the at least one data record to be inserted;
the second sending module is used for sending an allocation indication message to each second node corresponding to the target data table, wherein the allocation indication message comprises a transaction identifier of the first transaction and a start value of the first self-increment ID; the allocation indication message is used for indicating that the first self-increment ID is allocated to at least one data record to be inserted contained in the first transaction based on the initial value of the first self-increment ID.
According to a seventh aspect of the embodiment of the present application, there is provided a self-ID allocation apparatus, applied to any one second node of a distributed database node cluster, where the second node stores a target data table; the data records in each data row of the target data table are provided with a first self-increment ID;
The device comprises:
The pre-commit response module is used for responding to pre-commit of the first node to the first transaction, and storing a transaction identifier of the first transaction, at least one data record to be inserted for the target data table contained in the first transaction and a second self-increment ID of each data record to be inserted; wherein the second self-increment ID is a self-increment ID allocated to each data record to be inserted in the first transaction;
The second receiving module is used for receiving an allocation indication message sent by the third node, wherein the allocation indication message comprises a transaction identifier of the first transaction and a start value of the first self-increment ID; the allocation indication message is used for indicating that the first self-increment ID is allocated to at least one data record to be inserted contained in the first transaction based on the initial value of the first self-increment ID;
A second determining module, configured to determine, in response to the allocation indication message, a first self-increment ID of each data record to be inserted based on a start value of the first self-increment ID and a second self-increment ID of each data record to be inserted included in the transaction identifier; and/or
A third determining module, configured to determine a pre-commit time of a pre-committed first transaction, store, as a record to be synchronized, a transaction identifier of the first transaction, a start value of the first self-increment ID, a number of at least one data record to be inserted in the first transaction, and the pre-commit time, to a synchronization set preset, so that when a background of the distributed database periodically accesses the second node, the background asynchronously reads the synchronization set, determines a first self-increment ID of each data record to be inserted, and informs the second node;
The inserting module is used for inserting at least one new data row into the target data table, wherein each new data row comprises a data record to be inserted and a first self-increment ID corresponding to the data record to be inserted;
and the submitting module is used for submitting the first transaction if determining that all the data records to be inserted aiming at the target data table are inserted into the target data table in the first transaction.
According to an eighth aspect of an embodiment of the present application, there is provided a self-ID allocation apparatus, applied to a background of a distributed database, including:
An access module for periodically accessing each second node in the node cluster of the distributed database; the second node stores a target data table, and data records in each data row of the target data table are provided with a first self-increment ID; the second node also stores the transaction identification of each pre-committed first transaction, at least one data record to be inserted in the target data table, and a second self-increment ID of each data record to be inserted;
the reading module is used for reading the synchronous set of each second node in the current period; the synchronization set comprises at least one record to be synchronized, wherein each record to be synchronized comprises a transaction identifier of a first transaction, a starting value of the first self-increment ID and a pre-submitting time of the first transaction;
a fourth determining module, configured to determine, from the synchronization set, a transaction identifier of each first transaction in a previous cycle at a pre-commit time, and determine at least one data record to be inserted corresponding to the transaction identifier and a second self-increment ID of each data record to be inserted;
A fifth determining module, configured to determine, for each data record to be inserted, a first self-increment ID of each data record to be inserted based on a start value of a first self-increment ID corresponding to a transaction identifier of the first transaction and a second self-increment ID of the data record to be inserted;
And the informing module is used for informing the second node of the first self-increment ID of each data record to be inserted.
According to a ninth aspect of an embodiment of the present application, there is provided an electronic device comprising a memory, a processor and a computer program stored on the memory, the processor implementing the steps of the method as provided in any one of the first, second, third and fourth aspects when the program is executed by the processor.
According to a tenth aspect of embodiments of the present application, there is provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the method as provided by the first, second, third and fourth aspects.
According to an eleventh aspect of embodiments of the present application, there is provided a computer program product comprising computer instructions stored in a computer readable storage medium, which when read from the computer readable storage medium by a processor of a computer device, cause the computer device to perform the steps of the method as provided in the first, second, third and fourth aspects.
The technical scheme provided by the embodiment of the application has the beneficial effects that:
In the embodiment of the application, the application request sent by the first node each time is directed to the target data table, the first self-increment ID is allocated to all the data records to be inserted of the target data table by one application request allocation request instead of allocating one first self-increment ID to one data record to be inserted by one request, and the allocation efficiency can be improved by taking the data table as a unit.
In addition, the first self-increment ID is not allocated by the first node, but is directly allocated by the third node of each target data table, so that the workload of the first node is reduced, each third node is independently allocated, the allocation efficiency is further improved, and the consistency of the target data tables in each second node can be ensured.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings that are required to be used in the description of the embodiments of the present application will be briefly described below.
Fig. 1 is a flow chart of a self-increment ID allocation method according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a second self-increment ID allocated to each target data table in a first transaction according to an embodiment of the present application;
fig. 3 is a flow chart of another self-increment ID allocation method according to an embodiment of the present application;
fig. 4 is a flow chart of another self-increment ID allocation method according to an embodiment of the present application;
Fig. 5 is a schematic diagram of allocating self-increment IDs based on a synchronous allocation scheme according to an embodiment of the present application;
Fig. 6 is a flowchart of still another self-increment ID allocation method according to an embodiment of the present application;
Fig. 7 is a schematic diagram of allocating self-increment IDs based on an asynchronous allocation scheme according to an embodiment of the present application;
Fig. 8 is a schematic structural diagram of a self-ID-adding dispensing device according to an embodiment of the present application;
fig. 9 is a schematic structural diagram of another self-ID-adding dispensing device according to an embodiment of the present application;
Fig. 10 is a schematic structural diagram of another self-ID-increasing dispensing device according to an embodiment of the present application;
FIG. 11 is a schematic structural diagram of a self-ID adding device according to an embodiment of the present application;
Fig. 12 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
Embodiments of the present application are described below with reference to the drawings in the present application. It should be understood that the embodiments described below with reference to the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application, and the technical solutions of the embodiments of the present application are not limited.
As used herein, the singular forms "a", "an", "the" and "the" are intended to include the plural forms as well, unless expressly stated otherwise, as understood by those skilled in the art. It will be further understood that the terms "comprises" and "comprising," when used in this specification, specify the presence of stated features, information, data, steps, operations, elements, and/or components, but do not preclude the presence or addition of other features, information, data, steps, operations, elements, components, and/or groups thereof, all of which may be included in the present specification. It will be understood that when an element is referred to as being "connected" or "coupled" to another element, it can be directly connected or coupled to the other element or intervening elements may be present. Further, "connected" or "coupled" as used herein may include wirelessly connected or wirelessly coupled. The term "and/or" as used herein indicates that at least one of the items defined by the term, e.g., "a and/or B" may be implemented as "a", or as "B", or as "a and B".
For the purpose of making the objects, technical solutions and advantages of the present application more apparent, the embodiments of the present application will be described in further detail with reference to the accompanying drawings.
First, several terms related to the present application are described and explained:
a distributed database (distributed data base) is a database in which data is stored in different physical locations. A distributed database may be stored on multiple computers located at the same physical location (e.g., data center); or may be distributed across a network of interconnected computers, each of which may be located separately in a single location, each of which may have a full copy or partial copy of the DBMS, and have its own local database, with many computers located at different locations being interconnected by the network, together forming a complete, global, logically centralized, physically distributed, large database.
Database transactions (transactions), for short, are a sequence of database operations that access and potentially manipulate various data items, either all or none, and are an integral unit of work. A transaction consists of all database operations performed between the beginning of the transaction and the end of the transaction.
The self-increasing column (abbreviated as self-increasing column) of the database refers to a column which is provided in a data table and automatically distributes monotonically increasing numerical values, the self-increasing column is only applicable to integer types and is commonly used for a primary key or an ID field, when each data record is added in the data table, numerical values of fields corresponding to the self-increasing column are not required to be set for each data record, the numerical values of fields corresponding to the self-increasing column are automatically generated and are unique, the numerical values corresponding to the data rows in the self-increasing column can be called self-increasing IDs, and the self-increasing IDs of all the data rows are monotonically increasing.
In a single database mainly based on MySQL, all transactions are executed on one database node, so that continuous self-increment ID allocation is easy to realize, but only one data record in one transaction can be allocated with an ID at a time, that is, the whole process is to allocate an ID for each data record in each transaction in series, and the problem of data hot spots exists.
When the distributed database needs to perform continuous self-increment ID allocation, a central database is selected from at least two databases of the distributed database, and ID allocation is performed by the central database, however, the central database can only allocate ID for one data record in one transaction at a time, namely, the whole process is to allocate ID for each data record in each transaction in series, the allocation efficiency is lower, and larger allocation bottleneck and expansion bottleneck are brought. In addition, the central database is self-ID allocation performance and high availability (high availability, HA) conflict with each other, because the central node may fail, in which case, the central node needs to be fully allocated, if the transaction does not have a landing disc, the transaction may be locked, it is difficult to allocate self-ID to the data record in the transaction, it is necessary to trace back the context, and the difficulty is great.
The application provides a self-increment ID allocation method, a self-increment ID allocation device, electronic equipment, a computer readable storage medium and a computer program product, and aims to solve the technical problems in the prior art.
The technical solutions of the embodiments of the present application and technical effects produced by the technical solutions of the present application are described below by describing several exemplary embodiments. It should be noted that the following embodiments may be referred to, or combined with each other, and the description will not be repeated for the same terms, similar features, similar implementation steps, and the like in different embodiments.
The embodiment of the application provides a self-increment ID allocation method, as shown in fig. 1, applied to a first node of a node cluster of a distributed database, comprising the following steps:
Step S101, acquiring a first transaction to be submitted, wherein the first transaction aims at least one target data table; the data records in each data row of the target data table are provided with a first self-increment ID; the first transaction comprises at least one data record to be inserted, which corresponds to each target data table; each target data table is stored in at least one second node in the cluster of nodes.
The node cluster of the distributed database can comprise a plurality of nodes, each node represents one database, a first node can be called a coordinator (leader) or a central node of the node cluster of the distributed database, and the coordinator is opposite to a participant (player), namely the node cluster comprises a central node serving as the coordinator and at least one participating node serving as the participant; one first node and participating node may be selected from each node of the node cluster by a raft algorithm.
The first transaction to be submitted in the embodiment of the present application may be a database transaction including at least one data record to be inserted, where in general, the at least one data record to be inserted may be determined from an insert (insert) statement of the first transaction, where the data record targeted by the insert statement is the data record to be inserted, and when there is no data line corresponding to an update (update) statement in the data table, the data record to be inserted may also be determined from the update statement of the first transaction.
The number of the target data tables may be one or more, the target data tables include self-increment columns, the self-increment columns record first self-increment IDs of data rows in the target data tables, the first self-increment IDs may uniquely represent the data rows, and each data row includes a data record and a first self-increment ID.
In the first transaction according to the embodiment of the present application, the table identifier of the target data table corresponding to each data record to be inserted is included, and at least one data record to be inserted corresponding to each target data table may be determined based on the table identifier of each data record to be inserted.
In the distributed database, each target data table is stored in at least one second node, and the storage layer of the second node can completely store the target data table or can partially store the target data table.
In addition, from the data storage perspective, the first node may also perform data storage, so that the first node may also be a second node storing a certain target data table.
Step S102, responding to pre-submitting the first transaction to the corresponding second node, and determining a third node from the second nodes corresponding to each target data table; the third node is the first node storing the target data table in the at least one second node; the third node records a first target self-increment ID; the first target self-increment ID is the maximum value of the first self-increment ID of each data row in the target data table.
The commit of the first transaction of embodiments of the present application may be a two-phase commit, a pre-commit (commit) phase (also referred to as a prepare phase or voting phase) and a commit (commit), respectively.
In the embodiment of the application, the first transaction can be pre-submitted to the corresponding second nodes, and after the first node detects the pre-submission of the first transaction, for each target data table, a third node is determined from at least one second node corresponding to the target data table, wherein the third node is the first node for storing the target data table in the at least one node, and the third node is the most convenient node for the first node to search in each second node.
In the embodiment of the present application, a first target self-increment ID (also referred to as a persistence ID) is recorded in a third node, where the first target self-increment ID is the maximum value of the first self-increment IDs of the data rows in the target data table.
Step S103, for each target data table, sending an application request to a third node corresponding to the target data table, wherein the application request comprises the transaction identifier of the first transaction and the number of data records to be inserted corresponding to the target data table; the request is for requesting allocation of the number of first self-increment IDs to the target data table.
After the first transaction is pre-submitted, for each target data table, the first node sends an application request to a third node corresponding to the target data table, wherein the application request comprises a transaction identifier of the first transaction and the number of data records to be inserted corresponding to the target data table, and the application request is used for requesting the third node to allocate the first self-increment ID of the number for the target data table. After receiving the application request, the third node determines the step length required by the target data table to insert the number of data records to be inserted, if the target data table is determined to be free of overflow after being inserted into the data records to be inserted based on the step length and the first target self-increment ID, the first target self-increment ID is sent to the second node, the second node is instructed to allocate the first self-increment ID to each data record to be inserted based on the first target self-increment ID, and the detailed process is shown in the follow-up content.
In the embodiment of the application, each time the first node sends an application request aiming at the target data table, namely, one application request allocation request allocates a first self-increment ID for all data records to be inserted aiming at the target data table, instead of one request allocation of a first self-increment ID for one data record to be inserted, the allocation is carried out by taking the data table as a unit, and the allocation efficiency can be improved.
In addition, the first self-increment ID is not allocated by the first node, but is directly allocated by the third node of each target data table, so that the workload of the first node is reduced, each third node is independently allocated, the allocation efficiency is further improved, and the consistency of the target data tables in each second node can be ensured.
In one possible implementation manner, the pre-submitting the first transaction to the corresponding second node in response to the pre-submitting the first transaction further includes:
and distributing a second self-increment ID for each data record to be inserted in the first transaction, so that after the third node responds to the application request and sends a first target self-increment ID to each second node, each second node distributes a first self-increment ID for each data record to be inserted based on the first target self-increment ID and the second self-increment ID of each data record to be inserted.
In the embodiment of the application, before the first transaction of the first node is pre-submitted, a second self-increment ID is allocated to each data record to be inserted in the first transaction, after one transaction starts, the first data record to be inserted, which needs to be allocated with the first self-increment ID, is encountered, and the first node allocates a second self-increment ID for the data record to be inserted in the first transaction.
If the first transaction includes multiple target data tables, the second self-increment ID allocated to each data record to be inserted in each target data table is set to 0 or 1 as a starting value in the first transaction, and usually, the second self-increment ID allocated to each data record to be inserted in each target data table is set to 1 as a starting value, and is continuously and monotonically increased, it is noted that the second self-increment ID allocated to each data record to be inserted in each target data table in the first transaction changes the structure in the first transaction, and the changed first transaction is submitted in the pre-submitting or submitting stage of the first transaction.
As shown in fig. 2, a schematic diagram of a second self-increasing ID allocated to each target data table in the first transaction is shown in fig. 2, where the first transaction is shown in fig. 1 and 2 for 2 target data tables, the second self-increasing IDs of the data records to be inserted corresponding to the data table 1 are 1-n, the second self-increasing IDs of the data records to be inserted corresponding to the data table 2 are also 1-n, the second self-increasing IDs of the data records to be inserted corresponding to each target data table are all 1 as initial values, and the second self-increasing IDs of the data records to be inserted of each target data table are continuous and monotonically increasing.
As can be seen from the foregoing embodiments, the first node in the embodiment of the present application may modify the structure of the first transaction to allocate a second self-increment ID to each data record to be inserted, where the second self-increment ID is a logical ID, and meanwhile, the first node may request the third node and the second node to allocate the first self-increment ID together, when allocating the first self-increment ID, if the first node fails, it may wait until the other second node serving as a participant folower becomes a coordinator leader, and the new coordinator is a new first node, and may continue to allocate the second self-increment ID to the data record to be inserted in each transaction by the new first node, without checking that the first self-increment ID is specifically allocated to that process.
The embodiment of the application provides a self-increment ID allocation method which is applied to a third node in a node cluster of a distributed database, wherein the third node is a first node for storing a target data table in at least one second node; the target data table is stored in at least one second node in the node cluster; the third node records a first target self-increment ID; the data records in each data row of the target data table are provided with a first self-increment ID; the first target self-increment ID is the maximum value of the first self-increment ID of the data record in the target data table;
as shown in fig. 3, the method includes:
Step S301, receiving an application request sent by a first node, wherein the application request comprises a transaction identifier of the first transaction and the number of data records to be inserted corresponding to the target data table; the application request is used for requesting the target data table aiming at the first transaction characterized by the transaction identification to be allocated with the first self-increment ID of the quantity; the application request is generated by the first node in response to pre-commit of a first transaction to be committed, the first transaction including at least one data record to be inserted corresponding to the target data table.
The previous embodiment has been described, in this embodiment, each target data table is stored in at least one second node in a node cluster of the distributed database, a third node is a node storing the target data table first in at least one second node, a first target self-increasing ID is recorded in the third node, and the first target self-increasing ID is the maximum value of the first self-increasing IDs of all data records in the target data table, which is not described in detail herein.
After determining pre-submission of a first transaction, a first node determines a third node of a target data table for each target data table for which the first transaction aims, and sends an application request to the third node, wherein the application request comprises a transaction identifier of the first transaction and the number of data records to be inserted corresponding to the target data table, and the application request is used for requesting to allocate the first self-increment ID of the number to the target data table for which the first transaction represented by the transaction identifier aims.
In step S302, if it is determined that the target data table does not overflow after being inserted into the at least one data record to be inserted, the first target self-increment ID is used as a start value of the first self-increment ID of the at least one data record to be inserted.
After receiving an application request sent by a first node, a third node first determines whether a first target self-increment ID is in a locking state, the first target self-increment ID in the locking state cannot be modified by other transactions, and if the first target self-increment ID is not in the locking state, locks the first target self-increment ID for the first transaction, so that the first target self-increment ID is locked by the first transaction and is in the locking state. And if the first target self-increment ID is determined to be in a locking state, waiting until the first target self-increment ID is in an unlocking state.
After locking the first transaction to the first target self-increment ID, the embodiment of the application judges whether the target data table overflows after the target data table is inserted into the data record to be inserted, and specifically, the step length required for distributing the first self-increment ID to the at least one data record to be inserted can be determined based on the number of the data records to be inserted; determining a sum of the first self-increment ID and the step size; if the sum is not larger than the data quantity threshold value of the target data table, determining that the target data table is inserted into the at least one data record to be inserted and no overflow exists; and if the sum value is determined to be larger than the data quantity threshold value of the target data table, determining that the target data table overflows after the target data table is inserted into the at least one data record to be inserted.
If it is determined that the target data table does not overflow after being inserted into the at least one data record to be inserted, the first target self-increment ID is used as a starting value of a first self-increment ID of the at least one data record to be inserted, that is, the first self-increment ID of each data record to be inserted in the target data table in the first transaction is allocated on the basis of the starting value of the first self-increment ID.
Step S303, sending an allocation indication message to each second node corresponding to the target data table, wherein the allocation indication message comprises a transaction identifier of the first transaction and a start value of the first self-increment ID; the allocation indication message is used for indicating that the first self-increment ID is allocated to at least one data record to be inserted contained in the first transaction based on the initial value of the first self-increment ID.
After determining the starting value of the first self-increment ID, the third node sends an allocation indication message to each second node corresponding to the target data table, wherein the allocation indication message comprises a transaction identifier of the first transaction and the starting value of the first self-increment ID, and the allocation indication message is used for indicating the second transaction to allocate the first self-increment ID for at least one data record to be inserted contained in the first transaction based on the starting value of the first self-increment ID.
After receiving the application request, the third node provides the starting value of the first self-increment ID for each second node, the second node allocates the first self-increment ID for each data record to be inserted independently, the first self-increment ID allocation is not dependent on the first node, the allocation efficiency can be improved, meanwhile, each second node can obtain the starting value of the first self-increment ID, and the consistency of the allocation of the first self-increment ID for each data record to be inserted by each second node can be ensured.
In addition, the allocation of the first self-increment ID of each data record to be inserted is irrelevant to the master key pk or the unique index uk of the data record to be inserted, so that the problem of write hot spots caused by the fact that the self-increment must create uk or pk can be eliminated.
In one possible implementation manner provided in the embodiment of the present application, if it is determined that the target data table does not overflow after being inserted into the at least one data record to be inserted, the method further includes:
Determining a step size required for allocating a first self-increment ID to the at least one data record to be inserted based on the number;
determining a sum of the first self-increment ID and the step size;
If the sum is not larger than the data quantity threshold value of the target data table, determining that the target data table is inserted into the at least one data record to be inserted and no overflow exists;
And if the sum value is determined to be larger than the data quantity threshold value of the target data table, determining that the target data table overflows after the target data table is inserted into the at least one data record to be inserted.
Because the data size of the target data table is limited, before each data record to be inserted corresponding to the target data table is inserted into the target data table, it is required to determine whether overflow occurs after the target data table is inserted into each data record to be inserted.
Specifically, determining a step size required for allocating a first self-increment ID to the at least one data record to be inserted based on the number, wherein the step size is equal to the number of the data records to be inserted, and determining a sum of the first self-increment ID and the step size; if the sum is not greater than (less than or equal to) the data amount threshold of the target data table, determining that the target data table does not overflow after the target data table is inserted into the at least one data record to be inserted; if the sum is greater than the data quantity threshold of the target data table, determining that the target data table overflows after the at least one data record to be inserted is inserted, and when the overflow is determined to occur, alarming to remind a user that the data record to be inserted cannot be inserted normally due to insufficient capacity of the target data table, and expanding the data quantity threshold of the target data table to enable the data record to be inserted normally into the target data table.
In one possible implementation manner provided in the embodiment of the present application, if it is determined that the target data table does not overflow after being inserted into the at least one data record to be inserted, the method further includes:
Locking the first target self-increment ID for the first transaction so that the first target self-increment ID is not updated by other transactions;
The determining that the target data table has no overflow after being inserted into the at least one data record to be inserted further comprises:
Updating the first target self-increment ID based on the first target self-increment ID and the step length to obtain a new first target self-increment ID, wherein the new first target self-increment ID is the sum of the first target self-increment ID and the step length;
Releasing the lock of the first target self-increment ID.
In the embodiment of the application, after receiving the request sent by the first node, the third node locks the first target self-increment ID for the first transaction, so that the first target self-increment ID is not updated or modified by other transactions, and after determining that the target data table does not overflow after being inserted into the at least one data record to be inserted, the target data table is determined to be capable of being inserted into the at least one data record to be inserted, and in this case, the first target self-increment ID is also required to be updated, and the new first target self-increment ID is the latest first self-increment ID obtained after the target data table is inserted into the at least one data record to be inserted, and is the sum of the current first target self-increment ID and the step length.
After updating the first target self-increment ID to a new first target self-increment ID, the embodiment of the application releases the lock of the first target self-increment ID so that other transactions can lock the first target self-increment ID.
The embodiment of the application provides another self-increment ID allocation method which is applied to any one second node of a distributed database node cluster, wherein a target data table is stored in the second node; the data records in each data row of the target data table are provided with a first self-increment ID;
As shown in fig.4, the method includes:
step S401, in response to the pre-submission of the first node to the first transaction, storing the transaction identifier of the first transaction, at least one data record to be inserted in the target data table, and a second self-increment ID of each data record to be inserted; wherein the second self-increment ID is the self-increment ID allocated for each data record to be inserted in the first transaction.
The foregoing embodiment has been described, where the nodes in the node cluster according to the embodiment of the present application have a first node and a second node, where the first node is a coordinator in the node cluster, the second node is each participant in the node cluster, and each target data table is stored in at least one second node of the node cluster, and the third node is the first node in the node cluster to store the target data table.
The first transaction to be committed according to embodiments of the present application may be a database transaction that includes at least one data record to be inserted, which may be determined from an insert statement.
The number of the target data tables may be one or more, the target data tables include self-increment columns, the self-increment columns record first self-increment IDs of data rows in the target data tables, the first self-increment IDs may uniquely represent the data rows or data records in the data rows, and each data row includes a data record and a first self-increment ID.
In the first transaction according to the embodiment of the present application, the table identifier of the target data table corresponding to each data record to be inserted is included, and at least one data record to be inserted corresponding to each target data table may be determined based on the table identifier of each data record to be inserted.
The commit of the first transaction of the embodiment of the application can be a two-phase commit, a pre-commit phase and a commit, respectively. In the embodiment of the application, the second node responds to the pre-submission of the first transaction and stores the transaction identifier of the first transaction, at least one data record to be inserted in the target data table and a second self-increment ID of each data record to be inserted, wherein the transaction identifier can uniquely determine the first transaction, the second self-increment ID is the self-increment ID allocated to each data record to be inserted in the first transaction, the second self-increment ID takes 0 or 1 as a starting value, and in general, the second self-increment ID takes 1 as the starting value.
Step S402, receiving an allocation indication message sent by a third node, wherein the allocation indication message comprises a transaction identifier of the first transaction and a start value of the first self-increment ID; the allocation indication message is used for indicating that the first self-increment ID is allocated to at least one data record to be inserted contained in the first transaction based on the initial value of the first self-increment ID.
In step S403, in response to the allocation indication message, the first self-increment ID of each data record to be inserted is determined based on the start value of the first self-increment ID and the second self-increment ID of each data record to be inserted included in the transaction identifier. Step S404 and/or step S405 are/is performed.
After receiving the allocation indication message sent by the third node, the second node in the embodiment of the present application may respond to the allocation indication message, and may determine the first self-increment ID of the data record to be inserted directly based on the start value of the first self-increment ID in the allocation indication message and the second self-increment ID of each record to be inserted, and specifically, if the start value of the second self-increment ID is 1, may directly use the sum of the start value of the first self-increment ID and the second self-increment ID as the first self-increment ID of the data record to be inserted.
The second node directly determines the procedure of the first self-increment ID of the data record to be inserted as belonging to the synchronous allocation scheme based on the start value of the first self-increment ID and the second self-increment ID of each record to be inserted,
As shown in FIG. 5, which schematically illustrates a schematic diagram of the self-increment ID allocation based on the synchronous allocation scheme according to the embodiment of the present application, as shown in FIG. 5, a distributed database may be divided into a computation layer, a storage layer and an application layer (not shown), where the computation layer of the distributed database is composed of computation layers of each node, the computation layer of each node may be logically regarded as a computation layer, the storage layer of each node is regarded as a storage layer, and step ① is that a first node is included in its computation layer (computer layer) as each first transaction, assigning a second self-increment ID to each data record to be inserted of each target data table, the second self-increment ID taking 1 as a start value, the second self-increment ID of each data record to be inserted of each table being 1,2, 3. For example, for the first transaction 1, for the data table 1 and the data table 2, the data records to be inserted in the first transaction 1 are respectively a data record to be inserted a1, a data record to be inserted a2, a data record to be inserted an, and the second self-increment ID of each data record to be inserted is respectively 1,2, 3. The data records to be inserted are respectively a data record b1 to be inserted, a data record b2 to be inserted, and a data record bn to be inserted, and the second self-increment ID of each data record to be inserted is respectively 1,2 and 3. The second transaction 2 is aimed at the data table 3, each data record to be inserted of the first transaction 2 is respectively a data record to be inserted c1, a data record to be inserted c2 and a data record to be inserted cn, and the second self-increment ID of each data record to be inserted is respectively 1,2 and 3. Step ② characterizes that after the first transaction is pre-submitted, the first node sends an application request to a third node, a storage layer (storage layer) of the third node includes a first target self-increment ID, the first target self-increment ID is a maximum value of the first self-increment IDs in the target data table, the third node 1 is directed against the data table 1, the current first target self-increment ID of the data table 1 in the third node 1 is 46, the third node 2 is directed against the data table 2, and the current first target self-increment ID of the data table 2 in the third node 2 is 50; Step ③ characterizes that the third node sends an allocation indication message containing a start value of the first self-increment ID to each second node, and indicates the second node to allocate the first self-increment ID to each data record to be inserted based on the start value of the first self-increment ID, each second node may store a corresponding target data table, the second node 1 stores the data table 1, and the second node 2 stores the data table 2, and the specific implementation process is described in the foregoing embodiment, which is not repeated herein.
The embodiment of the application can also carry out asynchronous distribution by a background, the background asynchronous distribution belongs to an asynchronous distribution scheme, in practical application, the first self-increment ID distribution can be carried out based on the asynchronous distribution scheme or the asynchronous distribution scheme alone, and the first self-increment ID distribution can also be carried out by a synchronous distribution scheme and an asynchronous distribution scheme together.
Step S404, determining the pre-commit time of pre-commit the first transaction, storing the transaction identifier of the first transaction, the start value of the first self-increment ID, the number of at least one data record to be inserted in the first transaction for the target data table, and the pre-commit time as a synchronization set to be synchronized, so that when the background of the distributed database periodically accesses the second node, the background asynchronously reads the synchronization set, determines the first self-increment ID of each data record to be inserted, and informs the second node.
In the embodiment of the application, as the background periodically accesses each second node, if the first self-increment ID of each data record to be inserted is determined asynchronously by the background, the second node is required to determine the pre-commit time of pre-commit first transactions, and the pre-commit time of each first transaction is stored, so that the background can periodically allocate the first self-increment ID for each data record to be inserted in the target data table in the first transactions.
After determining the pre-commit time of the first transaction, the embodiment of the application stores the transaction identifier of the first transaction, the start value of the first self-increment ID, the number of data records to be inserted and the pre-commit time as a synchronization set to be synchronized, so that when the background periodically accesses the second node, the background asynchronously reads the synchronization set, determines the first self-increment ID of each data record to be inserted and informs the second node.
The process of allocating the first self-increment ID to the data record to be inserted of each target data table contained in the first transaction occurs after the pre-commit of the transaction, so that the fact that the transaction can be normally committed can be basically determined, and the void of the first self-increment ID is not caused.
In step S405, at least one new data row is inserted into the target data table, where each new data row includes a data record to be inserted and a first self-increment ID corresponding to the data record to be inserted.
After the first self-increment ID of each data record to be inserted is obtained, at least one new data row is inserted into the target data table, and each new row comprises one data record to be inserted and the first self-increment ID corresponding to the data record to be inserted.
In step S406, if it is determined that all the data records to be inserted in the first transaction are inserted into the target data table, the first transaction is committed.
For the first transaction, if it is determined that all data records to be inserted in the target data table are inserted into the target data table in the first transaction, it is indicated that the first transaction is completed, and the first transaction can be submitted at this time.
In the embodiment of the application, the first node does not directly allocate the first self-increment ID to each data record to be inserted, the third node does not allocate the first self-increment ID to each data record to be inserted, the third node allocates the initial value of the first self-increment ID to each data record to be inserted aiming at the target data table, and the second node or the background allocates the first self-increment ID to each data record to be inserted.
The embodiment of the application provides a possible implementation manner, which determines the first self-increment ID of each data record to be inserted based on the initial value of the first self-increment ID and the second self-increment ID of each data record to be inserted contained in the transaction identifier, and comprises the following steps:
For each data record to be inserted, updating the second self-increment ID of the data record to be inserted based on the initial value of the first self-increment ID and the second self-increment ID of the data record to be inserted to obtain an updated second self-increment ID;
and taking the updated second self-increment ID as the first self-increment ID corresponding to the data record to be inserted.
In the embodiment of the present application, the starting value of the second self-increasing ID is 0 or 1, the second self-increasing ID of each data record to be inserted is 1,2, 3..n, n is a positive integer, and for each data record to be inserted, the second self-increasing ID of the data record to be inserted may be updated based on the starting value of the first self-increasing ID and the second self-increasing ID of the data record to be inserted, so as to obtain an updated second self-increasing ID, and when the starting value of the second self-increasing ID is 1, the updated second self-increasing ID of the data record to be inserted is the sum of the starting value of the first self-increasing ID and the second self-increasing ID, and the updated second self-increasing ID is used as the first self-increasing ID corresponding to the data record to be inserted; when the start value of the second self-increment ID is 0, the updated second self-increment ID of the data record to be inserted is the sum of the start value of the first self-increment ID and the second self-increment ID, and 1 is added.
The embodiment of the application provides a self-increment ID allocation method which is applied to the background of a distributed database, as shown in fig. 6, and comprises the following steps:
Step S601, periodically accessing each second node in the node cluster of the distributed database; the second node stores a target data table, and data records in each data row of the target data table are provided with a first self-increment ID; the second node also stores a transaction identification of each of the first transactions that have been pre-committed, at least one data record to be inserted in the target data table, and a second self-increment ID for each data record to be inserted.
In the embodiment of the application, the background of the distributed node database can periodically access each second node in the node cluster of the distributed database, each second node stores at least one target data table, the data records in each data row of each target data table have a first self-increasing ID, and the column where the first self-increasing ID is located is a self-increasing column.
In the embodiment of the application, the first node can submit the first transaction to the second node, and the second node can store the transaction identification of each pre-submitted first transaction, at least one data record to be inserted in the target data table and the second self-increment ID of each data record to be inserted in response to the pre-submission of the first transaction.
Step S602, in the current period, for each second node, reading the synchronization set of the second node; the synchronization set comprises at least one record to be synchronized, and each record to be synchronized comprises a transaction identification of a first transaction, a starting value of the first self-increment ID and a pre-commit time of the first transaction.
In the embodiment of the application, in the current period, for each second node, the background will read each synchronization set of the second node, where the synchronization set includes at least one record to be synchronized, each record to be synchronized includes a transaction identifier of a first transaction, a start value of the first self-increment ID, and a pre-commit time of the first transaction, and of course, includes the number of at least one data record to be inserted for the target data table included in the first transaction.
Step S603 determines, from the synchronization set, a transaction identifier of each first transaction in the previous cycle at the pre-commit time, and determines at least one data record to be inserted corresponding to the transaction identifier and a second self-increment ID of each data record to be inserted.
In the embodiment of the application, the background is to periodically access the second node, and in each current period, the transaction identifier of each first transaction in the previous period at the pre-commit time is determined from the synchronous set, and at least one data record to be inserted and the second self-increment ID of each data record to be inserted corresponding to the transaction identifier are determined.
Step S604, for each data record to be inserted, determining a first self-increment ID of each data record to be inserted based on a start value of the first self-increment ID corresponding to the transaction identifier of the first transaction and a second self-increment ID of the data record to be inserted;
Step S605 informs the second node of the first self-increment ID of each data record to be inserted.
Similar to the manner of determining the first self-increment ID of each data record to be inserted by the second node, for each data record to be inserted, the background may also determine the first self-increment ID of each data record to be inserted based on the start value of the first self-increment ID corresponding to the transaction identifier of the first transaction and the second self-increment ID of the data record to be inserted, that is, when the start value of the second self-increment ID is 1, the first self-increment ID of each data record to be inserted is the sum value of the start value of the first self-increment ID and the second self-increment ID of the data record to be inserted. In addition, after determining the first self-increment ID of each data record to be inserted, the background also needs to inform the second node of the first self-increment ID of each data record to be inserted, so that the second node inserts a corresponding data row into the target data table, where the data row includes the inserted data record and the first self-increment ID of the data record to be inserted.
According to the embodiment of the application, the background allocates the first self-increment ID for each data record to be inserted based on the initial value of the first self-increment ID and the second self-increment ID of each data record to be inserted, and the process is an asynchronous process, so that the allocation performance can be improved.
The embodiment of the application provides a possible implementation manner, and the to-be-synchronized records also comprise the number of at least one to-be-inserted data record of the target data table;
The determining of the first self-increment ID of each data record to be inserted further comprises:
If the first self-increment ID in the target data table is equal to the sum of the initial value of the first self-increment ID corresponding to the transaction identifier and the number, deleting the record to be synchronized from the synchronization set.
The background of the embodiment of the application needs to check whether each record to be synchronized is processed, specifically, the background can judge whether a first self-increment ID is equal to the sum of the starting value of the first self-increment ID corresponding to the transaction identifier and the number in the target data table, if so, the record to be synchronized is processed, and the record to be synchronized can be deleted from the record to be synchronized. If a conflict occurs for deletion, the conflict can be ignored because the overlay is also idempotent.
The embodiment of the application provides a possible implementation manner, which comprises the following steps of determining a first self-increment ID of each data record to be inserted, and further comprising:
Establishing an association relationship between the transaction identifier of the first transaction and the first self-increment ID;
The method further comprises the steps of:
acquiring a transaction inquiry request initiated by a user, wherein the transaction inquiry request comprises a transaction identifier of a first transaction to be inquired, and the transaction inquiry request is used for inquiring an insertion result of the first transaction represented by the transaction identifier for each target data table; the insertion result indicates the data row into which each data record to be inserted is inserted;
If the fact that the record to be synchronized corresponding to the transaction identifier does not exist in the synchronization set is determined, each second target self-increment ID which has an association relation with the transaction identifier of the first transaction in the query request is determined from the target data table, and data rows corresponding to each second target self-increment ID are obtained and displayed from the target data table.
After determining the first self-increment ID of each data record to be inserted, the embodiment of the application also establishes the association relationship between the transaction identifier of the first transaction and the first self-increment ID, thereby facilitating backtracking and rollback.
The user can initiate a transaction inquiry request, wherein the transaction inquiry request comprises an insertion result of a first transaction, which is characterized by inquiring a transaction identifier, for each target data table; the insertion result indicates the data row inserted by each data record to be inserted, if the fact that the data record to be synchronized corresponding to the transaction identifier does not exist in the synchronization set is determined, the fact that the first transaction is submitted is indicated, each data record to be inserted is inserted into a target data table, at the moment, the data row corresponding to each second target self-increasing ID can be directly obtained from the target data table, and the data row corresponding to each second target self-increasing ID is displayed and obtained to a user.
The embodiment of the application provides a possible implementation manner, and the method comprises the following steps of:
if the fact that the record to be synchronized corresponding to the transaction identifier exists in the synchronization set is determined, executing any one of the following steps:
after a preset time length, determining each second target self-increment ID which has an association relation with the transaction identifier of the first transaction in the query request from the target data table, and acquiring and displaying data rows corresponding to each second target self-increment ID from the target data table;
transmitting the record to be synchronized to a calculation layer or a storage layer of the second node, and indicating the calculation layer or the storage layer to determine a first self-increment ID of each data record to be inserted based on a start value of the first self-increment ID in the record to be synchronized and a second self-increment ID of each data record to be inserted; for each data record to be inserted, combining the data record to be inserted and the first self-increment ID of the data record to be inserted to obtain a data row to be inserted; each row of data to be inserted is shown.
If it is determined that a record to be synchronized corresponding to the transaction identifier exists in the synchronization set, it is indicated that the first transaction has not been submitted, in this case, a preset duration may be waited, after the preset duration, each second target self-increment ID associated with the transaction identifier of the first transaction in the query request is determined from the target data table, and a data row corresponding to each second target self-increment ID is obtained and displayed from the target data table.
The background may also send the record to be synchronized to a computing layer or a storage layer of the second node, instruct the computing layer or the storage layer to determine a first self-increment ID of each data record to be inserted based on a start value of the first self-increment ID in the record to be synchronized and a second self-increment ID of each data record to be inserted, and combine the data record to be inserted and the first self-increment ID of the data record to be inserted after obtaining the first self-increment ID of each data record to be inserted, so as to obtain a data line to be inserted, and display the data line to be inserted, and insert the data line to be inserted into the target data table.
Of course, the start value of the first self-increment ID corresponding to the first transaction of the third node may be directly read, and the calculation layer may calculate the first self-increment ID based on the start value of the first self-increment ID and the second self-increment ID.
The process of allocating the first self-increment ID for each data line to be inserted by the background based on the synchronous set belongs to an asynchronous allocation scheme, and in practical application, the selection of the synchronous scheme or the asynchronous allocation scheme can be freely switched according to the system load requirement so as to achieve stable self-increment performance.
As shown in fig. 7, which illustrates a schematic diagram of the present application for allocating self-increment IDs based on an asynchronous allocation scheme, as shown in fig. 7, step ① is to allocate, for a first node, a second self-increment ID for each data record to be inserted of each target data table, which is included in each first transaction, at a calculation layer (computer layer) thereof, the second self-increment ID having a start value of 1, and the second self-increment IDs for each data record to be inserted of each table are 1,2, 3. For example, for the first transaction 1, for the data table 1 and the data table 2, the data records to be inserted in the first transaction 1 are respectively a data record to be inserted a1, a data record to be inserted a2, a data record to be inserted an, and the second self-increment ID of each data record to be inserted is respectively 1,2, 3. The data records to be inserted are respectively a data record b1 to be inserted, a data record b2 to be inserted, and a data record bn to be inserted, and the second self-increment ID of each data record to be inserted is respectively 1,2 and 3. The second transaction 2 is aimed at the data table 3, each data record to be inserted of the first transaction 2 is respectively a data record to be inserted c1, a data record to be inserted c2 and a data record to be inserted cn, and the second self-increment ID of each data record to be inserted is respectively 1,2 and 3. Step ② characterizes that after the first transaction is pre-submitted, the first node sends an application request to a third node, the storage layer of the third node includes a first target self-increment ID, the first target self-increment ID is the maximum value of the first self-increment ID in the target data table, the third node 1 is aimed at the data table 1, the current first target self-increment ID of the data table 1 in the third node 1 is 46, the third node 2 is aimed at the data table 2, and the current first target self-increment ID of the data table 2 in the third node 2 is 50; Step ③ characterizes that the third node sends an allocation indication message containing a start value of the first self-increment ID to each second node, and simultaneously instructs the second node to generate a synchronization set, the synchronization set including at least one record to be synchronized, the synchronization set including each record to be synchronized (record to be synchronized 1, record to be synchronized 2.), each record to be synchronized comprises a transaction identifier txnID of the first transaction, a start value IDmax of the first self-increment ID, a number num of at least one data record to be inserted for the target data table in the first transaction, and the pre-commit time t; Step ④ characterizes a background read synchronization set, and for each data record to be inserted, the first self-increment ID of each data record to be inserted is determined based on the start value of the first self-increment ID in each data record to be inserted and the second self-increment ID of the data record to be inserted, and detailed implementation process of each step is described in the foregoing embodiment, and the embodiments of the present application will not be repeated here.
The embodiment of the application provides a self-increment ID allocation device 80, as shown in FIG. 8, applied to a first node of a node cluster of a distributed database, where the device 80 includes:
A first obtaining module 810, configured to obtain a first transaction to be committed, where the first transaction is directed to at least one target data table; the data records in each data row of the target data table are provided with a first self-increment ID; the first transaction comprises at least one data record to be inserted, which corresponds to each target data table; each target data table is stored in at least one second node in the node cluster;
A first determining module 820, configured to determine, for each target data table, a third node from the second nodes corresponding to the target data table in response to pre-submitting the first transaction to the corresponding second nodes; the third node is the first node storing the target data table in the at least one second node; the third node records a first target self-increment ID; the first target self-increment ID is the maximum value of the first self-increment ID of each data line in the target data table;
A first sending module 830, configured to send, for each target data table, an application request to a third node corresponding to the target data table, where the application request includes a transaction identifier of the first transaction and a number of to-be-inserted data records corresponding to the target data table; the request is for requesting allocation of the number of first self-increment IDs to the target data table.
One possible implementation manner is provided in the embodiment of the present application, and the apparatus 80 further includes:
the second self-increment ID allocation module is configured to allocate a second self-increment ID to each data record to be inserted in the first transaction, so that after the third node responds to the application request to send a first target self-increment ID to each second node, each second node allocates a first self-increment ID to each data record to be inserted based on the first target self-increment ID and the second self-increment ID of each data record to be inserted.
The embodiment of the application provides a self-increment ID allocation device 90, as shown in FIG. 9, applied to a third node in a node cluster of a distributed database, wherein the third node is a first node for storing a target data table in at least one second node; the target data table is stored in at least one second node in the node cluster; the third node records a first target self-increment ID; the data records in each data row of the target data table are provided with a first self-increment ID; the first target self-increment ID is the maximum value of the first self-increment ID of the data record in the target data table;
The apparatus 90 includes:
A first receiving module 910, configured to receive an application request sent by a first node, where the application request includes a transaction identifier of a first transaction and a number of to-be-inserted data records corresponding to the target data table; the application request is used for requesting the target data table aiming at the first transaction characterized by the transaction identification to be allocated with the first self-increment ID of the quantity; the application request is generated by the first node in response to pre-submission of a first transaction to be submitted, wherein the first transaction comprises at least one data record to be inserted corresponding to the target data table;
The start value determining module 920 is configured to take the first target self-increasing ID as a start value of the first self-increasing ID of the at least one data record to be inserted if it is determined that the target data table does not overflow after the at least one data record to be inserted is inserted;
A second sending module 930, configured to send an allocation indication message to each second node corresponding to the target data table, where the allocation indication message includes a transaction identifier of the first transaction and a start value of the first self-increment ID; the allocation indication message is used for indicating that the first self-increment ID is allocated to at least one data record to be inserted contained in the first transaction based on the initial value of the first self-increment ID.
One possible implementation manner is provided in the embodiment of the present application, and the apparatus 90 further includes:
the overflow judging module is used for determining a step length required by distributing a first self-increment ID for the at least one data record to be inserted based on the number; determining a sum of the first self-increment ID and the step size; if the sum is not larger than the data quantity threshold value of the target data table, determining that the target data table is inserted into the at least one data record to be inserted and no overflow exists; and if the sum value is determined to be larger than the data quantity threshold value of the target data table, determining that the target data table overflows after the target data table is inserted into the at least one data record to be inserted.
One possible implementation manner is provided in the embodiment of the present application, and the apparatus 90 further includes:
a locking module, configured to lock the first target self-increment ID for the first transaction, so that the first target self-increment ID is not updated by other transactions; updating the first target self-increment ID based on the first target self-increment ID and the step length to obtain a new first target self-increment ID, wherein the new first target self-increment ID is the sum of the first target self-increment ID and the step length; releasing the lock of the first target self-increment ID.
The embodiment of the application provides another self-increment ID allocation device, as shown in FIG. 10, which is applied to any one second node of a distributed database node cluster, wherein a target data table is stored in the second node; the data records in each data row of the target data table are provided with a first self-increment ID;
The apparatus 100 includes:
A pre-commit response module 1001, configured to store, in response to a pre-commit of a first transaction by a first node, a transaction identifier of the first transaction, at least one data record to be inserted in the target data table, and a second self-increment ID of each data record to be inserted; wherein the second self-increment ID is a self-increment ID allocated to each data record to be inserted in the first transaction;
A second receiving module 1002, configured to receive an allocation indication message sent by a third node, where the allocation indication message includes a transaction identifier of the first transaction and a start value of the first self-increment ID; the allocation indication message is used for indicating that the first self-increment ID is allocated to at least one data record to be inserted contained in the first transaction based on the initial value of the first self-increment ID;
A second determining module 1003, configured to determine, in response to the allocation indication message, a first self-increment ID of each data record to be inserted based on the start value of the first self-increment ID and a second self-increment ID of each data record to be inserted included in the transaction identifier; and/or
A third determining module 1004, configured to determine a pre-commit time of a pre-committed first transaction, store, as a record to be synchronized, a transaction identifier of the first transaction, a start value of the first self-increment ID, a number of at least one data record to be inserted in the first transaction for the target data table, and the pre-commit time to a synchronization set preset, so that when the background of the distributed database periodically accesses the second node, the background asynchronously reads the synchronization set, determines a first self-increment ID of each data record to be inserted, and informs the second node;
An inserting module 1005, configured to insert at least one new data row into the target data table, where each new data row includes a data record to be inserted and a first self-increment ID corresponding to the data record to be inserted;
a commit module 1006, configured to commit the first transaction if it is determined that all data records to be inserted for the target data table in the first transaction are inserted into the target data table.
The embodiment of the application provides a possible implementation manner, and the second determining module is specifically configured to update, for each data record to be inserted, the second self-increasing ID of the data record to be inserted based on the start value of the first self-increasing ID and the second self-increasing ID of the data record to be inserted, so as to obtain an updated second self-increasing ID; and taking the updated second self-increment ID as the first self-increment ID corresponding to the data record to be inserted.
The embodiment of the present application provides a self-increment ID allocation apparatus, as shown in fig. 11, applied to the background of a distributed database, where the apparatus 110 includes:
An access module 1101 for periodically accessing each second node in the cluster of nodes of the distributed database; the second node stores a target data table, and data records in each data row of the target data table are provided with a first self-increment ID; the second node also stores the transaction identification of each pre-committed first transaction, at least one data record to be inserted in the target data table, and a second self-increment ID of each data record to be inserted;
A reading module 1102, configured to, for each second node, read a synchronization set of the second node in a current period; the synchronization set comprises at least one record to be synchronized, wherein each record to be synchronized comprises a transaction identifier of a first transaction, a starting value of the first self-increment ID and a pre-submitting time of the first transaction;
A fourth determining module 1103, configured to determine, from the synchronization set, a transaction identifier of each first transaction in a previous cycle at a pre-commit time, and determine at least one data record to be inserted and a second self-increment ID of each data record to be inserted corresponding to the transaction identifier;
A fifth determining module 1104, configured to determine, for each data record to be inserted, a first self-increment ID of each data record to be inserted based on a start value of the first self-increment ID corresponding to the transaction identifier of the first transaction and a second self-increment ID of the data record to be inserted;
A notification module 1105, configured to notify the second node of the first self-increment ID of each data record to be inserted.
The embodiment of the application provides a possible implementation manner, and the to-be-synchronized records also comprise the number of at least one to-be-inserted data record of the target data table; the apparatus 110 further comprises:
And the deleting module is used for deleting the record to be synchronized from the synchronization set if the fact that one first self-increment ID is equal to the sum of the starting value of the first self-increment ID corresponding to the transaction identifier and the number exists in the target data table is determined.
In one possible implementation manner provided in the embodiment of the present application, the apparatus 110 further includes:
The association relation establishing module is used for establishing an association relation between the transaction identifier of the first transaction and the first self-increment ID;
The query module is used for acquiring a transaction query request initiated by a user, wherein the transaction query request comprises a transaction identifier of a first transaction to be queried, and the transaction query request is used for querying the first transaction characterized by the transaction identifier; an insertion result for each target data table; the insertion result indicates the data row into which each data record to be inserted is inserted;
And the first display module is used for determining each second target self-increment ID with an association relation with the transaction identifier of the first transaction in the query request from the target data table if the to-be-synchronized record corresponding to the transaction identifier does not exist in the synchronization set, and acquiring and displaying the data row corresponding to each second target self-increment ID from the target data table.
The embodiment of the application provides a possible implementation manner, and the device further comprises:
the waiting module is used for determining each second target self-increment ID which has an association relation with the transaction identifier of the first transaction in the query request from the target data table after the preset time length, and acquiring and displaying data rows corresponding to each second target self-increment ID from the target data table;
The second display module is used for sending the record to be synchronized to a calculation layer or a storage layer of the second node, and indicating the calculation layer or the storage layer to determine the first self-increment ID of each data record to be inserted based on the starting value of the first self-increment ID in the record to be synchronized and the second self-increment ID of each data record to be inserted; for each data record to be inserted, combining the data record to be inserted and the first self-increment ID of the data record to be inserted to obtain a data row to be inserted; each row of data to be inserted is shown.
The device of the embodiment of the present application may perform the method provided by the embodiment of the present application, and its implementation principle is similar, and actions performed by each module in the device of the embodiment of the present application correspond to steps in the method of the embodiment of the present application, and detailed functional descriptions of each module of the device may be referred to the descriptions in the corresponding methods shown in the foregoing, which are not repeated herein.
The embodiment of the application provides electronic equipment, which comprises a memory, a processor and a computer program stored on the memory, wherein the processor executes the computer program to realize the steps of a self-increment ID allocation method, and compared with the related technology, the steps of the self-increment ID allocation method can be realized: in the embodiment of the application, the application request sent by the first node each time is directed to the target data table, the first self-increment ID is allocated to all the data records to be inserted of the target data table by one application request allocation request instead of allocating one first self-increment ID to one data record to be inserted by one request, and the allocation efficiency can be improved by taking the data table as a unit.
In addition, the first self-increment ID is not allocated by the first node, but is directly allocated by the third node of each target data table, so that the workload of the first node is reduced, each third node is independently allocated, the allocation efficiency is further improved, and the consistency of the target data tables in each second node can be ensured.
In an alternative embodiment, there is provided an electronic device, as shown in fig. 12, the electronic device 4000 shown in fig. 12 includes: a processor 4001 and a memory 4003. Wherein the processor 4001 is coupled to the memory 4003, such as via a bus 4002. Optionally, the electronic device 4000 may further comprise a transceiver 4004, the transceiver 4004 may be used for data interaction between the electronic device and other electronic devices, such as transmission of data and/or reception of data, etc. It should be noted that, in practical applications, the transceiver 4004 is not limited to one, and the structure of the electronic device 4000 is not limited to the embodiment of the present application.
The Processor 4001 may be a CPU (Central Processing Unit ), general purpose Processor, DSP (DIGITAL SIGNAL Processor, data signal Processor), ASIC (Application SPECIFIC INTEGRATED Circuit), FPGA (Field Programmable GATE ARRAY ) or other programmable logic device, transistor logic device, hardware component, or any combination thereof. Which may implement or perform the various exemplary logic blocks, modules and circuits described in connection with this disclosure. The processor 4001 may also be a combination that implements computing functionality, e.g., comprising one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.
Bus 4002 may include a path to transfer information between the aforementioned components. Bus 4002 may be a PCI (PERIPHERAL COMPONENT INTERCONNECT, peripheral component interconnect standard) bus or an EISA (Extended Industry Standard Architecture ) bus, or the like. The bus 4002 can be divided into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one thick line is shown in fig. 12, but not only one bus or one type of bus.
Memory 4003 may be, but is not limited to, ROM (Read Only Memory) or other type of static storage device that can store static information and instructions, RAM (Random Access Memory ) or other type of dynamic storage device that can store information and instructions, EEPROM (ELECTRICALLY ERASABLE PROGRAMMABLE READ ONLY MEMORY ), CD-ROM (Compact Disc Read Only Memory, compact disc Read Only Memory) or other optical disk storage, optical disk storage (including compact discs, laser discs, optical discs, digital versatile discs, blu-ray discs, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium that can be used to carry or store a computer program and that can be Read by a computer.
The memory 4003 is used for storing a computer program for executing an embodiment of the present application, and is controlled to be executed by the processor 4001. The processor 4001 is configured to execute a computer program stored in the memory 4003 to realize the steps shown in the foregoing method embodiment.
Among them, the electronic device package may include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and the like, and stationary terminals such as digital TVs, desktop computers, and the like. The electronic device shown in fig. 12 is merely an example, and should not impose any limitations on the functionality and scope of use of embodiments of the present disclosure.
Embodiments of the present application provide a computer readable storage medium having a computer program stored thereon, which when executed by a processor, implements the steps of the foregoing method embodiments and corresponding content. Compared with the prior art, can realize: in the embodiment of the application, the application request sent by the first node each time is directed to the target data table, the first self-increment ID is allocated to all the data records to be inserted of the target data table by one application request allocation request instead of allocating one first self-increment ID to one data record to be inserted by one request, and the allocation efficiency can be improved by taking the data table as a unit. In addition, the first self-increment ID is not allocated by the first node, but is directly allocated by the third node of each target data table, so that the workload of the first node is reduced, each third node is independently allocated, the allocation efficiency is further improved, and the consistency of the target data tables in each second node can be ensured.
It should be noted that the computer readable medium described in the present disclosure may be a computer readable signal medium or a computer readable medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this disclosure, a computer-readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present disclosure, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, fiber optic cables, RF (radio frequency), and the like, or any suitable combination of the foregoing.
The embodiment of the application also provides a computer program product, which comprises a computer program, wherein the computer program can realize the steps and corresponding contents of the embodiment of the method when being executed by a processor. Compared with the prior art, can realize: in the embodiment of the application, the application request sent by the first node each time is directed to the target data table, the first self-increment ID is allocated to all the data records to be inserted of the target data table by one application request allocation request instead of allocating one first self-increment ID to one data record to be inserted by one request, and the allocation efficiency can be improved by taking the data table as a unit. In addition, the first self-increment ID is not allocated by the first node, but is directly allocated by the third node of each target data table, so that the workload of the first node is reduced, each third node is independently allocated, the allocation efficiency is further improved, and the consistency of the target data tables in each second node can be ensured.
The terms "first," "second," "third," "fourth," "1," "2," and the like in the description and in the claims and in the above figures, if any, are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate, such that the embodiments of the application described herein may be implemented in other sequences than those illustrated or otherwise described.
It should be understood that, although various operation steps are indicated by arrows in the flowcharts of the embodiments of the present application, the order in which these steps are implemented is not limited to the order indicated by the arrows. In some implementations of embodiments of the application, the implementation steps in the flowcharts may be performed in other orders as desired, unless explicitly stated herein. Furthermore, some or all of the steps in the flowcharts may include multiple sub-steps or multiple stages based on the actual implementation scenario. Some or all of these sub-steps or phases may be performed at the same time, or each of these sub-steps or phases may be performed at different times, respectively. In the case of different execution time, the execution sequence of the sub-steps or stages can be flexibly configured according to the requirement, which is not limited by the embodiment of the present application.
The foregoing is only an optional implementation manner of some implementation scenarios of the present application, and it should be noted that, for those skilled in the art, other similar implementation manners based on the technical ideas of the present application are adopted without departing from the technical ideas of the scheme of the present application, which also belongs to the protection scope of the embodiments of the present application.

Claims (17)

1. A method of assigning a self-increasing ID, applied to a first node of a cluster of nodes of a distributed database, the method comprising:
Acquiring a first transaction to be submitted, wherein the first transaction aims at least one target data table; the target data table in the respective data line of (a) all of which are data records of (a) the method comprises the steps of providing a first self-increment ID; the first transaction comprises at least one data record to be inserted, which corresponds to each target data table; each target data table is stored in at least one second node in the node cluster;
Determining, for each of the target data tables, a third node from the second nodes corresponding to the target data table in response to pre-submitting the first transaction to the corresponding second node; the third node is a node for storing the target data table for the first time in the at least one second node; the third node is recorded with a first target self-increment ID; the first target self-increment ID is the maximum value of the first self-increment ID of each data line in the target data table;
For each target data table, sending an application request to a third node corresponding to the target data table, wherein the application request comprises a transaction identifier of the first transaction and the number of data records to be inserted corresponding to the target data table; the request is for requesting allocation of the number of first self-increment IDs to the target data table.
2. The method of claim 1, wherein the responding to pre-committing the first transaction to the corresponding second node further comprises:
And distributing a second self-increment ID (identity) for each data record to be inserted in the first transaction, so that after the third node responds to the application request and sends a first target self-increment ID to each second node, each second node distributes a first self-increment ID for each data record to be inserted based on the first target self-increment ID and the second self-increment ID of each data record to be inserted.
3. The self-increment ID allocation method is characterized by being applied to a third node in a node cluster of a distributed database, wherein the third node is a first node for storing a target data table in at least one second node; the target data table is stored in at least one second node in the node cluster; the third node is recorded with a first target self-increment ID; the data records in each data row of the target data table are provided with a first self-increment ID; the first target self-increment ID is the maximum value of the first self-increment ID of the data record in the target data table;
The method comprises the following steps:
Receiving an application request sent by a first node, wherein the application request comprises a transaction identifier of a first transaction and the number of data records to be inserted corresponding to the target data table; the application request is used for requesting to allocate the first self-increment IDs of the quantity to a target data table aiming at a first transaction characterized by the transaction identification; the application request is generated by the first node in response to pre-submission of a first transaction to be submitted, and the first transaction comprises at least one data record to be inserted corresponding to the target data table;
If the target data table is determined to be inserted into the at least one data record to be inserted without overflowing, taking the first target self-increasing ID as a starting value of a first self-increasing ID of the at least one data record to be inserted;
Sending an allocation indication message to each second node corresponding to the target data table, wherein the allocation indication message comprises a transaction identifier of the first transaction and a start value of the first self-increment ID; the allocation indication message is used for indicating that a first self-increment ID is allocated to at least one data record to be inserted, which is contained in the first transaction, based on the initial value of the first self-increment ID.
4. The method of claim 3, wherein if it is determined that the target data table does not overflow after being inserted into the at least one data record to be inserted, further comprising:
determining a step size required for allocating a first self-increment ID to the at least one data record to be inserted based on the number;
Determining a sum of the first self-increment ID and the step size;
if the sum is not larger than the data quantity threshold value of the target data table, determining that the target data table is inserted into the at least one data record to be inserted and no overflow exists;
and if the sum value is determined to be larger than the data quantity threshold value of the target data table, determining that the target data table overflows after the target data table is inserted into the at least one data record to be inserted.
5. The method of claim 4, wherein the determining, based on the number, a step size required to assign a first self-increment ID to the at least one data record to be inserted further comprises:
locking the first target self-increment ID for the first transaction so that the first target self-increment ID is not updated by other transactions;
the determining that the target data table does not overflow after being inserted into the at least one data record to be inserted further comprises:
updating the first target self-increment ID based on the first target self-increment ID and the step length to obtain a new first target self-increment ID, wherein the new first target self-increment ID is the sum of the first target self-increment ID and the step length;
Releasing the lock of the first target self-increment ID.
6. The self-increment ID allocation method is characterized by being applied to any one second node of a distributed database node cluster, wherein a target data table is stored in the second node; the data records in each data row of the target data table are provided with a first self-increment ID;
The method comprises the following steps:
Storing a transaction identification of a first transaction, at least one data record to be inserted for the target data table contained in the first transaction, and a second self-increment ID of each data record to be inserted in response to pre-commit of the first transaction by a first node; wherein the second self-increment ID is a self-increment ID allocated for the data record to be inserted in the first transaction;
Receiving an allocation indication message sent by a third node, wherein the allocation indication message comprises a transaction identifier of the first transaction and a start value of the first self-increment ID; the allocation indication message is used for indicating that a first self-increment ID is allocated to at least one data record to be inserted, which is contained in the first transaction, based on the initial value of the first self-increment ID;
Determining a first self-increment ID of each data record to be inserted based on a start value of the first self-increment ID and a second self-increment ID of each data record to be inserted contained in the transaction identifier in response to the allocation indication message; and/or
Determining a pre-commit time of pre-committing a first transaction, storing a transaction identifier of the first transaction, a start value of the first self-increment ID, the number of at least one data record to be inserted for the target data table in the first transaction and the pre-commit time as a synchronization set to be synchronized, so that when a background of the distributed database periodically accesses the second node, the background asynchronously reads the synchronization set to determine the first self-increment ID of each data record to be inserted and inform the second node;
Inserting at least one new data row into the target data table, wherein each new data row comprises a data record to be inserted and a first self-increment ID corresponding to the data record to be inserted;
And if the fact that all the data records to be inserted aiming at the target data table are inserted into the target data table in the first transaction is determined, submitting the first transaction.
7. The method of claim 6, wherein the determining the first self-increment ID for each of the data records to be inserted based on the start value of the first self-increment ID and the second self-increment ID for each of the data records to be inserted included in the transaction identification comprises:
For each data record to be inserted, updating the second self-increment ID of the data record to be inserted based on the initial value of the first self-increment ID and the second self-increment ID of the data record to be inserted to obtain an updated second self-increment ID;
and taking the updated second self-increment ID as the first self-increment ID corresponding to the data record to be inserted.
8. A method for assigning self-increment IDs, applied in the background of a distributed database, the method comprising:
Periodically accessing each second node in a cluster of nodes of the distributed database; the second node stores a target data table, and data records in each data row of the target data table are provided with a first self-increment ID; the second node also stores transaction identifications of each pre-submitted first transaction, at least one data record to be inserted in the target data table and a second self-increment ID of each data record to be inserted;
reading a synchronization set of the second nodes for each second node in the current period; the synchronization set comprises at least one record to be synchronized, wherein each record to be synchronized comprises a transaction identifier of a first transaction, a starting value of the first self-increment ID and a pre-commit time of pre-committing the first transaction;
Determining transaction identifiers of all first transactions in the previous period at the pre-commit time from the synchronous set, and determining at least one data record to be inserted corresponding to the transaction identifiers and a second self-increment ID of each data record to be inserted;
For each data record to be inserted, determining the first self-increment ID of each data record to be inserted based on the initial value of the first self-increment ID corresponding to the transaction identifier of the first transaction and the second self-increment ID of the data record to be inserted;
the second node is informed of the first self-increment ID of each data record to be inserted.
9. The method of claim 8, wherein the to-be-synchronized record further comprises a number of at least one to-be-inserted data record of the target data table;
The determining the first self-increment ID of each data record to be inserted further comprises:
And if the fact that one first self-increment ID is equal to the sum of the starting value of the first self-increment ID corresponding to the transaction identifier and the number exists in the target data table is determined, deleting the record to be synchronized from the synchronization set.
10. The method of claim 8, wherein said determining the first self-increment ID for each of said data records to be inserted further comprises:
establishing an association relationship between the transaction identifier of the first transaction and the first self-increment ID;
The method further comprises the steps of:
Acquiring a transaction inquiry request initiated by a user, wherein the transaction inquiry request comprises a transaction identifier of a first transaction to be inquired, and the transaction inquiry request is used for inquiring an insertion result of the first transaction represented by the transaction identifier for each target data table; the insertion result indicates the data row into which each data record to be inserted is inserted;
If the fact that the record to be synchronized corresponding to the transaction identifier does not exist in the synchronization set is determined, each second target self-increment ID which has an association relation with the transaction identifier of the first transaction in the query request is determined from the target data table, and data rows corresponding to each second target self-increment ID are obtained and displayed from the target data table.
11. The method of claim 10, wherein obtaining the user-initiated transaction query request is followed by:
If the fact that the record to be synchronized corresponding to the transaction identifier exists in the synchronization set is determined, executing any one of the following steps:
After a preset time length, determining each second target self-increment ID which has an association relation with the transaction identifier of the first transaction in the query request from the target data table, and acquiring and displaying a data row corresponding to each second target self-increment ID from the target data table;
Transmitting the record to be synchronized to a calculation layer or a storage layer of the second node, and indicating the calculation layer or the storage layer to determine a first self-increment ID of each data record to be inserted based on a starting value of the first self-increment ID in the record to be synchronized and a second self-increment ID of each data record to be inserted; for each data record to be inserted, combining the data record to be inserted and the first self-increment ID of the data record to be inserted to obtain a data row to be inserted; each row of data to be inserted is shown.
12. A self-increasing ID allocation apparatus, for use with a first node of a cluster of nodes of a distributed database, the apparatus comprising:
The first acquisition module is used for acquiring a first transaction to be submitted, wherein the first transaction aims at least one target data table; the data records in each data row of the target data table are provided with a first self-increment ID; the first transaction comprises at least one data record to be inserted, which corresponds to each target data table; each target data table is stored in at least one second node in the node cluster;
a first determining module, configured to determine, for each of the target data tables, a third node from the second nodes corresponding to the target data table in response to pre-submitting the first transaction to the corresponding second node; the third node is a node for storing the target data table for the first time in the at least one second node; the third node is recorded with a first target self-increment ID; the first target self-increment ID is the maximum value of the first self-increment ID of each data line in the target data table;
the first sending module is used for sending an application request to a third node corresponding to the target data table for each target data table, wherein the application request comprises a transaction identifier of the first transaction and the number of data records to be inserted corresponding to the target data table; the request is for requesting allocation of the number of first self-increment IDs to the target data table.
13. The self-increment ID allocation device is characterized by being applied to a third node in a node cluster of a distributed database, wherein the third node is a first node for storing a target data table in at least one second node; the target data table is stored in at least one second node in the node cluster; the third node is recorded with a first target self-increment ID; the data records in each data row of the target data table are provided with a first self-increment ID; the first target self-increment ID is the maximum value of the first self-increment ID of the data record in the target data table;
The device comprises:
The first receiving module is used for receiving an application request sent by a first node, wherein the application request comprises a transaction identifier of a first transaction and the number of data records to be inserted corresponding to the target data table; the application request is used for requesting to allocate the first self-increment IDs of the quantity to a target data table aiming at a first transaction characterized by the transaction identification; the application request is generated by the first node in response to pre-submission of a first transaction to be submitted, and the first transaction comprises at least one data record to be inserted corresponding to the target data table;
the initial value determining module is configured to, if it is determined that the target data table does not overflow after being inserted into the at least one data record to be inserted, use the first target self-increasing ID as an initial value of a first self-increasing ID of the at least one data record to be inserted;
The second sending module is used for sending an allocation indication message to each second node corresponding to the target data table, wherein the allocation indication message comprises a transaction identifier of the first transaction and a start value of the first self-increment ID; the allocation indication message is used for indicating that a first self-increment ID is allocated to at least one data record to be inserted, which is contained in the first transaction, based on the initial value of the first self-increment ID.
14. The self-increment ID distribution device is characterized by being applied to any one second node of a distributed database node cluster, wherein a target data table is stored in the second node; the data records in each data row of the target data table are provided with a first self-increment ID;
The device comprises:
the pre-commit response module is used for responding to pre-commit of a first node to a first transaction, and storing a transaction identifier of the first transaction, at least one data record to be inserted for the target data table contained in the first transaction and a second self-increment ID of each data record to be inserted; wherein the second self-increment ID is a self-increment ID allocated for the data record to be inserted in the first transaction;
the second receiving module is used for receiving an allocation indication message sent by a third node, wherein the allocation indication message comprises a transaction identifier of the first transaction and a start value of the first self-increment ID; the allocation indication message is used for indicating that a first self-increment ID is allocated to at least one data record to be inserted, which is contained in the first transaction, based on the initial value of the first self-increment ID;
A second determining module, configured to determine, in response to the allocation indication message, a first self-increment ID of each to-be-inserted data record based on a start value of the first self-increment ID and a second self-increment ID of each to-be-inserted data record included in the transaction identifier; and/or
A third determining module, configured to determine a pre-commit time of pre-committing a first transaction, store, as a to-be-synchronized record, a transaction identifier of the first transaction, a start value of the first self-increment ID, a number of at least one to-be-inserted data record for the target data table in the first transaction, and the pre-commit time to a synchronization set in advance, so that when a background of the distributed database periodically accesses the second node, the background asynchronously reads the synchronization set, determines a first self-increment ID of each to-be-inserted data record, and informs the second node;
the inserting module is used for inserting at least one new data row into the target data table, wherein each new data row comprises a data record to be inserted and a first self-increment ID corresponding to the data record to be inserted;
And the submitting module is used for submitting the first transaction if the fact that all the data records to be inserted aiming at the target data table are inserted into the target data table is determined in the first transaction.
15. A self-increasing ID assigning apparatus for use in the background of a distributed database, the apparatus comprising:
The access module is used for periodically accessing each second node in the node cluster of the distributed database; the second node stores a target data table, and data records in each data row of the target data table are provided with a first self-increment ID; the second node also stores transaction identifications of each pre-submitted first transaction, at least one data record to be inserted in the target data table and a second self-increment ID of each data record to be inserted;
The reading module is used for reading the synchronous set of the second nodes for each second node in the current period; the synchronization set comprises at least one record to be synchronized, wherein each record to be synchronized comprises a transaction identifier of a first transaction, a starting value of the first self-increment ID and a pre-commit time of pre-committing the first transaction;
a fourth determining module, configured to determine, from the synchronization set, a transaction identifier of each first transaction in a previous cycle at a pre-commit time, and determine at least one to-be-inserted data record corresponding to the transaction identifier and a second self-increment ID of each to-be-inserted data record;
a fifth determining module, configured to determine, for each data record to be inserted, a first self-increment ID of each data record to be inserted based on a start value of a first self-increment ID corresponding to a transaction identifier of the first transaction and a second self-increment ID of the data record to be inserted;
And the informing module is used for informing the second node of the first self-increment ID of each data record to be inserted.
16. An electronic device comprising a memory, a processor and a computer program stored on the memory, characterized in that the processor executes the computer program to implement the steps of the method of any one of claims 1-2, 3-5, 6-7 and 8-11.
17. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, carries out the steps of the method according to any one of claims 1-2, 3-5, 6-7 and 8-11.
CN202311094319.0A 2023-08-28 2023-08-28 Self-increment ID allocation method and device, electronic equipment and readable storage medium Active CN117112585B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311094319.0A CN117112585B (en) 2023-08-28 2023-08-28 Self-increment ID allocation method and device, electronic equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311094319.0A CN117112585B (en) 2023-08-28 2023-08-28 Self-increment ID allocation method and device, electronic equipment and readable storage medium

Publications (2)

Publication Number Publication Date
CN117112585A CN117112585A (en) 2023-11-24
CN117112585B true CN117112585B (en) 2024-08-02

Family

ID=88805220

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311094319.0A Active CN117112585B (en) 2023-08-28 2023-08-28 Self-increment ID allocation method and device, electronic equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN117112585B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110968589A (en) * 2019-12-18 2020-04-07 浙江明度智控科技有限公司 Self-adding ID management method and device in distributed system
CN112395284A (en) * 2019-08-15 2021-02-23 阿里巴巴集团控股有限公司 Data processing method and device, database system, electronic equipment and storage medium

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB201812375D0 (en) * 2018-07-30 2018-09-12 Ibm Updating a table using incremental and batch updates
CN116319766A (en) * 2021-12-20 2023-06-23 迈普通信技术股份有限公司 Distributed ID generation method and device, electronic equipment and storage medium

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112395284A (en) * 2019-08-15 2021-02-23 阿里巴巴集团控股有限公司 Data processing method and device, database system, electronic equipment and storage medium
CN110968589A (en) * 2019-12-18 2020-04-07 浙江明度智控科技有限公司 Self-adding ID management method and device in distributed system

Also Published As

Publication number Publication date
CN117112585A (en) 2023-11-24

Similar Documents

Publication Publication Date Title
US9317555B2 (en) Query method for a distributed database system and query apparatus
CN104598459B (en) database processing, data access method and system
US10599677B2 (en) Methods and systems of splitting database indexes and digests
CN111190935B (en) Data reading method and device, computer equipment and storage medium
CN107870954B (en) Method and device for expanding distributed database
JP7549137B2 (en) Transaction processing method, system, device, equipment, and program
CN112231070B (en) Data writing and reading method, device and server
US11720429B2 (en) Optimizing logging of decision outcomes in distributed transactions
CN103886109A (en) Method and device for realizing row lock of database
US6687798B1 (en) Methods for intra-partition parallelism for inserts
CN107122354B (en) Transaction execution method, device and system
CN113495872A (en) Transaction processing method and system in distributed database
US7574439B2 (en) Managing a nested request
JPH05128072A (en) Inter-system exclusive control system
CN117112585B (en) Self-increment ID allocation method and device, electronic equipment and readable storage medium
CN101344882A (en) Data query method, insertion method and deletion method
CN114185991A (en) Method and related device for realizing data synchronization based on distributed database
CN109901914B (en) Transaction processing method, device and equipment
Pankowski Consistency and availability of Data in replicated NoSQL databases
CN115629822A (en) Concurrent transaction processing method and system based on multi-core processor
CN111061759A (en) Data query method and device
CN116974983A (en) Data processing method, device, computer readable medium and electronic equipment
CN110399354B (en) Partition exchange method and device for database
Kumar Madria et al. A multi-version transaction model to improve data availability in mobile computing
CN110874382B (en) Data writing method, device and equipment thereof

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
GR01 Patent grant
GR01 Patent grant