A write consistency control method, device, apparatus and storage medium

By introducing a distributed lock mechanism into the caching system, the problem of differences in write consistency control between different applications is solved, a unified write consistency control standard and process is achieved, and reusability and flexibility are improved.

CN112925796BActive Publication Date: 2026-04-14CHINA CONSTRUCTION BANK
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CHINA CONSTRUCTION BANK
Filing Date
2021-03-30
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

In existing technologies, when concurrent read and write operations of a caching system require external system implementation, the implementation methods differ for each application, resulting in a lack of reusability between projects, high coupling, and inflexible implementation methods, making it difficult to meet the personalized needs proposed by the business.

Method used

A write consistency control method is provided, which receives a data write request, obtains a target distributed lock that identifies the writer, and determines whether to execute the write operation corresponding to the data write request based on the target distributed lock, thereby realizing a unified write consistency control standard and process.

Benefits of technology

It simplifies the write consistency control method, improves the reusability of write consistency control, realizes a unified standard and process in non-relational databases, and reduces the coupling between projects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112925796B_ABST
    Figure CN112925796B_ABST
Patent Text Reader

Abstract

Embodiments of the present application relate to the technical field of automatic programming, and disclose a write consistency control method, device and equipment and a storage medium, the method comprising: receiving a data write request, wherein the data write request contains a write party identifier; obtaining a target distributed lock of the write party identifier; and judging whether to execute a write operation corresponding to the data write request based on the target distributed lock. The method provided by the embodiments of the present application realizes setting a unified write consistency control standard in a non-relational database by judging whether to execute a write operation corresponding to a data write request based on a target distributed lock of a write party identifier when the data write request is received, realizes a unified standard and process for concurrent writing, simplifies the control mode of write consistency, and improves the reusability of write consistency control.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of automatic programming technology, and in particular to a write consistency control method, apparatus, device and storage medium. Background Technology

[0002] When using a caching system, concurrent read and write operations require an external system. In other words, existing application projects are all implemented by integrating their business logic according to their business characteristics. This approach has the following disadvantages: (1) Each application has its own implementation method, and each implementation method is different, making it impossible to reuse between projects; (2) It is tightly coupled with the project, with a high degree of coupling, making it difficult to split; (3) The implementation method is inflexible, and the code needs to be constantly modified to meet the personalized requirements put forward by the business. Summary of the Invention

[0003] This invention provides a write consistency control method, apparatus, device, and storage medium to achieve a unified standard and process for concurrent writes, simplify the write consistency control method, and improve the reusability of write consistency control.

[0004] In a first aspect, embodiments of the present invention provide a write consistency control method, comprising:

[0005] Receive a data write request, wherein the data write request contains the writer's identifier;

[0006] Acquire the target distributed lock identified by the writer;

[0007] The target distributed lock is used to determine whether to execute the write operation corresponding to the data write request.

[0008] Optionally, based on the above scheme, obtaining the target distributed lock with the writer's identifier includes:

[0009] Request a distributed lock as the target distributed lock for the writer identifier, and determine the target distributed lock identifier corresponding to the target distributed lock based on the writer identifier.

[0010] Optionally, based on the above scheme, determining whether to execute the write operation corresponding to the data write request based on the target distributed lock includes:

[0011] Determine if a write-distributed lock identical to the target distributed lock already exists;

[0012] If it does not exist, then perform the write operation corresponding to the data write request based on the target distributed lock;

[0013] If it exists, then determine whether to execute the write operation corresponding to the data write request based on the target distributed lock and the write distributed lock.

[0014] Optionally, in addition to the above solutions, the following also applies:

[0015] If it does not exist, the target distributed lock and its identifier will be stored together.

[0016] Optionally, based on the above scheme, determining whether to execute the write operation corresponding to the data write request based on the target distributed lock and the write distributed lock includes:

[0017] Retrieve the associated distributed lock corresponding to the target write identifier in the data write request;

[0018] Determine whether the target distributed lock is consistent with the associated distributed lock;

[0019] Based on the judgment result, determine whether to execute the write operation corresponding to the data write request.

[0020] Optionally, based on the above scheme, determining whether the target distributed lock is consistent with the associated distributed lock includes:

[0021] Retrieve the associated distributed lock identifier;

[0022] When the target distributed lock identifier is the same as the associated distributed lock identifier, it is determined that the target distributed lock is the same as the associated distributed lock.

[0023] When the target distributed lock identifier is inconsistent with the associated distributed lock identifier, it is determined that the target distributed lock and the associated distributed lock are inconsistent.

[0024] Optionally, based on the above scheme, determine whether to execute the write operation corresponding to the data write request according to the judgment result, including:

[0025] Write operations are not performed when the target distributed lock is inconsistent with the associated distributed lock.

[0026] When the target distributed lock matches the associated distributed lock, the write operation corresponding to the data write request is executed based on the target distributed lock.

[0027] Optionally, based on the above scheme, the write operation corresponding to the data write request is performed based on the target distributed lock, including:

[0028] Retrieve the target write identifier, target original value, and target updated value contained in the data write request;

[0029] Determine whether to perform a write operation based on the target update value based on the target write identifier and the original target value.

[0030] Optionally, based on the above scheme, determining whether to perform a write operation based on the target update value is done based on the target write identifier and the original target value, including:

[0031] Retrieve the associated original value corresponding to the target write identifier;

[0032] Compare the original target value with the associated original value;

[0033] Determine whether to perform a write operation based on the target update value based on the comparison results.

[0034] Optionally, based on the above scheme, determine whether to perform a write operation based on the target update value according to the comparison results, including:

[0035] When the original target value is consistent with the associated original value, perform a write operation based on the updated target value;

[0036] Write operations are not performed when the original target value is inconsistent with the original associated value.

[0037] Optionally, based on the above scheme, a write operation is performed based on the target update value, including:

[0038] Update the original value associated with the target identifier to the target updated value.

[0039] Optionally, in addition to the above solutions, the following also applies:

[0040] Release the target distributed lock identified by the writer.

[0041] Secondly, embodiments of the present invention also provide a write consistency control device, comprising:

[0042] The write request receiving module is used to receive data write requests, wherein the data write request contains the writer identifier;

[0043] The distributed lock acquisition module is used to acquire the target distributed lock identified by the writer.

[0044] The write operation execution module is used to determine whether to execute the write operation corresponding to the data write request based on the target distributed lock.

[0045] Optionally, based on the above scheme, the distributed lock acquisition module is specifically used for:

[0046] Request a distributed lock as the target distributed lock for the writer identifier, and determine the target distributed lock identifier corresponding to the target distributed lock based on the writer identifier.

[0047] Optionally, based on the above scheme, the write operation execution module includes:

[0048] The distributed lock judgment submodule is used to determine whether a write distributed lock identical to the target distributed lock already exists;

[0049] If the distributed lock does not exist, a submodule is used to perform the write operation corresponding to the data write request based on the target distributed lock if it does not exist.

[0050] The distributed lock has a submodule that, if it exists, determines whether to execute the write operation corresponding to the data write request based on the target distributed lock and the write distributed lock.

[0051] Optionally, based on the above scheme, the device further includes a distributed lock identifier storage module, used for:

[0052] If it does not exist, the target distributed lock and its identifier will be stored together.

[0053] Optionally, based on the above scheme, the distributed lock existence submodule includes:

[0054] The associated distributed lock unit is used to acquire the associated distributed lock corresponding to the target write identifier in the data write request;

[0055] The consistency judgment unit is used to determine whether the target distributed lock is consistent with the associated distributed lock;

[0056] The write operation execution judgment unit is used to determine whether to execute the write operation corresponding to the data write request based on the judgment result.

[0057] Optionally, based on the above scheme, the consistency judgment unit includes:

[0058] The associated distributed lock identifier subunit is used to obtain the associated distributed lock identifier;

[0059] The consistency determination subunit is used to determine that the target distributed lock is consistent with the associated distributed lock when the target distributed lock identifier is consistent with the associated distributed lock identifier.

[0060] The inconsistency determination subunit is used to determine that the target distributed lock and the associated distributed lock are inconsistent when the target distributed lock identifier is inconsistent with the associated distributed lock identifier.

[0061] Optionally, based on the above scheme, the write operation execution judgment unit includes:

[0062] The distributed lock inconsistency subunit is used to prevent write operations when the target distributed lock is inconsistent with the associated distributed lock.

[0063] The distributed lock consistency subunit is used to perform the write operation corresponding to the data write request based on the target distributed lock when the target distributed lock is consistent with the associated distributed lock.

[0064] Optionally, based on the above scheme, the distributed lock does not have a sub-module or the distributed lock consistency sub-unit is specifically used for:

[0065] Retrieve the target write identifier, target original value, and target updated value contained in the data write request;

[0066] Determine whether to perform a write operation based on the target update value based on the target write identifier and the original target value.

[0067] Optionally, based on the above scheme, the distributed lock does not have a sub-module or the distributed lock consistency sub-unit is specifically used for:

[0068] Retrieve the associated original value corresponding to the target write identifier;

[0069] Compare the original target value with the associated original value;

[0070] Determine whether to perform a write operation based on the target update value based on the comparison results.

[0071] Optionally, based on the above scheme, the distributed lock does not have a sub-module or the distributed lock consistency sub-unit is specifically used for:

[0072] When the original target value is consistent with the associated original value, perform a write operation based on the updated target value;

[0073] Write operations are not performed when the original target value is inconsistent with the original associated value.

[0074] Optionally, based on the above scheme, the distributed lock does not have a sub-module or the distributed lock consistency sub-unit is specifically used for:

[0075] Update the original value associated with the target identifier to the target updated value.

[0076] Optionally, based on the above scheme, the device further includes a distributed lock release module, used for:

[0077] Release the target distributed lock identified by the writer.

[0078] Thirdly, embodiments of the present invention also provide a computer device, the device comprising:

[0079] One or more processors;

[0080] Storage device for storing one or more programs;

[0081] When one or more programs are executed by one or more processors, the one or more processors implement the write consistency control method as provided in any embodiment of the present invention.

[0082] Fourthly, embodiments of the present invention also provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the write consistency control method as provided in any embodiment of the present invention.

[0083] This invention, through receiving a data write request (which includes a writer identifier), acquiring a target distributed lock for the writer identifier, and determining whether to execute the write operation corresponding to the data write request based on the target distributed lock, achieves a unified write consistency control standard within a non-relational database. This simplifies the write consistency control method and improves the reusability of write consistency control. Attached Figure Description

[0084] Figure 1 This is a flowchart illustrating a write consistency control method provided in Embodiment 1 of the present invention;

[0085] Figure 2 This is a flowchart illustrating a write consistency control method provided in Embodiment 2 of the present invention;

[0086] Figure 3 This is a flowchart illustrating a write consistency control method provided in Embodiment 3 of the present invention;

[0087] Figure 4 This is a flowchart illustrating a write consistency control method provided in Embodiment 4 of the present invention;

[0088] Figure 5 This is a schematic diagram of the structure of a write consistency control device provided in Embodiment 5 of the present invention;

[0089] Figure 6 This is a schematic diagram of the structure of a computer device provided in Embodiment Six of the present invention. Detailed Implementation

[0090] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, the accompanying drawings show only the parts relevant to the present invention, and not all of the structures.

[0091] Example 1

[0092] Figure 1 This is a flowchart illustrating a write consistency control method provided in Embodiment 1 of the present invention. This embodiment is applicable to situations where write consistency control is performed on non-relational databases. The method can be executed by a write consistency control device, which can be implemented in software and / or hardware; for example, the write consistency control device can be configured in a computer device. Figure 1 As shown, the method includes:

[0093] S110. Receive a data write request, wherein the data write request contains the writer's identifier.

[0094] In this embodiment, the data write request can be initiated by the application to write data. Taking a deduction application as an example, the balance after the deduction is written to replace the balance before the deduction, thus updating the balance of the deduction application. It is understood that the write consistency control device can receive data write requests through the concurrent access interface of a non-relational database.

[0095] Optionally, the writer generates a data write request based on its identifier, the original target value, and the updated target value, and sends the data write request to the write consistency control device. After receiving the data write request initiated by the writer, the write consistency control device parses the data write request to obtain the writer identifier, the original target value, and the updated target value contained in the data write request, and performs a write operation based on the writer identifier, the original target value, and the updated target value. The writer identifier can be the identifier of the application party writing the data.

[0096] Taking a deduction application as an example, the deduction application uses its application identifier as the writer identifier, the balance before deduction (i.e., the current balance) as the target original value, and the balance after deduction as the target updated value. It generates a data write request based on its identifier, target original value, and target updated value, and sends the data write request to the write consistency control device. After receiving the data write request initiated by the deduction application, the write consistency control device parses the data write request to obtain the writer identifier, target original value, and target updated value contained in the data write request. Based on the writer identifier, target original value, and target updated value, it performs the write operation, i.e., the deduction operation.

[0097] S120. Obtain the target distributed lock with the writer identifier.

[0098] In this embodiment, a distributed lock is used to ensure that only one data writer performs a write operation on the same data at any given time, thus achieving write consistency control. Overall, upon receiving a data write request from a data writer, a distributed lock is allocated to the data writer as a target distributed lock to identify the writer. Based on the target distributed lock, it is determined whether the current data writer is a permitted writer, thereby deciding whether to execute the data write operation corresponding to the data write request. The allocation of the target distributed lock can be determined based on the target write identifier (i.e., k in a non-relational database) contained in the data write request.

[0099] In one embodiment of the present invention, obtaining the target distributed lock for the writer identifier includes: requesting a distributed lock as the target distributed lock for the writer identifier, and determining the target distributed lock identifier corresponding to the target distributed lock based on the writer identifier. Optionally, after receiving a data write request, a distributed lock is requested as the target distributed lock, and the target distributed lock identifier is determined based on the writer identifier. Based on the target distributed lock and the target distributed lock identifier, it is determined whether the current data writer is an allowed data writer, so as to determine whether to execute the data write operation corresponding to the data write request.

[0100] S130. Determine whether to execute the write operation corresponding to the data write request based on the target distributed lock.

[0101] Generally speaking, when the data writer corresponding to the target distributed lock is the same data writer corresponding to the current data write request, the current data writer is determined to be an allowed data writer, and thus the data write operation corresponding to the data write request can be executed; when the data writer corresponding to the target distributed lock is not the same data writer corresponding to the previous data write request, the current data writer is determined to be an allowed data writer, and thus the data write operation corresponding to the data write request cannot be executed.

[0102] In one embodiment of the present invention, determining whether to execute a write operation corresponding to a data write request based on a target distributed lock includes: determining whether a write distributed lock identical to the target distributed lock already exists; if not, executing the write operation corresponding to the data write request based on the target distributed lock; if it exists, determining whether to execute the write operation corresponding to the data write request based on the target distributed lock and the write distributed lock. It can be understood that each time the write consistency control device receives a data write request, it allocates a distributed lock for the data write request, determines the distributed identifier of the distributed lock, uses the distributed lock as the write distributed lock, uses the distributed lock identifier as the write distributed lock identifier, and stores the write distributed lock and the write distributed lock identifier in association. When the data write request is completed, the write distributed lock is released, i.e., the storage of the write distributed lock and the write distributed lock identifier is cleared. Therefore, upon receiving a data write request, it can be directly determined whether a write distributed lock identical to the target distributed lock already exists. If a write distributed lock identical to the target distributed lock already exists, it indicates that a data writer initiated a related data write request before this data write request was initiated. Therefore, it is necessary to determine whether the current data writer is the same as the previous data writer to determine whether the corresponding write operation can be executed. That is, it is based on the target distributed lock and the write distributed lock to determine whether to execute the write operation corresponding to the data write request. If no write distributed lock identical to the target distributed lock exists, it indicates that no data writer initiated a related data write request before this data write request was initiated. Therefore, the write operation corresponding to the data write request can be directly executed based on the target distributed lock.

[0103] This invention, through receiving a data write request (which includes a writer identifier), acquiring a target distributed lock for the writer identifier, and determining whether to execute the write operation corresponding to the data write request based on the target distributed lock, achieves a unified write consistency control standard within a non-relational database. This simplifies the write consistency control method and improves the reusability of write consistency control.

[0104] Building upon the above scheme, the method also includes: releasing the target distributed lock identified by the writer. This means that after the data write request is completed (either without a write operation or with one), the target distributed lock identified by the writer is released promptly to reduce lock occupancy.

[0105] Example 2

[0106] Figure 2This is a flowchart illustrating a write consistency control method provided in Embodiment 2 of the present invention. Based on the above embodiments, this embodiment optimizes the write operation corresponding to the data write request when no write distributed lock identical to the target distributed lock exists. For example... Figure 2 As shown, the method includes:

[0107] S210. Receive a data write request, wherein the data write request contains the writer's identifier.

[0108] S220, Obtain the target distributed lock with the writer identifier.

[0109] S230. Determine whether a write distributed lock identical to the target distributed lock already exists.

[0110] S240. If not, obtain the target write identifier, target original value, and target updated value contained in the data write request.

[0111] In this embodiment, when there is no write distributed lock identical to the target distributed lock, the write operation corresponding to the data write request is specified based on the target distributed lock, that is, the write operation corresponding to the data write request is specified.

[0112] Building upon the above approach, to further ensure the accuracy of data writing, the target write identifier and target original value are obtained from the data write request. The target write identifier can be understood as the value 'k' in a non-relational database, and the target original value can be understood as the value corresponding to 'k' in the non-relational database. It is then determined whether the target original value matches the value corresponding to the target write identifier in the non-relational database, and based on the determination result, whether to execute the corresponding write operation.

[0113] S250. Determine whether to perform a write operation based on the target update value based on the target write identifier and the original target value.

[0114] In this embodiment, the target original value in the target write identifier is changed to determine whether other data writers have updated the target original value during the period from when the data writer obtains the target original value to when the target original value is updated, and then determines whether to perform a write operation.

[0115] In one embodiment, determining whether to perform a write operation based on a target update value, based on a target write identifier and a target original value, includes: obtaining the associated original value corresponding to the target write identifier; comparing the target original value and the associated original value; and determining whether to perform a write operation based on the comparison result. Specifically, this involves querying the actual value corresponding to the target write identifier in the non-relational database as the associated original value, and determining whether the target original value and the associated original value are consistent, in order to determine whether performing a write operation would lead to an update error.

[0116] Specifically, the decision to perform a write operation based on the target updated value is determined based on the comparison results. This includes: if the original target value is consistent with the associated original value, a write operation is performed based on the target updated value; if the original target value is inconsistent with the associated original value, a write operation is not performed. It can be understood that if the original target value is the value corresponding to the target write identifier in a non-relational database, it indicates that no other data writer has updated the data, and a write operation can be performed. If the original target value is not the value corresponding to the target write identifier in a non-relational database, it indicates that other data writers updated the original target value between the time the data writer obtained the original target value and the time the original target value was updated. Directly performing a write operation might lead to update errors, therefore, a write operation is not performed.

[0117] Optionally, performing a write operation based on the target update value includes: updating the original value associated with the target write identifier to the target update value. For example, assuming the target write identifier is identifier 1, the original target value is 100, and the target update value is 98, then performing a write operation based on the target update value specifically means: updating the value corresponding to identifier 1 in the non-relational database from 100 to 98.

[0118] Building upon the above scheme, the method further includes: if the target distributed lock does not exist, storing the target distributed lock and its identifier accordingly. When no write distributed lock identical to the target distributed lock exists, storing the target distributed lock and its identifier accordingly allows for determining whether to perform the corresponding write operation based on the stored target distributed lock and its identifier when a data write request is received again. It is understood that after a data write request is processed, the target distributed lock is released, and the stored target distributed lock and its identifier are deleted accordingly to avoid affecting subsequent data write requests.

[0119] Based on the above embodiments, this invention further specifies the write operation corresponding to the data write request when there is no write distributed lock identical to the target distributed lock. By obtaining the target write identifier, the target original value, and the target update value contained in the data write request, and determining whether to perform the write operation based on the target update value based on the target write identifier and the target original value, the accuracy of data writing is further guaranteed.

[0120] Example 3

[0121] Figure 3 This is a flowchart illustrating a write consistency control method provided in Embodiment 3 of the present invention. Based on the above embodiments, this embodiment optimizes the process of determining whether to execute the write operation corresponding to the data write request when a write distributed lock identical to the target distributed lock exists. For example... Figure 3As shown, the method includes:

[0122] S310. Receive a data write request, wherein the data write request contains the writer's identifier.

[0123] S320, Obtain the target distributed lock with the writer identifier.

[0124] S330. Determine if a write distributed lock identical to the target distributed lock already exists.

[0125] S340. If it exists, obtain the associated distributed lock corresponding to the target write identifier in the data write request.

[0126] In this embodiment, when a write distributed lock identical to the target distributed lock exists, the write operation corresponding to the data write request is specifically executed based on the target distributed lock.

[0127] Based on the above scheme, to ensure the accuracy of data writing, when a write distributed lock identical to the target distributed lock exists, this write distributed lock is designated as an associated distributed lock. The decision to execute the write operation corresponding to the data write request is then made based on the target distributed lock and the associated distributed lock. Here, a write distributed lock identical to the target distributed lock can be understood as one whose distributed lock ID is the same as the target distributed lock's distributed lock ID.

[0128] S350. Determine whether the target distributed lock is consistent with the associated distributed lock.

[0129] Generally speaking, when the target distributed lock is consistent with the associated distributed lock, it indicates that the data processing party is allowed to perform write operations and can execute the corresponding write operations; when the target distributed lock is inconsistent with the associated distributed lock, it indicates that the data processing party is not allowed to perform write operations and refuses to execute the corresponding write operations.

[0130] In one embodiment of the present invention, determining whether a target distributed lock and an associated distributed lock are consistent includes: obtaining the associated distributed lock identifier of the associated distributed lock; determining that the target distributed lock and the associated distributed lock are consistent when the target distributed lock identifier and the associated distributed lock identifier are consistent; determining that the target distributed lock and the associated distributed lock are inconsistent when the target distributed lock identifier and the associated distributed lock identifier are inconsistent. Optionally, the consistency between the target distributed lock and the associated distributed lock can be determined based on whether the associated distributed lock identifier corresponding to the associated distributed lock and the target distributed lock identifier corresponding to the target distributed lock are consistent. Specifically, determining that the target distributed lock and the associated distributed lock are consistent when the target distributed lock identifier and the associated distributed lock identifier are consistent; determining that the target distributed lock and the associated distributed lock are inconsistent when the target distributed lock identifier and the associated distributed lock identifier are inconsistent. Here, the target distributed lock identifier can be understood as the value corresponding to the target distributed lock (determined based on the data writer), and the associated distributed lock identifier can be understood as the value corresponding to the associated distributed lock.

[0131] S360. Based on the judgment result, determine whether to execute the write operation corresponding to the data write request.

[0132] Optionally, the decision on whether to execute the write operation corresponding to the data write request is based on the judgment result, including: when the target distributed lock is inconsistent with the associated distributed lock, no write operation is executed; when the target distributed lock is consistent with the associated distributed lock, the write operation corresponding to the data write request is executed based on the target distributed lock.

[0133] In one embodiment of the present invention, performing a write operation corresponding to a data write request based on a target distributed lock includes: obtaining a target write identifier, a target original value, and a target updated value contained in the data write request; and determining whether to perform a write operation based on the target updated value based on the target write identifier and the target original value. Here, the target write identifier can be understood as the k value in a non-relational database, and the target original value can be understood as the value corresponding to k in the non-relational database. It is determined whether the target original value is the value corresponding to the target write identifier in the non-relational database, and based on the determination result, it is decided whether to perform the corresponding write operation.

[0134] Based on the above scheme, the method for determining whether to perform a write operation based on the target update value is based on the target write identifier and the target original value, including: obtaining the associated original value corresponding to the target write identifier; comparing the target original value and the associated original value; and determining whether to perform a write operation based on the comparison result.

[0135] In one embodiment, determining whether to perform a write operation based on the target updated value according to the comparison result includes: performing a write operation based on the target updated value when the target original value is consistent with the associated original value; and not performing a write operation when the target original value is inconsistent with the associated original value.

[0136] Optionally, a write operation is performed based on the target update value, including: updating the associated original value corresponding to the target write identifier to the target update value.

[0137] For a more detailed explanation of how to determine and implement write operations, please refer to the explanation and implementation of write operations in the above embodiments, which will not be repeated here.

[0138] Based on the above embodiments, this invention optimizes the process of determining whether to execute the write operation corresponding to the data write request when a write distributed lock identical to the target distributed lock exists. This is achieved by obtaining the associated distributed lock corresponding to the target write identifier in the data write request; determining whether the target distributed lock is consistent with the associated distributed lock; and determining whether to execute the write operation corresponding to the data write request based on the determination result. This realizes write consistency control based on distributed locks, a unified standard and process for concurrent writes, simplifies the write consistency control method, and improves the reusability of write consistency control.

[0139] Example 4

[0140] Figure 4 This is a flowchart illustrating a write consistency control method provided in Embodiment 4 of the present invention. Based on the above embodiments, this embodiment provides a preferred embodiment.

[0141] like Figure 4 As shown, the write consistency control method provided in this embodiment of the invention mainly includes:

[0142] 1. In this embodiment, the data write request received by the concurrent access interface of the non-relational database needs to include three parameters: a unique identifier K (i.e., the data writer identifier), an original value V (i.e., the target original value), and a target value A (i.e., the target updated value).

[0143] 2. Before executing the update corresponding to the data write request, acquire the distributed lock of the non-relational database (i.e., the target distributed lock).

[0144] 3. Distributed locks are configured based on the recorded id (i.e., the distributed lock) and value (distributed lock identifier). The target distributed lock is retrieved based on the id. If the target distributed lock already exists, the value must be compared for consistency. Only when both the id and value match can they be considered the same distributed lock.

[0145] 4. After successfully acquiring the distributed lock of the non-relational database, the update is executed. First, the value of the record in the non-relational database (i.e., the associated original value) is obtained through k (i.e., the target write identifier), and compared with the original value v. If they are consistent, the update is executed; otherwise, the update fails.

[0146] 5. If acquiring the distributed lock for a non-relational database fails, abandon the update and return a failure message.

[0147] 6. Release the distributed locks of the non-relational database.

[0148] 7. Return the results to the client.

[0149] This invention provides a unified standard for concurrent updates in systems using non-relational databases (such as Redis) for storage, avoiding redundant implementations of write consistency control. By implementing distributed lock-based write consistency control within the non-relational database, a unified standard and process for concurrent writes is achieved, while simplifying the implementation and enabling project reuse.

[0150] Example 5

[0151] Figure 5 This is a schematic diagram of a write consistency control device provided in Embodiment 5 of the present invention. This write consistency control device can be implemented in software and / or hardware; for example, it can be configured in a computer device. Figure 5 As shown, the device includes a write request receiving module 510, a distributed lock acquisition module 520, and a write operation execution module 530, wherein:

[0152] The write request receiving module 510 is used to receive data write requests, wherein the data write request contains a writer identifier;

[0153] The distributed lock acquisition module 520 is used to acquire the target distributed lock identified by the writer.

[0154] The write operation execution module 530 is used to determine whether to execute the write operation corresponding to the data write request based on the target distributed lock.

[0155] In this embodiment of the invention, a write request receiving module 510 receives a data write request, wherein the data write request includes a writer identifier; a distributed lock acquisition module 520 acquires a target distributed lock for the writer identifier; and a write operation execution module 530 determines whether to execute the write operation corresponding to the data write request based on the target distributed lock. By determining whether to execute the write operation corresponding to the data write request based on the target distributed lock for the writer identifier when a data write request is received, a unified write consistency control standard is set in a non-relational database, a unified standard and process for concurrent writes are implemented, the write consistency control method is simplified, and the reusability of write consistency control is improved.

[0156] Optionally, based on the above scheme, the distributed lock acquisition module 520 is specifically used for:

[0157] Request a distributed lock as the target distributed lock for the writer identifier, and determine the target distributed lock identifier corresponding to the target distributed lock based on the writer identifier.

[0158] Optionally, based on the above scheme, the write operation execution module 530 includes:

[0159] The distributed lock judgment submodule is used to determine whether a write distributed lock identical to the target distributed lock already exists;

[0160] If the distributed lock does not exist, a submodule is used to perform the write operation corresponding to the data write request based on the target distributed lock if it does not exist.

[0161] The distributed lock has a submodule that, if it exists, determines whether to execute the write operation corresponding to the data write request based on the target distributed lock and the write distributed lock.

[0162] Optionally, based on the above scheme, the device further includes a distributed lock identifier storage module, used for:

[0163] If it does not exist, the target distributed lock and its identifier will be stored together.

[0164] Optionally, based on the above scheme, the distributed lock existence submodule includes:

[0165] The associated distributed lock unit is used to acquire the associated distributed lock corresponding to the target write identifier in the data write request;

[0166] The consistency judgment unit is used to determine whether the target distributed lock is consistent with the associated distributed lock;

[0167] The write operation execution judgment unit is used to determine whether to execute the write operation corresponding to the data write request based on the judgment result.

[0168] Optionally, based on the above scheme, the consistency judgment unit includes:

[0169] The associated distributed lock identifier subunit is used to obtain the associated distributed lock identifier;

[0170] The consistency determination subunit is used to determine that the target distributed lock is consistent with the associated distributed lock when the target distributed lock identifier is consistent with the associated distributed lock identifier.

[0171] The inconsistency determination subunit is used to determine that the target distributed lock and the associated distributed lock are inconsistent when the target distributed lock identifier is inconsistent with the associated distributed lock identifier.

[0172] Optionally, based on the above scheme, the write operation execution judgment unit includes:

[0173] The distributed lock inconsistency subunit is used to prevent write operations when the target distributed lock is inconsistent with the associated distributed lock.

[0174] The distributed lock consistency subunit is used to perform the write operation corresponding to the data write request based on the target distributed lock when the target distributed lock is consistent with the associated distributed lock.

[0175] Optionally, based on the above scheme, the distributed lock does not have a sub-module or the distributed lock consistency sub-unit is specifically used for:

[0176] Retrieve the target write identifier, target original value, and target updated value contained in the data write request;

[0177] Determine whether to perform a write operation based on the target update value based on the target write identifier and the original target value.

[0178] Optionally, based on the above scheme, the distributed lock does not have a sub-module or the distributed lock consistency sub-unit is specifically used for:

[0179] Retrieve the associated original value corresponding to the target write identifier;

[0180] Compare the original target value with the associated original value;

[0181] Determine whether to perform a write operation based on the target update value based on the comparison results.

[0182] Optionally, based on the above scheme, the distributed lock does not have a sub-module or the distributed lock consistency sub-unit is specifically used for:

[0183] When the original target value is consistent with the associated original value, perform a write operation based on the updated target value;

[0184] Write operations are not performed when the original target value is inconsistent with the original associated value.

[0185] Optionally, based on the above scheme, the distributed lock does not have a sub-module or the distributed lock consistency sub-unit is specifically used for:

[0186] Update the original value associated with the target identifier to the target updated value.

[0187] Optionally, based on the above scheme, the device further includes a distributed lock release module, used for:

[0188] Release the target distributed lock identified by the writer.

[0189] The write consistency control device provided in the embodiments of the present invention can execute the write consistency control method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0190] Example 6

[0191] Figure 6 This is a schematic diagram of the structure of a computer device provided in Embodiment Six of the present invention. Figure 6 This is a schematic diagram of the structure of the computer device provided in Embodiment Six of the present invention. Figure 6 A block diagram of an exemplary computer device 612 suitable for implementing embodiments of the present invention is shown. Figure 6 The computer device 612 shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of the present invention.

[0192] like Figure 6 As shown, the computer device 612 is presented in the form of a general-purpose computing device. The components of the computer device 612 may include, but are not limited to: one or more processors 616, system memory 628, and bus 618 connecting different system components (including system memory 628 and processor 616).

[0193] Bus 618 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor 616, or a local bus using any of the various bus architectures. For example, these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.

[0194] Computer device 612 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by computer device 612, including volatile and non-volatile media, removable and non-removable media.

[0195] System memory 628 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 630 and / or cache memory 632. Computer device 612 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage device 634 may be used to read and write non-removable, non-volatile magnetic media (…). Figure 6 Not shown; usually referred to as a "hard drive"). Although Figure 6 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 618 via one or more data media interfaces. Memory 628 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of the present invention.

[0196] A program / utility 640 having a set (at least one) of program modules 642 may be stored, for example, in memory 628. Such program modules 642 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 642 typically perform the functions and / or methods described in the embodiments of the present invention.

[0197] Computer device 612 can also communicate with one or more external devices 614 (e.g., keyboard, pointing device, display 624, etc.), and with one or more devices that enable a user to interact with computer device 612, and / or with any device that enables computer device 612 to communicate with one or more other computing devices (e.g., network card, modem, etc.). This communication can be performed via input / output (I / O) interface 622. Furthermore, computer device 612 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 620. As shown, network adapter 620 communicates with other modules of computer device 612 via bus 618. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with computer device 612, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0198] The processor 616 executes various functional applications and data processing by running programs stored in the system memory 628, such as implementing the write consistency control method provided in this embodiment of the invention, which includes:

[0199] Receive a data write request, wherein the data write request contains the writer's identifier;

[0200] Acquire the target distributed lock identified by the writer;

[0201] The target distributed lock is used to determine whether to execute the write operation corresponding to the data write request.

[0202] Of course, those skilled in the art will understand that the processor can also implement the technical solution of the write consistency control method provided in any embodiment of the present invention.

[0203] Example 7

[0204] Embodiment 7 of the present invention also provides a computer-readable storage medium having a computer program stored thereon. When executed by a processor, the program implements the write consistency control method provided in the embodiments of the present invention. The method includes:

[0205] Receive a data write request, wherein the data write request contains the writer's identifier;

[0206] Acquire the target distributed lock identified by the writer;

[0207] The target distributed lock is used to determine whether to execute the write operation corresponding to the data write request.

[0208] Of course, the computer program stored on the computer-readable storage medium provided in the embodiments of the present invention is not limited to the above-described method operation, but can also perform related operations of the write consistency control method provided in any embodiment of the present invention.

[0209] The computer storage medium of this invention can be any combination of one or more computer-readable media. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.

[0210] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, capable of sending, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device.

[0211] Program code contained on a computer-readable medium may be transmitted using any suitable medium, including—but not limited to—wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0212] Computer program code for performing the operations of this invention can be written in one or more programming languages ​​or a combination thereof. Programming languages ​​include object-oriented programming languages—such as Java, Smalltalk, and C++—as well as conventional procedural programming languages—such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0213] Note that the above description is merely a preferred embodiment of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of the present invention, the scope of which is determined by the scope of the appended claims.

Claims

1. A write consistency control method, characterized in that, include: Receive a data write request, wherein the data write request includes a writer identifier, which is the identifier of the application that writes the data; Obtain the target distributed lock identified by the writer; Based on the target distributed lock, determine whether to execute the write operation corresponding to the data write request; Once the data write request is completed, clear the storage of the write distributed lock and the write distributed lock identifier; Determining whether to execute the write operation corresponding to the data write request based on the target distributed lock includes: Determine whether a write distributed lock identical to the target distributed lock already exists, wherein a write distributed lock identical to the target distributed lock is a write distributed lock with the same distributed lock ID as the target distributed lock; If it does not exist, then the write operation corresponding to the data write request is executed based on the target distributed lock; If it exists, then based on the target distributed lock and the write distributed lock, determine whether to execute the write operation corresponding to the data write request; The step of determining whether to execute the write operation corresponding to the data write request based on the target distributed lock and the write distributed lock includes: Obtain the associated distributed lock corresponding to the target write identifier in the data write request; Determine whether the target distributed lock is consistent with the associated distributed lock; wherein, the consistency between the target distributed lock and the associated distributed lock is used to indicate that the data processing party corresponding to the target distributed lock is a data processing party that is allowed to perform write operations; Based on the judgment result, determine whether to execute the write operation corresponding to the data write request.

2. The method according to claim 1, characterized in that, The target distributed lock for obtaining the writer's identifier includes: Apply for a distributed lock as the target distributed lock for the writer identifier, and determine the target distributed lock identifier corresponding to the target distributed lock based on the writer identifier.

3. The method according to claim 2, characterized in that, Also includes: If it does not exist, the target distributed lock and the target distributed lock identifier are stored accordingly.

4. The method according to claim 2, characterized in that, The step of determining whether the target distributed lock is consistent with the associated distributed lock includes: Obtain the associated distributed lock identifier of the associated distributed lock; When the target distributed lock identifier is the same as the associated distributed lock identifier, it is determined that the target distributed lock is the same as the associated distributed lock; When the target distributed lock identifier is inconsistent with the associated distributed lock identifier, it is determined that the target distributed lock and the associated distributed lock are inconsistent.

5. The method according to claim 1, characterized in that, The step of determining whether to execute the write operation corresponding to the data write request based on the judgment result includes: The write operation is not performed when the target distributed lock is inconsistent with the associated distributed lock. When the target distributed lock is consistent with the associated distributed lock, the write operation corresponding to the data write request is executed based on the target distributed lock.

6. The method according to claim 1 or 5, characterized in that, The step of performing the write operation corresponding to the data write request based on the target distributed lock includes: Obtain the target write identifier, target original value, and target update value contained in the data write request; Based on the target write identifier and the original target value, determine whether to perform a write operation based on the target update value.

7. The method according to claim 6, characterized in that, The step of determining whether to perform a write operation based on the target update value based on the target write identifier and the target original value includes: Obtain the associated original value corresponding to the target write identifier; Compare the original target value with the associated original value; Determine whether to perform a write operation based on the target update value based on the comparison results.

8. The method according to claim 7, characterized in that, The step of determining whether to perform a write operation based on the target update value according to the comparison result includes: When the original target value is consistent with the original associated value, a write operation is performed based on the updated target value. When the original target value is inconsistent with the original associated value, no write operation is performed.

9. The method according to claim 8, characterized in that, The step of performing a write operation based on the target updated value includes: Update the original value associated with the target identifier to the target updated value.

10. The method according to claim 1, characterized in that, Also includes: Release the target distributed lock identified by the writer.

11. A write consistency control device, characterized in that, include: A write request receiving module is used to receive a data write request, wherein the data write request includes a writer identifier, which is the identifier of the application that writes the data; A distributed lock acquisition module is used to acquire the target distributed lock identified by the writer; The write operation execution module is used to determine whether to execute the write operation corresponding to the data write request based on the target distributed lock. Once the data write request is completed, clear the storage of the write distributed lock and the write distributed lock identifier; The write operation execution module includes: a distributed lock judgment submodule, used to determine whether a write distributed lock identical to the target distributed lock already exists, wherein the write distributed lock identical to the target distributed lock is a write distributed lock with the same distributed lock ID as the target distributed lock; a distributed lock non-existent submodule, used to execute the write operation corresponding to the data write request based on the target distributed lock if the target distributed lock does not exist; and a distributed lock exist submodule, used to determine whether to execute the write operation corresponding to the data write request based on the target distributed lock and the write distributed lock if the target distributed lock exists. The distributed lock submodule includes: an associated distributed lock unit, used to obtain the associated distributed lock corresponding to the target write identifier in the data write request; a consistency judgment unit, used to judge whether the target distributed lock and the associated distributed lock are consistent; wherein, the consistency between the target distributed lock and the associated distributed lock is used to indicate that the data processing party corresponding to the target distributed lock is the data processing party allowed to perform write operations; and a write operation execution judgment unit, used to determine whether to execute the write operation corresponding to the data write request based on the judgment result.

12. A computer device, characterized in that, The device includes: One or more processors; Storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the write consistency control method as described in any one of claims 1-10.

13. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the write consistency control method as described in any one of claims 1-10.

Citation Information

Patent Citations

  • A method and apparatus for distribute lock scheduling

    CN109257396A

  • Distributed lock implementation method, system and apparatus and storage medium

    CN111258976A