Method, device and equipment for solving uneven distribution of distributed transaction data
By monitoring configuration information updates and randomly allocating data shards, the problem of uneven data distribution caused by device failures in the distributed transaction framework is solved, achieving uniform data storage across multiple device shards and alleviating the storage pressure on a single device.
Patent Information
- Application Number
- CN202311648519.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-04
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2043-12-04
AI Technical Summary
In a distributed transaction framework, equipment failures can lead to an increase in the number of transaction tasks on normally functioning equipment, increasing the pressure on data storage. Existing technologies have failed to effectively address the problem of uneven data distribution.
By monitoring configuration information updates, adjusting the combination of unit identifier and shard number, and using random transaction serial numbers to determine data shards, data is allocated to shards on multiple devices for storage, thus alleviating the storage pressure on a single device.
It effectively reduces the data storage pressure on a single device, achieves uniform data distribution, and avoids overloading of a single device.
Smart Images

Figure CN117608492B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of distributed systems, and more specifically, to methods, apparatus, and devices for solving the problem of uneven distribution of distributed transaction data. Background Technology
[0002] In a distributed transaction framework, multiple devices can execute transaction tasks. If a device fails, the transaction tasks originally handled by the failed device can be reassigned to the normally functioning devices. This increases the number of transaction tasks that the normally functioning devices need to handle, and the data involved in the transaction process is stored on the normally functioning devices, increasing the data storage pressure on them. Summary of the Invention
[0003] In view of this, this application provides a method, apparatus and device for solving the problem of uneven distribution of distributed transaction data.
[0004] To achieve the above objectives, this application provides the following technical solution:
[0005] According to a first aspect of the present disclosure, a method for resolving uneven distribution of distributed transaction data is provided, applied to a first device, comprising:
[0006] Listen for updated configuration items in the configuration information, which includes the correspondence between unit identifier combinations and unit fragment number combinations. The unit identifier combination includes one or more unit identifiers, and the unit fragment number combination corresponding to the unit identifier combination includes the number of unit fragments corresponding to each unit identifier in the unit identifier combination. The configuration item includes the updated target unit identifier combination and the updated target unit fragment number combination.
[0007] Update the combination of unit identifiers stored in the cache to the target combination of unit identifiers, and update the combination of unit fragment numbers stored in the cache to the target combination of unit fragment numbers;
[0008] Receive the transaction task and the task status of the transaction task;
[0009] If the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device, and the task status of the transaction task is unprocessed, obtain a random transaction serial number.
[0010] The remainder between the transaction serial number and the number of unit fragments in the first unit is determined as the target label of the fragment storing the data of the transaction task;
[0011] From the fragments with the target number in the first unit and the fragments with the target number in the second unit, a target fragment is randomly selected as the fragment for storing the data of the transaction task; the unit identifier of the unit to which the target fragment belongs and the target number constitute the first fragment key of the target fragment;
[0012] The data involved in executing the transaction task will be stored in the target shard with the first shard key.
[0013] According to a second aspect of the present disclosure, an apparatus for resolving uneven distribution of distributed transaction data is provided, applied to a first device, comprising:
[0014] The monitoring module is used to monitor the updated configuration items in the configuration information. The configuration information includes the correspondence between unit identifier combinations and unit fragment number combinations. The unit identifier combination includes one or more unit identifiers. The unit fragment number combination corresponding to the unit identifier combination includes the number of unit fragments corresponding to each unit identifier in the unit identifier combination. The configuration item includes the updated target unit identifier combination and the updated target unit fragment number combination.
[0015] The update module is used to update the combination of unit identifiers stored in the cache to the target combination of unit identifiers, and to update the combination of unit fragment numbers stored in the cache to the target combination of unit fragment numbers.
[0016] The receiving module is used to receive transaction tasks and the task status of the transaction tasks;
[0017] The first acquisition module is configured to acquire a random transaction serial number if the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device, and the task status of the transaction task is unprocessed.
[0018] The first determining module is used to determine the target label of the fragment storing the data of the transaction task as the remainder between the transaction serial number and the number of unit fragments of the first unit.
[0019] The second determining module is used to randomly determine a target segment as the segment for storing the data of the transaction task from the segment with the target number in the first unit and the segment with the target number in the second unit; the unit identifier of the unit to which the target segment belongs and the target number constitute the first segment key of the target segment;
[0020] The first storage module is used to store the data involved in the execution of the transaction task into a target shard having the first shard key.
[0021] According to a third aspect of the present disclosure, a first device is provided, comprising:
[0022] processor;
[0023] Memory used to store the processor's executable instructions;
[0024] The processor is configured to execute the instructions to implement the method for resolving uneven distribution of distributed transaction data as described in the first aspect.
[0025] As can be seen from the above technical solution, this application provides a method to solve the problem of uneven distribution of distributed transaction data. If the second device fails, the transaction tasks originally processed by the second device may be assigned to the first device, resulting in a significant increase in the number of transaction tasks processed by the first device. Since a large amount of data is involved in the process of processing transaction tasks, in order to reduce the data storage pressure of the first unit in the first device, the configuration items can be changed so that the first device can perform read or storage operations on the shards in the first unit of the first device and the shards in the second unit of the second device. This allows the data involved in processing transaction tasks to be stored in the shards in the first unit and the shards in the second unit, thus alleviating the data storage pressure of the first unit in the first device. Attached Figure Description
[0026] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0027] Figure 1 This is a schematic diagram illustrating a hardware architecture according to an exemplary embodiment;
[0028] Figure 2 This is a flowchart illustrating the operation of a device related to a hardware architecture according to an exemplary embodiment;
[0029] Figure 3 This is a schematic diagram illustrating, according to an exemplary embodiment, a data storage segment in a first unit and a data storage segment in a second unit;
[0030] Figure 4 This is a flowchart illustrating a method for resolving uneven distribution of distributed transaction data according to an exemplary embodiment;
[0031] Figure 5 This is a schematic diagram illustrating a global transaction identifier according to an exemplary embodiment;
[0032] Figure 6 This is a block diagram of an apparatus for solving uneven distribution of distributed transaction data, according to an exemplary embodiment.
[0033] Figure 7 This is a block diagram illustrating an apparatus for a first device according to an exemplary embodiment. Detailed Implementation
[0034] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0035] This application provides a method, apparatus, and device for solving the problem of uneven distribution of distributed transaction data. Before introducing the technical solutions involved in the embodiments of this application, the hardware architecture and related technologies involved in this application will be described first.
[0036] Figure 1 This is a schematic diagram of a hardware architecture according to an exemplary embodiment, which includes, but is not limited to, a task allocation device 11, a first device 12, and one or more second devices 13.
[0037] For example, different devices in "first device 12 and one or more second devices 13" may be located in different cities. For example, some devices in "first device 12 and one or more second devices 13" may be located in the same city.
[0038] For example, different second devices 13 may be located in different cities or in the same city.
[0039] For example, the method for solving uneven distribution of distributed transaction data provided in this application embodiment can be applied to a first device or a second device.
[0040] In this application, the faulty device is referred to as the second device; the normally operating device is referred to as the first device. Since transaction tasks originally processed by one or more second devices may be reassigned to the first device, leading to an increase in the number of transaction tasks processed by the first device, this application provides a technical solution to address this problem. This application describes a method for resolving uneven distribution of distributed transaction data from the perspective of the first device.
[0041] For example, the task assignment device 11 can be any electronic product that can interact with the user through one or more means such as a keyboard, touchpad, touch screen, remote control, voice interaction or handwriting device, such as mobile phone, tablet computer, PDA, personal computer, wearable device, smart TV, etc.
[0042] For example, the task allocation device 11 can be a single server, a server cluster consisting of multiple servers, or a cloud computing service center.
[0043] For example, any of the first device 12 and one or more second devices 13 can be any electronic product that can interact with a user through one or more means such as a keyboard, touchpad, touch screen, remote control, voice interaction or handwriting device, such as mobile phone, tablet computer, PDA, personal computer, wearable device, smart TV, etc.
[0044] For example, any one of the first device 12 and one or more second devices 13 can be a server, a server cluster consisting of multiple servers, or a cloud computing service center.
[0045] The following explains the working process of the devices included in the hardware architecture. Figure 2 This is a flowchart illustrating the operation of a device related to a hardware architecture according to an exemplary embodiment, the method including steps A1 to A6.
[0046] Step A1: The task allocation device 11 receives a new transaction task and determines, based on preset rules, that the transaction task needs to be allocated to the second device 13.
[0047] In this application embodiment, the new transaction task refers to a task that has not been processed by other devices.
[0048] For example, the preset rules can be determined based on the actual situation, and no restrictions are imposed here.
[0049] For example, a preset rule could be used to determine which devices located in the city where the transaction task is to be performed are the devices that need to perform the transaction task.
[0050] It is understandable that the transaction task is initiated by the user or the enterprise. When initiating the transaction task, the geographical location of the transaction task can be obtained, and thus the city where the transaction task is located can be obtained.
[0051] Step A2: After receiving the transaction task, the distributed number generator in the second device 13 randomly issues a transaction serial number. Based on the remainder of the transaction serial number and the number of unit shards stored in the second device 13, and the unit identifier of the unit stored in the second device 13, the target shard key is obtained.
[0052] It is understood that any one of the first device 12 and one or more second devices 13 includes one or more units, and each unit includes multiple shards. Each shard corresponds to a storage space.
[0053] Assume the second device 13 includes a second unit with unit identifier B, and the number of unit fragments in this second unit is 4, with the fragment keys of the 4 fragments being B0, B1, B2, and B3 respectively. Assume the transaction sequence number is 9234235655, then the remainder of 9234235655 divided by 4 is 3, so the target fragment key obtained in step A2 is B3, which includes the unit identifier B and the label 3.
[0054] Step A3: The second device 13 executes the transaction task and stores the data involved in the execution of the transaction task into a shard with a target shard key.
[0055] Step A4: If the second device malfunctions and the above transaction task has not been completed, the task status of the transaction task is "processing". For example, the task allocation device 11 can allocate the transaction task to the first device 12. For example, the disaster recovery device can allocate the transaction to the first device 12.
[0056] For example, a disaster recovery device can be a single server, a server cluster consisting of multiple servers, or a cloud computing service center.
[0057] For example, a second device malfunction means that the application module in the second device used to process transaction tasks malfunctions and cannot continue to process transaction tasks, but the second unit in the second device can still be used.
[0058] Step A5: The first device 12 receives the transaction task, and the task status of the transaction task is "processing".
[0059] Step A6: The first device 12 receives a new transaction task assigned by the task allocation device 11. The task status of the transaction task is unprocessed.
[0060] In step A6, the first device 12 can execute the method for resolving uneven distribution of distributed transaction data provided in the embodiments of this application.
[0061] Understandably, transaction tasks that should have been processed by the second device 13 were instead processed by the first device due to a malfunction in the second device, resulting in a significant increase in the number of transaction tasks processed by the first device.
[0062] For example, the number of first devices may be one or more.
[0063] In related technologies, after receiving a new transaction task, the first device 12 can perform the following steps B1 to B2.
[0064] Step B1: The distributed number generator in the first device 12 randomly publishes transaction serial numbers. Based on the remainder of the transaction serial number and the number of unit fragments of the first unit in the first device 12, and the unit identifier of the first unit in the first device 12, the fragmentation key is obtained.
[0065] It is understood that any one of the first device 12 and one or more second devices 13 includes one or more units, and each unit includes multiple shards. Each shard corresponds to a storage space.
[0066] Assume the first device 12 includes a first unit with unit identifier A, and the number of unit fragments in this first unit is 4, with the fragment keys of the 4 fragments being A0, A1, A2, and A3 respectively. Assume the transaction sequence number is 9234235655, then the remainder of 9234235655 divided by 4 is 3, so the fragment key obtained in step B1 is A3, which includes the unit identifier A and the label 3.
[0067] Step B2: The first device 12 executes the transaction task and stores the data involved in the execution of the transaction task into a shard with a sharding key A3.
[0068] In summary, in the relevant technologies, the first device 12 stores the data related to the received transaction tasks in a fragment within the first unit of the first device. Therefore, the storage pressure is concentrated in the first unit of the first device 12.
[0069] Figure 2 This is a schematic diagram illustrating a segment of a first unit in a first device 12, where all data is stored, according to an exemplary embodiment.
[0070] Assume that the first device 12 stores a first unit identified as A, which contains four shards with shard keys A0, A1, A2, and A3. The second device 13 stores a second unit identified as B, which also contains four shards with shard keys B0, B1, B2, and B3. If the application module of the second device 13 fails, transaction tasks originally processed by the second device 13 will be processed by the first device 12. The first device 12 will then store all data involved in the transaction processing in the shards of its first unit. This results in the second unit's shards in the second device 13 becoming idle, while the data storage pressure on the first unit's shards in the first device 12 increases.
[0071] The method for resolving uneven distribution of distributed transaction data provided in this application embodiment allows the first device 12 to store the data involved in processing the transaction task into a fragment of the second unit in the second device, such as... Figure 3 As shown. Figure 3 This is a schematic diagram illustrating, according to an exemplary embodiment, that data is stored in a fragment of a first unit and a fragment of a second unit.
[0072] Assume that the first device 12 stores a first unit with unit identifier A, which contains four shards with shard keys A0, A1, A2, and A3 respectively; and the second device 13 stores a second unit with unit identifier B, which also contains four shards with shard keys B0, B1, B2, and B3 respectively. If the application module of the second device 13 fails, all transaction tasks originally processed by the second device 13 will be processed by the first device 12.
[0073] The first device 12 stores the data involved in the transaction task processing in the first unit of the first device 12 and the second unit of the second device 13, respectively. This reduces the data storage pressure on the first unit of the first device 12.
[0074] The method for solving the uneven distribution of distributed transaction data provided in the embodiments of this application will be described below in conjunction with the above hardware architecture and related technologies.
[0075] Figure 4 This is a flowchart illustrating a method for resolving uneven data distribution in distributed transactions, according to an exemplary embodiment. Figure 4 As shown, the method for solving the uneven distribution of distributed transaction data is used in the first device 12, including the following steps S41 to S47.
[0076] Step S41: Listen for updated configuration items in the configuration information.
[0077] The configuration information includes the correspondence between unit identifier combinations and unit fragment number combinations. The unit identifier combination includes one or more unit identifiers, and the unit fragment number combination corresponding to the unit identifier combination includes the number of unit fragments corresponding to each unit identifier in the unit identifier combination. The configuration item includes the updated target unit identifier combination and the updated target unit fragment number combination.
[0078] For example, the configuration information in the first device includes a combination of unit identifiers, which refers to the unit identifiers of the units that the first device can read, write, and store.
[0079] The following example illustrates the correspondence between the combination of unit identifiers and the combination of the number of unit segments.
[0080] Suppose that the first device stores a first unit, the unit identifier of which is A, and the first unit includes 4 shards. If there is no second device in a faulty state, then the configuration information in the first device includes the unit identifier combination A, and the unit shard number combination corresponding to the unit identifier combination is 4, which can be represented as: datazone = A, set-count = 4.
[0081] Suppose a first device stores a first unit, whose unit identifier is A, and the first unit includes 4 shards. If there is a second device in a faulty state, and the second device stores a second unit, whose unit identifier is B, and the second unit includes 5 shards, then the configuration information in the first device includes the combination of unit identifiers A and B, and the combination of the number of unit shards corresponding to the combination of unit identifiers is 4 and 5, which can be represented as: datazone = A, B; set-count = 4, 5.
[0082] For example, multiple unit identifiers in a unit identifier combination can be separated by a set symbol, which can be any symbol; the above example uses a comma (",") as a specific symbol. Similarly, multiple unit fragment numbers in a unit fragment number combination can be separated by a set symbol, which can be any symbol; the above example uses a comma (",") as a specific symbol.
[0083] For example, if the unit identifier combination is updated from A to A,B and the unit shard number combination is updated from 4 to 4,5, then the monitored configuration items are datazone=A,B; set-count=4,5.
[0084] For example, a cell identifier combination may include one or more cell identifiers, and the number of cell identifiers included in the cell identifier combination is the same as the number of cell fragments included in the cell fragment number combination. This is because each cell identifier corresponds to one cell fragment.
[0085] It is understandable that the first device can be a device under different models. The implementation of step S41 may differ for different models, which will be explained separately below.
[0086] If the first device is based on the Try-Confirm-Cancel (TCC) model, then the updated configuration items in the configuration information can be listened to through the preset ConfigurationChangeListener interface.
[0087] For example, add an implementation of the ConfigurationChangeListener interface to the TCC-generated shard key class.
[0088] For example, the configuration information loading method under the TCC model supports dcc, which is a listener that is independently implemented based on the distributed configuration center API (Application Programming Interface) to listen for configuration change information.
[0089] If the first device is based on the Saga model, the @Value annotation is used to listen for updated configuration items in the configuration information.
[0090] For example, Saga uses the @Value annotation to mark attributes such as the combination of cell identifiers and the combination of cell shard numbers that support hot refresh, based on the automatic hot refresh mechanism of the distributed configuration center.
[0091] Step S42: Update the unit identifier combination stored in the cache to the target unit identifier combination, and update the unit fragment number combination stored in the cache to the target unit fragment number combination.
[0092] It can be understood that when the first device obtains the shard key, it retrieves the cell identifier combination and the cell shard number combination from the first device's cache, so it needs to update the cache.
[0093] It is understandable that the first device can be a device under different models. The way to implement step S42 may be different for different models, which will be explained below.
[0094] If the first device is based on the Try-Confirm-Cancel (TCC) model, then the pre-defined onChangeEvent(ConfigurationChangeEvent event) method updates the unit identifier combination stored in the cache to the target unit identifier combination, and updates the unit fragment number combination stored in the cache to the target unit fragment number combination.
[0095] For example, the onChangeEvent(ConfigurationChangeEvent event) method is used to trigger relevant processing logic when configuration items change.
[0096] If the first device is a Saga model-based device, the @Value annotation updates the unit identifier combination stored in the cache to the target unit identifier combination, and updates the unit shard number combination stored in the cache to the target unit shard number combination.
[0097] Step S43: Receive the transaction task and the task status of the transaction task.
[0098] For example, if the transaction task is a new transaction task assigned by the task allocation device 11, the task status is unprocessed. If the transaction task is a task that the second device has not completed due to a malfunction, the task status is in progress.
[0099] Step S44: If the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device, and the task status of the transaction task is unprocessed, obtain a random transaction serial number.
[0100] In this application, the unit in the first device is referred to as the first unit, and the unit in the second device is referred to as the second unit.
[0101] It is understood that if the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device, and the task status of the transaction task is unprocessed, it indicates that the transaction task is a new transaction task assigned by the task allocation device. If the second device is not malfunctioning, the new transaction task may be assigned to the second device.
[0102] It is understandable that if the target unit identifier combination includes one unit identifier, it means that the first device has not undertaken the transaction task of the faulty second device, so it is a normal scenario; if the target unit identifier combination includes multiple unit identifiers, it means that the first device has undertaken the transaction task that was originally handled by the faulty second device, so it is a disaster recovery application scenario.
[0103] For example, different unit identifiers in the unit identifier combination are separated by a set symbol, and different unit fragment numbers in the unit fragment number combination are separated by a set symbol. Wherein, if the target unit identifier combination includes one or more set symbols, the target unit identifier combination is determined to include the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device.
[0104] It is understood that if the target unit identifier combination includes multiple unit identifiers, for example, the target unit identifier combination includes: the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device.
[0105] For example, transaction serial numbers can be randomly distributed by a distributed serial number generator in the first device. It is understood that a transaction serial number is randomly assigned each time a new transaction task is received.
[0106] Step S45: Determine the target label of the fragment storing the transaction task data as the remainder between the transaction serial number and the number of unit fragments of the first unit.
[0107] Assuming the transaction sequence number is 9234235655 and the number of unit fragments in the first unit is 4, then the remainder of 9234235655 and 4 is 3, which means the target number is 3.
[0108] Assuming the transaction sequence number is 9234235656 and the number of unit fragments in the first unit is 4, then the remainder of 9234235656 and 4 is 0, which means the target label is 0.
[0109] Step S46: Randomly select a target fragment from the fragments with the target number in the first unit and the fragments with the target number in the second unit as the fragments for storing the data of the transaction task.
[0110] The unit identifier of the unit to which the target fragment belongs and the target label constitute the first fragment key of the target fragment.
[0111] The following example illustrates this. Assume the target number is 3, and the first unit contains 4 shards with shard keys A0, A1, A2, and A3. Assume the second unit contains 5 shards with shard keys B0, B1, B2, B3, and B4. The shard key for target number 3 in the first unit is A3, and the shard key for target number 3 in the second unit is B3. Therefore, a target shard can be randomly selected from the shards corresponding to shard key A3 and the shards corresponding to shard key B3 to store the data involved in this transaction task.
[0112] Since a target shard is randomly selected from the shards corresponding to shard key A3 and shard key B3, A0, A1, A2, A3, B0, B1, B2, and B3 can store the data involved in the transaction task with equal probability, thus avoiding concentrating the data storage pressure on the first unit.
[0113] It is understandable that the first device can be a device under different models. The way to implement steps S45 to S46 may be different for different models, which will be explained below.
[0114] If the first device is based on the Try-Confirm-Cancel (TCC) model, then steps S45 to S46 can be executed using the shardid(long transactionId) method to calculate and concatenate the final first shard key.
[0115] If the first device is a Saga model-based device, steps S45 to S46 can be executed through the generateShardId(String id) method to calculate and concatenate the final first shard key.
[0116] Step S47: Store the data involved in executing the transaction task into the target shard with the first shard key.
[0117] For example, the first device may also read data from the target shard having the first shard key during the execution of a transaction task.
[0118] This application provides a method for resolving uneven distribution of distributed transaction data. If the second device malfunctions, transaction tasks originally processed by the second device may be reassigned to the first device, causing a significant increase in the number of transaction tasks processed by the first device. Since a large amount of data is involved in processing transaction tasks, in order to reduce the data storage pressure on the first unit of the first device, configuration items can be modified so that the first device can perform read or storage operations on the shards in the first unit of the first device and the shards in the second unit of the second device. This allows the data involved in processing transaction tasks to be stored in the shards in the first unit and the shards in the second unit, thus alleviating the data storage pressure on the first unit of the first device.
[0119] It is understandable that the transaction task received by the first device may be an incomplete transaction task from the second device. In related technologies, when the first device processes this type of transaction task, it will also execute steps B1 to B2 as described above, that is, reallocate a sharding key in the first unit of the first device. An example is given below. Suppose that before processing transaction task A, the second device assigned sharding key B3 to transaction task A. During the processing of transaction task A, the application module of the second device malfunctions, but some data of transaction task A has already been stored in the shard with sharding key B3. Suppose that before processing transaction task A, the first device, after executing steps B1 to B2, reallocates sharding key A3. Since the shard with sharding key A3 does not store the data from the shard with sharding key B3, transaction task A may fail to be processed.
[0120] It is understandable that the first device can be a device from different models. The methods for solving the above problems may differ for different models, which will be explained below.
[0121] The first device is a device based on the Try-Confirm-Cancel (TCC) model. To address the problems existing in the aforementioned related technologies, embodiments of this application provide the following method, which includes steps C1 to C3.
[0122] Step C1: If the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device, and the task status of the transaction task is in processing, obtain the second shard key allocated to the transaction task before the execution of the transaction task.
[0123] It is understood that if the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device, and the task status of the transaction task is "processing", it indicates that the transaction task may be a transaction task that the second device has not completed due to a malfunction, or it may be a transaction task that the first device continues to process.
[0124] In TCC mode, the shard key assigned to a transaction task is registered in the global transaction identifier (XID), so the second shard key can be obtained from the global transaction identifier.
[0125] Figure 5 This is a schematic diagram illustrating a global transaction identifier according to an exemplary embodiment.
[0126] Assuming the transaction sequence number is represented by `transactionId`, the number of unit shards is represented by `set-count`, and the second unit in the second device includes four shards, designated B0, B1, B2, and B3; the unit identifier of the second unit in the second device is B, and the unit identifier is represented by `datazone`. Figure 5 As shown, the second shard key B3 can be obtained from the first two digits of XID.
[0127] Step C2: Store the data involved in executing the transaction task into a shard with the second sharding key.
[0128] Step C3: Access the shard with the second shard key to obtain the data involved in the transaction task.
[0129] Since the second device processes the data involved in transaction task A through the shard storage with the second shard key during the execution of transaction task A, and the first device continues to read or store data from the shard with the second shard key while executing transaction task A, the aforementioned problem will not occur.
[0130] If the first unit in the first device includes four shards with shard keys A0, A1, A2, and A3, and after receiving transaction task B, the distributed serial number issued by the first device's distributed serial number is 9234235654, then the remainder of 9234235654 divided by 4 is 2. Therefore, the shard key assigned to transaction task B is A2. If the first unit is expanded during the processing of transaction task B, for example, from four shards to eight shards, then during the continued processing of transaction task B, it is not necessary to obtain the shard key in real time. Instead, the shard key A2 corresponding to transaction task B is obtained from the global transaction identifier (XID). Therefore, there will be no situation where the shard key A2 cannot be found during the continued processing of transaction task B.
[0131] The first device is a device based on the Saga model. To address the problems existing in the aforementioned related technologies, this application provides the following method, which includes steps D1 to D3.
[0132] Step D1: If the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device, and the task status of the transaction task is in processing, search for the second shard key of the data involved in the transaction task from the unit corresponding to the unit identifier included in the target unit identifier combination.
[0133] For example, a full database routing query can be added to ensure that the data involved in the transaction task (i.e., transaction data) can be retrieved. In the full database routing query, the query conditions do not include the shard key, i.e., a global search.
[0134] Step D2: Store the data involved in executing the transaction task into a shard with the second sharding key.
[0135] Step D3: Access the shard with the second shard key to obtain the data involved in the transaction task.
[0136] If the first device is based on the Saga model, and the first unit in the first device comprises 4 shards, with unit identifier A, and after receiving transaction task C, the transaction sequence number (this is the global transaction number, represented by globalId) distributed by the distributed identifier of the first device is 9234235654, then the remainder of 9234235654 divided by 4 is 2, and the shard key assigned to transaction task C is A2. If, during the processing of transaction task C, the first unit is expanded, for example, from 4 shards to 8 shards, in related technologies, the shard key is calculated in real time during the continued processing of transaction task C. That is, the identifier of the shard key is determined to be the remainder of 9234235654 divided by 8, which is 6. Therefore, during the continued processing of transaction task C, access and reading will be performed on A6. Since the data involved in transaction task C is stored in the shard with shard key A2, this may cause transaction task C to fail. To avoid the above problems, the above problems can also be solved by performing steps D1 to D3.
[0137] In this scenario, "if the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device, and the task status of the transaction task is processing", it indicates that the transaction task may be transaction task C that the first device continues to process.
[0138] The methods described in the above-disclosed embodiments of this application are detailed in terms of the methods. The methods of this application can be implemented by various forms of apparatus. Therefore, this application also discloses an apparatus. Specific embodiments are given below for detailed description.
[0139] Figure 6 This is a block diagram illustrating an apparatus for resolving uneven data distribution in distributed transactions, according to an exemplary embodiment. (Refer to...) Figure 6 The device includes: a listening module 61, an updating module 62, a receiving module 63, a first acquisition module 64, a first determination module 65, a second determination module 66, and a first storage module 67, wherein:
[0140] The monitoring module 61 is used to monitor the updated configuration items in the configuration information. The configuration information includes the correspondence between unit identifier combinations and unit fragment number combinations. The unit identifier combination includes one or more unit identifiers. The unit fragment number combination corresponding to the unit identifier combination includes the number of unit fragments corresponding to each unit identifier in the unit identifier combination. The configuration item includes the updated target unit identifier combination and the updated target unit fragment number combination.
[0141] The update module 62 is used to update the combination of unit identifiers stored in the cache to the target combination of unit identifiers, and to update the combination of unit fragment numbers stored in the cache to the target combination of unit fragment numbers.
[0142] Receiving module 63 is used to receive the transaction task and the task status of the transaction task;
[0143] The first acquisition module 64 is used to acquire a random transaction serial number if the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device, and the task status of the transaction task is unprocessed.
[0144] The first determining module 65 is used to determine the target label of the fragment storing the data of the transaction task as the remainder between the transaction serial number and the number of unit fragments of the first unit.
[0145] The second determining module 66 is used to randomly determine a target segment as the segment for storing the data of the transaction task from the segment with the target number in the first unit and the segment with the target number in the second unit; the unit identifier of the unit to which the target segment belongs and the target number constitute the first segment key of the target segment;
[0146] The first storage module 67 is used to store the data involved in the execution of the transaction task into a target shard having the first shard key.
[0147] In an alternative implementation, the first device is a device based on the Try-Confirm-Cancel model, and further includes:
[0148] The second acquisition module is used to acquire the second shard key allocated to the transaction task before the execution of the transaction task if the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device, and the task status of the transaction task is in processing.
[0149] The second storage module is used to store the data involved in the execution of the transaction task into a shard with the second sharding key;
[0150] The third acquisition module is used to access the shard with the second sharding key to obtain the data involved in the transaction task.
[0151] In an alternative implementation, the first device is a Saga-based device, further comprising:
[0152] The search module is configured to search for the second shard key storing the data involved in the transaction task from the unit corresponding to the unit identifier included in the target unit identifier combination if the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device, and the task status of the transaction task is in processing.
[0153] The third storage module is used to store the data involved in the execution of the transaction task into a shard with the second sharding key;
[0154] The fourth acquisition module is used to access the shard with the second sharding key to obtain the data involved in the transaction task.
[0155] In an alternative implementation, the first device is a device based on the Try-Confirm-Cancel model, and the listening module is specifically used for:
[0156] The system listens for updated configuration items in the configuration information through the preset ConfigurationChangeListener interface.
[0157] In one alternative implementation, the update module includes:
[0158] The first update submodule is used to update the unit identifier combination stored in the cache to the target unit identifier combination and update the unit fragment number combination stored in the cache to the target unit fragment number combination through the preset onChangeEvent(ConfigurationChangeEventevent) method.
[0159] In one alternative implementation, the first device is a Saga-based device, and the listening module is specifically used to: listen for updated configuration items in the configuration information through the @Value annotation.
[0160] In one alternative implementation, the update module includes:
[0161] The second update submodule is used to update the unit identifier combination stored in the cache to the target unit identifier combination through the @Value annotation, and to update the unit fragment number combination stored in the cache to the target unit fragment number combination.
[0162] In an optional implementation, the different unit identifiers in the unit identifier combination are separated by a set symbol, and further include:
[0163] The third determining module is used to determine that, if the target unit identifier combination includes one or more set symbols, the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device.
[0164] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0165] Figure 7 This is a block diagram illustrating an apparatus for a first device according to an exemplary embodiment.
[0166] The first device includes, but is not limited to, a processor 71, a memory 72, a network interface 73, an I / O controller 74, and a communication bus 75.
[0167] It should be noted that those skilled in the art will understand that Figure 7 The structure of the first device shown in the diagram does not constitute a limitation on the first device; the first device may include devices that are more advanced than those shown in the diagram. Figure 7 This may indicate more or fewer components, or a combination of certain components, or a different arrangement of components.
[0168] The following is combined with Figure 7 A detailed description of each component of the first device is provided below:
[0169] Processor 71 is the control center of the first device, connecting various parts of the first device through various interfaces and lines. It performs various functions and processes data by running or executing software programs and / or modules stored in memory 72, and by calling data stored in memory 72, thereby providing overall monitoring of the first device. Processor 71 may include one or more processing units; for example, processor 71 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may also not be integrated into processor 71.
[0170] The processor 71 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present invention.
[0171] The memory 72 may include memory such as high-speed random-access memory (RAM) 721 and read-only memory (ROM) 722, and may also include a mass storage device 723, such as at least one disk storage device. Of course, the first device may also include other hardware required for other services.
[0172] The memory 72 described above is used to store executable instructions of the processor 71. The processor 71 has the function of executing a method to resolve uneven distribution of distributed transaction data.
[0173] A wired or wireless network interface 73 is configured to connect the first device to the network.
[0174] The processor 71, memory 72, network interface 73, and I / O controller 74 can be interconnected via a communication bus 75. This communication bus can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc.
[0175] In an exemplary embodiment, the first device may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above-described method for resolving uneven distribution of distributed transaction data.
[0176] In an exemplary embodiment, this disclosure provides a storage medium including instructions, such as a memory 72 including instructions, which can be executed by a processor 71 of a first device to perform the above-described method. Optionally, the storage medium may be a non-transitory computer-readable storage medium, such as a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device.
[0177] In an exemplary embodiment, a computer-readable storage medium is also provided, which can be directly loaded into the computer's internal memory, such as the memory 72 described above, and contains software code. After being loaded and executed by the computer, the computer program can implement the above-described method for solving the uneven distribution of distributed transaction data.
[0178] In an exemplary embodiment, a computer program product is also provided, which can be directly loaded into the internal memory of a computer, such as the memory included in the first device, and contains software code. After being loaded and executed by the computer, the computer program can implement the method described above for solving the uneven distribution of distributed transaction data.
[0179] It should be noted that the features described in the various embodiments of this specification can be substituted for or combined with each other. For apparatus or system embodiments, since they are basically similar to the method embodiments, the descriptions are relatively simple; relevant details can be found in the descriptions of the method embodiments.
[0180] It should also be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, 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, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0181] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0182] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for solving the problem of uneven data distribution in distributed transactions, characterized in that, Applied to the first device, including: Listen for updated configuration items in the configuration information, which includes the correspondence between unit identifier combinations and unit fragment number combinations. The unit identifier combination includes one or more unit identifiers, and the unit fragment number combination corresponding to the unit identifier combination includes the number of unit fragments corresponding to each unit identifier in the unit identifier combination. The configuration item includes the updated target unit identifier combination and the updated target unit fragment number combination. Update the combination of unit identifiers stored in the cache to the target combination of unit identifiers, and update the combination of unit fragment numbers stored in the cache to the target combination of unit fragment numbers; Receive the transaction task and the task status of the transaction task; If the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device, and the task status of the transaction task is unprocessed, obtain a random transaction serial number. The remainder between the transaction sequence number and the number of unit fragments in the first unit is determined as the target label of the fragment storing the data of the transaction task; From the fragments with the target number in the first unit and the fragments with the target number in the second unit, a target fragment is randomly selected as the fragment for storing the data of the transaction task; the unit identifier of the unit to which the target fragment belongs and the target number constitute the first fragment key of the target fragment; The data involved in executing the transaction task will be stored in the target shard with the first shard key.
2. The method for solving the problem of uneven distribution of distributed transaction data according to claim 1, characterized in that, The first device is a device based on the Try-Confirm-Cancel model, and also includes: If the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device, and the task status of the transaction task is in processing, obtain the second shard key allocated to the transaction task before the execution of the transaction task; The data involved in executing the transaction task will be stored in a shard with the second sharding key; Access the shard with the second shard key to obtain the data involved in the transaction task.
3. The method for solving the problem of uneven distribution of distributed transaction data according to claim 1, characterized in that, The first device is a Saga-based device, and also includes: If the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device, and the task status of the transaction task is in processing, then search for the second shard key that stores the data involved in the transaction task from the unit corresponding to the unit identifier included in the target unit identifier combination; The data involved in executing the transaction task will be stored in a shard with the second sharding key; Access the shard with the second shard key to obtain the data involved in the transaction task.
4. The method for solving the problem of uneven distribution of distributed transaction data according to claim 1, characterized in that, The first device is a device based on the Try-Confirm-Cancel model, and the updated configuration items in the monitoring configuration information include: The system listens for updated configuration items in the configuration information through the preset ConfigurationChangeListener interface.
5. The method for solving the problem of uneven distribution of distributed transaction data according to claim 4, characterized in that, The steps of updating the combination of unit identifiers stored in the cache to the target combination of unit identifiers and updating the combination of unit fragment numbers stored in the cache to the target combination of unit fragment numbers include: The predefined onChangeEvent(ConfigurationChangeEvent event) method updates the unit identifier combination stored in the cache to the target unit identifier combination, and updates the unit fragment number combination stored in the cache to the target unit fragment number combination.
6. The method for solving the problem of uneven distribution of distributed transaction data according to claim 1, characterized in that, The first device is a Saga-based device, and the updated configuration items in the monitoring configuration information include: The @Value annotation can be used to monitor updated configuration items in the configuration information.
7. The method for solving the problem of uneven distribution of distributed transaction data according to claim 6, characterized in that, The steps of updating the combination of unit identifiers stored in the cache to the target combination of unit identifiers and updating the combination of unit fragment numbers stored in the cache to the target combination of unit fragment numbers include: The @Value annotation updates the combination of unit identifiers stored in the cache to the target combination of unit identifiers, and updates the combination of unit shard numbers stored in the cache to the target combination of unit shard numbers.
8. The method for solving the uneven distribution of distributed transaction data according to any one of claims 1 to 7, characterized in that, The different unit identifiers in the unit identifier combination are separated by a set symbol, and also include: If the target unit identifier combination includes one or more set symbols, the target unit identifier combination is determined to include the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device.
9. An apparatus for solving the problem of uneven data distribution in distributed transactions, characterized in that, Applied to the first device, including: The monitoring module is used to monitor the updated configuration items in the configuration information. The configuration information includes the correspondence between unit identifier combinations and unit fragment number combinations. The unit identifier combination includes one or more unit identifiers. The unit fragment number combination corresponding to the unit identifier combination includes the number of unit fragments corresponding to each unit identifier in the unit identifier combination. The configuration item includes the updated target unit identifier combination and the updated target unit fragment number combination. The update module is used to update the combination of unit identifiers stored in the cache to the target combination of unit identifiers, and to update the combination of unit fragment numbers stored in the cache to the target combination of unit fragment numbers. The receiving module is used to receive transaction tasks and the task status of the transaction tasks; The first acquisition module is configured to acquire a random transaction serial number if the target unit identifier combination includes the first unit identifier of the first unit in the first device and the second unit identifier of the second unit in the second device, and the task status of the transaction task is unprocessed. The first determining module is used to determine the target label of the fragment storing the data of the transaction task as the remainder between the transaction serial number and the number of unit fragments of the first unit. The second determining module is used to randomly determine a target segment as the segment for storing the data of the transaction task from the segment with the target number in the first unit and the segment with the target number in the second unit; the unit identifier of the unit to which the target segment belongs and the target number constitute the first segment key of the target segment; The first storage module is used to store the data involved in the execution of the transaction task into a target shard having the first shard key.
10. A first device, characterized in that, include: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the method for resolving uneven distribution of distributed transaction data as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Load distribution in distributed database system
CN101465877A
Transaction processing method and device, equipment and storage medium
CN113961315A
