WO2022068660A1 - 保持不同存储系统的数据一致的方法以及装置 - Google Patents

保持不同存储系统的数据一致的方法以及装置 Download PDF

Info

Publication number
WO2022068660A1
WO2022068660A1 PCT/CN2021/119791 CN2021119791W WO2022068660A1 WO 2022068660 A1 WO2022068660 A1 WO 2022068660A1 CN 2021119791 W CN2021119791 W CN 2021119791W WO 2022068660 A1 WO2022068660 A1 WO 2022068660A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
storage system
primary key
version number
read
Prior art date
Application number
PCT/CN2021/119791
Other languages
English (en)
French (fr)
Inventor
刘欢
王若
朱国云
Original Assignee
阿里云计算有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 阿里云计算有限公司 filed Critical 阿里云计算有限公司
Priority to US18/246,666 priority Critical patent/US20230281187A1/en
Publication of WO2022068660A1 publication Critical patent/WO2022068660A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/172Caching, prefetching or hoarding of files
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2365Ensuring data consistency and integrity
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Definitions

  • the embodiments of this specification relate to the field of computer technology, and in particular, to a method for keeping data consistent in different storage systems.
  • One or more embodiments of the present specification simultaneously relate to an apparatus for maintaining data consistency in different storage systems, a computing device, and a computer-readable storage medium.
  • a storage system such as a persistent data source
  • an application service often need to use another storage system (such as a cache system) to obtain data.
  • another storage system such as a cache system
  • the data of the other storage system also needs to be updated. For example, in order to keep the latest data in the B storage system stored in the A storage system, currently, the A storage system is updated during the write operation, and then the data corresponding to the B storage system is deleted. During the read operation, the B storage system is read first. Return if the data exists, otherwise read the data of the A storage system and update the B storage system.
  • the embodiments of the present specification provide a method for keeping data of different storage systems consistent.
  • One or more embodiments of this specification simultaneously relate to an apparatus for maintaining data consistency in different storage systems, a computing device, and a computer-readable storage medium, so as to solve the technical defects existing in the prior art.
  • a method for maintaining data consistency in different storage systems including: in the case of updating a first storage system by a write operation, processing the first data as a read-incompatible operation with an atomic operation to, and generate or update the corresponding version number for the first primary key in the atomic operation, wherein the first data is the data corresponding to the first primary key targeted by the write operation in the second storage system; in the read operation If the first data cannot be read from the second storage system, the latest version number of the first primary key is obtained, and the second data is read from the first storage system.
  • the data is the data corresponding to the first primary key in the first storage system; if they are consistent, the second data is updated to the second storage system by an atomic operation, and in the atomic operation, the The version number corresponding to the first primary key update; if inconsistent, re-enter the step of acquiring the latest version number of the first primary key and reading the second data from the first storage system.
  • the first storage system is a persistent data source
  • the second storage system is a cache system
  • the method further includes: if the latest version number of the first primary key cannot be obtained, generating a corresponding initial value of the version number for the first primary key with an atomic operation.
  • acquiring the latest version number of the first primary key includes: sending the second storage system the A request for reading data by a read operation; receiving a message that the data fed back by the second storage system for the request cannot be read, the message carrying the latest version number of the first primary key; obtaining according to the message The latest version number of the first primary key.
  • the second storage system provides a hidden acquisition interface, and the hidden acquisition interface is used to acquire the latest version number of the first primary key.
  • acquiring the latest version number of the first primary key includes: sending the read operation to the second storage system request for data; receive a message that the data fed back by the second storage system for the request cannot be read; obtain the latest version of the first primary key through the hidden acquisition interface of the second storage system according to the message No.
  • the second storage system provides a hidden interface, the hidden interface is used to mark the data as hidden so that it cannot be read by an atomic operation, and in the atomic operation, a corresponding primary key of the data is generated or updated. version number.
  • processing the first data as unreadable by an atomic operation, and generating or updating a corresponding version number for the first primary key in the atomic operation includes:
  • the operation to update the first storage system by calling the hidden interface, the first data is marked as hidden so that it cannot be read by an atomic operation, and in the atomic operation, the corresponding data is generated or updated for the first primary key. version number.
  • processing the first data to be unreadable by an atomic operation includes: in the case of updating the first storage system by a write operation, performing an atomic operation on all data. The data corresponding to the first primary key targeted by the write operation is deleted in the second storage system.
  • an apparatus for maintaining data consistency in different storage systems comprising: a writing module configured to, in the case of updating the first storage system by a writing operation, perform atomic operations on the first storage system The data processing cannot be read, and the corresponding version number is generated or updated for the first primary key in the atomic operation, wherein the first data is the first primary key for which the write operation is in the second storage system corresponding data.
  • a read module configured to obtain the latest version number of the first primary key in the case that the read operation cannot read the first data from the second storage system, and read the first data from the first storage system Second data, where the second data is data corresponding to the first primary key in the first storage system.
  • the comparison module is configured to compare the acquired version number with the latest version number of the first primary key, and if it is inconsistent, trigger the reading module to re-enter the acquisition of the latest version number of the first primary key, and from the first primary key A step of reading out the second data from the storage system.
  • a data update module is configured to update the second data to the second storage system with an atomic operation if the comparison module determines that they are consistent, and update the corresponding first primary key in the atomic operation version number.
  • a computing device including: a memory and a processor; the memory is used for storing computer-executable instructions, and the processor is used for executing the computer-executable instructions: in writing In the case of operating to update the first storage system, an atomic operation is used to process the first data as unreadable, and in the atomic operation, a corresponding version number is generated or updated for the first primary key, wherein the first data The data corresponding to the first primary key for the write operation in the second storage system; in the case that the read operation cannot read the first data from the second storage system, obtain the latest data of the first primary key.
  • the second data is the data corresponding to the first primary key in the first storage system; compare the obtained version number with the first Compare the latest version numbers of a primary key; if they are consistent, update the second data to the second storage system with an atomic operation, and update the corresponding version number for the first primary key in the atomic operation; If not, re-enter the step of acquiring the latest version number of the first primary key and reading the second data from the first storage system.
  • a computer-readable storage medium which stores computer-executable instructions, and when the instructions are executed by a processor, implements any one of the methods for maintaining data consistency in different storage systems A step of.
  • An embodiment of the present specification provides a method for keeping data in different storage systems consistent, because in the case of updating the first storage system by a write operation, the method uses an atomic operation to process the first data as unreadable and for the first storage system.
  • a primary key generates or updates the corresponding version number
  • the first data is the data corresponding to the first primary key targeted by the write operation in the second storage system, so that the update of the data and the version number as a whole through the atomic operation is stored in the second storage system.
  • Pre-occupancy is implemented in the second storage system to effectively prevent inconsistencies caused by concurrent updates.
  • the latest version number of the first primary key is obtained, and the second data is read from the first storage system , and compare the obtained version number with the latest version number of the first primary key. If the version numbers are the same, it means that after the read operation reads the second data from the first storage system, the read data is not updated, and the read second data can be updated to the second storage system by atomic operation
  • the system also updates the corresponding version number for the first primary key in the atomic operation, which can effectively prevent inconsistency caused by concurrent reads.
  • the version numbers are inconsistent, it means that after the read operation reads the second data from the first storage system, the second data in the first storage system has been updated, and the corresponding version numbers need to be re-obtained for comparison, so as to compare the latest The second data is updated to the second storage system, thereby keeping the data of the first storage system and the second storage system consistent. It can be seen that the method provided by the embodiments of this specification uses the update of the data and the version number as an atomic operation in the second storage system to achieve data consistency between the first storage system and the second storage system by pre-occupying.
  • FIG. 1 is a flowchart of a method for maintaining data consistency in different storage systems provided by an embodiment of the present specification
  • FIG. 2 is a flow chart of a write processing process of a method for maintaining data consistency in different storage systems provided by an embodiment of the present specification
  • FIG. 3 is a flow chart of a read processing process of a method for maintaining data consistency in different storage systems provided by an embodiment of the present specification
  • FIG. 4 is a schematic structural diagram of an apparatus for maintaining data consistency in different storage systems provided by an embodiment of the present specification
  • FIG. 5 is a schematic structural diagram of an apparatus for maintaining data consistency in different storage systems provided by another embodiment of the present specification.
  • FIG. 6 is a structural block diagram of a computing device provided by an embodiment of the present specification.
  • Primary key The representation of data stored in the storage system, which is used to obtain the corresponding data (value).
  • Version number The version information of the data, which can be updated by means of atomic auto-increment when it is modified in the storage system.
  • Atomic operation refers to an operation that will not be interrupted by the thread scheduling mechanism. Once the atomic operation starts, it will run until the end of the atomic operation, without switching to another thread in the middle.
  • the data update in the cache and the atomic auto-increment of the version number are a complete whole, updated together in one atomic operation without being interrupted by the thread scheduling mechanism.
  • a method for maintaining data consistency in different storage systems is provided, and this specification also relates to a device for maintaining data consistency in different storage systems, a computing device, and a computer-readable storage medium. Detailed descriptions are given in the following examples one by one.
  • FIG. 1 shows a flowchart of a method for maintaining data consistency in different storage systems according to an embodiment of the present specification, including steps 102 to 108 .
  • Step 102 In the case of updating the first storage system by a write operation, the first data is processed as unreadable by an atomic operation, and a corresponding version number is generated or updated for the first primary key in the atomic operation, wherein, The first data is data corresponding to the first primary key targeted by the write operation in the second storage system.
  • Step 104 In the case that the read operation cannot read the first data from the second storage system, obtain the latest version number of the first primary key, and read the second data from the first storage system , and the second data is the data corresponding to the first primary key in the first storage system.
  • Step 106 Compare the acquired version number with the latest version number of the first primary key.
  • step 104 If not, then re-enter the step of obtaining the latest version number of the first primary key in step 104 and reading the second data from the first storage system.
  • Step 108 If they are consistent, update the second data to the second storage system in an atomic operation, and update the corresponding version number for the first primary key in the atomic operation.
  • the method processes the first data to be unreadable with an atomic operation and generates or updates the corresponding version number for the first primary key, while the first data is
  • the data corresponding to the first primary key of the write operation is in the second storage system, so that the update of the data and the version number through the atomic operation as a whole realizes pre-occupancy in the second storage system, effectively preventing concurrent updates from causing of inconsistency.
  • the first data needs to be read, if it cannot be read from the second storage system, the latest version number of the first primary key is obtained, and the second data is read from the first storage system , and compare the obtained version number with the latest version number of the first primary key.
  • the version numbers are the same, it means that after the read operation reads the second data from the first storage system, the read data is not updated, and the read second data can be updated to the second storage system by atomic operation
  • the system also updates the corresponding version number for the first primary key in the atomic operation, which can effectively prevent inconsistency caused by concurrent reads.
  • the version numbers are inconsistent, it means that after the read operation reads the second data from the first storage system, the second data in the first storage system has been updated, and the corresponding version numbers need to be re-obtained for comparison, so as to compare the latest
  • the second data is updated to the second storage system, thereby keeping the data of the first storage system and the second storage system consistent. It can be seen that the method provided by the embodiments of this specification uses the update of the data and the version number as an atomic operation in the second storage system to achieve data consistency between the first storage system and the second storage system by pre-occupying.
  • the method performs the update of the data and the version number as a whole in an atomic operation, thereby ensuring that the data of the first storage system and the second storage system are consistent.
  • the methods provided by the embodiments of this specification can be applied to an application scenario in which a persistent data source (eg, a database) is kept consistent with cached data.
  • a persistent data source eg, a database
  • the first storage system may be a persistent data source
  • the second storage system may be a cache system.
  • the methods provided in the embodiments of the present specification can be applied inside a cache system, so that data update and version update can be updated together in an atomic manner in an atomic operation as a complete whole within the cache system.
  • the method provided by the embodiments of the present specification by pre-occupying the entire data and the update of the version number as an atomic operation in the cache system, the consistency of the data of the persistent data source and the cache system is realized.
  • one or more embodiments of this specification further include: if the latest version number of the first primary key cannot be obtained, performing an atomic operation on The first primary key generates a corresponding initial value of the version number.
  • the reading process is further improved, which can effectively ensure that the data corresponding to the primary key is not updated, and the initial version number can still be used to maintain the different storage systems. Data consistency purpose.
  • the specific implementation manner of acquiring the latest version number of the primary key is not limited.
  • a message fed back by the second storage system may carry a version number.
  • acquiring the latest version number of the first primary key includes: sending the data to the second storage system. the request for reading data by the read operation; receive a message that the data fed back by the second storage system for the request cannot be read, and the message carries the latest version number of the first primary key; according to the message Obtain the latest version number of the first primary key.
  • the version number carried in the message can be directly extracted from the message returned by the second storage system, the process is clear, and the amount of data transmission is small.
  • the second storage system provides a hidden acquisition interface, and the hidden acquisition interface is used to acquire the latest version number of the first primary key.
  • acquiring the latest version number of the first primary key includes: sending the read operation to the second storage system request for data; receive a message that the data fed back by the second storage system for the request cannot be read; obtain the latest version of the first primary key through the hidden acquisition interface of the second storage system according to the message No.
  • the version number can be obtained through the hidden acquisition interface.
  • the second storage system does not need to return additional information and attributes, which can reduce the need for necessary data transfer.
  • the specific implementation manner in which the data processing cannot be read is not limited.
  • the data can be identified as hidden, and for another example, the data can be deleted so that it cannot be read.
  • the second storage system provides a hidden interface, and the hidden interface is used to identify data as hidden so that it cannot be read by an atomic operation, and in the Generate or update the corresponding version number for the primary key of the data in the atomic operation.
  • processing the first data as unreadable by an atomic operation, and generating or updating a corresponding version number for the first primary key in the atomic operation includes:
  • the operation to update the first storage system by calling the hidden interface, the first data corresponding to the first primary key in the second storage system is marked as hidden so that it cannot be read by an atomic operation, and the atomic operation is performed.
  • processing the first data to be unreadable by an atomic operation includes: updating the first storage system by a write operation
  • the first data corresponding to the first primary key targeted by the write operation in the second storage system is deleted by an atomic operation.
  • the primary key when the data corresponding to the primary key in the second storage system is deleted, the primary key can be retained, and its corresponding value can be set to null, which facilitates setting the corresponding version number and improves the processing efficiency of write logic.
  • the method for maintaining data consistency of different storage systems provided by the embodiments of this specification is used as an example to maintain the consistency between persistent data sources and caches.
  • the data-consistent method is further described.
  • a version number management mechanism is added to the cache system, and a data read and write interface is provided externally.
  • a set of protocols supports the special attributes of the identification data, that is, the identification data exists but the ordinary data access interface cannot read it. , which can only be accessed by a special interface, and supports atomically incremental version numbers of data, which can support consistent updates of persistent data and caches.
  • the cache system provides a protocol to support the existence of identification data, but ordinary data access interfaces such as “get” interface cannot be read, while the hidden access interface such as “getHidden” described in the embodiments of this specification can be accessed, and supports atomic data Increment the version number. Therefore, the cache system of this embodiment additionally provides a set of interfaces such as "hide/getHidden” to support hidden identification of data.
  • FIG. 2 shows a flow chart of a write processing process of a method for maintaining data consistency in different storage systems provided by an embodiment of the present specification, and the specific steps include steps 202 to 204 .
  • Step 202 Write the update data to the persistent data source.
  • Step 204 Use the "hide” interface to hide the data corresponding to the primary key of the updated data in the cache system, and at the same time increment the version number corresponding to the primary key.
  • Version number When data is being written, the version number corresponding to the primary key is incremented.
  • FIG. 3 shows a flow chart of a read processing process of a method for keeping data in different storage systems consistent according to an embodiment of the present specification, and the specific steps include steps 302 to 318 .
  • Step 302 Read the data corresponding to the key in the cache system through the "get" interface.
  • Step 304 Determine whether the "get" interface returns the data corresponding to the key.
  • step 306 If not returned, go to step 306 .
  • Step 306 Use the "getHidden” interface to obtain the version number corresponding to the key.
  • Step 308 Determine whether the "getHidden” interface returns the version number corresponding to the key.
  • Step 310 If not, hide the data corresponding to the key by using the "hide" interface with atomic operations, so that the data corresponding to the key in the cache system is initialized to be empty and the corresponding version number is initialized to "1".
  • Re-enter step 306 If not, hide the data corresponding to the key by using the "hide" interface with atomic operations, so that the data corresponding to the key in the cache system is initialized to be empty and the corresponding version number is initialized to "1".
  • Step 312 If yes, obtain the data corresponding to the key from the persistent data source.
  • Step 314 Use the version number and the data obtained in Step 306 to call the "put" interface to write the cache, "put": used to perform the write operation of the cache, if the input version number is equal to the current latest version of the data in the cache system number, it is allowed to write to the cache while the version number of the data in the cache system is atomically incremented, and the write succeeds, otherwise the write fails.
  • Step 316 Determine whether the writing is successful.
  • step 306 If not, return to step 306 . If yes, go to step 318.
  • Step 318 end the process.
  • step 314 the "put" interface is called in step 314, and the "put" operation will compare the version number obtained in step 306 with the latest version number of the key in the cache system. If it is inconsistent, the writing fails and returns to step 306 , if they are consistent, the writing is successful, and the process goes to step 318 to end the process.
  • FIG. 4 shows the structure of an apparatus for keeping data in different storage systems consistent according to an embodiment of this specification. Schematic. As shown in FIG. 4 , the apparatus includes: a writing module 402 , a reading module 404 , a comparing module 406 and a data updating module 408 .
  • the writing module 402 can be configured to process the first data as unreadable by an atomic operation when the first storage system is updated by a write operation, and generate or update the corresponding first primary key in the atomic operation , where the first data is the data corresponding to the first primary key targeted by the write operation in the second storage system.
  • the read module 404 can be configured to obtain the latest version number of the first primary key in the case that the read operation cannot read the first data from the second storage system, and obtain the latest version number of the first primary key from the first storage system Second data is read out, where the second data is data corresponding to the first primary key in the first storage system.
  • the comparison module 406 can be configured to compare the acquired version number with the latest version number of the first primary key, and if they are inconsistent, trigger the reading module 404 to re-enter the acquisition of the latest version number of the first primary key, and the step of reading the second data from the first storage system.
  • the data update module 408 can be configured to update the second data to the second storage system in an atomic operation if the comparison module 406 determines that they are consistent, and in the atomic operation for the first The version number corresponding to the primary key update.
  • the device processes the first data as unreadable by atomic operations and generates or updates the corresponding version number for the first primary key, while the first data is
  • the data corresponding to the first primary key of the write operation is in the second storage system, so that the update of the data and the version number through the atomic operation as a whole realizes pre-occupancy in the second storage system, effectively preventing concurrent updates from causing of inconsistency.
  • the first data needs to be read, if it cannot be read from the second storage system, the latest version number of the first primary key is obtained, and the second data is read from the first storage system , and compare the obtained version number with the latest version number of the first primary key.
  • the version numbers are the same, it means that after the read operation reads the second data from the first storage system, the read data is not updated, and the read second data can be updated to the second storage system by atomic operation
  • the system also updates the corresponding version number for the first primary key in the atomic operation, which can effectively prevent inconsistency caused by concurrent reads.
  • the version numbers are inconsistent, it means that after the read operation reads the second data from the first storage system, the second data in the first storage system has been updated, and the corresponding version numbers need to be re-obtained for comparison, so as to compare the latest
  • the second data is updated to the second storage system, thereby keeping the data of the first storage system and the second storage system consistent. It can be seen that the apparatus provided in the embodiments of this specification uses the update of the data and the version number as an atomic operation in the second storage system to achieve data consistency between the first storage system and the second storage system by pre-occupying.
  • FIG. 5 shows a schematic structural diagram of an apparatus for maintaining data consistency in different storage systems according to another embodiment of the present specification.
  • the apparatus may further include: a version initialization module 412, which may be configured to perform an atomic operation on the first primary key if the reading module 404 cannot obtain the latest version number of the first primary key Generate the corresponding version number initial value.
  • a version initialization module 412 which may be configured to perform an atomic operation on the first primary key if the reading module 404 cannot obtain the latest version number of the first primary key Generate the corresponding version number initial value.
  • the reading process is further improved, which can effectively ensure that the data corresponding to the primary key is not updated, and the initial version number can still be used to maintain the different storage systems. Data consistency purpose.
  • the reading module 404 may include: a request sending submodule 4042 , a message receiving submodule 4044 , a version obtaining submodule 4046 and a data obtaining submodule 4048 .
  • the request sending sub-module 4042 may be configured to send a request for reading data by the read operation to the second storage system.
  • the message receiving sub-module 4044 may be configured to receive a message that the data fed back by the second storage system for the request cannot be read, and the message carries the latest version number of the first primary key.
  • the version obtaining sub-module 4046 may be configured to obtain the latest version number of the first primary key according to the message.
  • the data acquisition sub-module 4048 may be configured to read data corresponding to the first primary key from the first storage system.
  • the version number carried in the message can be directly extracted from the message returned by the second storage system, the process is clear, and the amount of data transmission is small.
  • the second storage system provides a hidden acquisition interface, and the hidden acquisition interface is used to acquire the latest version number of the first primary key.
  • the request sending sub-module 4042 may be configured to send a request for reading data by the read operation to the second storage system.
  • the message receiving sub-module 4044 may be configured to receive a message that the data fed back by the second storage system for the request cannot be read.
  • the version obtaining sub-module 4046 may be configured to obtain the latest version number of the first primary key through a hidden obtaining interface of the second storage system according to the message.
  • the version number can be obtained through the hidden acquisition interface.
  • the second storage system does not need to return additional information and attributes, which can reduce the need for necessary data transfer.
  • the second storage system provides a hidden interface
  • the hidden interface is used to identify data as hidden so that it cannot be read in an atomic operation, and in the atomic operation, the data is targeted
  • the primary key for generating or updating the corresponding version number.
  • the writing module 402 can be configured to, in the case of updating the first storage system by a writing operation, by calling the hidden interface, to mark the first data as hidden so that it cannot be read by an atomic operation, and in the atomic operation. In the operation, a corresponding version number is generated or updated for the first primary key.
  • marking the data as hidden the existence of the primary key in the second storage system can be maintained, so that the corresponding version number can be directly set for the primary key, and the processing efficiency of the write logic can be improved.
  • the writing module 402 may be configured to, in the case that the writing operation updates the first storage system, use an atomic operation to store the first primary key targeted by the writing operation in the second storage system Delete the corresponding data in .
  • the primary key when the first data corresponding to the primary key in the second storage system is deleted, the primary key can be retained, and its corresponding value can be set to null, which facilitates setting the corresponding version number and improves the processing efficiency of write logic .
  • the above is a schematic solution of an apparatus for maintaining data consistency of different storage systems according to this embodiment. It should be noted that the technical solution of the device for maintaining data consistency in different storage systems and the technical solution of the above-mentioned method for maintaining data consistency in different storage systems belong to the same concept, and the technical solution of the device for maintaining data consistency in different storage systems is not the same. For details of the detailed description, reference may be made to the description of the technical solution of the method for maintaining data consistency in different storage systems above.
  • FIG. 6 shows a structural block diagram of a computing device 600 provided according to an embodiment of the present specification.
  • Components of the computing device 600 include, but are not limited to, memory 610 and processor 620 .
  • the processor 620 is connected with the memory 610 through the bus 630, and the database 650 is used for saving data.
  • Computing device 600 also includes access device 640 that enables computing device 600 to communicate via one or more networks 660 .
  • networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet.
  • Access device 640 may include one or more of any type of network interface (eg, network interface card (NIC)), wired or wireless, such as IEEE 802.11 wireless local area network (WLAN) wireless interface, World Interoperability for Microwave Access ( Wi-MAX) interface, Ethernet interface, Universal Serial Bus (USB) interface, cellular network interface, Bluetooth interface, Near Field Communication (NFC) interface, and the like.
  • NIC network interface card
  • computing device 600 may also be connected to each other, such as through a bus.
  • bus may also be connected to each other, such as through a bus.
  • FIG. 6 the structural block diagram of the computing device shown in FIG. 6 is only for the purpose of example, rather than limiting the scope of this specification. Those skilled in the art can add or replace other components as required.
  • Computing device 600 may be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (eg, tablet computers, personal digital assistants, laptop computers, notebook computers, netbooks, etc.), mobile phones (eg, smart phones) ), wearable computing devices (eg, smart watches, smart glasses, etc.) or other types of mobile devices, or stationary computing devices such as desktop computers or PCs.
  • Computing device 600 may also be a mobile or stationary server.
  • the processor 620 is configured to execute the following computer-executable instructions:
  • the first data is processed as unreadable by an atomic operation, and a corresponding version number is generated or updated for the first primary key in the atomic operation, wherein the first data
  • One piece of data is the data corresponding to the first primary key targeted by the write operation in the second storage system
  • the read operation cannot read the first data from the second storage system, obtain the latest version number of the first primary key, and read the second data from the first storage system, and the The second data is the data corresponding to the first primary key in the first storage system;
  • the above is a schematic solution of a computing device according to this embodiment. It should be noted that the technical solution of the computing device and the technical solution of the above-mentioned method for maintaining data consistency in different storage systems belong to the same concept, and the details that are not described in detail in the technical solution of the computing device can be referred to above. A description of the technical scheme of the data-consistent method.
  • An embodiment of the present specification further provides a computer-readable storage medium, which stores computer instructions, which, when executed by a processor, are used for:
  • the first data is processed as unreadable by an atomic operation, and a corresponding version number is generated or updated for the first primary key in the atomic operation, wherein the first data
  • One piece of data is the data corresponding to the first primary key targeted by the write operation in the second storage system
  • the read operation cannot read the first data from the second storage system, obtain the latest version number of the first primary key, and read the second data from the first storage system, and the The second data is the data corresponding to the first primary key in the first storage system;
  • the computer instructions include computer program code, which may be in source code form, object code form, an executable file, some intermediate form, or the like.
  • the computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, removable hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory) , Random Access Memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable media may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction, for example, in some jurisdictions, according to legislation and patent practice, the computer-readable media Electric carrier signals and telecommunication signals are not included.

Landscapes

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

Abstract

一种保持不同存储系统的数据一致的方法以及装置,所述保持不同存储系统的数据一致的方法包括:在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到,且在所述原子操作中针对第一主键生成或更新对应的版本号;在读操作从第二存储系统读取不到第一数据的情况下,获取第一主键最新的版本号,且从第一存储系统读取出第二数据;将获取的版本号与第一主键最新的版本号进行比较;如果一致,则以原子操作将第二数据更新到第二存储系统且针对第一主键更新对应的版本号;如果不一致,则重新进入获取第一主键最新的版本号,且从第一存储系统读取出第二数据的步骤。

Description

保持不同存储系统的数据一致的方法以及装置
本申请要求2020年09月29日递交的申请号为202011052190.3、发明名称为“保持不同存储系统的数据一致的方法以及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本说明书实施例涉及计算机技术领域,特别涉及一种保持不同存储系统的数据一致的方法。本说明书一个或者多个实施例同时涉及一种保持不同存储系统的数据一致的装置,一种计算设备,以及一种计算机可读存储介质。
背景技术
在一些应用场景中,一个存储系统(如持久化数据源)和应用服务之间往往需要使用另一个存储系统(如缓存系统)来获取数据。当一个存储系统更新,也需要更新另一个存储系统的数据。例如,为了保持A存储系统中保存的是B存储系统中的最新数据,目前在写操作时先更新A存储系统,然后删除B存储系统对应的数据,在读操作时,先读取B存储系统,如果数据存在则返回,否则读取A存储系统的数据并更新B存储系统。
但是,经过上述操作仍然会发生两个存储系统的数据不一致的情况。
发明内容
有鉴于此,本说明书施例提供了一种保持不同存储系统的数据一致的方法。本说明书一个或者多个实施例同时涉及一种保持不同存储系统的数据一致的装置,一种计算设备,以及一种计算机可读存储介质,以解决现有技术中存在的技术缺陷。
根据本说明书实施例的第一方面,提供了一种保持不同存储系统的数据一致的方法,包括:在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到,且在所述原子操作中针对第一主键生成或更新对应的版本号,其中,所述第一数据为所述写操作针对的第一主键在第二存储系统中对应的数据;在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据,所述第二数据为所述第一主键在所述第一存储系统中对应的数据;如果一致,则以原子操作将所述第二数据更新到所述第二存储系统,且在所述原子操作中针对所述第一主键更新对应的版本号;如果不一致,则重新进入所述获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据的步骤。
可选地,所述第一存储系统为持久化数据源,所述第二存储系统为缓存系统。
可选地,所述方法还包括:如果获取不到所述第一主键最新的版本号,则以原子操作针对所述第一主键生成对应的版本号初始值。
可选地,所述在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号包括:向所述第二存储系统发送所述读操作读取数据的请求;接收所述第二存储系统针对所述请求反馈的数据无法被读取到的消息,所述消息携带了 所述第一主键最新的版本号;根据所述消息获取所述第一主键最新的版本号。
可选地,所述第二存储系统提供了隐藏获取接口,所述隐藏获取接口用于获取所述第一主键最新的版本号。所述在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号包括:向所述第二存储系统发送所述读操作读取数据的请求;接收所述第二存储系统针对所述请求反馈的数据无法被读取到的消息;根据所述消息通过所述第二存储系统的隐藏获取接口获取所述第一主键最新的版本号。
可选地,所述第二存储系统提供了隐藏接口,所述隐藏接口用于以原子操作将数据标识为隐藏以无法被读取,且在所述原子操作中针对数据的主键生成或更新对应的版本号。所述在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到,且在所述原子操作中针对第一主键生成或更新对应的版本号包括:在写操作更新第一存储系统的情况下,通过调用所述隐藏接口,以原子操作将第一数据标识为隐藏以无法被读取,且在所述原子操作中针对所述第一主键生成或更新对应的版本号。
可选地,所述在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到包括:在写操作更新第一存储系统的情况下,以原子操作将所述写操作针对的第一主键在第二存储系统中对应的数据删除。
根据本说明书实施例的第二方面,提供了一种保持不同存储系统的数据一致的装置,包括:写模块,被配置为在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到,且在所述原子操作中针对第一主键生成或更新对应的版本号,其中,所述第一数据为所述写操作针对的第一主键在第二存储系统中对应的数据。读模块,被配置为在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据,所述第二数据为所述第一主键在所述第一存储系统中对应的数据。比较模块,被配置为将获取的版本号与所述第一主键最新的版本号进行比较,如果不一致,触发读模块重新进入所述获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据的步骤。数据更新模块,被配置为如果所述比较模块判定一致,则以原子操作将所述第二数据更新到所述第二存储系统,且在所述原子操作中针对所述第一主键更新对应的版本号。
根据本说明书实施例的第三方面,提供了一种计算设备,包括:存储器和处理器;所述存储器用于存储计算机可执行指令,所述处理器用于执行所述计算机可执行指令:在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到,且在所述原子操作中针对第一主键生成或更新对应的版本号,其中,所述第一数据为所述写操作针对的第一主键在第二存储系统中对应的数据;在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据,所述第二数据为所述第一主键在所述第一存储系统中对应的数据;将获取的版本号与所述第一主键最新的版本号进行比较;如果一致,则以原子操作将所述第 二数据更新到所述第二存储系统,且在所述原子操作中针对所述第一主键更新对应的版本号;如果不一致,则重新进入所述获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据的步骤。
根据本说明书实施例的第四方面,提供了一种计算机可读存储介质,其存储有计算机可执行指令,该指令被处理器执行时实现任意一项所述保持不同存储系统的数据一致的方法的步骤。
本说明书一个实施例提供了保持不同存储系统的数据一致的方法,由于该方法在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到且针对所述第一主键生成或更新对应的版本号,而第一数据为所述写操作针对的第一主键在第二存储系统中对应的数据,从而通过原子操作对数据以及版本号的更新作为一个整体在第二存储系统中实现了预占位,有效防止并发更新导致的不一致性。在需要读取第一数据的情况下,如果从所述第二存储系统读取不到,则获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据,将获取的版本号与所述第一主键最新的版本号进行比较。如果版本号一致,说明读操作从第一存储系统读取出第二数据之后,读取出的数据并未发生更新,则可以原子操作将读取出的第二数据更新到所述第二存储系统且在所述原子操作中针对所述第一主键更新对应的版本号,能够有效防止并发读导致的不一致性。如果版本号不一致,则说明读操作从第一存储系统读取出第二数据之后,第一存储系统中的第二数据发生了更新,需要重新获取对应的版本号进行比较,以便将最新的第二数据更新到第二存储系统,从而保持第一存储系统与第二存储系统的数据一致。可见,本说明书实施例提供的方法将数据以及版本号的更新整体作为一个原子操作在第二存储系统中通过预占位实现了第一存储系统和第二存储系统的数据的一致性。
附图说明
图1是本说明书一个实施例提供的一种保持不同存储系统的数据一致的方法的流程图;
图2是本说明书一个实施例提供的一种保持不同存储系统的数据一致的方法的写处理过程流程图;
图3是本说明书一个实施例提供的一种保持不同存储系统的数据一致的方法的读处理过程流程图;
图4是本说明书一个实施例提供的一种保持不同存储系统的数据一致的装置的结构示意图;
图5是本说明书另一个实施例提供的一种保持不同存储系统的数据一致的装置的结构示意图;
图6是本说明书一个实施例提供的一种计算设备的结构框图。
具体实施方式
在下面的描述中阐述了很多具体细节以便于充分理解本说明书。但是本说明书能够以很多不同于在此描述的其它方式来实施,本领域技术人员可以在不违背本说明书内涵的情况下做类似推广,因此本说明书不受下面公开的具体实施的限制。
在本说明书一个或多个实施例中使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本说明书一个或多个实施例。在本说明书一个或多个实施例和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。还应当理解,本说明书一个或多个实施例中使用的术语“和/或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。
应当理解,尽管在本说明书一个或多个实施例中可能采用术语第一、第二等来描述各种信息,但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。例如,在不脱离本说明书一个或多个实施例范围的情况下,第一也可以被称为第二,类似地,第二也可以被称为第一。取决于语境,如在此所使用的词语“如果”可以被解释成为“在……时”或“当……时”或“响应于确定”。
首先,对本说明书一个或多个实施例涉及的名词术语进行解释。
主键(key):数据存储在存储系统中的表示,用于获取对应的数据(value)。
版本号:数据的版本信息,在存储系统中修改时可以通过如原子性自增的方式更新。
原子操作,是指不会被线程调度机制打断的操作,原子操作一旦开始,就一直运行到原子操作的结束,中间不会切换到另一个线程。例如,在本说明书一个或多个实施例中,缓存内部的数据更新和版本号的原子性自增是一个完整的整体,在一个原子操作内一起更新,中间不会被线程调度机制打断。
在本说明书中,提供了一种保持不同存储系统的数据一致的方法,本说明书同时涉及一种保持不同存储系统的数据一致的装置,一种计算设备,以及一种计算机可读存储介质,在下面的实施例中逐一进行详细说明。
图1示出了根据本说明书一个实施例提供的一种保持不同存储系统的数据一致的方法的流程图,包括步骤102至步骤108。
步骤102:在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到,且在所述原子操作中针对第一主键生成或更新对应的版本号,其中,所述第一数据为所述写操作针对的第一主键在第二存储系统中对应的数据。
步骤104:在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据,所述第二数据为所述第一主键在所述第一存储系统中对应的数据。
步骤106:将获取的版本号与所述第一主键最新的版本号进行比较。
如果不一致,则重新进入步骤104所述获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据的步骤。
步骤108:如果一致,则以原子操作将所述第二数据更新到所述第二存储系统,且在所述原子操作中针对所述第一主键更新对应的版本号。
可见,由于该方法在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到且针对所述第一主键生成或更新对应的版本号,而第一数据为所述写操作针对的第一主键在第二存储系统中对应的数据,从而通过原子操作对数据以及版本号的更新作为一个整体在第二存储系统中实现了预占位,有效防止并发更新导致的不一致性。在需要读取第一数据的情况下,如果从所述第二存储系统读取不到,则获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据,将获取的版本号与所述第一主键最新的版本号进行比较。如果版本号一致,说明读操作从第一存储系统读取出第二数据之后,读取出的数据并未发生更新,则可以原子操作将读取出的第二数据更新到所述第二存储系统且在所述原子操作中针对所述第一主键更新对应的版本号,能够有效防止并发读导致的不一致性。如果版本号不一致,则说明读操作从第一存储系统读取出第二数据之后,第一存储系统中的第二数据发生了更新,需要重新获取对应的版本号进行比较,以便将最新的第二数据更新到第二存储系统,从而保持第一存储系统与第二存储系统的数据一致。可见,本说明书实施例提供的方法将数据以及版本号的更新整体作为一个原子操作在第二存储系统中通过预占位实现了第一存储系统和第二存储系统的数据的一致性。
可以理解的是,在实际应用场景中,可能存在有多个针对同一个主键的数据的更新操作或读操作并行执行,也可能这些操作会以任意的顺序交织执行,而由于本说明书实施例提供的方法对数据以及版本号的更新作为一个整体以原子操作来执行,从而能够保证第一存储系统和第二存储系统的数据一致。
例如,本说明书实施例提供的方法可以应用于保持持久化数据源(如数据库)与缓存的数据一致的应用场景。在该应用场景中,所述第一存储系统可以为持久化数据源,所述第二存储系统可以为缓存系统。例如,本说明书实施例提供的方法可以应用于缓存系统内部,从而在缓存系统内部使数据更新和版本更新成为一个完整的整体在原子操作内以原子方式一起更新。根据本说明书实施例提供的方法,通过将数据以及版本号的更新整体作为一个原子操作在缓存系统中预占位,实现了持久化数据源与缓存系统的数据的一致性。
为了避免从第二存储系统获取不到主键对应的版本号的情况,本说明书一个或多个实施例中,还包括:如果获取不到所述第一主键最新的版本号,则以原子操作针对所述第一主键生成对应的版本号初始值。该实施例中,通过为获取不到的版本号赋予初始值,进一步完善了读流程,能够有效保证主键对应的数据未发生更新的情况下,依然能利用初始的版本号实现保持不同存储系统的数据一致的目的。
本说明书实施例提供的方法中,对获取主键最新的版本号的具体实施方式不限。
例如,本说明书一实施例中,可以由第二存储系统反馈的消息携带版本号。具体地,例如,所述在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号包括:向所述第二存储系统发送所述读操作读取数据的请求;接收所述第二存储系统针对所述请求反馈的数据无法被读取到的消息,所述消息携带了所述第一主键最新的版本号;根据所述消息获取所述第一主键最新的版本号。在该实施例中,在数据读取不到的情况下,直接通过第二存储系统返回的消息提取消息携带的版本号即可,流程清晰,数据传输量少。
再例如,本说明书另一实施例中,所述第二存储系统提供了隐藏获取接口,所述隐藏获取接口用于获取所述第一主键最新的版本号。所述在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号包括:向所述第二存储系统发送所述读操作读取数据的请求;接收所述第二存储系统针对所述请求反馈的数据无法被读取到的消息;根据所述消息通过所述第二存储系统的隐藏获取接口获取所述第一主键最新的版本号。在该实施例中,在数据读取不到的情况下根据第二存储系统返回的消息,相应通过隐藏获取接口获取版本号即可,第二存储系统不必返回额外的信息、属性,可以减少不必要的数据传输。
需要说明的是,本说明书实施例提供的方法中,数据处理为读取不到的具体实施方式不限。例如,可以将数据标识为隐藏,再例如,可以将数据删除使其读取不到。
具体地,例如,本说明书一个或多个实施例中,所述第二存储系统提供了隐藏接口,所述隐藏接口用于以原子操作将数据标识为隐藏以无法被读取,且在所述原子操作中针对数据的主键生成或更新对应的版本号。所述在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到,且在所述原子操作中针对第一主键生成或更新对应的版本号包括:在写操作更新第一存储系统的情况下,通过调用所述隐藏接口,以原子操作将第一主键在第二存储系统中对应的第一数据标识为隐藏以无法被读取,且在所述原子操作中针对所述第一主键生成或更新对应的版本号。在该实施例中,通过将数据标识为隐藏,可以保持主键在第二存储系统中的存在,便于直接为主键设置对应的版本号,提高写逻辑的处理效率。
再例如,本说明书另一个或多个实施例中,所述在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到包括:在写操作更新第一存储系统的情况下,以原子操作将所述写操作针对的第一主键在第二存储系统中对应的第一数据删除。在该实施例中,将主键在第二存储系统中对应的数据删除的情况下,可以保留主键,将其对应的值设置为空,便于设置对应的版本号,提高写逻辑的处理效率。
下述结合附图2以及附图3,以本说明书实施例提供的保持不同存储系统的数据一致的方法在保持持久化数据源与缓存一致性的应用为例,对所述保持不同存储系统的数据一致的方法进行进一步说明。需要说明的是,在该实施例中,缓存系统增加了版本 号管理机制,且对外提供数据读写接口,一套协议支持标识数据的特殊属性,即标识数据存在但是普通数据访问接口读不到,只能由特殊接口访问到,且支持数据的原子递增版本号,即可支持持久化数据和缓存的一致性更新。例如,缓存系统提供了协议以支持标识数据存在但是普通数据访问接口如“get”接口读不到,而本说明书实施例所述的隐藏获取接口如“getHidden”能访问到,且支持数据的原子递增版本号。因此,该实施例的缓存系统额外提供了一组接口如“hide/getHidden”以支持对数据进行隐藏标识。
具体地,图2示出了本说明书一个实施例提供的一种保持不同存储系统的数据一致的方法的写处理过程流程图,具体步骤包括步骤202至步骤204。
步骤202:向持久化数据源写入更新数据。
步骤204:使用“hide”接口隐藏所述更新数据的主键在缓存系统中对应的数据,同时递增所述主键对应的版本号。
“hide”:缓存系统的隐藏操作,以原子操作隐藏数据且递增数据的主键对应的版本号,使得数据不会被普通的“get”读请求获取到,但是可以被“getHidden”这个特殊的请求获取到。
版本号:当数据在进行写操作时,主键对应的版本号递增。
图3示出了本说明书一个实施例提供的一种保持不同存储系统的数据一致的方法的读处理过程流程图,具体步骤包括步骤302至步骤318。
步骤302:通过“get”接口读取key在缓存系统中对应的数据。
“get”:缓存系统的普通读取操作,用于获取数据。
步骤304:判断“get”接口是否返回key对应的数据。
如果未返回,进入步骤306。
步骤306:使用“getHidden”接口获取key对应的版本号。
“getHidden”:缓存系统的特殊读取操作,用于获取被隐藏(hide)数据的版本信息。
步骤308:判断“getHidden”接口是否返回key对应的版本号。
步骤310:如果否,通过使用“hide”接口以原子操作隐藏key对应的数据,使缓存系统中该key对应的数据初始化为空且对应的版本号初始化为“1”。重新进入步骤306。
步骤312:如果是,从持久化数据源获取key对应的数据。
步骤314:利用步骤306获取的版本号以及获取的数据,调用“put”接口写缓存,“put”:用于执行缓存的写操作,如果输入的版本号等于缓存系统内该数据当前最新的版本号,则允许写入缓存同时缓存系统内该数据的版本号原子递增,写入成功,否则写入失败。
步骤316:判断是否写入成功。
如果否,返回到步骤306。如果是,则进入步骤318。
步骤318,结束流程。
可见,在步骤314中调用“put”接口,“put”操作会将步骤306获取的版本号与key在所述缓存系统中最新的版本号进行比较,如果不一致,则写入失败返回到步骤306,如果一致,则写入成功,进入步骤318,结束流程。
与上述方法实施例相对应,本说明书还提供了保持不同存储系统的数据一致的装置实施例,图4示出了本说明书一个实施例提供的一种保持不同存储系统的数据一致的装置的结构示意图。如图4所示,该装置包括:写模块402、读模块404、比较模块406及数据更新模块408。
该写模块402,可以被配置为在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到,且在所述原子操作中针对第一主键生成或更新对应的版本号,其中,所述第一数据为所述写操作针对的第一主键在第二存储系统中对应的数据。
该读模块404,可以被配置为在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据,所述第二数据为所述第一主键在所述第一存储系统中对应的数据。
该比较模块406,可以被配置为将获取的版本号与所述第一主键最新的版本号进行比较,如果不一致,则触发读模块404重新进入所述获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据的步骤。
该数据更新模块408,可以被配置为如果所述比较模块406判定一致,则以原子操作将所述第二数据更新到所述第二存储系统,且在所述原子操作中针对所述第一主键更新对应的版本号。
可见,由于该装置在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到且针对所述第一主键生成或更新对应的版本号,而第一数据为所述写操作针对的第一主键在第二存储系统中对应的数据,从而通过原子操作对数据以及版本号的更新作为一个整体在第二存储系统中实现了预占位,有效防止并发更新导致的不一致性。在需要读取第一数据的情况下,如果从所述第二存储系统读取不到,则获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据,将获取的版本号与所述第一主键最新的版本号进行比较。如果版本号一致,说明读操作从第一存储系统读取出第二数据之后,读取出的数据并未发生更新,则可以原子操作将读取出的第二数据更新到所述第二存储系统且在所述原子操作中针对所述第一主键更新对应的版本号,能够有效防止并发读导致的不一致性。如果版本号不一致,则说明读操作从第一存储系统读取出第二数据之后,第一存储系统中的第二数据发生了更新,需要重新获取对应的版本号进行比较,以便将最新的第二数据更新到第二存储系统,从而保持第一存储系统与第二存储系统的数据一致。可见,本说明书实施例提供的装置将数据以及版本号的更新整体作为一个原子操作在第二存储系统中通过预占位实现了第一存储系统和第二存储系统的数据 的一致性。
图5示出了本说明书另一个实施例提供的一种保持不同存储系统的数据一致的装置的结构示意图。如图5所示,该装置还可以包括:版本初始化模块412,可以被配置为如果所述读模块404获取不到所述第一主键最新的版本号,则以原子操作针对所述第一主键生成对应的版本号初始值。该实施例中,通过为获取不到的版本号赋予初始值,进一步完善了读流程,能够有效保证主键对应的数据未发生更新的情况下,依然能利用初始的版本号实现保持不同存储系统的数据一致的目的。
本说明书一个或多个实施例中,如图5所示,所述读模块404可以包括:请求发送子模块4042、消息接收子模块4044、版本获取子模块4046及数据获取子模块4048。
该请求发送子模块4042,可以被配置为向所述第二存储系统发送所述读操作读取数据的请求。
该消息接收子模块4044,可以被配置为接收所述第二存储系统针对所述请求反馈的数据无法被读取到的消息,所述消息携带了所述第一主键最新的版本号。
该版本获取子模块4046,可以被配置为根据所述消息获取所述第一主键最新的版本号。
该数据获取子模块4048,可以被配置为从所述第一存储系统读取出所述第一主键对应的数据。
在该实施例中,在从第二存储系统读取不到数据的情况下,直接通过第二存储系统返回的消息提取消息携带的版本号即可,流程清晰,数据传输量少。
本说明书一个或多个实施例中,所述第二存储系统提供了隐藏获取接口,所述隐藏获取接口用于获取所述第一主键最新的版本号。
所述请求发送子模块4042,可以被配置为向所述第二存储系统发送所述读操作读取数据的请求。
所述消息接收子模块4044,可以被配置为接收所述第二存储系统针对所述请求反馈的数据无法被读取到的消息。
所述版本获取子模块4046,可以被配置为根据所述消息通过所述第二存储系统的隐藏获取接口获取所述第一主键最新的版本号。
在该实施例中,在数据读取不到的情况下根据第二存储系统返回的消息,相应通过隐藏获取接口获取版本号即可,第二存储系统不必返回额外的信息、属性,可以减少不必要的数据传输。
本说明书一个或多个实施例中,所述第二存储系统提供了隐藏接口,所述隐藏接口用于以原子操作将数据标识为隐藏以无法被读取,且在所述原子操作中针对数据的主键生成或更新对应的版本号。所述写模块402,可以被配置为在写操作更新第一存储系统的情况下,通过调用所述隐藏接口,以原子操作将第一数据标识为隐藏以无法被读取, 且在所述原子操作中针对所述第一主键生成或更新对应的版本号。在该实施例中,通过将数据标识为隐藏,可以保持主键在第二存储系统中的存在,便于直接为主键设置对应的版本号,提高写逻辑的处理效率。
本说明书一个或多个实施例中,所述写模块402,可以被配置为在写操作更新第一存储系统的情况下,以原子操作将所述写操作针对的第一主键在第二存储系统中对应的数据删除。在该实施例中,将主键在第二存储系统中对应的第一数据删除的情况下,可以保留主键,将其对应的值设置为空,便于设置对应的版本号,提高写逻辑的处理效率。
上述为本实施例的一种保持不同存储系统的数据一致的装置的示意性方案。需要说明的是,该保持不同存储系统的数据一致的装置的技术方案与上述的保持不同存储系统的数据一致的方法的技术方案属于同一构思,保持不同存储系统的数据一致的装置的技术方案未详细描述的细节内容,均可以参见上述保持不同存储系统的数据一致的方法的技术方案的描述。
图6示出了根据本说明书一个实施例提供的一种计算设备600的结构框图。该计算设备600的部件包括但不限于存储器610和处理器620。处理器620与存储器610通过总线630相连接,数据库650用于保存数据。
计算设备600还包括接入设备640,接入设备640使得计算设备600能够经由一个或多个网络660通信。这些网络的示例包括公用交换电话网(PSTN)、局域网(LAN)、广域网(WAN)、个域网(PAN)或诸如因特网的通信网络的组合。接入设备640可以包括有线或无线的任何类型的网络接口(例如,网络接口卡(NIC))中的一个或多个,诸如IEEE802.11无线局域网(WLAN)无线接口、全球微波互联接入(Wi-MAX)接口、以太网接口、通用串行总线(USB)接口、蜂窝网络接口、蓝牙接口、近场通信(NFC)接口,等等。
在本说明书的一个实施例中,计算设备600的上述部件以及图6中未示出的其他部件也可以彼此相连接,例如通过总线。应当理解,图6所示的计算设备结构框图仅仅是出于示例的目的,而不是对本说明书范围的限制。本领域技术人员可以根据需要,增添或替换其他部件。
计算设备600可以是任何类型的静止或移动计算设备,包括移动计算机或移动计算设备(例如,平板计算机、个人数字助理、膝上型计算机、笔记本计算机、上网本等)、移动电话(例如,智能手机)、可佩戴的计算设备(例如,智能手表、智能眼镜等)或其他类型的移动设备,或者诸如台式计算机或PC的静止计算设备。计算设备600还可以是移动式或静止式的服务器。
其中,处理器620用于执行如下计算机可执行指令:
在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到,且在所述原子操作中针对第一主键生成或更新对应的版本号,其中,所述第一数据为所述 写操作针对的第一主键在第二存储系统中对应的数据;
在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据,所述第二数据为所述第一主键在所述第一存储系统中对应的数据;
将获取的版本号与所述第一主键最新的版本号进行比较;
如果一致,则以原子操作将所述第二数据更新到所述第二存储系统,且在所述原子操作中针对所述第一主键更新对应的版本号;
如果不一致,则重新进入所述获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据的步骤。
上述为本实施例的一种计算设备的示意性方案。需要说明的是,该计算设备的技术方案与上述的保持不同存储系统的数据一致的方法的技术方案属于同一构思,计算设备的技术方案未详细描述的细节内容,均可以参见上述保持不同存储系统的数据一致的方法的技术方案的描述。
本说明书一实施例还提供一种计算机可读存储介质,其存储有计算机指令,该指令被处理器执行时以用于:
在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到,且在所述原子操作中针对第一主键生成或更新对应的版本号,其中,所述第一数据为所述写操作针对的第一主键在第二存储系统中对应的数据;
在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据,所述第二数据为所述第一主键在所述第一存储系统中对应的数据;
将获取的版本号与所述第一主键最新的版本号进行比较;
如果一致,则以原子操作将所述第二数据更新到所述第二存储系统,且在所述原子操作中针对所述第一主键更新对应的版本号;
如果不一致,则重新进入所述获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据的步骤。
上述为本实施例的一种计算机可读存储介质的示意性方案。需要说明的是,该存储介质的技术方案与上述的保持不同存储系统的数据一致的方法的技术方案属于同一构思,存储介质的技术方案未详细描述的细节内容,均可以参见上述保持不同存储系统的数据一致的方法的技术方案的描述。
上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是 可以的或者可能是有利的。
所述计算机指令包括计算机程序代码,所述计算机程序代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。所述计算机可读介质可以包括:能够携带所述计算机程序代码的任何实体或装置、记录介质、U盘、移动硬盘、磁碟、光盘、计算机存储器、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、电载波信号、电信信号以及软件分发介质等。需要说明的是,所述计算机可读介质包含的内容可以根据司法管辖区内立法和专利实践的要求进行适当的增减,例如在某些司法管辖区,根据立法和专利实践,计算机可读介质不包括电载波信号和电信信号。
需要说明的是,对于前述的各方法实施例,为了简便描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本说明书实施例并不受所描述的动作顺序的限制,因为依据本说明书实施例,某些步骤可以采用其它顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作和模块并不一定都是本说明书实施例所必须的。
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其它实施例的相关描述。
以上公开的本说明书优选实施例只是用于帮助阐述本说明书。可选实施例并没有详尽叙述所有的细节,也不限制该发明仅为所述的具体实施方式。显然,根据本说明书实施例的内容,可作很多的修改和变化。本说明书选取并具体描述这些实施例,是为了更好地解释本说明书实施例的原理和实际应用,从而使所属技术领域技术人员能很好地理解和利用本说明书。本说明书仅受权利要求书及其全部范围和等效物的限制。

Claims (10)

  1. 一种保持不同存储系统的数据一致的方法,包括:
    在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到,且在所述原子操作中针对第一主键生成或更新对应的版本号,其中,所述第一数据为所述写操作针对的第一主键在第二存储系统中对应的数据;
    在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据,所述第二数据为所述第一主键在所述第一存储系统中对应的数据;
    将获取的版本号与所述第一主键最新的版本号进行比较;
    如果一致,则以原子操作将所述第二数据更新到所述第二存储系统,且在所述原子操作中针对所述第一主键更新对应的版本号;
    如果不一致,则重新进入所述获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据的步骤。
  2. 根据权利要求1所述的方法,所述第一存储系统为持久化数据源,所述第二存储系统为缓存系统。
  3. 根据权利要求1所述的方法,还包括:
    如果获取不到所述第一主键最新的版本号,则以原子操作针对所述第一主键生成对应的版本号初始值。
  4. 根据权利要求1所述的方法,所述在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号包括:
    向所述第二存储系统发送所述读操作读取数据的请求;
    接收所述第二存储系统针对所述请求反馈的数据无法被读取到的消息,所述消息携带了所述第一主键最新的版本号;
    根据所述消息获取所述第一主键最新的版本号。
  5. 根据权利要求1所述的方法,所述第二存储系统提供了隐藏获取接口,所述隐藏获取接口用于获取所述第一主键最新的版本号;
    所述在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号包括:
    向所述第二存储系统发送所述读操作读取数据的请求;
    接收所述第二存储系统针对所述请求反馈的数据无法被读取到的消息;
    根据所述消息通过所述第二存储系统的隐藏获取接口获取所述第一主键最新的版本号。
  6. 根据权利要求1所述的方法,所述第二存储系统提供了隐藏接口,所述隐藏接口用于以原子操作将数据标识为隐藏以无法被读取,且在所述原子操作中针对数据的主键生成或更新对应的版本号;
    所述在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到,且在所述原子操作中针对第一主键生成或更新对应的版本号包括:
    在写操作更新第一存储系统的情况下,通过调用所述隐藏接口,以原子操作将第一数据标识为隐藏以无法被读取,且在所述原子操作中针对所述第一主键生成或更新对应的版本号。
  7. 根据权利要求1所述的方法,所述在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到包括:
    在写操作更新第一存储系统的情况下,以原子操作将所述写操作针对的第一主键在第二存储系统中对应的第一数据删除。
  8. 一种保持不同存储系统的数据一致的装置,包括:
    写模块,被配置为在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到,且在所述原子操作中针对第一主键生成或更新对应的版本号,其中,所述第一数据为所述写操作针对的第一主键在第二存储系统中对应的数据;
    读模块,被配置为在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据,所述第二数据为所述第一主键在所述第一存储系统中对应的数据;
    比较模块,被配置为将获取的版本号与所述第一主键最新的版本号进行比较,如果不一致,触发读模块重新进入所述获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据的步骤;
    数据更新模块,被配置为如果所述比较模块判定一致,则以原子操作将所述第二数据更新到所述第二存储系统,且在所述原子操作中针对所述第一主键更新对应的版本号。
  9. 一种计算设备,包括:
    存储器和处理器;
    所述存储器用于存储计算机可执行指令,所述处理器用于执行所述计算机可执行指令:
    在写操作更新第一存储系统的情况下,以原子操作将第一数据处理为读取不到,且在所述原子操作中针对第一主键生成或更新对应的版本号,其中,所述第一数据为所述写操作针对的第一主键在第二存储系统中对应的数据;
    在读操作从所述第二存储系统读取不到所述第一数据的情况下,获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据,所述第二数据为所述第一主键在所述第一存储系统中对应的数据;
    将获取的版本号与所述第一主键最新的版本号进行比较;
    如果一致,则以原子操作将所述第二数据更新到所述第二存储系统,且在所述原子操作中针对所述第一主键更新对应的版本号;
    如果不一致,则重新进入所述获取所述第一主键最新的版本号,且从所述第一存储系统读取出第二数据的步骤。
  10. 一种计算机可读存储介质,其存储有计算机指令,该指令被处理器执行时实现权利要求1至7任意一项所述保持不同存储系统的数据一致的方法的步骤。
PCT/CN2021/119791 2020-09-29 2021-09-23 保持不同存储系统的数据一致的方法以及装置 WO2022068660A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
US18/246,666 US20230281187A1 (en) 2020-09-29 2021-09-23 Method for keeping data consistent across different storage systems, computing device, and storage medium

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011052190.3A CN112286947B (zh) 2020-09-29 2020-09-29 保持不同存储系统的数据一致的方法以及装置
CN202011052190.3 2020-09-29

Publications (1)

Publication Number Publication Date
WO2022068660A1 true WO2022068660A1 (zh) 2022-04-07

Family

ID=74422294

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/119791 WO2022068660A1 (zh) 2020-09-29 2021-09-23 保持不同存储系统的数据一致的方法以及装置

Country Status (3)

Country Link
US (1) US20230281187A1 (zh)
CN (1) CN112286947B (zh)
WO (1) WO2022068660A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112286947B (zh) * 2020-09-29 2022-10-04 阿里云计算有限公司 保持不同存储系统的数据一致的方法以及装置

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170054802A1 (en) * 2015-08-19 2017-02-23 Facebook, Inc. Read-after-write consistency in data replication
CN109862102A (zh) * 2019-02-25 2019-06-07 交通银行股份有限公司 一种分布式数据多副本并发控制系统、服务器及方法
CN110955719A (zh) * 2018-09-27 2020-04-03 阿里巴巴集团控股有限公司 一种数据存取处理设备、系统和方法
CN112286947A (zh) * 2020-09-29 2021-01-29 阿里云计算有限公司 保持不同存储系统的数据一致的方法以及装置

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7636814B1 (en) * 2005-04-28 2009-12-22 Symantec Operating Corporation System and method for asynchronous reads of old data blocks updated through a write-back cache
CN102073494B (zh) * 2010-12-30 2014-05-07 用友软件股份有限公司 缓存数据管理方法和装置
JP6199808B2 (ja) * 2014-06-06 2017-09-20 株式会社東芝 データベース装置およびデータアクセス方法
CN106557278A (zh) * 2015-09-30 2017-04-05 腾讯科技(深圳)有限公司 一种缓存数据持久化的方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170054802A1 (en) * 2015-08-19 2017-02-23 Facebook, Inc. Read-after-write consistency in data replication
CN110955719A (zh) * 2018-09-27 2020-04-03 阿里巴巴集团控股有限公司 一种数据存取处理设备、系统和方法
CN109862102A (zh) * 2019-02-25 2019-06-07 交通银行股份有限公司 一种分布式数据多副本并发控制系统、服务器及方法
CN112286947A (zh) * 2020-09-29 2021-01-29 阿里云计算有限公司 保持不同存储系统的数据一致的方法以及装置

Also Published As

Publication number Publication date
CN112286947B (zh) 2022-10-04
CN112286947A (zh) 2021-01-29
US20230281187A1 (en) 2023-09-07

Similar Documents

Publication Publication Date Title
CN110399356B (zh) 一种在线数据迁移方法、装置、计算设备及存储介质
US8719845B2 (en) Sharing and synchronization of objects
CN110096334B (zh) 缓存处理方法、装置、设备及计算机可读存储介质
JP2005222533A (ja) 挿入されたメッセージ修正を使用した、コード作成のため受信したメッセージディスパッチの調整
CN114661248B (zh) 数据处理方法及装置
CN113204435B (zh) 数据处理方法以及系统
CN111737002B (zh) 一种链式存储请求的处理方法、装置、设备及可读介质
CN113297320A (zh) 分布式数据库系统及数据处理方法
CN112306993B (zh) 基于Redis的数据读取方法、装置、设备及可读存储介质
WO2022068660A1 (zh) 保持不同存储系统的数据一致的方法以及装置
CN107451070B (zh) 一种数据的处理方法和服务器
WO2021259188A1 (zh) 路由读请求、反馈报文的方法以及各自装置、数据库
CN114328626A (zh) 多数据源动态切换方法、系统及存储介质
CN113297231A (zh) 数据库处理方法及装置
US10467143B1 (en) Event-driven cache
CN110955719A (zh) 一种数据存取处理设备、系统和方法
CN116483556A (zh) 数据处理方法及加速器系统
CN109445966B (zh) 事件处理方法、装置、介质和计算设备
CN112546617B (zh) 任务处理方法及装置
CN114217986A (zh) 数据处理方法、装置、设备、存储介质及产品
US20140149463A1 (en) Method, apparatus, system and computer program product for managing data in database
CN113342270A (zh) 卷卸载方法、装置和电子设备
CN111078632A (zh) 一种文件数据的管理方法及装置
CN115361435B (zh) 数据处理方法
CN116028677B (zh) 数据操作方法以及系统

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21874321

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21874321

Country of ref document: EP

Kind code of ref document: A1

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 13.11.2023)

122 Ep: pct application non-entry in european phase

Ref document number: 21874321

Country of ref document: EP

Kind code of ref document: A1