Data processing method, device, electronic device, storage medium and program product
The method addresses the issue of long locking times during primary key changes by managing data table states to enable online changes, ensuring stable database performance and data integrity.
Patent Information
- Application Number
- CN202411391331.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2044-09-30
AI Technical Summary
Traditional methods for modifying clustered primary keys in databases result in long locking times, causing service unavailability and reduced database performance, especially with large data volumes.
A data processing method that involves setting the processing state of a data table to different states (first and second states) to allow re-encoding and writing data into a target table, updating based on change data, and completing the primary key change only when all transactions are finished, thereby avoiding table locking.
Enables online primary key changes without business interruption, ensuring stable database performance by reducing conflicts and maintaining data integrity through conflict detection and version management.
Smart Images

Figure CN118885497B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of database recovery, and in particular to a data processing method, device, electronic device, storage medium and program product. Background Art
[0002] With the development of computer technology, databases have been used more and more widely. In the process of storing data, databases or data processing systems usually use relational models to represent an entity object with a row of records, or object storage methods. In order to distinguish each object, a unique identifier is usually set for each object. In the database, the unique identifier used to distinguish a group of records of the same type is called the primary key. In order to improve the efficiency of finding and modifying objects, we usually store data in the table in the order of the primary key when storing data. This type of primary key is also called a clustered primary key.
[0003] Usually, when a clustered primary key needs to be modified on a traditional database, the table needs to be locked. After the switch between the old and new tables is completed, the lock is released. However, when the amount of data in the database table is large, such as tens of millions, the locking time of the database table may be long, causing services related to the database table to be unavailable for a long time, reducing database performance. Summary of the invention
[0004] The embodiments of the present disclosure provide a data processing method, device, electronic device, computer-readable storage medium, and computer program product, which aim to solve the technical problem in the prior art that the table needs to be locked during the primary key change process, resulting in low database performance.
[0005] In a first aspect, a data processing method is provided, the method comprising:
[0006] Receive a primary key change command for a data table to be processed; the primary key change command includes target primary key information to be changed in the data table to be processed;
[0007] Based on the target primary key information, a target data table is generated, and the processing state of the data table to be processed is set to the first state; the first data corresponding to the target primary key information in the data table to be processed is re-encoded and written into the target data table;
[0008] When the first data is written into the target data table, the processing state of the data table to be processed is set to the second state; first change data during the period when the processing state of the data table to be processed is in the first state is obtained, and the target data table is updated based on the first change data;
[0009] If the first changed data update is completed, and it is detected that all transactions on the pending data table are completed, the primary key change for the pending data table is completed.
[0010] Optionally, the method further includes:
[0011] If the processing state of the data table to be processed is in the first state, sequentially scan the data in the data table to be processed, and use the scanned data as recordable data;
[0012] If a data change request for the data table to be processed is detected, obtaining second data and change information based on the data change request; the second data includes original data before the change;
[0013] If the recordable data includes the second data, corresponding first change data is generated based on the second data and the change information.
[0014] Optionally, after obtaining the first change data when the processing state of the to-be-processed data table is in the first state, the method further includes:
[0015] Mark the first changed data as a first version; the first version is used to indicate that the first changed data has not been written into the target data table;
[0016] Updating the target data table based on the first changed data includes:
[0017] The target data table is updated based on the first target data marked as the first version in the first change data, and the first target data updated in the target data table is marked as the second version.
[0018] Optionally, if the first changed data is updated and it is detected that all transactions on the pending data table are completed, the method further includes:
[0019] The processing state of the data table to be processed is updated to a third state; the third state is used to indicate that the data in the data table to be processed is no longer updated;
[0020] Acquire second change data during a period in which the processing state of the to-be-processed data table is in a second state;
[0021] The target data table is updated based on the second changed data to complete the primary key change for the data table to be processed.
[0022] Optionally, obtaining second change data during a period in which the processing state of the to-be-processed data table is in a second state includes:
[0023] Acquire a first change operation on the data table to be processed and a second change operation on the target data table during a period in which the processing state of the data table to be processed is in the second state;
[0024] generating first record data based on the first change operation, and generating second record data based on the second change operation;
[0025] The second change data is generated based on the first record data and the second record data.
[0026] Optionally, generating the second change data based on the first record data and the second record data includes:
[0027] storing the first record data and the second record data in a preset record table;
[0028] Determine first synchronization data based on the first record data and the data stored in the preset record table;
[0029] Determine second synchronization data based on the second record data and the data stored in the preset record table;
[0030] The second change data is generated based on the first synchronization data and the second synchronization data.
[0031] Optionally, the method further includes:
[0032] Marking the first recorded data as a first source; marking the second recorded data as a second source;
[0033] Determining first synchronization data based on the first record data and data stored in a preset record table includes:
[0034] Determine whether there is third record data matching the first record data in the preset record table;
[0035] If it does not exist, the first recorded data is used as the first synchronization data;
[0036] If it exists, and the third recorded data is marked as the second source, determine the timestamp corresponding to the first recorded data and the timestamp corresponding to the third recorded data; and use the recorded data corresponding to the timestamp closest to the current time as the first synchronization data.
[0037] Optionally, determining the second synchronization data based on the second record data and the data stored in the preset record table includes:
[0038] Determine whether there is fourth record data matching the second record data in the preset record table;
[0039] If it does not exist, the second recorded data is used as the second synchronization data;
[0040] If it exists, and the fourth record data is marked as the first source, determine the timestamp corresponding to the second record data and the timestamp corresponding to the fourth record data; and use the record data corresponding to the timestamp closest to the current time as the second synchronization data.
[0041] In a second aspect, a data processing device is provided, the device comprising:
[0042] A command receiving module, used for receiving a primary key change command for a data table to be processed; the primary key change command includes target primary key information to be changed in the data table to be processed;
[0043] A first state module is used to generate a target data table based on the target primary key information, and set the processing state of the data table to be processed to the first state; re-encode the first data corresponding to the target primary key information in the data table to be processed and write it into the target data table;
[0044] A second state module is used to set the processing state of the data table to be processed to the second state when the first data is written into the target data table; obtain the first change data during the period when the processing state of the data table to be processed is in the first state, and update the target data table based on the first change data;
[0045] The change module is used to complete the primary key change for the data table to be processed if the first change data update is completed and it is detected that all transactions on the data table to be processed are completed.
[0046] In a third aspect, an electronic device is provided, the electronic device comprising:
[0047] A memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of any one of the methods in the first aspect of the present disclosure.
[0048] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, characterized in that when the computer program is executed by a processor, the data processing method shown in any one of the first aspects of the present disclosure is implemented.
[0049] In a fifth aspect, a computer program product is provided, comprising a computer program, characterized in that when the computer program is executed by a processor, the steps of any one of the methods in the first aspect of the present disclosure are implemented.
[0050] The technical solution provided by the embodiments of the present disclosure brings the following beneficial effects:
[0051] The data processing method provided by the present disclosure receives a primary key change command for a data table to be processed, obtains target primary key information, generates a target data table based on the target primary key information, sets the processing state of the data table to be processed to a first state, re-encodes the first data corresponding to the target primary key information in the data table to be processed and writes it into the target data table, when the first data is completely written into the target data table, sets the processing state of the data table to be processed to a second state, obtains first change data during the period when the processing state of the data table to be processed is in the first state, updates the target data table based on the first change data, completes the primary key change for the data table to be processed if the first change data is updated and the transactions on the data table to be processed are all completed, performs different data processing in different processing states by setting the processing state of the data table to be processed, writes the first data into the target data table in the first state, and updates the change data in the first state on the target data table in the second state, realizes the online primary key change of the database table, avoids the business interruption caused by locking the data table, can ensure the normal execution of the business, and makes the performance of the database system more stable.
[0052] Furthermore, when the first changed data is updated to the target data table in the second state, new data changes will continue to occur. The first record data is generated based on the first change operation, and the second record data is generated based on the second change operation. The data version and data source of the first record data and the second record data are judged, and the second change data is generated based on the record data that meets the requirements. The target data table is updated based on the second change data during the second state. When the changed data of the first state is updated to the target data table, the changed data of the second state can also be updated to the target data table through conflict detection, so as to avoid data errors caused by the simultaneous modification of one data in the two tables in the second state, reduce data conflicts, and make the database system performance more stable. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure, the drawings required for describing the embodiments of the present disclosure are briefly introduced below.
[0054] Figure 1 A schematic diagram of an application scenario of a data processing method provided by an embodiment of the present disclosure;
[0055] Figure 2 A flowchart of a data processing method provided by an embodiment of the present disclosure;
[0056] Figure 3 A schematic diagram of a preset record table in a data processing method provided in an embodiment of the present disclosure;
[0057] Figure 4A flowchart of an example of a data processing method provided in an embodiment of the present disclosure;
[0058] Figure 5 A schematic diagram of the structure of a data processing device provided in an embodiment of the present disclosure;
[0059] Figure 6 A schematic diagram of the structure of an electronic device applicable to a data processing method provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0060] The embodiments of the present disclosure are described below in conjunction with the drawings in the present disclosure. It should be understood that the implementation methods described below in conjunction with the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present disclosure and do not constitute a limitation on the technical solutions of the embodiments of the present disclosure.
[0061] It will be understood by those skilled in the art that, unless specifically stated, the singular forms "one", "an", "said" and "the" used herein may also include plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present disclosure refer to that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements and / or components, but do not exclude the implementation as other features, information, data, steps, operations, elements, components and / or combinations thereof supported by the technical field. It should be understood that when we say that an element is "connected" or "coupled" to another element, the one element may be directly connected or coupled to the other element, or it may refer to that the one element and the other element establish a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The terms "or", "and / or", "including at least one of the following" used in the present disclosure may be interpreted as inclusive, or mean any one or any combination. For example, “including at least one of the following: A, B, C” means “any of the following: A; B; C; A and B; A and C; B and C; A and B and C” and, for example, “A, B or C” or “A, B and / or C” means “any of the following: A; B; C; A and B; A and C; B and C; A and B and C”.
[0062] In order to make the objectives, technical solutions and advantages of the present disclosure more clear, the embodiments of the present disclosure will be further described in detail below with reference to the accompanying drawings.
[0063] First, the technical terms involved in this disclosure are introduced and explained:
[0064] Primary key: In a database, a unique identifier used to distinguish a group of records of the same type is called a primary key. Usually, in order to improve the efficiency of finding and modifying objects, we store data in the table in the order of primary keys. This type of primary key is also called a clustered primary key. In actual application, in order to adapt to changes in business logic, optimize database performance, and ensure the uniqueness and integrity of data, it is necessary to modify the primary key.
[0065] Usually, if a clustered primary key needs to be modified on a traditional database, it is necessary to first lock the write operation on the table, then read the data into a new table created according to the new primary key rule, lock the table after completion, and then rename the new table to the old table name, delete the old table and release the lock before the user can modify the data in the table. However, this solution for modifying the primary key has brought great obstacles to the normal use of user services, because the table needs to be locked during the operation, and user services cannot be performed normally. As the amount of data increases, the length of time that the above solution requires users to suspend their services becomes unacceptable to users.
[0066] Another solution is to start scanning the table data at time T1 and sort the data in the new table according to the new primary key. At time T2, all table records are scanned and the log data is started from time T1 and updated in the new table. At a certain time, the table is locked and the last log is chased. The name change of the old and new tables is completed and the lock is released. However, this solution may still cause the old table to fail to reach a certain time because the log update exceeds the speed of chasing logs, resulting in the inability to carry out user business.
[0067] The data processing method, device, electronic device, computer-readable storage medium, and computer program product provided by the present disclosure are intended to solve at least one of the above technical problems in the prior art.
[0068] In view of at least one of the above-mentioned technical problems or areas that need improvement in the related art, the present disclosure proposes a data processing method, device, electronic device and computer storage medium. The data processing method provided by the scheme receives a primary key change command for a data table to be processed, obtains target primary key information, generates a target data table based on the target primary key information, sets the processing state of the data table to be processed to a first state, re-encodes the first data corresponding to the target primary key information in the data table to be processed and writes it to the target data table. When the first data is completed being written into the target data table, the processing state of the data table to be processed is set to a second state, and the data to be processed is obtained. The processing state of the table is the first change data during the first state, and the target data table is updated based on the first change data. If the first change data update is completed and the transactions on the data table to be processed are completed, the primary key change for the data table to be processed is completed. By setting the processing state of the data table to be processed, different data processing is performed under different processing states. In the first state, the first data is written to the target data table, and in the second state, the change data in the first state is updated on the target data table, so as to realize the online primary key change of the database table, avoid business interruption caused by locking the data table, ensure the normal execution of the business, and make the database system performance more stable.
[0069] Furthermore, when the first changed data is updated to the target data table in the second state, new data changes will continue to occur. The first record data is generated based on the first change operation, and the second record data is generated based on the second change operation. The data version and data source of the first record data and the second record data are judged, and the second change data is generated based on the record data that meets the requirements. The target data table is updated based on the second change data during the second state. When the changed data of the first state is updated to the target data table, the changed data of the second state can also be updated to the target data table through conflict detection, so as to avoid data errors caused by the simultaneous modification of one data in the two tables in the second state, reduce data conflicts, and make the database system performance more stable.
[0070] The following describes several exemplary embodiments to illustrate the technical solutions of the embodiments of the present disclosure and the technical effects produced by the technical solutions of the present disclosure. It should be noted that the following embodiments can refer to, draw on or combine with each other, and the same terms, similar features and similar implementation steps in different embodiments will not be described repeatedly.
[0071] Figure 1 A schematic diagram of an application scenario of the data processing method provided in an embodiment of the present disclosure, wherein the application environment may be included in a terminal 101, and a database system for managing data table changes may be installed on the terminal 101.
[0072] Specifically, the database system in the terminal 101 receives a primary key change command for a data table to be processed, the primary key change command includes target primary key information to be changed in the data table to be processed, generates a target data table based on the target primary key information, and sets the processing status of the data table to be processed to a first status, re-encodes the first data corresponding to the target primary key information in the data table to be processed and writes it into the target data table, and when the first data is completely written into the target data table, sets the processing status of the data table to be processed to a second status, obtains first change data during the period when the processing status of the data table to be processed is in the first status, updates the target data table based on the first change data, and if the first change data update is completed and it is detected that all transactions on the data table to be processed are completed, the primary key change for the data table to be processed is completed.
[0073] The above application scenario is only an example and does not limit the application scenario of the functional testing method disclosed in the present invention.
[0074] Technicians in this technical field can understand that the terminal can be a smart phone (such as Android phone, iOS phone, etc.), a tablet computer, a laptop computer, a digital broadcast receiver, a MID (Mobile Internet Devices), a PDA (Personal Digital Assistant), a desktop computer, a smart home appliance, a vehicle-mounted terminal (such as a vehicle-mounted navigation terminal, a vehicle-mounted computer, etc.), a smart speaker, a smart watch, etc. The terminal and the server can be directly or indirectly connected via wired or wireless communication, but is not limited to this.
[0075] The server may include a server that is installed with a computer capable of processing database operations. The server may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It may also be a cloud server or server cluster that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The embodiments of the present invention can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, assisted driving, etc. The specific requirements can also be determined based on the actual application scenario requirements, which is not limited here.
[0076] In some possible implementations, taking the execution subject as a database system as an example, the embodiment of the present disclosure provides a data processing method, such as Figure 2 As shown, the following steps may be included:
[0077] S201, receiving a primary key change command for a data table to be processed.
[0078] The primary key change command includes target primary key information to be changed in the data table to be processed.
[0079] The data table to be processed includes a database table that needs to have its primary key changed; the primary key change command may be uploaded by a user to the database system, including the correspondence between the data and the new target primary key.
[0080] Specifically, a primary key change command is received, and based on the primary key change command uploaded by the user, a pending data table that needs to have its primary key modified is determined, and target primary key information to be changed in the pending data table is determined, including data corresponding to the target primary key and the target primary key.
[0081] In the specific implementation process, after receiving the primary key change command for the data table to be processed from the user, check the syntax, semantics, permissions and other information. Among them, checking the syntax includes using the database client or management tool to confirm whether the statement has an error prompt; checking the semantics includes: confirming whether the new primary key field name is correct, confirming whether the new primary key field exists in the table, and checking whether the new primary key field contains unique values and has no NULL values, checking whether there are other tables that depend on the primary key of the current table through foreign keys, and confirming whether the foreign key relationship is still valid after the primary key is changed; checking permissions includes: confirming whether the database user who performs the operation has the permission to modify the table structure. After confirming that the above syntax, semantics and permissions are correct, you can continue to perform the primary key change operation. If any check fails, you should solve the corresponding problem before performing the primary key change operation.
[0082] S202, based on the target primary key information, generate a target data table, and set the processing state of the data table to be processed to the first state; re-encode the first data corresponding to the target primary key information in the data table to be processed and write it into the target data table.
[0083] The first state may be used to indicate that a new data table created according to a target primary key has been successfully created, and may also be used to indicate that subsequent data changes in the data table to be processed need to be recorded.
[0084] Specifically, after obtaining the target primary key information, the target data table is defined and created according to the target primary key information. After the creation is completed, the processing status of the data table to be processed is set to the first status. In the first status, the data in the data table to be processed containing the original data needs to be transferred to the target data table. For the first data in the data table to be processed corresponding to the target primary key information, the first data is re-encoded according to the target primary key information, and the re-encoded first data is written into the target data table. For the data without primary key change, it can also be rearranged according to the primary key arrangement order in the target primary key information and written into the target data table.
[0085] In the specific implementation process, the database system may include a stand-alone database and a distributed database. For a stand-alone database, the data table to be processed in this process can be set to the first state. For a distributed database, it is required that the data tables to be processed of all nodes are set to the first state before entering the first state. The above judgment on the first state also applies to the subsequent second state and third state.
[0086] In the specific implementation process, when the data table to be processed is in the first state, there will only be data changes in the data table to be processed. At this time, a simple conflict detection can be performed on the data table to be processed; after the processing state of the data table to be processed is set to the first state, the data in the data table to be processed can be scanned at a preset timestamp, and each row of data can be scanned in turn, and the scanned data can be marked as scanned, that is, the recordable data below. For the data that has been scanned, it is possible to start recording the data changes generated during the period when the data table to be processed is in the first state. Such processing can reduce the amount of recorded change data and reduce resource usage. Among them, the preset timestamp can be a time point after the first state and before the second state.
[0087] S203, when the first data is written into the target data table, the processing state of the data table to be processed is set to the second state; first change data during the period when the processing state of the data table to be processed is in the first state is obtained, and the target data table is updated based on the first change data.
[0088] The second state is used to indicate that the original data in the to-be-processed data table has been scanned and written into the new target data table. The first changed data has the same format as the data in the target data table.
[0089] Specifically, when the first data is completed written into the target data table, the processing state of the data table to be processed is set to the second state. After entering the second state, the first change data generated during the first state can be replayed on the target data table, that is, the target data table is updated based on the first change data.
[0090] In the specific implementation process, when the processing state of the data table to be processed is in the first state, the data change operation on the data table to be processed is recorded to obtain the first change data. When the processing state is in the second state, the data can be updated on the target data table based on the recorded first change data, wherein the first change data can be recorded in the form of a data table, and each first change data in the data table is provided with version information, indicating whether each data has been updated in the target data table. The version information of each recorded data will be initialized to the first version, indicating that the data has not been updated to the target data table. When a first change data is updated, the version information corresponding to the first change data is updated to the second version, indicating that the data has been updated to the target data table. By setting the version information to indicate whether the first change data has been updated, the data can be updated to the target data table more stably and continuously, and will not slow down due to the increase in data volume, and the update speed is relatively stable.
[0091] S204: If the first changed data is updated and it is detected that all transactions on the pending data table are completed, the primary key change for the pending data table is completed.
[0092] Among them, a transaction is composed of at least one operation, so the transaction also corresponds to at least one piece of data. When all corresponding operations and data changes are completed, the transaction can be committed, that is, the transaction is completed.
[0093] Specifically, if the first changed data updates the target data table, and it is detected that all transactions on the data table to be processed are completed or ended, the processing status of the data table to be processed can be set to the third state. It can be considered that all transactions and data changes in the third state are performed on the new target data table. After setting the processing status to the third state, the target data table can be renamed to the name of the data table to be processed, and the original table can be deleted. In this way, the primary key change for the data table to be processed is completed.
[0094] In the specific implementation process, since the transaction corresponding to the data in the data table to be processed may be a long transaction, after the data is written to the target data table in the first state and the second state and the first change data is updated to the target data table, the transaction on the data table to be processed has not been committed or rolled back. Therefore, it is necessary to determine whether the data and transactions on the data table to be processed are completed. After the data and transactions on the data table to be processed are completed, the processing state of the data to be processed is converted to the third state. After that, the target data table can be renamed, and the user can see the new table structure and process it. In this way, the primary key change for the data table to be processed is completed.
[0095] In some possible implementations, the above method further includes:
[0096] (1) If the processing state of the data table to be processed is in the first state, the data in the data table to be processed are scanned in sequence, and the scanned data are used as recordable data;
[0097] (2) If a data change request for the data table to be processed is detected, obtaining the second data and change information based on the data change request;
[0098] (3) If the recordable data includes the second data, generating corresponding first change data based on the second data and the change information.
[0099] The second data may include original data before the change; the change information may include relevant information of the change operation on the second data, for example, if the original data is 1, the change information may be plus 1, and the changed data may be 2.
[0100] The second data may indicate which data has been changed, and the change information may indicate what kind of change operation has been performed on the data.
[0101] Specifically, if the processing state of the table to be processed is the first state, the data in the data table to be processed is scanned in sequence, and re-encoded and written into the target data table based on the target primary key information. In this process, the data in the data table to be processed forms recordable data after scanning, and a mark can be set on the corresponding recordable data, which is used to indicate that the data has been scanned. During the first state, if a data change request for the data table to be processed is detected, the corresponding second data and change information are obtained according to the data change request, and it is determined whether the recordable data contains the second data. If it does, the first change data is generated based on the second data and the corresponding change information. If it does not, the first change data is not generated, and the data is changed directly in the data table to be processed. The present disclosure generates the first change data based on the scanned second data and the corresponding change information to record data changes, which can reduce the amount of recorded data, reduce the burden on system resources, and speed up the change process of the data table.
[0102] During the specific implementation process, the data in the data table to be processed is scanned in sequence, and re-encoded and written into the target data table based on the target primary key information. Among them, the data encoded according to the new target primary key information can be inserted into the new target data table in a transactional manner, or written into the target data table in a batch writing manner.
[0103] In the specific implementation process, Figure 3As shown, if a data change request for the data table to be processed is detected, the second data and its change information are obtained based on the data table change request, and the second data is matched with the recordable data. If the recordable data includes the second data, the first change data is generated based on the second data and the corresponding change information and recorded, wherein the first change data can be converted into a new record format and saved in a preset record table, and the new record format can be the corresponding table format of the target data table. The data in the data table to be processed may include target primary key information (i.e., the new primary key shown in the figure), record information and a deletion mark, wherein the deletion mark is used to indicate whether the data has been deleted.
[0104] In some possible implementations, after obtaining the first change data of the processing state of the to-be-processed data table being in the first state, the method further includes:
[0105] (1) Mark the first changed data as the first version;
[0106] Updating the target data table based on the first changed data includes:
[0107] (2) The target data table is updated based on the first target data marked as the first version in the first change data, and the first target data updated in the target data table is marked as the second version.
[0108] The first version is used to indicate that the first changed data has not yet been written into the target data table.
[0109] Specifically, when generating the first change data, since during the first state, the user's data modification of the table is performed on the data table to be processed, the first data change comes from the data table to be processed, and it is necessary to update the first change data on the data table to be processed to the target data table during the second state. When generating the first change data, each piece of data is marked as the first version, indicating that it has not been updated to the target data table. The target data table is updated based on the first change data of the first version, and the updated first change data is marked as the second version, indicating that the data has been updated.
[0110] During the specific implementation process, when the first change data is generated and converted into a new record format for storage, the first change data is marked as the first version. When the first change data is played back in the target data table in the second state, the target data table is updated based on the first change data of the first version. The first change data that is not the first version does not need to be updated. This solution can maintain a relatively stable speed to complete the playback of the change data under high load or low load conditions.
[0111] In some possible implementations, if the first changed data is updated and it is detected that all transactions on the to-be-processed data table are completed, the method further includes:
[0112] (1) updating the processing state of the data table to be processed to a third state; the third state is used to indicate that the data in the data table to be processed is no longer updated;
[0113] (2) obtaining second change data during a period in which the processing state of the to-be-processed data table is in the second state;
[0114] (3) Update the target data table based on the second change data to complete the primary key change for the data table to be processed.
[0115] Specifically, if the first change data is updated in the target data table and all transactions on the data table to be processed are completed, the processing status of the data table to be processed can be set to the third state, indicating that the data and transactions in the data table to be processed are no longer updated, and all data changes and updates are performed on the target data table. The second change data during the period when the processing status of the data table to be processed is in the second state can be obtained, and the target data table is updated based on the second change data, thereby completing the primary key change for the data table to be processed.
[0116] During the specific implementation process, when the processing status of the data table to be processed is in the second state, when a change occurs during the second state, the second change data of the processing status of the data table to be processed during the second state can be obtained in real time during the process of synchronizing the first change data to the target data table, and the target data table can be updated based on the obtained second change data. The update here also requires conflict detection.
[0117] In the specific implementation process, the above method also includes: modifying the table name of the target data table to the table name of the data table to be processed, deleting the data table to be processed, and completing the primary key change, so that the user can know the primary key structure of the new table.
[0118] In some possible implementations, obtaining second change data during a period in which the processing state of the to-be-processed data table is in the second state includes:
[0119] (1) acquiring a first change operation on the data table to be processed and a second change operation on the target data table during a period in which the processing state of the data table to be processed is in the second state;
[0120] (2) generating first record data based on the first change operation, and generating second record data based on the second change operation;
[0121] (3) Generating second change data based on the first record data and the second record data.
[0122] When the processing state of the data table to be processed is in the second state, no new transactions are added to the data table to be processed, existing unfinished transactions continue to be updated until the transactions are completed, and new transactions are all performed in the target data table.
[0123] Specifically, while the processing status of the pending data table is in the second state, newly started transactions are no longer recorded on the pending data table, but the long transaction in the pending data table is still in progress. Before the long transaction is committed or rolled back, the user will also perform data change operations on the pending data table. At this time, the operation is recorded, that is, based on the first change operation on the pending data table, first record data is generated. During the second state, new transactions can be added and changed on the target data table. Based on the second change operation on the target data table, second record data is generated, and second change data is generated based on the first record data and the second record data.
[0124] In the specific implementation process, when the processing state of the pending data table is in the second state, the newly started user transactions are all processed on the target data table, but the user still knows the primary key and format of the pending data table at this time, so it is necessary to convert the data changes submitted by the user into the format corresponding to the pending data table. In addition, before the second record data is updated on the target data table, it is necessary to perform conflict detection on the second record data to obtain the second change data. The detailed method of conflict detection is described later.
[0125] In some possible implementations, generating the second change data based on the first record data and the second record data includes:
[0126] (1) storing the first record data and the second record data in a preset record table;
[0127] (2) determining first synchronization data based on the first record data and the data stored in the preset record table;
[0128] (3) determining second synchronization data based on the second record data and the data stored in the preset record table;
[0129] (4) Generate second change data based on the first synchronization data and the second synchronization data.
[0130] Specifically, the preset record table will store the first record data and the second record data during the second state of the data table to be processed. When the target data table needs to be updated with the first record data and the second record data, conflict detection is performed: the first synchronization data is determined based on the first record data and the data stored in the preset record table, and the second synchronization data is determined based on the second record data and the data stored in the preset record table; the first synchronization data and the second synchronization data obtained after the conflict detection are used as data that can be updated to the target data table to generate second change data.
[0131] During the specific implementation process, when the processing status of the data table to be processed is in the second state, the format of the generated first record data can be the data format of the data table to be processed; when the transaction corresponding to the first record data is submitted on the data table to be processed, a submission record is generated, and the submission record is updated to the target data table to achieve synchronization of transaction submission.
[0132] In the specific implementation process, Figure 3 As shown, the format of the first record data and the second record data stored in the preset record table can be an old record format, which includes the primary key information in the data table to be processed (i.e., the old primary key shown in the figure), record content and deletion mark. Using the preset record table for conflict detection can avoid conflicts caused by concurrent modifications to the same data on two data tables without affecting the performance of the database system.
[0133] In some possible implementations, the method further includes:
[0134] (1) Mark the first recorded data as the first source; mark the second recorded data as the second source;
[0135] Determining first synchronization data based on the first record data and data stored in a preset record table includes:
[0136] (2) determining whether there is third record data matching the first record data in the preset record table;
[0137] (3) If it does not exist, the first recorded data is used as the first synchronization data;
[0138] (4) If it exists, and the third recorded data is marked as the second source, determine the timestamp corresponding to the first recorded data and the timestamp corresponding to the third recorded data; and take the recorded data corresponding to the timestamp closest to the current time as the first synchronization data.
[0139] The first source is used to indicate that the first record data is from the data table to be processed, and the first source and the second source can become source marks of the data.
[0140] Specifically, when storing the first record data in the preset record table, the first record data is marked as the first source. Before determining the first synchronization data to update the target data table, the first record data can be matched with the existing records in the preset record table to determine whether there is third record data matching the first record data in the preset record table. If not, the first record data is used as the first synchronization data. If it does exist, and the third record data is marked as the second source, that is, the third record data and the first record data are not change operations submitted on the same table, then the timestamp corresponding to the first record data and the timestamp corresponding to the third record data are determined, and the timestamp closest to the current time, that is, the latest record data, is used as the first synchronization data to update the target data table.
[0141] In the specific implementation process, the database transactions submitted on the pending data table need to be subject to conflict detection, including optimistic transaction conflict detection and pessimistic transaction conflict detection. Among them, the optimistic transaction conflict detection includes: when the transaction is submitted, the submitted items are conflict detected. If there is no conflict, the transaction is successfully submitted or rolled back, and the source mark of the submitted item is determined. If the source mark is the first source, indicating that the transaction is submitted on the pending data table, the submitted item is synchronized to the target data table; the pessimistic transaction conflict detection includes: when the transaction is submitted, the data record corresponding to the transaction is locked, and after submission, the submitted items are recorded and synchronized to the target data table to avoid conflicts.
[0142] In some possible implementations, determining the second synchronization data based on the second record data and the data stored in the preset record table includes:
[0143] (1) determining whether there is fourth record data matching the second record data in the preset record table;
[0144] (2) If it does not exist, the second recorded data is used as the second synchronization data;
[0145] (3) If it exists, and the fourth recorded data is marked as the first source, determine the timestamp corresponding to the second recorded data and the timestamp corresponding to the fourth recorded data; and use the recorded data corresponding to the timestamp closest to the current time as the second synchronization data.
[0146] The second source is used to indicate that the second record data is from the target data table.
[0147] Specifically, when storing the second record data in the preset record table, the second record data is marked as the second source. Before determining the second synchronization data to update the target data table, the second record data can be matched with the existing records in the preset record table to determine whether there is fourth record data matching the second record data in the preset record table. If not, the second record data is used as the second synchronization data. If it does, and the fourth record data is marked as the first source, that is, the fourth record data and the second record data are not change operations submitted on the same table, then the timestamp corresponding to the second record data and the timestamp corresponding to the fourth record data are determined, and the timestamp closest to the current time, that is, the latest record data, is used as the second synchronization data to update the target data table.
[0148] In the specific implementation process, when the processing status of the pending data table is in the second status, the database transaction submitted on the pending data table needs to be conflict detected, and the second synchronization data that passes the conflict detection can be used as the second change data to update the target data table.
[0149] In the above embodiment, by receiving a primary key change command for a data table to be processed, target primary key information is obtained, a target data table is generated based on the target primary key information, and the processing state of the data table to be processed is set to a first state, and the first data corresponding to the target primary key information in the data table to be processed is re-encoded and written into the target data table. When the first data is completed being written into the target data table, the processing state of the data table to be processed is set to a second state, and the first change data during the period when the processing state of the data table to be processed is in the first state is obtained, and the target data table is updated based on the first change data. If the first change data is updated and the transactions on the data table to be processed are completed, the primary key change for the data table to be processed is completed. By setting the processing state of the data table to be processed, different data processing is performed in different processing states. In the first state, the first data is written into the target data table, and in the second state, the change data in the first state is updated on the target data table, so as to realize the online primary key change of the database table, avoid business interruption caused by locking the data table, ensure the normal execution of the business, and make the performance of the database system more stable.
[0150] Furthermore, when the first changed data is updated to the target data table in the second state, new data changes will continue to occur. The first record data is generated based on the first change operation, and the second record data is generated based on the second change operation. The data version and data source of the first record data and the second record data are judged, and the second change data is generated based on the record data that meets the requirements. The target data table is updated based on the second change data during the second state. When the changed data of the first state is updated to the target data table, the changed data of the second state can also be updated to the target data table through conflict detection, so as to avoid data errors caused by the simultaneous modification of one data in the two tables in the second state, reduce data conflicts, and make the database system performance more stable.
[0151] In one example, the data processing method of the present disclosure, such as Figure 4 As shown, it may include:
[0152] Receive a primary key change command for a data table to be processed, where the primary key change command includes target primary key information to be changed in the data table to be processed;
[0153] Based on the target primary key information, a target data table is generated, and the processing state of the data table to be processed is set to a first state;
[0154] Re-encode the first data corresponding to the target primary key information in the data table to be processed and write it into the target data table (i.e., step 1 shown in the figure);
[0155] If the processing state of the data table to be processed is in the first state, the data in the data table to be processed are scanned in sequence, and the scanned data are used as recordable data; if it is detected that the second data in the data table to be processed has a data change, then based on the recordable data and the second data, corresponding first change data are generated (i.e., step 4 shown in the figure), wherein the format of the first change data is the format of the target data table (i.e., the new record format shown in the figure);
[0156] When the first data is completely written into the target data table, the processing state of the data table to be processed is set to the second state;
[0157] The target data table is updated based on the first change data (i.e., step 3 shown in the figure); if the first change data is updated, a first change operation on the data table to be processed during the period when the processing state of the data table to be processed is in the second state and a second change operation on the target data table are obtained, first record data is generated based on the first change operation, and second record data is generated based on the second change operation;
[0158] The first record data and the second record data are stored in a preset record table (i.e., step 2 shown in the figure), the format of the first record data may be a format of a data table to be processed (i.e., the old record format shown in the figure), first synchronization data is determined based on the first record data and the data stored in the preset record table, and second synchronization data is determined based on the second record data and the data stored in the preset record table; second change data is generated based on the first synchronization data and the second synchronization data, and the target data table is updated based on the second change data;
[0159] If the first changed data is updated and it is detected that all transactions on the pending data table are completed, the processing state of the pending data table is updated to a third state;
[0160] Rename the target data table to the table name of the data table to be processed, rename the data table to be processed to another table name, and delete the data table to be processed (i.e. the rename shown in the figure) to complete the primary key change for the data table to be processed.
[0161] The above-mentioned data processing method receives a primary key change command for a data table to be processed, obtains target primary key information, generates a target data table based on the target primary key information, sets the processing state of the data table to be processed to a first state, re-encodes the first data corresponding to the target primary key information in the data table to be processed and writes it into the target data table, when the first data is completed to be written into the target data table, sets the processing state of the data table to be processed to a second state, obtains the first change data during the period when the processing state of the data table to be processed is in the first state, updates the target data table based on the first change data, if the first change data is updated and the transactions on the data table to be processed are completed, completes the primary key change for the data table to be processed, and performs different data processing in different processing states by setting the processing state of the data table to be processed, writes the first data into the target data table in the first state, and updates the change data in the first state on the target data table in the second state, thereby realizing the online primary key change of the database table, avoiding the business interruption caused by locking the data table, ensuring the normal execution of the business, and making the performance of the database system more stable.
[0162] Furthermore, when the first changed data is updated to the target data table in the second state, new data changes will continue to occur. The first record data is generated based on the first change operation, and the second record data is generated based on the second change operation. The data version and data source of the first record data and the second record data are judged, and the second change data is generated based on the record data that meets the requirements. The target data table is updated based on the second change data during the second state. When the changed data of the first state is updated to the target data table, the changed data of the second state can also be updated to the target data table through conflict detection, so as to avoid data errors caused by the simultaneous modification of one data in the two tables in the second state, reduce data conflicts, and make the database system performance more stable.
[0163] The present disclosure provides a data processing device, such as Figure 5 As shown, the data processing device 50 may include: a command receiving module 501, a first state module 502, a second state module 503 and a change module 504, wherein:
[0164] The command receiving module 501 is used to receive a primary key change command for a data table to be processed; the primary key change command includes target primary key information to be changed in the data table to be processed;
[0165] The first state module 502 is used to generate a target data table based on the target primary key information, and set the processing state of the data table to be processed to the first state; re-encode the first data corresponding to the target primary key information in the data table to be processed and write it into the target data table;
[0166] The second state module 503 is used to set the processing state of the data table to be processed to the second state when the first data is written into the target data table; obtain the first change data during the period when the processing state of the data table to be processed is in the first state, and update the target data table based on the first change data;
[0167] The change module 504 is used to complete the primary key change for the data table to be processed if the first change data update is completed and it is detected that all transactions on the data table to be processed are completed.
[0168] As an optional embodiment, in the device, the changing module 504 is specifically used for:
[0169] If the processing state of the data table to be processed is in the first state, sequentially scan the data in the data table to be processed, and use the scanned data as recordable data;
[0170] If a data change request for the data table to be processed is detected, obtaining second data and change information based on the data change request; the second data includes original data before the change;
[0171] If the recordable data includes the second data, corresponding first change data is generated based on the second data and the change information.
[0172] As an optional embodiment, in the device, the second state module 503 is specifically used to:
[0173] After obtaining the first change data of the processing state of the to-be-processed data table being in the first state, the method further includes:
[0174] Mark the first changed data as a first version; the first version is used to indicate that the first changed data has not been written into the target data table;
[0175] Updating the target data table based on the first changed data includes:
[0176] The target data table is updated based on the first target data marked as the first version in the first change data, and the first target data updated in the target data table is marked as the second version.
[0177] As an optional embodiment, in the device, the changing module 504 is specifically used for:
[0178] If the first change data is updated and it is detected that all transactions on the pending data table are completed, the method further includes:
[0179] The processing state of the data table to be processed is updated to a third state; the third state is used to indicate that the data in the data table to be processed is no longer updated;
[0180] Acquire second change data during a period in which the processing state of the to-be-processed data table is in a second state;
[0181] The target data table is updated based on the second changed data to complete the primary key change for the data table to be processed.
[0182] As an optional embodiment, in the device, the changing module 504 is specifically used for:
[0183] Acquiring second change data when the processing state of the to-be-processed data table is in the second state includes:
[0184] Acquire a first change operation on the data table to be processed and a second change operation on the target data table during a period in which the processing state of the data table to be processed is in the second state;
[0185] generating first record data based on the first change operation, and generating second record data based on the second change operation;
[0186] The second change data is generated based on the first record data and the second record data.
[0187] As an optional embodiment, in the device, the changing module 504 is specifically used for:
[0188] Generating second change data based on the first record data and the second record data includes:
[0189] storing the first record data and the second record data in a preset record table;
[0190] Determine first synchronization data based on the first record data and the data stored in the preset record table;
[0191] Determine second synchronization data based on the second record data and the data stored in the preset record table;
[0192] The second change data is generated based on the first synchronization data and the second synchronization data.
[0193] As an optional embodiment, in the device, the changing module 504 is specifically used for:
[0194] Marking the first recorded data as a first source; marking the second recorded data as a second source;
[0195] Determining first synchronization data based on the first record data and data stored in a preset record table includes:
[0196] Determine whether there is third record data matching the first record data in the preset record table;
[0197] If it does not exist, the first recorded data is used as the first synchronization data;
[0198] If it exists, and the third recorded data is marked as the second source, determine the timestamp corresponding to the first recorded data and the timestamp corresponding to the third recorded data; and use the recorded data corresponding to the timestamp closest to the current time as the first synchronization data.
[0199] As an optional embodiment, in the device, the changing module 504 is specifically used for:
[0200] Determining the second synchronization data based on the second record data and the data stored in the preset record table includes:
[0201] Determine whether there is fourth record data matching the second record data in the preset record table;
[0202] If it does not exist, the second recorded data is used as the second synchronization data;
[0203] If it exists, and the fourth record data is marked as the first source, determine the timestamp corresponding to the second record data and the timestamp corresponding to the fourth record data; and use the record data corresponding to the timestamp closest to the current time as the second synchronization data.
[0204] The data processing device provided by the present disclosure receives a primary key change command for a data table to be processed, obtains target primary key information, generates a target data table based on the target primary key information, sets the processing state of the data table to be processed to a first state, re-encodes the first data corresponding to the target primary key information in the data table to be processed and writes it into the target data table, when the first data is completed to be written into the target data table, sets the processing state of the data table to be processed to a second state, obtains the first change data during the period when the processing state of the data table to be processed is in the first state, updates the target data table based on the first change data, and completes the primary key change for the data table to be processed if the first change data is updated and the transactions on the data table to be processed are completed, performs different data processing in different processing states by setting the processing state of the data table to be processed, writes the first data into the target data table in the first state, and updates the change data in the first state on the target data table in the second state, thereby realizing the online primary key change of the database table, avoiding the business interruption caused by locking the data table, ensuring the normal execution of the business, and making the performance of the database system more stable.
[0205] Furthermore, when the first changed data is updated to the target data table in the second state, new data changes will continue to occur. The first record data is generated based on the first change operation, and the second record data is generated based on the second change operation. The data version and data source of the first record data and the second record data are judged, and the second change data is generated based on the record data that meets the requirements. The target data table is updated based on the second change data during the second state. When the changed data of the first state is updated to the target data table, the changed data of the second state can also be updated to the target data table through conflict detection, so as to avoid data errors caused by the simultaneous modification of one data in the two tables in the second state, reduce data conflicts, and make the database system performance more stable.
[0206] The device of the embodiment of the present disclosure can execute the method provided by the embodiment of the present disclosure, and its implementation principle is similar and has corresponding technical effects. The actions performed by each module in the device of each embodiment of the present disclosure correspond to the steps in the method of each embodiment of the present disclosure. For the detailed functional description of each module of the device, please refer to the description in the corresponding method shown in the previous text, which will not be repeated here.
[0207] An embodiment of the present disclosure provides an electronic device, including a memory, a processor, and a computer program stored in the memory, and the processor executes the above computer program to implement the steps of the method provided in any optional embodiment of the present disclosure. Compared with the prior art, the present invention can achieve: by receiving a primary key change command for a data table to be processed, obtaining target primary key information, generating a target data table based on the target primary key information, setting the processing state of the data table to be processed to a first state, re-encoding the first data corresponding to the target primary key information in the data table to be processed and writing it into the target data table, when the first data is completed to be written into the target data table, setting the processing state of the data table to be processed to a second state, obtaining the first change data during the period when the processing state of the data table to be processed is in the first state, updating the target data table based on the first change data, if the first change data is updated and the transactions on the data table to be processed are completed, completing the primary key change for the data table to be processed, performing different data processing in different processing states by setting the processing state of the data table to be processed, writing the first data into the target data table in the first state, and updating the change data in the first state on the target data table in the second state, realizing the online primary key change of the database table, avoiding the business interruption caused by locking the data table, ensuring the normal execution of the business, and making the performance of the database system more stable.
[0208] In an alternative embodiment, an electronic device is provided, such as Figure 6 As shown, Figure 6 The electronic device 6000 shown includes: a processor 6001 and a memory 6003. The processor 6001 and the memory 6003 are connected, such as through a bus 6002. Optionally, the electronic device 6000 may also include a transceiver 6004, which may be used for data interaction between the electronic device and other electronic devices, such as data transmission and / or data reception. It should be noted that in actual applications, the transceiver 6004 is not limited to one, and the structure of the electronic device 6000 does not constitute a limitation on the embodiments of the present disclosure.
[0209] Processor 6001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of the present invention. Processor 6001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0210] The bus 6002 may include a path to transmit information between the above components. The bus 6002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 6002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0211] The memory 6003 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), magnetic disk storage medium, other magnetic storage devices, or any other medium that can be used to carry or store computer programs and can be read by a computer, without limitation herein.
[0212] The memory 6003 is used to store the computer program for executing the embodiment of the present disclosure, and the execution is controlled by the processor 6001. The processor 6001 is used to execute the computer program stored in the memory 6003 to implement the steps shown in the above method embodiment.
[0213] The electronic device includes but is not limited to: a terminal or a server capable of implementing the above data processing method.
[0214] An embodiment of the present disclosure provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps and corresponding contents of the aforementioned method embodiment can be implemented.
[0215] The embodiments of the present disclosure also provide a computer program product, including a computer program, which can implement the steps and corresponding contents of the aforementioned method embodiments when executed by a processor.
[0216] The terms "first", "second", "third", "fourth", "1", "2", etc. (if any) in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than that shown or described in the text.
[0217] It should be understood that, although the flowchart of the embodiment of the present disclosure indicates each operation step by arrows, the implementation order of these steps is not limited to the order indicated by the arrows. Unless clearly stated herein, in some implementation scenarios of the embodiment of the present disclosure, the implementation steps in each flowchart can be executed in other orders according to demand. In addition, some or all of the steps in each flowchart may include multiple sub-steps or multiple stages based on the actual implementation scenario. Some or all of these sub-steps or stages can be executed at the same time, and each sub-step or stage in these sub-steps or stages can also be executed at different times. In scenarios with different execution times, the execution order of these sub-steps or stages can be flexibly configured according to demand, and the embodiment of the present disclosure does not limit this.
[0218] The above is only an optional implementation method for some implementation scenarios of the present disclosure. It should be pointed out that for ordinary technicians in this technical field, without departing from the technical concept of the scheme of the present disclosure, other similar implementation methods based on the technical ideas of the present disclosure are also within the protection scope of the embodiments of the present disclosure.
Claims
1. A data processing method, characterized in that: include: Receive a primary key change command for the data table to be processed; The primary key change command includes target primary key information to be changed in the data table to be processed; Based on the target primary key information, a target data table is generated, and the processing state of the to-be-processed data table is set to a first state; Re-encode the first data corresponding to the target primary key information in the data table to be processed and write the data into the target data table; When the first data is completely written into the target data table, the processing state of the to-be-processed data table is set to a second state; Acquire first change data during a period in which the processing state of the to-be-processed data table is in the first state, and update the target data table based on the first change data; If the first changed data is updated and it is detected that all transactions on the pending data table are completed, the primary key change for the pending data table is completed; Wherein, if the first change data is updated and it is detected that all transactions on the pending data table are completed, specifically includes: updating the processing state of the data table to be processed to a third state; the third state is used to indicate that the data in the data table to be processed is no longer updated; Acquire second change data during a period in which the processing state of the to-be-processed data table is in a second state; The target data table is updated based on the second change data to complete the primary key change for the data table to be processed.
2. The data processing method according to claim 1, characterized in that: The method further comprises: If the processing state of the data table to be processed is in the first state, sequentially scanning the data in the data table to be processed, and using the scanned data as recordable data; If a data change request for the to-be-processed data table is detected, obtaining second data and change information based on the data change request; the second data includes original data before the change; If the recordable data includes the second data, corresponding first change data is generated based on the second data and the change information.
3. The data processing method according to claim 1, characterized in that: After obtaining the first change data of the processing state of the to-be-processed data table being in the first state, the method further includes: Marking the first changed data as a first version; the first version is used to indicate that the first changed data has not been written into the target data table; The updating of the target data table based on the first change data includes: The target data table is updated based on the first target data marked as the first version in the first change data, and the first target data updated in the target data table is marked as the second version.
4. The data processing method according to claim 1, characterized in that: The obtaining of second change data during a period in which the processing state of the to-be-processed data table is in the second state includes: Acquire a first change operation on the data table to be processed and a second change operation on the target data table during a period in which the processing state of the data table to be processed is in the second state; generating first record data based on the first change operation, and generating second record data based on the second change operation; The second change data is generated based on the first record data and the second record data.
5. The data processing method according to claim 4, characterized in that: The generating the second change data based on the first record data and the second record data includes: storing the first record data and the second record data in a preset record table; Determine first synchronization data based on the first record data and the data stored in the preset record table; Determine second synchronization data based on the second record data and the data stored in the preset record table; The second change data is generated based on the first synchronization data and the second synchronization data.
6. The data processing method according to claim 5, characterized in that: The method further comprises: Marking the first recorded data as a first source; marking the second recorded data as a second source; The determining the first synchronization data based on the first record data and the data stored in the preset record table includes: Determine whether there is third record data matching the first record data in the preset record table; If not, taking the first recorded data as the first synchronization data; If it exists, and the third recorded data is marked as the second source, determine the timestamp corresponding to the first recorded data and the timestamp corresponding to the third recorded data; and use the recorded data corresponding to the timestamp closest to the current time as the first synchronization data.
7. The data processing method according to claim 6, characterized in that: The determining the second synchronization data based on the second record data and the data stored in the preset record table includes: Determine whether there is fourth record data matching the second record data in the preset record table; If not, taking the second recorded data as the second synchronization data; If it exists, and the fourth record data is marked as the first source, determine the timestamp corresponding to the second record data and the timestamp corresponding to the fourth record data; and use the record data corresponding to the timestamp closest to the current time as the second synchronization data.
8. A data processing device, characterized in that: include: A command receiving module, used for receiving a primary key change command for a data table to be processed; The primary key change command includes target primary key information to be changed in the data table to be processed; A first state module, used for generating a target data table based on the target primary key information, and setting the processing state of the to-be-processed data table to a first state; Re-encode the first data corresponding to the target primary key information in the data table to be processed and write the data into the target data table; A second state module, configured to set the processing state of the to-be-processed data table to a second state when the first data is completely written into the target data table; Acquire first change data during a period in which the processing state of the to-be-processed data table is in the first state, and update the target data table based on the first change data; A change module, configured to complete the primary key change for the data table to be processed if the update of the first change data is completed and it is detected that all transactions on the data table to be processed are completed; The change module is specifically used for: updating the processing state of the data table to be processed to a third state; the third state is used to indicate that the data in the data table to be processed is no longer updated; Acquire second change data during a period in which the processing state of the to-be-processed data table is in a second state; The target data table is updated based on the second change data to complete the primary key change for the data table to be processed.
9. An electronic device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the data processing method according to any one of claims 1 to 7 are implemented.
11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
