Partition migration method and device of distributed database
By performing write-blocking operations on the partitions to be migrated in the distributed database and centrally identifying the transactions to be migrated, the problems of irrelevant partition blocking and active transaction termination caused by global locks are solved, achieving an efficient partition migration process and improving system performance and data consistency.
Patent Information
- Application Number
- CN202611329082.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-28
- Publication Date
- 2026-11-17
AI Technical Summary
During partition migration, existing distributed databases use global coordination locks, which cause read and write operations on unrelated partitions to be blocked for a long time, reducing system throughput and response speed. At the same time, forcibly terminating active transactions will destroy business transparency and data consistency.
By performing write blocking operations on the partition to be migrated itself, the blocking write time point is determined, the list of transactions to be migrated is filtered out, and the transactions to be migrated are identified in the source node group. The context is restored in the target node group, avoiding irrelevant blocking of global locks and forced termination of active transactions.
It ensures data consistency and transaction integrity without interrupting business writes or terminating active transactions, improving system throughput and response speed, and avoiding serialization bottlenecks and irrelevant partition blocking caused by global locks.
Smart Images

Figure CN123115089A_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of distributed database technology, and more particularly to a method and apparatus for partition migration of a distributed database. Background Technology
[0002] Currently, in distributed database systems, to achieve horizontal scaling, load balancing, and disaster recovery switching, these systems frequently need to perform online partition migrations. This involves seamlessly migrating data shards from source physical nodes or log streams to target nodes. During this process, to ensure data consistency and transaction integrity, the distributed database system must determine the cutoff boundary for data writes without interrupting business writes or forcibly terminating active transactions. It must also identify all transactions that have accessed the partition to be migrated, so that their contexts can be migrated along with the partition.
[0003] In existing distributed database technologies, global coordination locks are typically used to control concurrent writes to ensure data consistency and transaction integrity during migration. For example, to prevent data inconsistency caused by new writes during online migration, distributed database systems usually apply a global lock to the entire table or even the entire cluster to ensure that no concurrent write operations occur during the migration. However, global locks do not only lock the partition being migrated but cover the entire table or all partitions. This means that even if some partitions are not involved in the migration at all, read and write operations on them still need to acquire locks or wait for lock release. During the lock holding period, requests to these unrelated partitions will also be blocked for a long time, thereby reducing the overall throughput and response speed of the distributed database system. Summary of the Invention
[0004] In view of the above, one or more embodiments of this specification provide the following technical solutions: According to a first aspect of one or more embodiments of this specification, a partition migration method for a distributed database is proposed. The distributed database includes several node groups, each node group maintaining a log stream for recording data change logs of multiple data partitions within the node group. When any data partition of any node group is determined to be a partition to be migrated, the partition to be migrated corresponds to a source node group and a target node group. The method is applied to the master node of the source node group, including: In response to a migration request for the partition to be migrated, a write blocking operation is performed to prevent new data write requests for the partition to be migrated, and the blocking write time point for the partition to be migrated is determined. Iterate through the transaction set corresponding to the source log stream maintained by the source node group, filter out the transactions that have accessed the partition to be migrated before the blocking write time point and are still not finished, and determine the list of transaction identifiers to be migrated. The list of transaction identifiers to be migrated and the blocking write time point are submitted as migration metadata to the source log stream so that the target node group can obtain the migration metadata, pull the transaction context of the transaction to be migrated from the source node group based on the migration metadata, and restore the transaction context in the target log stream maintained by the target node group so that the partition to be migrated can be migrated to the target node group.
[0005] According to a second aspect of one or more embodiments of this specification, a partition migration method for a distributed database is proposed. The distributed database includes several node groups, each node group maintaining a log stream for recording data change logs of multiple data partitions within the node group. When any data partition of any node group is determined to be a partition to be migrated, the partition to be migrated corresponds to a source node group and a target node group. The method is applied to the master node of the target node group, including: The migration metadata is obtained, which includes at least a list of transaction identifiers to be migrated and a blocking write time point. The blocking write time point is determined by the source node group after executing a write blocking operation to prevent new data write requests to the partition to be migrated in response to a migration request. The list of transaction identifiers to be migrated indicates transactions that the source node group accessed the partition to be migrated before the blocking write time point and are still ongoing. The migration metadata is obtained by the source node group after submitting the list of transaction identifiers to be migrated and the blocking write time point as migration metadata to the source log stream maintained by the source node group. Based on the list of transaction identifiers to be migrated in the migration metadata, the transaction context of the transaction to be migrated is retrieved from the source node group; The transaction context is restored in the target log stream maintained by the target node group so that the partition to be migrated can be migrated to the target node group.
[0006] According to a third aspect of one or more embodiments of this specification, a partition migration apparatus for a distributed database is provided. The distributed database includes several node groups, each node group maintaining a log stream for recording data change logs of multiple data partitions within the node group. When any data partition of any node group is determined to be a partition to be migrated, the partition to be migrated corresponds to a source node group and a target node group. The apparatus is applied to the master node of the source node group and includes: A blocking module is used to respond to a migration request for the partition to be migrated, perform a write blocking operation to prevent new data write requests for the partition to be migrated, and determine the blocking write time point of the partition to be migrated. The filtering module is used to traverse the transaction set corresponding to the source log stream maintained by the source node group, filter out the transactions that have accessed the partition to be migrated before the blocking write time point and are still not finished, as the transactions to be migrated, and determine the list of transaction identifiers to be migrated. The migration module is used to submit the list of transaction identifiers to be migrated and the blocking write time point as migration metadata to the source log stream, so that the target node group can obtain the migration metadata, pull the transaction context of the transaction to be migrated from the source node group based on the migration metadata, and restore the transaction context in the target log stream maintained by the target node group, so that the partition to be migrated can be migrated to the target node group.
[0007] According to a fourth aspect of one or more embodiments of this specification, a partition migration apparatus for a distributed database is provided. The distributed database includes several node groups, each node group maintaining a log stream for recording data change logs of multiple data partitions within the node group. When any data partition of any node group is determined to be a partition to be migrated, the partition to be migrated corresponds to a source node group and a target node group. The apparatus is applied to the master node of the target node group and includes: The acquisition module is used to acquire migration metadata, which includes at least a list of transaction identifiers to be migrated and a blocking write time point. The blocking write time point is determined by the source node group after executing a write blocking operation to prevent new data write requests to the partition to be migrated in response to a migration request. The list of transaction identifiers to be migrated indicates transactions that the source node group accessed the partition to be migrated before the blocking write time point and are still ongoing. The migration metadata is acquired by the source node group after submitting the list of transaction identifiers to be migrated and the blocking write time point as migration metadata to the source log stream maintained by the source node group. The pull module is used to pull the transaction context of the transaction to be migrated from the source node group based on the list of transaction identifiers to be migrated in the migration metadata; The migration module is used to restore the transaction context of the transaction to be migrated in the target log stream maintained by the target node group, so that the partition to be migrated can be migrated to the target node group.
[0008] According to a fifth aspect of one or more embodiments of this specification, an electronic device is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor implements the steps of the distributed database partition migration method described above by executing the executable instructions.
[0009] According to a sixth aspect of one or more embodiments of this specification, a computer-readable storage medium is provided that stores computer instructions thereon, which, when executed by a processor, implement the steps of the partition migration method for a distributed database as described above.
[0010] According to a fifth aspect of one or more embodiments of this specification, a computer program product is provided, comprising a computer program / instructions that, when executed by a processor, implement the steps of the partition migration method for the distributed database described above.
[0011] In this method, the distributed database comprises several node groups, each maintaining a log stream to record data change logs for multiple data partitions within that node group. When any data partition in any node group is identified as a partition to be migrated, that partition corresponds to a source node group and a target node group. This method is applied to the master node of the source node group and specifically includes: responding to a migration request for the partition to be migrated, executing a write blocking operation to prevent new data write requests to the partition to be migrated, and determining the blocking write time point of the partition to be migrated; subsequently, traversing the transaction set corresponding to the source log stream maintained by the source node group, filtering out transactions that have accessed the partition to be migrated before the blocking write time point and are still not finished as transactions to be migrated, and determining a list of transaction identifiers to be migrated; finally, submitting the list of transaction identifiers to be migrated and the blocking write time point as migration metadata to the source log stream, so that the target node group can obtain the migration metadata, and pull the transaction context of the transactions to be migrated from the source node group based on the migration metadata, and then restore the transaction context in the target log stream maintained by the target node group to complete the migration of the partition to be migrated to the target node group.
[0012] As can be seen from the above method, on the one hand, it can respond to migration requests by performing write blocking operations only on the partition to be migrated itself, rather than applying a global lock to the entire table or cluster. This ensures that while determining the data write cutoff boundary, read and write requests for other data partitions within the same node group that are not involved in the migration are completely unaffected, eliminating irrelevant blocking caused by global locks. On the other hand, based on the determined blocking write time point, by traversing the transaction set corresponding to the source log stream, transactions that have accessed the partition to be migrated before the blocking write time point and are not yet finished are centrally selected as transactions to be migrated, generating a list of transactions to be migrated. This allows the transaction identification process to be performed only once at the source end, avoiding the problems of large coordination overhead and inconsistent decision windows caused by multiple participants scanning separately, and without forcibly terminating any running active transactions. Thus, by decoupling write control and transaction identification into two independent and orderly connected stages, and executing them separately at different granularities, the serialization bottleneck caused by global locks and the problem of irrelevant partitions being blocked are solved. Attached Figure Description
[0013] Figure 1 This is a schematic diagram of a distributed database provided in an exemplary embodiment.
[0014] Figure 2 This is a flowchart illustrating a distributed database partition migration method provided in an exemplary embodiment.
[0015] Figure 3A This is a timing diagram of a blocking process provided in an exemplary embodiment.
[0016] Figure 3B This is a schematic diagram of the ABA race condition protection process provided in an exemplary embodiment.
[0017] Figure 3C This is a schematic diagram of the blocking state reset process during master-slave switching provided in an exemplary embodiment.
[0018] Figure 4 This is a schematic diagram of a transaction filtering process provided in an exemplary embodiment.
[0019] Figure 5 This is a schematic diagram of a data partition migration process provided in an exemplary embodiment.
[0020] Figure 6 This is a flowchart illustrating a distributed database partition migration method provided in an exemplary embodiment.
[0021] Figure 7 This is a schematic structural diagram of a device provided in an exemplary embodiment.
[0022] Figure 8 This is a block diagram of a distributed database partition migration apparatus provided in an exemplary embodiment.
[0023] Figure 9 This is a block diagram of a distributed database partition migration apparatus provided in an exemplary embodiment. Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of this specification clearer, the technical solutions of this specification will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this specification, and not all of them. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this specification.
[0025] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties. The collection, use and processing of related data shall comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals shall be provided for users to choose to authorize or refuse.
[0026] In distributed database systems, to achieve horizontal scaling, load balancing, and disaster recovery switching, the system needs to frequently perform online partition migration operations, which involves seamlessly migrating data shards from source physical nodes or log streams to target nodes. During this process, to ensure data consistency and transaction integrity, the system must precisely define the cutoff boundary for data writes without interrupting business writes or forcibly terminating active transactions, and accurately identify which active transactions have already accessed the migrated partition, thus migrating their transaction context along with the partition.
[0027] However, partition migration solutions in related technologies have several problems in handling the above requirements. Specifically, one solution uses a global coordination lock to control concurrent writes during migration. To prevent data inconsistency caused by new write requests during online migration, the distributed database applies a global lock to the entire table and even the entire cluster to ensure that no concurrent write operations occur during the migration. However, the granularity of the global lock is coarse; it does not only lock the partition being migrated but covers the entire table or all partitions. This means that even if some partitions are not involved in the migration at all, read and write operations on them must wait for the global lock to be released. During the lock holding period, requests from these unrelated partitions will also be blocked for a long time, significantly reducing the overall throughput and response speed of the distributed database system.
[0028] Another approach handles migration concurrency by forcibly terminating active transactions (i.e., database transactions that have started execution but have not yet undergone commit or rollback operations to end their lifecycle). For example, when active transactions are detected on the partition to be migrated, the distributed database directly aborts these transactions, requiring the client to retry. While this approach simplifies the migration logic, it undermines the fundamental requirement of online migration to be transparent to upper-layer business transactions. Forcibly terminating transactions can lead to business logic errors, data inconsistencies, and a degraded user experience.
[0029] Building upon this, this specification provides a method for partition migration in a distributed database. On one hand, in response to a migration request, it executes write-blocking operations only on the partition to be migrated, rather than imposing a global lock on the entire table or cluster. This ensures that read and write requests for other data partitions within the same node group that are not involved in the migration remain completely unaffected while determining the data write cutoff boundary, eliminating irrelevant blocking caused by global locks. On the other hand, based on the determined blocking write time point, by traversing the transaction set corresponding to the source log stream, it centrally selects transactions that have accessed the partition to be migrated before the blocking write time point and are not yet completed as the migration targets. The method generates a list of transaction identifiers to be migrated, so that the transaction identification process only needs to be performed once at the source end. This avoids the problems of large coordination overhead and inconsistent decision windows caused by multiple participants scanning separately, and does not require the forced termination of any running active transactions. Thus, this method can decouple write control and transaction identification into two independent and orderly connected stages, and execute them at different granularities. That is, write blocking is performed at the partition granularity, and transaction scanning and identification are performed at the log stream granularity. Finally, the consensus persistence of migration metadata realizes the collaboration between the source and target ends, thereby solving the serialization bottleneck caused by global locks and the problem of unrelated partitions being blocked.
[0030] To clearly describe the cache management method provided in this manual, some concepts involved in this manual will be explained below.
[0031] A node group is a collection of multiple nodes in a distributed database that jointly maintain the same log stream. Specifically, a log stream has a copy stored on multiple physical nodes, and these physical nodes collectively constitute the node group corresponding to that log stream. Multiple copies within the same node group maintain log data consistency through a consensus protocol (such as Paxos), where one copy is the primary copy (Leader) and the rest are secondary copies (Followers). In this specification, node groups correspond one-to-one with log streams; that is, each node group maintains one and only one log stream. This log stream serves the data change logs of all data partitions within the node group. In other words, multiple data partitions within the node group share this log stream, and the data change logs of these data partitions are sequentially written to this log stream.
[0032] Data partition: The basic unit of data sharding in a distributed database. Each data partition contains several rows of data and belongs to a specific log stream. All data and its change logs for that partition are recorded within that log stream and are not distributed across log streams. A single log stream can simultaneously host multiple data partitions. These partitions share the log write channel and consensus protocol of that log stream, allowing transactions on multiple partitions within the same log stream to be committed without cross-partition coordination, thus avoiding the overhead of two-phase commit across log streams. When a data partition is identified as a partition to be migrated, the log stream to which that partition belongs becomes the source log stream, and the log stream to which it is to be migrated becomes the target log stream. The migration operation is performed at the partition level, and other partitions on the same log stream are unaffected.
[0033] Blocking Write Time Point: A timestamp determined by the source node group after performing a write blocking operation, indicating the moment when new data write requests to the partition to be migrated have completely stopped. After this time point, the distributed database will no longer accept any new write requests (including adding data, modifying existing data, etc.) for that partition, thus ensuring that the data view before the migration start point is static and deterministic. This timestamp will be used as the time boundary for subsequent transaction filtering to determine which active transactions need to be migrated with the data partition.
[0034] List of Transaction IDs to be migrated: This is a collection of transaction IDs for all transactions that need to be migrated with the partition, selected by the source node group after iterating through the transaction sets corresponding to its log streams. This list is a core component of the migration metadata, indicating which transaction contexts the destination node group needs to pull from the source.
[0035] Transaction context: Metadata information generated during transaction execution that characterizes the current state of the transaction. Each active transaction stores its corresponding transaction context in the transaction context management module of the node group. Transaction context information includes, but is not limited to: the transaction's commit status (e.g., active, pre-commit), the list of data partitions accessed by the transaction and their access timestamps, the transaction's isolation level, and the transaction identifier.
[0036] Write blocking service: An independent service module deployed within each node group, with the log stream as its scope. Each log stream has a corresponding write blocking service instance, used to maintain the current write blocking state of that log stream. Specifically, the write blocking service maintains a monotonic operation sequence number to sort blocking and unblocking operations. Every blocking or unblocking request must carry an operation sequence number. Upon receiving a request, the write blocking service verifies the relationship between the operation sequence number carried in the blocking or unblocking request and its currently recorded operation sequence number. Only after the verification passes will the corresponding blocking or unblocking operation be executed, thus preventing the ABA race condition.
[0037] The technical solutions provided in the various embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0038] Figure 1 This is a schematic diagram of a distributed database architecture provided in an exemplary embodiment. For example... Figure 1 As shown, the distributed database contains several node groups, each corresponding to a log stream. Each node group contains multiple physical nodes, which together maintain multiple replicas of the log stream.
[0039] For example, node group 110 maintains log stream 112, which stores data change logs for multiple data partitions, including data partition A, data partition B, and data partition C. Similarly, node group 120 maintains log stream 122, which stores data change logs for multiple data partitions, including data partition D and data partition E. The node groups communicate with each other over a network to exchange metadata and transmit transaction context during partition migration. It should be noted that... Figure 1 The number of node groups and the number of data partitions within each node group shown are merely illustrative. In actual deployments, each node group can support any reasonable number of data partitions, and this specification does not impose any restrictions on this.
[0040] Figure 2 This is a flowchart illustrating a partition migration method for a distributed database, provided in an exemplary embodiment. This method can be applied to the master node of a source node group. The master node is the node in the node group corresponding to the source log stream that maintains the primary replica of the source log stream, and is responsible for handling read / write requests and maintaining the consensus protocol. Figure 2 As shown, the method may include the following steps: S200: In response to a migration request for the partition to be migrated, perform a write blocking operation to prevent new data write requests for the partition to be migrated, and determine the blocking write time point for the partition to be migrated.
[0041] In this specification, the scheduling module in the distributed database can monitor the load status, data distribution, storage capacity and throughput of each node group, and determine the data partition that needs to be migrated based on the preset load balancing strategy, disaster recovery switching requirements, cluster expansion requirements or node failure recovery strategy. This partition is designated as the partition to be migrated, and the migration process for the partition to be migrated is triggered by sending a migration request to the master node of the source node group to which the partition to be migrated belongs.
[0042] The aforementioned scheduling module can refer to a global metadata management node independently deployed in the distributed database system, or it can be a built-in coordination component in the distributed database system (such as a scheduling submodule built into the cluster management service). In practical applications, when the scheduling module detects that a node group is overloaded, the data volume of a log stream exceeds a preset threshold, or a data partition's access hotspot causes a performance bottleneck, it can trigger a partition migration process to migrate the partition from a high-load node group to a low-load node group, thereby achieving overall system load balancing. In another embodiment, when the scheduling module receives a disaster recovery switchover command or detects a node group failure, it can also trigger a partition migration process to migrate data partitions on the failed node group to other healthy node groups, ensuring data availability and business continuity.
[0043] Of course, the triggering method for migration requests is not limited to the scenario where the scheduling module initiates the request actively. For example, migration requests can also be manually triggered by database administrators or operations personnel through an interface (such as command-line tools, graphical management platforms, or API interfaces), and this manual does not impose any restrictions on this.
[0044] It should be noted that the number of partitions to be migrated in the above content can be one or more. Multiple data partitions to be migrated can be located in the same source log stream or distributed in different source log streams. This specification does not impose any restrictions on this.
[0045] Furthermore, after receiving the migration request, the master node of the source node group can execute a write blocking operation on the partition to be migrated. The purpose of this write blocking operation is to ensure that no new data write requests (including but not limited to INSERT, UPDATE, DELETE, and other data change operations) are generated on the partition to be migrated during the subsequent migration process. This ensures that after the determined blocking write time point, the data view of the data partition remains static, and there will be no data omissions or unclear migration boundaries due to new write requests.
[0046] In practical applications, to prevent the master node of the source node group from maintaining its own blocking state and handling out-of-order arrival issues caused by concurrent requests when performing write blocking operations, the master node of the source node group can call the write blocking service to perform blocking operations on the partition to be migrated, as follows: Figure 3A As shown.
[0047] Figure 3A This is a timing diagram of a blocking process provided in an exemplary embodiment.
[0048] Combination Figure 3AAs can be seen, when the master node of the source node group needs to perform a write blocking operation, it can first send a blocking request carrying a monotonic operation sequence number to the write blocking service. This monotonic operation sequence number is used to identify the operation order of this blocking request, ensuring the orderliness between blocking and subsequent unblocking operations.
[0049] Furthermore, upon receiving the blocking request, the write blocking service can first verify whether the current node is the master node. If it is not the master node, the write blocking operation will be refused to avoid state splitting or data inconsistency caused by multiple replicas concurrently executing blocking control. If the current node is the master node, the write blocking service can further verify whether the monotonic operation sequence number carried in the blocking request is not less than the operation sequence number currently recorded by the write blocking service. If it is less, the operation will be refused; otherwise, the write blocking service can update the currently recorded operation sequence number to the monotonic operation sequence number carried in the blocking request, and execute the write blocking operation to prevent new data write requests for the partition to be migrated, and determine the current time as the blocking write time point for the partition to be migrated. Subsequently, the write blocking service returns a blocking success response to the master node of the source node group.
[0050] As can be seen from the above, the operation sequence number of the current record of the write blocking service is the monotonic operation sequence number of the most recently successfully executed blocking operation. If the current blocking request is the first one initiated (i.e. there is no previously successfully executed blocking operation that is closest to the current blocking request), then the operation sequence number of the current record can be a preset minimum initial value (e.g., 0) to ensure that any monotonic operation sequence number is not less than the initial value and can pass the verification.
[0051] In the above context, if the monotonic operation sequence number carried in the blocking request is less than the operation sequence number currently recorded by the write blocking service, it indicates that the blocking request is a late, old request whose operation sequence number has been overwritten by an updated operation. In this case, the write blocking service refuses to execute the blocking request to prevent expired requests from incorrectly overwriting the currently valid blocking state. After receiving the rejection response, the master node of the source node group can regenerate a new monotonic operation sequence number and initiate a new blocking request to ensure that the blocking operations can be successfully executed in the correct order.
[0052] Furthermore, in practical applications, distributed databases also have the ABA race condition problem, which is that an old unblocking request arrives after a new blocking request due to network delays or retries. Without a protection mechanism, the old unblocking request will incorrectly unblock the blocking state established by the new blocking request, causing the partition to be migrated to be resumed and written prematurely before the migration is completed, thus causing the migration boundary to get out of control.
[0053] Based on this, in this specification, the distributed database, through the aforementioned monotonic operation sequence numbers, can also ensure that blocking and deblocking operations correspond one-to-one in the correct timing, thereby avoiding the aforementioned ABA race condition problem. For ease of understanding, the following will combine... Figure 3B Please provide a detailed explanation.
[0054] Figure 3B This is a schematic diagram of the ABA race condition protection process provided in an exemplary embodiment.
[0055] Combination Figure 3B As can be seen, assuming that in a certain migration task, the master node of the source node group generates a monotonic operation sequence number 10 and successfully sends a blocking request carrying the monotonic operation sequence number 10 to the write blocking service, after the write blocking service verifies the request, it updates the operation sequence number of the current record to 10 and executes the write blocking operation.
[0056] Subsequently, due to network timeouts, task retries, or other anomalies, the migration task may be re-initiated or a new migration task may be started. The new migration task generates a new monotonic operation sequence number 20 and sends a new blocking request carrying the monotonic operation sequence number 20 to the write blocking service. After receiving the new blocking request, the write blocking service verifies that the carried monotonic operation sequence number 20 is not less than the operation sequence number 10 of the current record. If the verification passes, the operation sequence number of the current record is updated to 20, and the write blocking operation is re-executed.
[0057] If, due to network latency or other reasons, the unblocking request of the old migration task (carrying monotonic operation sequence number 10) arrives at the write blocking service after the blocking request of the new migration task, the write blocking service, upon receiving the unblocking request of the old migration task, checks whether the monotonic operation sequence number 10 carried in it matches the currently recorded operation sequence number 20. Since 10 is not equal to 20, the check fails, the write blocking service refuses to execute the old unblocking request, and returns a sequence number mismatch error. At this time, the partition to be migrated remains in a blocked state, and the write boundary established by the new blocking request remains valid. This effectively prevents the old request from incorrectly affecting the current blocking state due to out-of-order arrival or replay, thereby improving the reliability of the write boundary during the migration startup phase.
[0058] Furthermore, in practical applications, distributed databases also suffer from the problem of residual blocking states caused by master-slave switching. Specifically, when a master node in the source node group becomes a slave node due to failure, restart, or active switching, if the node still retains previously executed write blocking states, these blocking states may be incorrectly preserved, causing the partition to be migrated to remain blocked after the switch and unable to be written to normally. Alternatively, if the newly elected master node incorrectly inherits the blocking state of the old master node, it may continue to block writes at inappropriate times, thus affecting the normal operation of the system. Moreover, if a master-slave switch occurs after the old master node performs a write blocking operation, and the blocking state is not cleared in time, the new master node will not be aware of the blocking state held by the old master node, causing the blocking write time point in the migration process to be inconsistent with the actual blocking state, thus leading to errors in migration boundary judgment.
[0059] To address the aforementioned issues, this specification specifies that when the primary node in the source node group determines that the currently maintained replica type is being switched from primary replica to secondary replica, the node can send a clear request to the write blocking service during the switchover process. This request invokes the write blocking server's clear interface to clear the current record's operation sequence number and write blocking status, ensuring that no old blocking status remains after the downgrade, thus preventing it from affecting the normal operation of the new primary node. Specifically, as follows... Figure 3C As shown.
[0060] Figure 3C This is a schematic diagram of the blocking state reset process during master-slave switching provided in an exemplary embodiment.
[0061] Combination Figure 3C It can be seen that the master-slave switchover process involves the downgrade and cleanup process on the old master node side and the takeover and reset process on the new master node side.
[0062] Specifically, on the old master node side, when the node group triggers the master-slave switchover process, the old master node first performs a degradation operation. During this degradation operation, the old master node can send a clear request to the write blocking service. Upon receiving this clear request, the write blocking service clears the currently recorded operation sequence number and clears its own write blocking state (if any). After the clearing is complete, the old master node officially switches to a slave node and no longer assumes the responsibilities of handling write requests and maintaining the consensus protocol. The purpose of this clearing operation is to ensure that after the old master node is degraded, the blocking state previously set due to the migration task is not left behind, thereby preventing the blocking state from continuing to be effective when the old master node is running as a slave node and affecting other normal services on that node.
[0063] On the new master node side, after the old master node completes its degradation, the distributed database can elect a new master node through a consensus protocol. During its inaugural operation, the new master node can also send a cleanup request to the write blocking service to clear any remaining blocking states. In normal scenarios, since the old master node has already cleared the blocking states during degradation, this cleanup operation by the new master node usually has no actual clearing effect. However, in abnormal scenarios (e.g., the old master node fails to perform the degradation cleanup operation due to a failure), the new master node can proactively perform the cleanup to ensure it does not inherit the blocking states left by the old master node, thus preventing the migration process from falling into an unknown state due to residual blocking states. Furthermore, the new master node does not inherit the operation sequence number history of the old master node; instead, it starts working with a clean state, and subsequent blocking operations will be managed based on newly generated operation sequence numbers.
[0064] Based on this, after the new master node successfully takes over, if there are migration tasks that need to be continued or re-executed, these migration tasks can re-initiate the blocking process. The new migration task generates a new monotonic operation sequence number and sends a blocking request carrying this sequence number to the write blocking service. After receiving the blocking request, the write blocking service performs verification and blocking operations according to the blocking process described above. The currently recorded operation sequence number can be recovered by the new master node through synchronization with other replicas in the cluster using the consensus log in the replay log stream, ensuring that the global monotonicity of the operation sequence number is not violated.
[0065] S202: Traverse the transaction set corresponding to the source log stream maintained by the source node group, filter out the transactions that have accessed the partition to be migrated before the blocking write time point and are still not finished, as the transactions to be migrated, and determine the list of transaction identifiers to be migrated.
[0066] Furthermore, after the write blocking operation is successfully executed and the blocking write time has been determined, the master node of the source node group can traverse the transaction set corresponding to the source log stream to identify which active transactions should be migrated along with the partition to be migrated, specifically as follows: Figure 4 As shown.
[0067] Figure 4 This is a schematic diagram of a transaction filtering process provided in an exemplary embodiment.
[0068] Combination Figure 4 As can be seen, the master node of the source node group can determine whether a transaction t is an active transaction (i.e., not yet completed) based on its transaction context for each transaction t it traverses. If the transaction has already ended (committed or rolled back), then the transaction does not need to be migrated, and the transaction is skipped, and the next transaction is traversed.
[0069] Based on this, if the transaction is not yet completed, it can be determined whether the transaction has accessed the partition to be migrated before the blocking write time point. If so, the transaction can be identified as the transaction to be migrated, and the next transaction can be traversed until the transaction set corresponding to the source log stream is traversed.
[0070] It should be noted that the transaction context of each transaction in the above transaction set can be stored in the transaction context management module. Therefore, the master node of the source node group can call the transaction context management module to traverse all active transaction contexts stored therein in order to obtain the transaction context of each transaction.
[0071] The aforementioned transaction context management module can be a memory management module within the source node group responsible for managing the execution status of each transaction and the two-phase commit progress. It can store the transaction context of each transaction using the transaction identifier as an index.
[0072] In addition, during the traversal process, to ensure that the state of the selected transactions does not change concurrently during the generation of the list of transactions to be migrated, thereby ensuring the accuracy and consistency of the list of transactions to be migrated, the master node of the source node group can also apply a transaction-level mutex lock to any transaction to be migrated when it is determined to be a transaction to be migrated. This will block the state changes of the transaction to be migrated (e.g., block the transaction's commit, rollback, or state advancement operations) until the list of transactions to be migrated is determined. After the migration metadata containing the list of transactions to be migrated is committed to the source log stream, the transaction-level mutex locks on each transaction to be migrated are released.
[0073] It should be noted that, in the above content, by applying transaction-level mutex locks to transactions that meet the filtering conditions during the traversal process, it can be ensured that the state of these transactions will not undergo unexpected changes (e.g., they will not be prematurely committed or rolled back on the source side) within the time window from the generation of the list of transaction identifiers to the completion of the persistence of migration metadata. This ensures the accuracy and consistency of the migration metadata. Furthermore, the granularity of the aforementioned mutex lock is that of a single transaction rather than the entire transaction pool. Therefore, other transactions unrelated to the partition to be migrated are not affected by this mutex lock and can still proceed with their state changes and execution processes normally.
[0074] S204: Submit the list of transaction identifiers to be migrated and the blocking write time point as migration metadata to the source log stream, so that the target node group can obtain the migration metadata, pull the transaction context of the transaction to be migrated from the source node group based on the migration metadata, and restore the transaction context in the target log stream maintained by the target node group, so that the partition to be migrated can be migrated to the target node group.
[0075] Furthermore, after determining the list of transactions to be migrated and the blocking write time point, the master node needs to persist these determination results to the log stream to ensure that the migration metadata is not lost due to node failure or master-slave switch, and to enable the target node group to obtain this migration metadata to perform subsequent migration operations.
[0076] Specifically, the master node of the source node group can encapsulate metadata such as the list of transactions to be migrated, the blocking write time, the source log stream identifier, and the destination log stream identifier into a transfer-out log. Subsequently, the master node of the source node group can submit this transfer-out log as a log entry to the majority replica of the source log stream through a consensus protocol (such as the Paxos protocol).
[0077] The aforementioned commit operation can only be considered complete after a majority of replicas confirm the successful write. This ensures that even if a master-slave switch occurs during the commit process, the newly elected master replica can fully restore the migration metadata by replaying the migration logs in the log stream and continue the migration process.
[0078] After the migration log is committed, all log entries preceding it represent data that has already been persisted to the partition to be migrated, and the associated transaction states will be migrated based on the list of transaction identifiers to be migrated. After this log entry, the source log stream will no longer accept new writes to the partition to be migrated. Once the migration log is successfully committed, the master node of the source node group can unblock writes and resume new data write requests for the partition to be migrated.
[0079] Subsequently, the master node of the target node group can obtain the migration log through log stream synchronization or active pull, and parse the migration metadata from it, specifically as follows: Figure 5 As shown.
[0080] Figure 5 This is a schematic diagram of a data partition migration process provided in an exemplary embodiment.
[0081] Combination Figure 5 As can be seen, the master node of the target node group can initiate a transaction context retrieval request to the source node group based on the list of transaction identifiers to be migrated in the migration metadata. In response to this request, the source node group retrieves the transaction status information of each transaction from the transaction context management module and returns it as the transaction context to the target node group.
[0082] Furthermore, upon receiving the transaction context, the target node group can restore the transaction context in the target log stream maintained by the target node group, and reconstruct the current state of each transaction in the transaction context management module on the target side, so that these transactions can continue their subsequent execution process on the target node group. When all transaction contexts in the list of transactions to be migrated have been successfully migrated and restored, the data partition to be migrated has completed the migration from the source log stream to the target log stream.
[0083] It should be noted that the list of transaction identifiers to be migrated may contain a large number of transaction identifiers. If all transaction contexts are pulled from the source node group and transferred to the target node group at once, the amount of data transferred in a single transaction may be too large, which may affect the performance of the distributed database or cause network congestion. Therefore, transaction contexts can be migrated in batches.
[0084] Specifically, after obtaining the migration metadata, the master node of the target node group can divide the list of transaction identifiers to be migrated into several subsets according to a preset batching strategy, with each subset serving as an independent transmission batch. The division of each batch may be limited by a preset maximum number of transactions per batch (e.g., each batch may contain a maximum of 100 transaction identifiers) or a maximum log size allowed per batch (e.g., each batch may transmit a maximum of 10MB of data).
[0085] After the batch partitioning is completed, the master node of the target node group can initiate a context migration request to the master node of the source node group for each batch. The request carries a subset of transaction identifiers corresponding to that batch.
[0086] Accordingly, after the primary node of the source node group receives the context migration request for any batch of transaction subsets sent by the target node group, it can retrieve the transaction status information of each transaction in the subset from the local transaction context management module based on the transaction identifier subset carried in the request, and return the retrieved transaction status information as the transaction context corresponding to the batch to the target node group.
[0087] After the primary node of the target node group receives the transaction contexts for this batch, it can restore the current state of each transaction corresponding to this batch in the target log stream maintained by the target node group, until all transaction contexts in the transaction identifier list to be migrated have been successfully migrated and restored to the target node group.
[0088] Furthermore, in practical applications, the same data partition to be migrated may undergo multiple migration tasks within a short period. For example, the scheduling module may reissue the migration request due to network timeout and failure to receive a response from the source end, or the system may automatically initiate a retry after a previous migration task fails, or the scheduling module may initiate a new migration for the same partition based on a new load balancing strategy. In these scenarios, the migration logs and transaction contexts generated by different migration tasks may be interleaved in the network, and the transaction context of the previous task may even arrive at the destination only after the migration log of the subsequent task has been committed due to network latency. If the destination node group cannot distinguish which migration task the currently received migration instruction or transaction context belongs to, it may incorrectly restore the transaction context of the previous task to the context of the subsequent task, or mistakenly regard the context of the subsequent task as residual data of the previous task and refuse to restore it, thus leading to chaotic transaction context migration, data inconsistency, or even incorrect transaction commit paths.
[0089] Based on this, although the leader epoch of the consensus group can be used to filter residual instructions from the previous leader, it only reflects the dimension of the leader-slave switch of the consensus group and cannot cover the instruction confusion caused by multiple migration task retries within the same leader epoch. When the leader epoch has not been switched, the two migration tasks issued successively carry the same leader epoch, and the target node group cannot distinguish between the two based on this.
[0090] For example, suppose a data partition to be migrated undergoes two independent migration tasks, both occurring within the same primary replica term (i.e., no master-slave switch occurred between the two tasks). The first migration task submits the migration log to the source log stream and begins transmitting the transaction context to the target node group; however, due to network latency, the corresponding transaction context is still en route after the migration log arrives at the target node group and has not yet reached the target node group. At this time, the scheduling module initiates a second migration task for some reason (such as determining that the first task timed out), similarly submitting the migration log to the source log stream. This migration log arrives at the target node group before the transaction context of the first task. In this scenario, if the target node group relies solely on the primary replica term identifier to distinguish migration tasks, since both tasks occurred within the same term and the two migration logs carry the same term identifier, the target node group cannot distinguish that the second migration log belongs to a different migration task than the first. When the transaction context of the first task subsequently arrives, the target node group cannot determine whether the transaction context belongs to the first or second task based solely on the term identifier, leading to confusion in subsequent transaction context recovery. If the transaction context is incorrectly associated with the migration log of the second task, it may restore a transaction context that should not belong to the second migration task to the target log stream, resulting in data inconsistency or abnormal transaction state.
[0091] Therefore, to avoid the above problems, in this specification, after receiving the migration request, the master node of the source node group can assign a task identifier (TransferEpoch, E) that is independent of the consensus group master replica term identifier for this migration task, and can encapsulate the task identifier into the migration metadata when submitting the migration log in the future, so that it is solidified with the persistence of the migration log.
[0092] Accordingly, after obtaining the migration log, the target node group can extract the task identifier and record it locally as the currently valid task identifier. When receiving the transaction context subsequently, it verifies whether the task identifier carried in the transaction context matches the locally recorded currently valid task identifier. If they match, the transaction context is accepted and restored; otherwise, the restoration of the transaction context is rejected. Through this task identifier mechanism, even if the same data partition undergoes multiple migration tasks within the same primary replica term, each migration task can be clearly distinguished by carrying a different task identifier, thereby effectively avoiding instruction confusion and incorrect transaction context recovery between different migration tasks.
[0093] Of course, the task identifier mentioned above can also be assigned by the scheduling module when initiating the migration request, and the task identifier can be sent to the master node of the source node group in the migration request.
[0094] Based on this, when the master node of the source node group commits the migration log, it can use the list of transaction identifiers to be migrated, the blocked write time point, and the task identifier as migration metadata, and encapsulate this migration metadata into the migration log. Subsequently, the master node of the source node group can submit this migration log to the majority replica of the source log stream through the consensus protocol.
[0095] The task identifier is bound to the log sequence number of the migration log. Since the log sequence number monotonically increases globally throughout the log stream's lifecycle, after obtaining the migration log, the target node group can not only extract the task identifier from it but also naturally determine the time order of each migration task based on the chronological order of the log sequence numbers. Thus, when receiving the transaction context, it can accurately determine the migration task to which the transaction context belongs and its relative order by combining the dual information of the task identifier and the log sequence number. The consensus mechanism of submitting to the majority replica ensures the persistence and consistency of the migration log in the source log stream. Even if a master-slave switch occurs, the new master node can recover the migration metadata and continue the migration process by replaying the migration log in the log stream.
[0096] As can be seen from the above, in this specification, write control and transaction identification are two independent yet sequentially connected operational phases. In the write control phase, the master node of the source node group performs a write blocking operation on the data partition to be migrated and determines the blocking write time point. This operation operates at the data partition granularity, meaning it only blocks write requests for the data partition to be migrated itself, without affecting other data partitions on the same log stream, thus avoiding the cascading blocking of unrelated partitions by the global lock. In the transaction identification phase, the master node traverses the transaction set corresponding to the log stream, filters out active transactions that need to be migrated based on the blocking write time point, and generates a list of transaction identifiers to be migrated. This operation operates at the log stream granularity, meaning it traverses all active transactions on the log stream and identifies transactions related to the partition to be migrated. The two phases are connected by the blocking write time point; that is, the write control phase determines the time boundary, and the transaction identification phase uses this boundary as a benchmark for filtering. The two phases cooperate in an orderly manner without interference.
[0097] Based on this, after the migration log is committed, the subsequent migration process can be divided into two parallel main lines: the first is data migration, which is the migration of the physical data of the data partition to be migrated (including the existing data already persisted in the partition) from the source to the destination. The data migration process can be divided into two stages. The first stage is logical migration, which establishes a logical reference relationship for the data partition in the target node group, so that the target node group can identify and route read and write requests for the data partition through the logical reference before the actual physical data is actually migrated to the target node group. The second stage is the migration of the actual physical data executed asynchronously in the background. After the migration metadata is persisted and the write of the data partition to be migrated is restored, the distributed database gradually migrates the existing physical data of the data partition to be migrated from the source node group to the target node group in the background. This process does not block the normal execution of other operations. The second is transaction migration, which is that the target node group pulls the transaction context of each transaction to be migrated from the source node group based on the list of transaction identifiers to be migrated in the migration log and restores it in the target node group, so that these transactions can continue to advance on the target node group. The data migration and transaction migration described above can be performed in parallel without blocking each other. Data migration focuses on the physical data content of the partition, while transaction migration focuses on the state recovery of each transaction at the destination. They have different targets and independent execution paths. By decoupling write control, transaction identification, and data migration, the distributed database can complete the entire migration process of the data partition to be migrated without interrupting the writing of unrelated data partitions or forcibly terminating active transactions.
[0098] It is important to note that this specification involves two levels of replica concepts: first, log stream replicas, which are log copies stored on multiple nodes within a node group for the same log stream, with consistency of log entries maintained among these replicas through a consensus protocol; and second, data partition replicas, which are physical copies of the data partition to be migrated stored on each node. Since a single log stream carries multiple data partitions, and all data and change logs for each data partition are recorded within this log stream, the data partition replicas and log stream replicas are physically identical. That is, a data partition on a node has a replica of the log stream, and the data partition replica on any node maintains eventual consistency with data partition replicas on other nodes by replaying the logs from the log stream replica on that node. Under this architecture, data partition migration must be performed holistically at the node group level; all replicas (including one primary replica and multiple secondary replicas) in the node group to which the partition to be migrated belongs must be synchronously migrated to the target node group. The reason is that if only one replica is migrated (e.g., only the node containing the primary replica is migrated), while the other replicas remain in the source node group, the data distribution of that partition across different nodes will split. That is, the remaining secondary replicas on the source node group will still hold the data for that partition, while the new replicas on the target node group will hold a different copy of the data for that partition. They will no longer share the same log stream, and the consensus protocol will be unable to maintain cross-replica data consistency. Subsequent write requests for that partition will fail to reach a consensus among the majority of replicas, rendering the read / write service for that partition unavailable. Therefore, partition migration must be performed as a whole on a node group basis. All replicas of the partition to be migrated must be moved out of the source node group and into the target node group to ensure that all replicas of the partition continue to maintain the same log stream after the migration, and that the consensus protocol can continue to function normally.
[0099] Based on this, during the migration log submission process, the master node of the source node group submits the migration log containing migration metadata to the majority replica of the log stream through the consensus protocol. According to the basic properties of the consensus protocol, the log entry will be automatically replicated to all slave nodes of the log stream, so that all nodes in the source node group hold the same migration metadata.
[0100] Furthermore, during the transaction context migration process, the master node of the source node group responds to the pull request from the target node group by returning the transaction context to be migrated. This process only involves data transmission between the master node and the target node group. The slave nodes within the source node group do not participate in the transaction context pull response, and their state consistency is maintained by the regular log replication mechanism of the consensus protocol, unaffected by the additional impact of the data partition migration process. After receiving the transaction context, the target node group also restores the current state of each transaction on its master node and synchronizes this restored state to all slave nodes within the target node group through the consensus protocol of the target log stream, ensuring eventual consistency of the transaction state on all nodes within the target node group.
[0101] To facilitate understanding, the following provides a detailed explanation of the methods executed by the master node of the target node group during the partition migration process of a distributed database. Specifically... Figure 6 As shown.
[0102] Figure 6 This is a flowchart illustrating a distributed database partition migration method provided in an exemplary embodiment, including the following steps: S601: Obtain migration metadata, which includes at least a list of transaction identifiers to be migrated and the blocking write time point.
[0103] The blocking write time point is determined by the source node group after it executes a write blocking operation to prevent new data write requests to the data partition to be migrated in response to a migration request for the data partition to be migrated; the list of transactions to be migrated is used to indicate transactions that the source node group has accessed the data partition to be migrated before the blocking write time point and that are not yet completed; the migration metadata is obtained by the target node group from the source log stream by means of log stream synchronization or active pull after the source node group submits the list of transactions to be migrated and the blocking write time point as migration metadata to the source log stream maintained by the source node group.
[0104] S602: Based on the list of transaction identifiers to be migrated in the migration metadata, retrieve the transaction context of the transaction to be migrated from the source node group.
[0105] The master node of the target node group initiates a transaction context retrieval request to the source node group based on the list of transaction identifiers to be migrated. The source node group responds to this request by returning the transaction status information of each transaction to the target node group. The transaction context can be retrieved in batches, with each batch corresponding to a subset of the list of transaction identifiers to be migrated. The transmission of each batch is limited by a preset maximum number of transactions per batch or a maximum allowed log size per batch, to avoid excessive data volume in a single transmission, which could impact system performance or cause network congestion.
[0106] S603: Restore the transaction context in the target log stream maintained by the target node group so that the partition to be migrated can be migrated to the target node group.
[0107] The master node of the target node group restores the received transaction context in the target log stream maintained by the target node group. This involves creating or updating the context records for each transaction in the transaction context management module of the target node group, enabling these transactions to continue their subsequent execution flow on the target node group. Before restoring the transaction context, the target node group can also verify whether the task identifier carried in the transaction context matches a valid task identifier recorded locally. If they match, the transaction context is restored; otherwise, restoration is rejected, thus avoiding instruction confusion between different migration tasks. Once all transaction contexts in the list of transaction identifiers to be migrated have been successfully restored, the data partition to be migrated is migrated from the source node group to the target node group.
[0108] Figure 7 This is a schematic structural diagram of a device provided in an exemplary embodiment. For example... Figure 7 As shown, device 700 mainly consists of a communication interface 702, a user interface 704, a processor 706, and a data storage 708. These components are interconnected and communicate with each other via a system bus, network, or other connection mechanism 710. The communication interface 702 enables device 700 to communicate with other devices, access networks, and transmission networks via analog or digital modulation. For example, the communication interface 702 may include a chipset and antenna for wireless communication with a radio access network or access point. Furthermore, the communication interface 702 can be a wired interface such as Ethernet, Token Ring, or a USB port, or a wireless interface such as Wi-Fi, Bluetooth, Global Positioning System (GPS), or a wide-area wireless interface (e.g., WiMAX or LTE). Of course, the communication interface 702 can also support other forms of physical layer interfaces and standard or proprietary communication protocols. The communication interface 702 may also include multiple physical communication interfaces, such as Wi-Fi, Bluetooth, and wide-area wireless interfaces.
[0109] User interface 704 includes receiving user input and providing output to the user. Therefore, user interface 704 may include input components such as a keypad, keyboard, touch-sensitive or presence-sensitive panel, computer mouse, trackball, joystick, microphone, still camera, and video camera, and output components such as a display screen (which may be combined with a touch-sensitive panel), CRT, LCD, LED, display using DLP technology, printer, and other similar devices known or developed in the future. User interface 704 may also generate auditory output via speakers, speaker jacks, audio output ports, audio output devices, headphones, and other similar devices known or developed in the future. In some embodiments, user interface 704 may include software, circuitry, or other forms of logic capable of transmitting and receiving data from external user input / output devices. Additionally or alternatively, device 700 may support remote access from other devices via communication interface 702 or another physical interface (not shown). User interface 704 may be configured to receive user input, the position and movement of which may be indicated by indicators or cursors described herein. User interface 704 may also be configured as a display device for rendering or displaying text fragments.
[0110] Processor 706 may contain one or more general-purpose processors and / or special-purpose processors.
[0111] Data storage 708 may include one or more volatile and / or non-volatile storage components and may be integrated wholly or partially with processor 706. Data storage 708 may include removable and non-removable components.
[0112] Processor 706 is capable of executing program instructions 718 (e.g., compiled or uncompiled program logic and / or machine code) stored in data storage 708 to perform the various functions described herein. Data storage 708 may contain a non-transitory computer-readable medium on which program instructions are stored, which, when executed by device 700, enable device 700 to perform any methods, processes, or functions disclosed in this specification and / or the accompanying drawings. Processor 706 executing program instructions 718 may result in processor 706 using data 712.
[0113] For example, program instructions 718 may include an operating system 722 (e.g., an operating system kernel, device drivers, and / or other modules) installed on device 700 and one or more applications 720 (e.g., a browser, social application, or game application). Similarly, data 712 may include operating system data 716 and application data 714. Operating system data 716 is primarily accessible to the operating system 722, while application data 714 is primarily accessible to one or more applications 720. Application data 714 may reside in a file system visible or hidden from the user of device 700.
[0114] Application 720 can communicate with operating system 722 through one or more application programming interfaces (APIs). These APIs help application 720 read and / or write application data 714, transmit or receive information via communication interface 702, receive or display information on user interface 704, etc.
[0115] In some terminology, application 720 may be simply referred to as "app". Furthermore, application 720 can be downloaded to device 700 through one or more online app stores or app markets. However, applications can also be installed on device 700 in other ways, such as through a web browser or a physical interface on device 700 (e.g., a USB port).
[0116] Please refer to Figure 8 Distributed database partition migration devices can be applied to, for example... Figure 7 The device shown implements the technical solution described in this specification. The partition migration device for the distributed database may include: The blocking module 801 is configured to, in response to a migration request for the partition to be migrated, perform a write blocking operation to prevent new data write requests for the partition to be migrated, and determine the blocking write time point of the partition to be migrated. The filtering module 802 is used to traverse the transaction set corresponding to the source log stream maintained by the source node group, filter out the transactions that have accessed the partition to be migrated before the blocking write time point and are still not finished, as the transactions to be migrated, and determine the list of transaction identifiers to be migrated. The migration module 803 is used to submit the list of transaction identifiers to be migrated and the blocking write time point as migration metadata to the source log stream, so that the target node group can obtain the migration metadata, pull the transaction context of the transaction to be migrated from the source node group based on the migration metadata, and restore the transaction context in the target log stream maintained by the target node group, so that the partition to be migrated can be migrated to the target node group.
[0117] Optionally, during the process of traversing the transaction set corresponding to the source log stream, a transaction-granular mutex lock is applied to each selected transaction to be migrated to block the state change of the transaction to be migrated until the list of transaction identifiers to be migrated is determined and the migration metadata containing the list of transaction identifiers to be migrated is persistently stored in the source log stream, at which point the transaction-granular mutex lock is released.
[0118] Optionally, the blocking module 801 is specifically configured to: generate a monotonic operation sequence number corresponding to the current write blocking operation; send a blocking request carrying the monotonic operation sequence number to the write blocking service corresponding to the source log stream, so that after determining that the monotonic operation sequence number is not less than the operation sequence number of its current record, the write blocking service updates the operation sequence number of its current record to the monotonic operation sequence number, performs a write blocking operation to block new data write requests for the partition to be migrated, and determines the current time as the blocking write time point of the partition to be migrated.
[0119] Optionally, the device further includes: a cleaning module 804; The clearing module 804 is specifically used to, after determining the list of transaction identifiers to be migrated and submitting the migration metadata containing the list of transaction identifiers to be migrated to the source log stream, send an unblocking request carrying the monotonic operation sequence number to the write blocking service, so that the write blocking service clears the write blocking state and resumes new data write requests for the partition to be migrated after determining that the monotonic operation sequence number carried in the unblocking request is consistent with the operation sequence number currently recorded by it.
[0120] Optionally, for any log stream, the log stream has multiple replicas, and the multiple replicas are distributed across multiple nodes in a corresponding node group; one of the multiple replicas is a primary replica and the rest are secondary replicas; The clearing module 804 is further configured to send a clearing request to the write blocking service when it is determined that the currently maintained replica type has been switched from primary replica to secondary replica, so that the write blocking service clears the operation sequence number of the current record.
[0121] Optionally, for any log stream, the log stream has multiple replicas, and the multiple replicas are distributed across multiple nodes in a corresponding node group; The migration module 803 is specifically used to: use the list of transaction identifiers to be migrated and the blocking write time point as migration metadata, and encapsulate the migration metadata into a migration log; and submit the migration log to the majority replica of the source log stream through a consensus protocol, so that the migration log is persistently stored in the majority replica of the source log stream.
[0122] Optionally, the transaction context of the transaction to be migrated is configured to be transmitted in batches, wherein each batch contains the transaction context of a subset of transaction identifiers in the list of transaction identifiers to be migrated, and the transmission of each batch is limited by a preset maximum number of transactions per batch or maximum allowed log size per batch.
[0123] Optionally, the migration module 803 is specifically configured to: submit the list of transaction identifiers to be migrated and the blocking write time point as migration metadata to the source log stream; respond to the target node group's context migration request for any batch of transaction identifier subset sent based on the migration metadata after obtaining the migration metadata, retrieve the transaction status information of each transaction corresponding to the transaction identifier subset as the transaction context corresponding to the transaction identifier subset; return the transaction context corresponding to the transaction identifier subset to the target node group, so that the target node group can restore the transaction context corresponding to the transaction identifier subset in the target log stream maintained by the target node group, so as to reconstruct the current state of each transaction corresponding to the transaction identifier subset in the target log stream.
[0124] Optionally, the migration metadata further includes: a task identifier corresponding to the current migration task; the task identifier corresponding to the current migration task is generated after receiving a migration request for the partition to be migrated; the task identifier is used as a currently valid task identifier in the target node group after the target node group obtains the migration metadata, and is used to perform consistency verification on the task identifier carried in the received transaction context during the subsequent process of the target node group pulling the transaction context of the transaction to be migrated from the source node group; wherein, during the consistency verification process, if the task identifier carried in the received transaction context is consistent with the currently valid task identifier, the application operation is allowed to be executed; otherwise, the recovery of the transaction context is rejected.
[0125] Optionally, for any log stream, the log stream has multiple replicas, and the multiple replicas are distributed across multiple nodes in a corresponding node group; The migration module 803 is specifically used to: use the list of transaction identifiers to be migrated, the blocking write time point, and the task identifier as migration metadata, and encapsulate the migration metadata into a migration log; submit the migration log to the majority replica of the source log stream through a consensus protocol; wherein, the task identifier is bound to the log sequence number of the migration log, so that the target node group determines the order of the task identifiers based on the global monotonicity of the log sequence number.
[0126] Please refer to Figure 9 Distributed database partition migration devices can be applied to, for example... Figure 7 The device shown implements the technical solution described in this specification. The partition migration device for the distributed database may include: The acquisition module 901 is used to acquire migration metadata, which includes at least a list of transaction identifiers to be migrated and a blocking write time point; wherein, the blocking write time point is determined by the source node group after executing a write blocking operation to prevent new data write requests to the partition to be migrated in response to a migration request for the partition to be migrated; the list of transaction identifiers to be migrated is used to indicate transactions that the source node group has accessed the partition to be migrated before the blocking write time point and which are still not completed; the migration metadata is obtained by the source node group after submitting the list of transaction identifiers to be migrated and the blocking write time point as migration metadata to the source log stream maintained by the source node group; The pull module 902 is used to pull the transaction context of the transaction to be migrated from the source node group based on the list of transaction identifiers to be migrated in the migration metadata; The migration module 903 is used to restore the transaction context of the transaction to be migrated in the target log stream maintained by the target node group, so that the partition to be migrated can be migrated to the target node group.
[0127] For ease of description, the above devices are described by dividing them into various modules or units based on their functions. Of course, when implementing one or more of these specifications, the functions of each module or unit can be implemented in the same or different software and / or hardware, or a module that performs the same function can be implemented by a combination of multiple sub-modules or sub-units, etc. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.
[0128] Based on the same concept as the methods described above, this specification also provides an electronic device, including: a processor; a memory for storing processor-executable instructions; wherein the processor performs the steps of the method as described in any of the above embodiments by executing the executable instructions.
[0129] Based on the same concept as the methods described above, this specification also provides a computer-readable storage medium having computer instructions stored thereon that, when executed by a processor, implement the steps of the methods as described in any of the above embodiments.
[0130] Based on the same concept as the methods described above, this specification also provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of the methods as described in any of the above embodiments.
[0131] What those skilled in the art will understand is: In this specification, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, product, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, product, or apparatus. Without further limitation, the presence of additional identical or equivalent elements in a process, method, product, or apparatus that includes said elements is not excluded.
[0132] In this specification, “a,” “an,” and “the” do not specifically refer to the singular, but may also include the plural.
[0133] In this specification, ordinal numbers such as "first," "second," etc., do not necessarily indicate order; they are often used to distinguish between objects. For example, "first server" and "second server" usually refer to two servers. To differentiate between these two servers, they are described as "first server" and "second server." Of course, sometimes these two servers may be the same server.
[0134] In this specification, unless explicitly stated otherwise, "receiving and sending data" does not necessarily mean direct receiving and sending; it can also mean indirect receiving and sending. For example, A receiving data sent by B can be understood as A directly receiving the data sent by B, or it can be understood as A indirectly receiving the data sent by B through other entities such as C. Similarly, B sending data to A can be understood as B sending the data directly to A, or it can be understood as B indirectly sending the data to A through other entities such as C. Here, C can be one entity, or it can be two or more entities.
[0135] In this specification, unless explicitly stated otherwise, the relationships between structures can be direct or indirect. For example, when describing "A is connected to B," unless it is explicitly stated that A and B are directly connected, it should be understood that A can be directly connected to B or indirectly connected to B. Similarly, when describing "A is on top of B," unless it is explicitly stated that A is directly above B (AB is adjacent and A is above B), it should be understood that A can be directly above B or indirectly above B (AB is separated by other elements, and A is above B). And so on.
[0136] This specification uses specific terms to describe embodiments thereof. Terms such as "an embodiment," "one embodiment," and / or "some embodiments" refer to a particular feature, structure, or characteristic associated with at least one embodiment of this specification. Therefore, it should be emphasized and noted that references to "an embodiment," "one embodiment," or "an alternative embodiment" in different locations throughout this specification do not necessarily refer to the same embodiment. Furthermore, those skilled in the art can combine and integrate the different embodiments or examples described herein, as well as the features of those different embodiments or examples, without contradiction.
[0137] Although one or more embodiments of this specification provide method steps as described in the embodiments or flowcharts, it is understood that the order of steps listed in the embodiments or flowcharts is only one of many possible execution orders and does not represent the only execution order. Therefore, when the claims involve method steps, any changes or adjustments to the order of such steps, or the parallelism between steps, are also within the scope of protection of the claims.
Claims
1. A partition migration method for a distributed database, wherein the distributed database comprises several node groups, each node group maintains a log stream, the log stream being used to record data change logs of multiple data partitions within the node group; when any data partition of any node group is determined to be a partition to be migrated, the partition to be migrated corresponds to a source node group and a target node group, the method being applied to the master node of the source node group, comprising: In response to a migration request for the partition to be migrated, a write blocking operation is performed to prevent new data write requests for the partition to be migrated, and the blocking write time point for the partition to be migrated is determined. Iterate through the transaction set corresponding to the source log stream maintained by the source node group, filter out the transactions that have accessed the partition to be migrated before the blocking write time point and are still not finished, and determine the list of transaction identifiers to be migrated. The list of transaction identifiers to be migrated and the blocking write time point are submitted as migration metadata to the source log stream so that the target node group can obtain the migration metadata, pull the transaction context of the transaction to be migrated from the source node group based on the migration metadata, and restore the transaction context in the target log stream maintained by the target node group so that the partition to be migrated can be migrated to the target node group.
2. The method as described in claim 1, wherein during the process of traversing the transaction set corresponding to the source log stream, a transaction-granular mutex lock is applied to each selected transaction to be migrated to block the state change of the transaction to be migrated until the list of transaction identifiers to be migrated is determined and the migration metadata containing the list of transaction identifiers to be migrated is persistently stored in the source log stream, and then the transaction-granular mutex lock is released.
3. The method of claim 1, wherein performing a write blocking operation to prevent new data write requests to the partition to be migrated, and determining the blocking write time point of the partition to be migrated, specifically includes: Generate the monotonic operation number corresponding to the current write blocking operation; A blocking request carrying the monotonic operation sequence number is sent to the write blocking service corresponding to the source log stream, so that after the write blocking service determines that the monotonic operation sequence number is not less than the operation sequence number of its current record, it updates the operation sequence number of its current record to the monotonic operation sequence number, performs a write blocking operation to block new data write requests for the partition to be migrated, and determines the current time as the blocking write time point of the partition to be migrated.
4. The method of claim 3, further comprising: After determining the list of transaction identifiers to be migrated and submitting the migration metadata containing the list of transaction identifiers to the source log stream, an unblocking request carrying the monotonic operation sequence number is sent to the write blocking service. This allows the write blocking service to clear the write blocking state and resume new data write requests for the partition to be migrated after determining that the monotonic operation sequence number carried in the unblocking request is consistent with the operation sequence number currently recorded.
5. The method of claim 3, wherein for any log stream, the log stream has multiple replicas, and the multiple replicas are distributed across multiple nodes in a corresponding node group; one of the multiple replicas is a primary replica, and the rest are secondary replicas; the method further comprises: When it is determined that the currently maintained replica type is being switched from primary replica to secondary replica, a clear request is sent to the write blocking service so that the write blocking service clears the operation sequence number of the current record.
6. The method of claim 1, wherein for any log stream, the log stream has multiple replicas, and the multiple replicas are distributed across multiple nodes in a corresponding node group; The list of transactions to be migrated and the blocking write time points are submitted as migration metadata to the source log stream, specifically including: The list of transactions to be migrated and the blocking write time point are used as migration metadata, and the migration metadata is encapsulated into a migration log; Through a consensus protocol, the migration log is submitted to a majority copy of the source log stream so that the migration log is persistently stored in the majority copy of the source log stream.
7. The method of claim 1, wherein the transaction context of the transaction to be migrated is configured to be transmitted in batches, wherein each batch contains the transaction context of a subset of transaction identifiers in the list of transaction identifiers to be migrated, and the transmission of each batch is limited by a preset maximum number of transactions per batch or a maximum allowed log size per batch.
8. The method as described in claim 7, wherein the list of transaction identifiers to be migrated and the blocking write time point are submitted as migration metadata to the source log stream, so that the target node group can obtain the migration metadata, and pull the transaction context of the transaction to be migrated from the source node group based on the migration metadata, and restore the transaction context in the target log stream maintained by the target node group, specifically includes: The list of transactions to be migrated and the blocking write time point are submitted as migration metadata to the source log stream; In response to the target node group receiving the migration metadata and sending a context migration request for any batch of transaction identifier subset based on the migration metadata, the transaction status information of each transaction corresponding to the transaction identifier subset is retrieved and used as the transaction context corresponding to the transaction identifier subset. The transaction context corresponding to the subset of transaction identifiers is returned to the target node group so that the target node group can restore the transaction context corresponding to the subset of transaction identifiers in the target log stream maintained by the target node group, so as to reconstruct the current state of each transaction corresponding to the subset of transaction identifiers in the target log stream.
9. The method of claim 1, wherein the migration metadata further comprises: The task identifier corresponding to the current migration task; The task identifier corresponding to the current migration task is generated after receiving a migration request for the partition to be migrated; The task identifier is used as the currently valid task identifier in the target node group after the target node group obtains the migration metadata. During the subsequent process of the target node group pulling the transaction context of the transaction to be migrated from the source node group, the task identifier carried in the received transaction context is used to perform consistency verification. In the consistency verification process, if the task identifier carried in the received transaction context is consistent with the currently valid task identifier, the application operation is allowed to be executed; otherwise, the recovery of the transaction context is rejected.
10. The method of claim 9, wherein for any log stream, the log stream has multiple replicas, and the multiple replicas are distributed across multiple nodes in a corresponding node group; The list of transactions to be migrated and the blocking write time points are submitted as migration metadata to the source log stream, specifically including: The list of transactions to be migrated, the blocking write time point, and the task identifier are used as migration metadata, and the migration metadata is encapsulated into a migration log. The migration log is submitted to a majority replica of the source log stream via a consensus protocol; wherein the task identifier is bound to the log sequence number of the migration log, so that the target node group determines the order of the task identifiers based on the global monotonicity of the log sequence number.
11. A partition migration method for a distributed database, wherein the distributed database comprises several node groups, each node group maintains a log stream, the log stream being used to record data change logs of multiple data partitions within the node group; when any data partition of any node group is determined to be a partition to be migrated, the partition to be migrated corresponds to a source node group and a target node group, the method being applied to the master node of the target node group, comprising: The migration metadata is obtained, which includes at least a list of transaction identifiers to be migrated and a blocking write time point. The blocking write time point is determined by the source node group after executing a write blocking operation to prevent new data write requests to the partition to be migrated in response to a migration request. The list of transaction identifiers to be migrated indicates transactions that the source node group accessed the partition to be migrated before the blocking write time point and are still ongoing. The migration metadata is obtained by the source node group after submitting the list of transaction identifiers to be migrated and the blocking write time point as migration metadata to the source log stream maintained by the source node group. Based on the list of transaction identifiers to be migrated in the migration metadata, the transaction context of the transaction to be migrated is pulled from the source node group; The transaction context is restored in the target log stream maintained by the target node group so that the partition to be migrated can be migrated to the target node group.
12. A partition migration device for a distributed database, wherein the distributed database comprises several node groups, each node group maintains a log stream, the log stream being used to record data change logs of multiple data partitions within the node group; when any data partition of any node group is determined to be a partition to be migrated, the partition to be migrated corresponds to a source node group and a target node group, the device being applied to the master node of the source node group, comprising: A blocking module is used to respond to a migration request for the partition to be migrated, perform a write blocking operation to prevent new data write requests for the partition to be migrated, and determine the blocking write time point of the partition to be migrated. The filtering module is used to traverse the transaction set corresponding to the source log stream maintained by the source node group, filter out the transactions that have accessed the partition to be migrated before the blocking write time point and are still not finished, as the transactions to be migrated, and determine the list of transaction identifiers to be migrated. The migration module is used to submit the list of transaction identifiers to be migrated and the blocking write time point as migration metadata to the source log stream, so that the target node group can obtain the migration metadata, pull the transaction context of the transaction to be migrated from the source node group based on the migration metadata, and restore the transaction context in the target log stream maintained by the target node group, so that the partition to be migrated can be migrated to the target node group.
13. A partition migration device for a distributed database, wherein the distributed database comprises several node groups, each node group maintains a log stream, the log stream being used to record data change logs of multiple data partitions within the node group; when any data partition of any node group is determined to be a partition to be migrated, the partition to be migrated corresponds to a source node group and a target node group, the device being applied to the master node of the target node group, comprising: The acquisition module is used to acquire migration metadata, which includes at least a list of transaction identifiers to be migrated and a blocking write time point. The blocking write time point is determined by the source node group after executing a write blocking operation to prevent new data write requests to the partition to be migrated in response to a migration request. The list of transaction identifiers to be migrated indicates transactions that the source node group accessed the partition to be migrated before the blocking write time point and are still ongoing. The migration metadata is acquired by the source node group after submitting the list of transaction identifiers to be migrated and the blocking write time point as migration metadata to the source log stream maintained by the source node group. The pull module is used to pull the transaction context of the transaction to be migrated from the source node group based on the list of transaction identifiers to be migrated in the migration metadata; The migration module is used to restore the transaction context of the transaction to be migrated in the target log stream maintained by the target node group, so that the partition to be migrated can be migrated to the target node group.
14. An electronic device comprising: processor; A memory for storing processor-executable instructions; wherein the processor implements the steps of the method as described in any one of claims 1-11 by executing the executable instructions.
15. A computer-readable storage medium having stored thereon computer instructions that, when executed by a processor, implement the steps of the method as claimed in any one of claims 1-11.
16. A computer program product comprising a computer program / instructions that, when executed by a processor, implement the steps of the method as claimed in any one of claims 1-11.
