CN111752977B - Data reading request and data writing request processing method and device - Google Patents

Data reading request and data writing request processing method and device Download PDF

Info

Publication number
CN111752977B
CN111752977B CN202010551153.0A CN202010551153A CN111752977B CN 111752977 B CN111752977 B CN 111752977B CN 202010551153 A CN202010551153 A CN 202010551153A CN 111752977 B CN111752977 B CN 111752977B
Authority
CN
China
Prior art keywords
target data
cache
data
version number
target
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN202010551153.0A
Other languages
Chinese (zh)
Other versions
CN111752977A (en
Inventor
王海彬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Douyin Vision Co Ltd
Original Assignee
Douyin Vision Co Ltd
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 Douyin Vision Co Ltd filed Critical Douyin Vision Co Ltd
Priority to CN202010551153.0A priority Critical patent/CN111752977B/en
Publication of CN111752977A publication Critical patent/CN111752977A/en
Application granted granted Critical
Publication of CN111752977B publication Critical patent/CN111752977B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • 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/22Indexing; Data structures therefor; Storage structures
    • 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

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)
  • Computational Linguistics (AREA)
  • Computer Security & Cryptography (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The disclosure provides a processing method and a device for a data read request and a data write request, wherein the processing method for the data read request comprises the steps of responding to the data read request based on a target object, if first target data corresponding to the target object exists in a cache and the first target data is in an invalid state, reading second target data corresponding to the target object in a persistent memory, marking the second target data with a first version number of the first target data, and if the version number of third target data matched with the second target data exists in the cache is the first version number, replacing the third target data with the second target data and writing the third target data into the cache. The data stored in the cache of the present disclosure has a version number, and further, when the version number of the data requested to be written is the same as the version number of the corresponding data in the current cache, the data is allowed to be written into the cache, so that the data stored in the cache and the data stored in the persistent memory can be kept consistent.

Description

Data reading request and data writing request processing method and device
Technical Field
The disclosure relates to the technical field of data processing, and in particular relates to a method and a device for processing a data read request and a data write request.
Background
In a high concurrency data read-write service, in order to improve the performance of a data storage system, a cache is generally introduced in a service flow to share the performance pressure of a persistent memory. Here, common usage scenarios for caching include read-write scenarios: when the data is read, firstly searching the required data from the cache, if the required data is available, directly reading the required data from the cache, if the required data is not available, inquiring the persistent memory, and writing the inquired data into the cache; when writing data, the data to be written is written into the persistent memory for storage, and then invalid data in the cache is deleted or the latest data is written into the cache.
However, under the condition of high concurrent data read-write, invalid data is easy to store in the cache, so that the data stored in the cache and the persistent memory are inconsistent. For example, in a high concurrency scenario, a read request reads a user nickname from persistent storage, where the thread is blocked, execution of the read request is suspended, while a write request updates the persistent storage, changing the user nickname from a to B, and deleting the user nickname a in the cache; at this time, the read request resumes execution, writing the read user nickname a into the cache; thus, the old user nickname a is stored in the cache, and the updated user nickname B is stored in the persistent memory, and the user nickname a in the cache is the invalid data.
Therefore, how to keep the data stored in the cache and the persistent memory consistent is a technical problem that needs to be solved at present.
Disclosure of Invention
The embodiment of the disclosure at least provides a method and a device for processing a data read request and a data write request, which can keep the data stored in a cache and a persistent memory consistent.
In a first aspect, an embodiment of the present disclosure provides a method for processing a data read request, where the method includes:
responding to a data reading request based on a target object, and judging whether first target data corresponding to the target object exists in a cache;
if the first target data exist and are in an invalid state, reading second target data corresponding to the target object in a persistent memory, and marking the second target data with a first version number; the first version number is the version number of the first target data in the cache;
judging whether third target data matched with the second target data exists in the cache or not based on the target object;
if the third target data exist, judging whether the version number of the third target data is the first version number, if so, replacing the third target data with the second target data, and writing the second target data into the cache.
In an alternative embodiment, after the determining whether the version number of the third target data is the first version number, the processing method further includes:
and if the first version number is not the first version number, refusing to write the second target data into the cache, and setting the third target data in the cache into an invalid state.
In an alternative embodiment, after said replacing the third target data with the second target data and writing to the cache, the processing method further includes:
updating the first version number of the second target data written into the cache to a third version number.
In an optional embodiment, after determining whether there is first target data corresponding to the target object in the cache, the processing method further includes:
if the first target data does not exist, reading the second target data in the persistent memory, and marking the second target data with a second version number;
judging whether third target data matched with the second target data exists in the cache or not based on the target object;
and if the third target data exists, refusing to write the second target data into the cache.
In an alternative embodiment, after said determining whether there is third target data in the cache that matches the second target data, the processing method further includes:
and if the third target data does not exist, writing the second target data into the cache, and updating the second version number of the second target data written into the cache into a fourth version number.
In an optional embodiment, after determining whether there is first target data corresponding to the target object in the cache, the processing method further includes:
and if the first target data exist and are in a valid state, reading the first target data in the cache.
In a second aspect, an embodiment of the present disclosure provides a method for processing a data write request, where the method includes:
responding to a data writing request based on a target object, and judging whether second target data matched with first target data exists in a cache or not based on the first target data and the target object in the data writing request;
if the second target data exists, marking the first target data with a first version number, and writing the first target data into a persistent memory; the first version number is the version number of the second target data in the cache;
Judging whether third target data matched with the first target data exists in the cache or not based on the target object;
if the third target data exist, judging whether the version number of the third target data is the first version number, if so, replacing the third target data with the first target data, and writing the first target data into the cache.
In an alternative embodiment, after the determining whether the version number of the third target data is the first version number, the processing method further includes:
and if the first version number is not the first version number, refusing to write the first target data into the cache, and setting the third target data in the cache into an invalid state.
In an alternative embodiment, after said replacing the third target data with the first target data and writing to the cache, the processing method further includes:
and updating the first version number of the first target data in the cache to a third version number.
In an alternative embodiment, after determining whether there is second target data in the cache that matches the first target data in the data write request, the processing method further includes:
If the second target data does not exist, marking the version number of the first target data as a second version number;
judging whether third target data matched with the first target data exists in the cache or not based on the target object;
and if the third target data does not exist, writing the first target data into the cache, and updating the second version number of the first target data written into the cache into a fourth version number.
In an alternative embodiment, after said determining whether there is third target data in the cache that matches the first target data, the processing method further includes:
and if the third target data exists, refusing to write the first target data into the cache.
In a third aspect, a processing apparatus for a data read request, the processing apparatus comprising:
the first judging module is used for responding to a data reading request based on a target object and judging whether first target data corresponding to the target object exists in a cache;
the marking module is used for reading second target data corresponding to the target object from the persistent memory if the first target data exist and are in an invalid state, and marking the second target data by using a first version number; the first version number is the version number of the first target data in the cache;
The second judging module is used for judging whether third target data matched with the second target data exists in the cache or not based on the target object;
and the first writing module is used for judging whether the version number of the third target data is the first version number if the third target data exists, and if so, replacing the third target data with the second target data and writing the second target data into the cache.
In an alternative embodiment, the first writing module includes:
and the setting unit is used for refusing to write the second target data into the cache if the second target data is not the first version number, and setting the third target data in the cache into an invalid state.
In an alternative embodiment, the first writing module further includes:
and the updating unit is used for updating the first version number written into the cached second target data into a third version number.
In an alternative embodiment, the marking module is further configured to read the second target data in the persistent memory and mark the second target data with a second version number if the first target data does not exist;
The second judging module is used for judging whether third target data matched with the second target data exists in the cache or not based on the target object;
the first writing module is further configured to refuse to write the second target data into the cache if the third target data exists.
In an alternative embodiment, the first writing module is further configured to:
and if the third target data does not exist, writing the second target data into the cache, and updating the second version number of the second target data written into the cache into a fourth version number.
In an alternative embodiment, the processing device further comprises:
and the second writing module is used for reading the first target data in the cache if the first target data exists and the first target data is in a valid state.
In a fourth aspect, a processing apparatus for reading and writing data, the processing apparatus comprising:
the first judging module is used for responding to a data writing request based on a target object, and judging whether second target data matched with the first target data exists in a cache or not based on the first target data in the data writing request and the target object;
The first writing module is used for marking the first target data with a first version number and writing the first target data into a persistent memory if the second target data exists; the first version number is the version number of the second target data in the cache;
the second judging module is used for judging whether third target data matched with the first target data exists in the cache or not based on the target object;
and the second writing module is used for judging whether the version number of the third target data is the first version number if the third target data exists, and if so, replacing the third target data with the first target data and writing the first target data into the cache.
In an alternative embodiment, the second writing module includes:
and the setting unit is used for refusing to write the first target data into the cache if the first version number is not the first version number, and setting the third target data in the cache into an invalid state.
In an alternative embodiment, the second writing module further includes:
and the updating unit is used for updating the first version number of the first target data in the cache to a third version number.
In an optional implementation manner, the first writing module is further configured to mark a version number of the first target data as a second version number if the second target data does not exist;
the second judging module is further configured to judge whether third target data matched with the first target data exists in the cache based on the target object;
the second writing module is further configured to write the first target data into the cache if the third target data does not exist, and update the second version number of the first target data written into the cache to a fourth version number.
In an alternative embodiment, the second writing module is further configured to:
and if the third target data exists, refusing to write the first target data into the cache.
In a fifth aspect, embodiments of the present disclosure further provide a computer device, comprising: a processor, a memory and a bus, the memory storing machine-readable instructions executable by the processor, the processor and the memory when the computer device is running, communicating over the bus, the machine-readable instructions when executed by the processor performing the steps of the first aspect, or any of the possible implementations of the first aspect, and/or the steps of the second aspect, or any of the possible implementations of the second aspect.
In a sixth aspect, the disclosed embodiments further provide a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the first aspect, or any of the possible implementations of the first aspect, and/or performs the steps of the second aspect, or any of the possible implementations of the second aspect.
According to the processing method and the processing device for the data reading request and the data writing request, the version number of the data stored in the cache is the same as the version number of the corresponding data in the current cache, and then the data is allowed to be written into the cache.
Further, according to the processing method and the processing device for the data reading request and the data writing request provided by the embodiment of the disclosure, the data stored in the cache has the version number, and when the version number of the data requested to be written is different from the corresponding version number of the data in the current cache, the data is refused to be written into the cache.
The foregoing objects, features and advantages of the disclosure will be more readily apparent from the following detailed description of the preferred embodiments taken in conjunction with the accompanying drawings.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings required for the embodiments are briefly described below, which are incorporated in and constitute a part of the specification, these drawings showing embodiments consistent with the present disclosure and together with the description serve to illustrate the technical solutions of the present disclosure. It is to be understood that the following drawings illustrate only certain embodiments of the present disclosure and are therefore not to be considered limiting of its scope, for the person of ordinary skill in the art may admit to other equally relevant drawings without inventive effort.
FIG. 1 is a flow chart illustrating a method of processing a data read request provided by an embodiment of the present disclosure;
FIG. 2 is a flow chart illustrating a method of processing a data read request in a particular embodiment;
FIG. 3 illustrates a flow chart of a method of processing a data write request provided by an embodiment of the present disclosure;
FIG. 4 is a flow chart illustrating a method of processing a data write request in a particular embodiment;
FIG. 5 illustrates one of the schematic diagrams of a processing apparatus for data read requests provided by embodiments of the present disclosure;
fig. 6 is a schematic diagram of a first writing module in a processing apparatus for a data read request according to an embodiment of the disclosure;
FIG. 7 is a second schematic diagram of a data read request processing apparatus according to an embodiment of the disclosure;
FIG. 8 is a schematic diagram of a processing device for data write requests according to an embodiment of the present disclosure;
FIG. 9 is a schematic diagram of a second writing module in a processing device for a data writing request according to an embodiment of the disclosure;
fig. 10 shows a schematic diagram of a computer device provided by an embodiment of the present disclosure.
Illustration of: 500-processing means of a data read request; 510-a first judgment module; 520-a marking module; 530-a second judgment module; 540-a first write module; 541-a setting unit; 542-updating unit; 550-a second write module; 800-processing means of a data write request; 810-a first judgment module; 820-a first write module; 830-a second determination module; 840-a second write module; 841-a setting unit; 842-an updating unit; 1000-a computer device; 1100-a processor; 1200-memory; 1210-memory; 1220 external memory; 1300-bus.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present disclosure. It will be apparent that the described embodiments are merely some, but not all embodiments of the present disclosure. The components of the embodiments of the present disclosure, which are generally described and illustrated in the figures herein, may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present disclosure provided in the accompanying drawings is not intended to limit the scope of the disclosure, as claimed, but is merely representative of selected embodiments of the disclosure. All other embodiments, which can be made by those skilled in the art based on the embodiments of this disclosure without making any inventive effort, are intended to be within the scope of this disclosure.
It is found that in the high concurrency data read-write service, in order to improve the performance of the data storage system, a cache is generally introduced in the service flow to share the performance pressure of the persistent storage. However, under the condition of high concurrent data read-write, invalid data is easy to store in the cache, so that the data stored in the cache and the persistent memory are inconsistent. For example, in a high concurrency scenario, a read request reads a user nickname from persistent storage, where the thread is blocked, execution of the read request is suspended, while a write request updates the persistent storage, changing the user nickname from a to B, and deleting the user nickname a in the cache; at this time, the read request resumes execution, writing the read user nickname a into the cache; thus, the old user nickname a is stored in the cache, and the updated user nickname B is stored in the persistent memory, and the user nickname a in the cache is the invalid data.
For the case of inconsistent data stored in the cache and the persistent storage, two modes are generally adopted in the prior art for processing, namely: the final consistency is achieved by shortening the effective time of the cache; mode two: and aiming at the data writing request, deleting the data in the cache in a delayed manner. For the first mode, under a high concurrency scene, the cache valid time is shortened, and the read pressure of the persistent storage can be increased; for the second mode, the data in the cache is deleted in a delayed manner, so that more data is stored in the cache, and the efficiency of processing the data read-write request is reduced.
Based on the above study, the disclosure provides a method and a device for processing a data read request and a data write request, where the method for processing a data read request includes responding to a data read request based on a target object, if there is first target data corresponding to the target object in a cache, and the first target data is in an invalid state, reading second target data corresponding to the target object in a persistent memory, marking the second target data with a first version number of the first target data, and if a version number of third target data matching the second target data in the cache is the first version number, replacing the third target data with the second target data, and writing the third target data into the cache. The data stored in the cache has a version number, and the data is allowed to be written into the cache when the version number of the data requested to be written is the same as the version number of the corresponding data in the current cache, so that the cache and the data stored in the persistent memory can be kept consistent, and meanwhile, the efficiency of data reading or writing can be improved by utilizing the cache.
It should be noted that, the cache may be a single-machine cache, such as a server memory, and the cache may also be a cluster cache, such as a redis cache; the persistent memory may be a disk, or it may be a DataBase (DB), such as a mysql DataBase.
The solutions set forth in the present disclosure are all results obtained by the inventors after practice and careful study, and thus, the discovery process of the above-described problems and the solutions proposed by the present disclosure hereinafter for the above-described problems should be all contributions to the present disclosure by the inventors.
It should be noted that: like reference numerals and letters denote like items in the following figures, and thus once an item is defined in one figure, no further definition or explanation thereof is necessary in the following figures.
For the sake of understanding the present embodiment, first, a detailed description will be given of a processing method of a data read request disclosed in an embodiment of the present disclosure, where an execution body of the processing method of a data read request provided in an embodiment of the present disclosure is generally a computer device having a certain computing capability, where the computer device includes, for example: the terminal device, or server or other processing device, may be a User Equipment (UE), mobile device, user terminal, cellular telephone, wireless telephone, personal digital assistant (Personal Digital Assistant, PDA), handheld device, computing device, vehicle mounted device, wearable device, etc. In some possible implementations, the method of processing the data read request may be implemented by way of a processor invoking computer readable instructions stored in a memory.
The processing method of the data read request provided in the embodiment of the present disclosure will be described below by taking the execution body as an example of a computer device.
Example 1
Referring to fig. 1, a flowchart of a method for processing a data read request according to an embodiment of the disclosure is shown, where the method includes steps S101 to S104, where:
s101: and responding to a data reading request based on the target object, and judging whether first target data corresponding to the target object exists in the cache.
The data stored in the cache and the persistent memory are both stored in the form of key-value pairs, wherein a key is a target object, and a value is target data corresponding to the target object, for example, the target object is a nickname of a user A, and the target data is a nickname a of the user A. When the data reading request is received, the target object can be analyzed from the data reading request, and then whether the first target data corresponding to the target object exists in the cache or not is judged according to the target object.
In the step, after a data reading request aiming at a target object is received, whether first target data for requesting to read exist in a cache or not is judged, and normally, when the first target data exist in the cache, the first target data are directly read from the cache, so that the data reading request is processed; when the first target data does not exist in the cache, the second target data corresponding to the target object is required to be read from the persistent memory, and after the second target data is read, the read second target data is written into the cache, so that the second target data can be directly read from the cache when a next reading request for the second target data is needed, the second target data does not need to be read from the persistent memory, and the data reading efficiency and the performance of the data storage system can be improved by using the cache.
Further, after the determining whether the first target data corresponding to the target object exists in the cache, there are two cases:
case one: the first target data corresponding to the target object exists in the cache, but the states of the first target data are divided into two types, namely an effective state and an ineffective state, and when the first target data are in the effective state, the first target data are available, namely the first target data can be directly read from the cache; when the first target data is in an invalid state, the first target data is not available and the data needs to be read from the persistent memory.
Here, the data in the cache has a status in addition to the version number, and specifically, one field of the data may be used to display the status, i.e., the field is a status bit. For data in the valid state, the data can be directly used, and for data in the invalid state, the data is not trusted and cannot be used. The following describes the cases of the valid state and the invalid state of the first target data, respectively:
state one: the first target data is in a valid state;
and if the first target data corresponding to the target object exists in the cache and the first target data is in a valid state, reading the first target data in the cache.
In the step, when a data reading request is received, if it is determined that first target data corresponding to a target object exists in the cache and the first target data is in an effective state, it is indicated that the first target data in the cache is available, the first target data can be directly read from the cache, and processing of the data reading request is completed.
State two: the first target data is in an invalid state;
s102: if the first target data exist and are in an invalid state, reading second target data corresponding to the target object in a persistent memory, and marking the second target data with a first version number; the first version number is the version number of the first target data in the cache.
In the step, when a data reading request is received, if it is determined that first target data corresponding to a target object exists in a cache and the first target data is in an invalid state, it is indicated that the first target data in the cache is unavailable, that is, the first target data in the cache is invalid, second target data corresponding to the target object needs to be read from a persistent memory, and the read second target data is marked by a first version number of the first target data in the cache. That is, the version number of the second target data read from the persistent memory is set to the same version number as that of the first target data stored in the current cache. In this way, when judging whether the read second target data can be written into the cache, the judgment can be made by judging whether the version number changes, specifically, judging whether the data matched with the data reading request is updated in a period of time between the time when the second target data is read from the persistent memory and the time when the second target data is read from the persistent memory, if not, the second target data can be directly written into the cache, and if not, the second target data is refused to be written into the cache.
The data in the cache or the persistent memory is stored as a key-value pair (key-value), for example, a nickname a of the user a, which is "key" and a is "value". For the present disclosure, the first target data, the third target data in the cache, and the second target data in the persistent memory are data corresponding to the same "key", but the "values" of the first target data, the second target data, and the third target data may be different, and the version numbers of the data corresponding to the same "key" different "values" may be different.
Here, the data in the cache of the present disclosure all have a version number and state information, and when a data read request is received, the state information and the version number of the first target data corresponding to the target object in the cache are acquired. Wherein the version number may be represented numerically such that, upon reading the second target data from the persistent memory, the second target data may be marked with the first version number of the first target data, i.e., the version number of the data in the current cache.
S103: and judging whether third target data matched with the second target data exists in the cache or not based on the target object.
In this step, after the second target data corresponding to the target object is read from the persistent memory, it is again determined whether there is third target data matching the second target data in the cache, that is, whether there is third target data corresponding to the target object of the second target data, and both the third target data and the "key" of the second target data are target objects. Here, the third target data may be the same as the first target data, and the third target data may be different from the first target data, and if the third target data is the same as the first target data, it indicates that the cache is not updated for the first target data during the period when the second target data is read from the persistent memory and the second target data is about to be written into the cache; if the third target data is different from the first target data, it is indicated that the cache is updated for the first target data during the time period between reading the second target data and writing the second target data into the cache.
Here, whether the data is updated or not can be judged by the version number of the data, and if the version number of the third target data in the current cache is inconsistent with the version number of the first target data in the previous cache, the cache is updated. When the data reading request is actually processed, the version number of the second target data read from the persistent memory is set to be the first version number of the first target data in the previous cache, so that whether the cache is updated in the previous and subsequent time can be judged by judging whether the version number of the third target data is the first version number.
S104: if the third target data exist, judging whether the version number of the third target data is the first version number, if so, replacing the third target data with the second target data, and writing the second target data into the cache.
In this step, after the second target data is read from the persistent memory, the second target data needs to be written into the cache, and at this time, it needs to be determined again whether or not there is third target data matching the second target data in the cache. If so, further judging whether the version number of the third target data is the first version number.
If the version number of the third target data is the first version number, it is indicated that the cache is not updated for the first target data during the period of time when the second target data is read by the persistent storage and the second target data is about to be written into the cache, that is, the version number of the second target data to be written is consistent with the version number of the third target data to be modified. Therefore, the second target data can be replaced by the third target data to be written into the cache, and the condition that invalid data is covered by updated data can be avoided, so that the consistency of the data between the sustainable memory and the cache is realized.
Here, after the second target data is written into the cache with the third target data being replaced by the second target data, the first version number of the second target data written into the cache is updated to a third version number.
In this step, after the second target data is replaced by the third target data and written into the cache, it is indicated that the data in the cache has been updated, and by updating the first version number of the second target data written into the cache, it can be clarified which version number the data is written for each time, where each time the version number is updated, it may be that a preset value is added to the current version number, and the preset value is preferably 1, that is, the third version number is obtained by adding the first version number to the preset value.
Further, if the version of the third target data is not the first version number, writing the second target data into the cache is refused, and the third target data in the cache is set to be in an invalid state.
In this step, if the version number of the third target data is not the first version number, it is indicated that the version number of the third target data in the current cache is different from the version number of the first target data in the previous cache, and in the period of time when the second target data is read from the persistent memory and is about to be written into the cache, the first target data is updated into the third target data, that is, the version number of the second target data to be written is inconsistent with the version number of the third target data to be modified, and the second target data to be written may be invalid data. Therefore, the second target data is refused to be written into the cache, and the third target data in the cache is set to be in an invalid state, namely, the operation on the third target data is not allowed, so that the condition that the invalid data is covered by updated data can be avoided, and the consistency of the data between the sustainable memory and the cache is realized.
In an example, in a high concurrency scenario, when a request for reading a user nickname is received, if it is determined that the user nickname exists in the cache but the user nickname is in an invalid state, the user nickname is read from the persistent memory as a, and the version number of the a is set to be the same as the version number 1 corresponding to the user nickname in the current cache, at this time, the thread is blocked, and execution of the read request is suspended. And the write request is used for updating the persistent memory, the user first nickname is changed from A to B, the user first nickname in the cache is changed to B, and the version number of the user first nickname B is 2. At this time, the read request resumes execution, and before writing the read user nickname a into the cache, it is determined whether the version number 1 of the read user nickname a is identical to the version number 2 of the user nickname B in the current cache, and 1 and 2 are different from each other, which indicates that the cache is updated for the user nickname a, and the read user nickname a is old data, that is, invalid data, and cannot be written into the cache. Therefore, the latest user first nickname B is stored in the final cache and the persistent storage, and the situation that the invalid data A is covered by the updated data B can be avoided, so that the consistency of the data between the persistent storage and the cache is realized.
It should be noted that, by adding the version number and the state information to the data in the cache, determining whether to allow the data to be written into the cache or not, and adding the state information, retry of the data which is not allowed to be written into the cache can be avoided, retry cost can be reduced, and when the problem of data consistency between the cache and the persistent memory is processed, the fast processing can be realized even in a scene with high concurrency performance requirement, and processing time is controlled at millisecond level.
And a second case: the first target data corresponding to the target object does not exist in the cache, and this will be explained below:
step a1: and responding to a data reading request based on the target object, and judging whether first target data corresponding to the target object exists in the cache.
Step a2: and if the first target data does not exist, reading the second target data in the persistent memory, and marking the second target data with a second version number.
In the step, when a data reading request is received, if it is determined that the first target data corresponding to the target object does not exist in the cache, second target data corresponding to the target object needs to be read from the persistent memory, and the read second target data is marked with a second version number. Here, the second version number is different from the version number of any data in the cache, for example, the second version number is set to 0, and the version number of any data stored in the cache is not 0, so that no first target data in the current cache can be represented by the second version number.
Step a3: and judging whether third target data matched with the second target data exists in the cache or not based on the target object.
Step a4: and if the third target data exists, refusing to write the second target data into the cache.
In the step, after the second target data is read from the persistent memory, it is determined that third target data matched with the second target data exists in the current cache, that is, the data matched with the data reading request is updated in the period that the second target data is read from the persistent memory and is about to be written into the cache, the version number of the second target data to be written is inconsistent with the version number of the third target data stored currently, the second target data is invalid, and the second target data is refused to be written into the cache.
Step a5: and if the third target data does not exist, writing the second target data into the cache, and updating the second version number of the second target data written into the cache into a fourth version number.
In this step, after the second target data is read from the persistent memory, the second target data needs to be written into the cache, and at this time, it needs to be determined again whether or not there is third target data matching the second target data in the cache. If the data is not stored, the data matched with the data reading request is not stored in the period of time when the second target data is read by the persistent storage and the second target data is about to be written into the cache. Therefore, the second target data may be written into the cache, and the second version number of the second target data written into the cache may be updated, where the fourth version number is obtained by adding the second version number to a preset value, and the preset value may be 1. In this way, the situation that invalid data is covered by updated data can be avoided, and accordingly data consistency between the sustainable memory and the cache can be achieved.
FIG. 2 is a flow chart illustrating a method of processing a data read request in a particular embodiment; the processing method of the data reading request comprises the following steps:
s201: in response to the nickname reading request for the user b, it is determined whether or not the nickname a of the user b exists in the cache, and if so, the process goes to S202, and if not, the process goes to S209.
S202: if so, it is determined whether the nickname A of the user B is in an effective state, and if so, the process proceeds to S203, and if not, the process proceeds to S204.
S203: if the nickname A of the user B is in an effective state, the nickname A of the user B is directly read from the cache, and the nickname reading request for the user B is ended.
S204: if the nickname a of the user B is in the invalid state, the nickname B of the user B is read from the persistent memory, and the read nickname B of the user B is marked with the version number 1 of the nickname a of the user B in the cache, and the process goes to S205.
S205: whether or not there is a nickname C of the user B matching the nickname B of the user B in the cache is judged, and the process goes to S206.
S206: if so, it is determined whether the version number of the nickname C of the user B is version number 1, if so, the process goes to S207, and if not, the process goes to S208.
S207: if yes, the nickname B of the user B is replaced by the nickname C of the user B and written into the cache, the version number 1 of the nickname B of the user B written into the cache is changed into the version number 2, and the nickname reading request for the user B is ended.
S208: if not, the nickname B of the user B is refused to be written into the cache, the nickname C of the user B in the cache is set to be in an invalid state, and the nickname reading request for the user B is ended.
S209: if not, the nickname B of the user B is read from the persistent memory, and the read nickname B of the user B is marked with the version number 0, and the process goes to S210.
S210: judging whether a nickname C of the user B matched with the nickname B of the user B exists in the cache, if so, jumping to S211, and if not, jumping to S212.
S211: if yes, the nickname B of the user B is refused to be written into the cache, and the nickname reading request for the user B is ended.
S212: if the nickname B does not exist, the nickname B of the user B is directly written into the cache, the version number 0 of the nickname B of the user B written into the cache is changed into the version number 1, and the nickname reading request for the user B is ended.
Here, as can be seen from fig. 2, the data is allowed to be written into the cache only when the version of the data stored in the cache matches the version of the data to be written, wherein A, B, C is the nickname of the user b, and if A, B, C is different, A, B, C belongs to the nickname of the user b of different versions, and by the above steps, the nicknames of the user b stored in the cache and the persistent memory can be kept identical.
In the embodiment of the disclosure, if first target data corresponding to a target object exists in a cache and the first target data is in an invalid state in response to a data reading request based on the target data, second target data corresponding to the target object is read in a persistent memory, the second target data is marked with a first version number of the first target data, and if a version number of third target data matched with the second target data exists in the cache is the first version number, the third target data is replaced with the second target data and written into the cache. The data stored in the cache of the present disclosure has a version number, and further, when the version number of the data requested to be written is the same as the version number of the corresponding data in the current cache, the data is allowed to be written into the cache, so that the data stored in the cache and the data stored in the persistent memory can be kept consistent.
Example two
Referring to fig. 3, a flowchart of a method for processing a data write request according to an embodiment of the disclosure is shown, where the method includes steps S301 to S304, where:
s301: and responding to a data writing request based on a target object, and judging whether second target data matched with the first target data exists in a cache or not based on the first target data in the data writing request and the target object.
The data stored in the cache and the persistent memory are both stored in the form of key-value pairs, wherein a key is a target object, and a value is target data corresponding to the target object, for example, the target object is a nickname of a user A, and the target data is a nickname a of the user A. When a data writing request is received, a target object can be parsed from the data reading and writing request, and then whether second target data corresponding to the target object exists in a cache or not is judged according to the target object, specifically, the target object can be used as a key, the second target data which is stored in association with the target object can be searched in the cache, and the target data is a value.
In this step, after receiving a data writing request, the data requested to be written is generally written to the persistent storage first, and then written to the cache. Here, when a data writing request based on a target object is received, first target data to be written in the data writing request is analyzed, and based on the target object, whether second target data matched with the first target data to be written is present in the cache is judged first, so that the condition of data matched with the first target data in the current cache is known. Further, a version number of the first target data written into the persistent memory is determined according to the current cached condition. If second target data matched with the first target data exists in the cache, marking the first target data with a first version number, wherein the first version number is the version number of the second target data in the cache; and if the second target data matched with the first target data does not exist in the cache, marking the first target data with a second version number, wherein the second version number is a preset version number.
Further, after the determining whether there is second target data in the cache that matches the first target data in the data write request, there are two cases:
case one: there is second target data in the cache that matches the first target data in the data write request, as will be explained below:
s302: if the second target data exists, marking the first target data with a first version number, and writing the first target data into a persistent memory; the first version number is the version number of the second target data in the cache.
In the step, when a data writing request is received, if it is determined that second target data matched with first target data in the data writing request exists in the cache, a version number of the second target data is obtained, and the version number of the first target data is marked with the first version number of the second target data, so that the first target data to be written into the cache is provided with the version number of the second target data in the current cache, and whether the cache is updated for the second target data can be determined according to the first version number.
S303: and judging whether third target data matched with the first target data exists in the cache or not based on the target object.
In this step, after the first target data in the data writing request is written into the persistent storage, it is again determined whether there is third target data matching the first target data in the cache, where the third target data may be the same as the second target data, and the third target data may be different from the second target data, and if the third target data is the same as the second target data, it is indicated that the cache is not updated for the second target data during the period of time when the first target data is written into the persistent storage and the first target data is about to be written into the cache; if the third target data is different from the second target data, it is indicated that the update to the second target data occurred during the period of time when the first target data is written to the persistent storage and the first target data is about to be written to the cache.
Here, whether the data is updated or not can be judged by the version of the data, if the version number of the third target data in the current cache is inconsistent with the version number of the second target data in the previous cache, the update of the cache is indicated, and when the data writing request is actually processed, the version number of the first target data written into the persistent memory is set to be the first version number of the second target data in the previous cache, so that whether the cache is updated or not can be judged in the previous and subsequent time by judging whether the version number of the third target data is the first version number or not.
S304: if the third target data exist, judging whether the version number of the third target data is the first version number, if so, replacing the third target data with the first target data, and writing the first target data into the cache.
In this step, after the first target data is written into the persistent memory, the first target data needs to be written into the cache, at this time, it needs to be determined again whether there is third target data matching the first target data in the cache, if there is third target data, further, whether the version number of the third target data is the first version number is determined, if there is the first version number, which indicates that there is no update to the second target data between the previous cache when the first target data is written into the persistent memory and the current cache when the first target data is about to be written into the cache, that is, the version number of the first target data to be written is consistent with the version number of the third target data to be modified, so that the third target data can be replaced with the first target data to be written into the cache, and thus, the situation that the invalid data is covered with the updated data can be avoided, thereby realizing the consistency of the data between the persistent memory and the cache.
Here, after the first target data is replaced with the third target data and written into the cache, the first version number of the first target data in the cache is updated to a third version number.
In this step, after the first target data is replaced by the third target data and written into the cache, it is indicated that the data in the cache has been updated, and by updating the first version number of the first target data written into the cache, it can be clarified which version number the data is written for each time, where each time the version number is updated, it may be that a preset value is added to the current version number, and the preset value is preferably 1, that is, the third version number is obtained by adding the first version number to the preset value.
Further, after judging whether the version number of the third target data is the first version number, if not, the first target data is refused to be written into the cache, and the third target data in the cache is set to be in an invalid state.
In this step, if the version number of the third target data is not the first version number, it is indicated that the version number of the third target data in the current cache is different from the version number of the second target data in the previous cache, and during the period of time when the first target data is written into the persistent memory and the first target data is about to be written into the cache, the second target data is updated into the third target data, that is, the version number of the first target data to be written is inconsistent with the version number of the third target data to be modified, and the first target data to be written may be invalid data. Therefore, the first target data is refused to be written into the cache, and the third target data in the cache is set to be in an invalid state, namely, the operation on the third target data is not allowed, so that the condition that the invalid data is covered by updated data can be avoided, and the consistency of the data between the sustainable memory and the cache is realized.
Further, after determining whether there is third target data matching the first target data in the cache based on the target object in step S303, the method further includes the following steps:
and if the third target data does not exist, refusing to write the first target data into the cache.
In this step, if the third target data is not present, it may be indicated that the second target data is deleted during the period of time between the writing of the first target data into the persistent storage and the writing of the first target data into the cache, or it may be indicated that the first target data to be written may be invalid data, and thus the writing of the first target data into the cache is denied.
And a second case: there is no second target data in the cache that matches the first target data in the data write request, as will be explained below:
step b1: and responding to a data writing request based on target data, and judging whether second target data matched with the first target data exists in a cache or not based on the first target data and a target object in the data writing request.
Step b2: and if the second target data does not exist, marking the version number of the first target data as a second version number.
In this step, when the data writing request is received, if it is determined that there is no second target data matching the first target data in the data writing request in the cache, the first target data in the data writing request is marked with a second version number, where the second version number is different from the version number of any data in the cache, for example, the second version number is set to 0, and the version number of any data stored in the cache is not 0, so that no second target data in the current cache can be represented by the second version number.
Step b3: and judging whether third target data matched with the first target data exists in the cache or not based on the target object.
Step b4: and if the third target data does not exist, writing the first target data into the cache, and updating the second version number of the first target data written into the cache into a fourth version number.
In this step, after the first target data is written to the persistent memory, the first target data needs to be written to the cache. At this time, it is necessary to determine whether there is third target data matching the first target data in the cache again, and if there is no third target data matching the first target data, it means that during the period of time when the first target data is written into the persistent memory and the first target data is about to be written into the cache, no data matching the data writing request is stored, so that the first target data may be written into the cache, the second version number of the first target data written into the cache may be updated, and the fourth version number is obtained by adding the second version number to a preset value, where the preset value may be 1. In this way, the situation that invalid data is covered by updated data can be avoided, and accordingly data consistency between the sustainable memory and the cache can be achieved.
Step b5: and if the third target data exists, refusing to write the first target data into the cache.
In the step, after the first target data is written into the persistent memory, it is determined that third target data matched with the first target data exists in the current cache, the update occurs between the current cache and the previous cache before the first target data is written into the persistent memory, the version number of the first target data to be written is inconsistent with the version number of the third target data stored currently, the first target data is invalid, and the first target data is refused to be written into the cache.
FIG. 4 is a flow chart illustrating a method of processing a data write request in a particular embodiment; the processing method of the data writing request comprises the following steps:
s401: in response to the nickname a writing request for the user B, it is determined whether or not there is a user B nickname B matching the nickname a of the user B in the cache, and if there is a user B nickname B, the process goes to S402, and if there is no user B nickname B, the process goes to S407.
S402: if so, the nickname A of the user B is marked with the version number 1 of the nickname B of the user B in the cache, and the nickname A of the user B is written into the persistent memory, and the process goes to S403.
S403: and judging whether a nickname C of the user B matched with the nickname A of the user B exists in the cache, and if yes, jumping to S404.
S404: if so, it is determined whether the version number of the nickname C of the user B is version number 1, if so, the process proceeds to S405, and if not, the process proceeds to S406.
S405: if yes, the nickname A of the user B is replaced by the nickname C of the user B and written into the cache, the version number 1 of the nickname A of the user B written into the cache is changed into the version number 2, and the nickname reading request for the user B is ended.
S406: if not, the nickname A of the user B is refused to be written into the cache, the nickname C of the user B in the cache is set to be in an invalid state, and the nickname reading request for the user B is ended.
S407: if not, the nickname A of the user B is marked with version number 0 and the process goes to S408.
S408: and judging whether a nickname C of the user B matched with the nickname A of the user B exists in the cache, if so, jumping to S410, and jumping to S409.
S409: if yes, the nickname A of the user B is refused to be written into the cache, and the nickname reading request for the user B is ended.
S410: if the nickname A does not exist, the nickname A of the user B is directly written into the cache, the version number 0 of the nickname A of the user B written into the cache is changed into the version number 1, and the nickname writing request for the user B is ended.
In the embodiment of the disclosure, if there is second target data matching first target data in a data writing request in a cache by responding to the data writing request based on the target object, marking a version number of the first target data with a first version number of the second target data, and writing the first target data into a persistent memory, if there is third target data matching the first target data in the cache and the version number of the third target data is the first version number, replacing the third target data with the first target data and writing the third target data into the cache. The data stored in the cache of the present disclosure has a version number, and further, when the version number of the data requested to be written is the same as the version number of the corresponding data in the current cache, the data is allowed to be written into the cache, so that the data stored in the cache and the data stored in the persistent memory can be kept consistent.
It will be appreciated by those skilled in the art that in the above-described method of the specific embodiments, the written order of steps is not meant to imply a strict order of execution but rather should be construed according to the function and possibly inherent logic of the steps.
Based on the same inventive concept, the embodiments of the present disclosure further provide a processing device for a data read request corresponding to the processing method for a data read request, and since the principle of solving the problem of the device in the embodiments of the present disclosure is similar to that of the processing method for the data read request in the embodiments of the present disclosure, the implementation of the device may refer to the implementation of the method, and the repetition is omitted.
Example III
Referring to fig. 5-7, fig. 5 illustrates one of schematic diagrams of a processing apparatus 500 for data read requests according to an embodiment of the present disclosure; fig. 6 is a schematic diagram of a first writing module 540 in a processing apparatus 500 for data read request according to an embodiment of the disclosure; fig. 7 shows a second schematic diagram of a processing device 500 for data read requests according to an embodiment of the disclosure.
As shown in fig. 5, the processing device 500 for data read request includes:
a first determining module 510, configured to determine, in response to a data reading request based on a target object, whether first target data corresponding to the target object exists in a cache;
the marking module 520 is configured to read, in the persistent memory, second target data corresponding to the target object if the first target data exists and the first target data is in an invalid state, and mark the second target data with a first version number; the first version number is the version number of the first target data in the cache;
A second determining module 530, configured to determine, based on the target object, whether third target data matching the second target data exists in the cache;
the first writing module 540 is configured to determine whether the version number of the third target data is the first version number if the third target data exists, and if so, replace the third target data with the second target data and write the third target data into the cache.
In one possible implementation, as shown in fig. 6, the first writing module 540 includes:
and a setting unit 541 configured to refuse to write the second target data into the cache if the second target data is not the first version number, and set the third target data in the cache to an invalid state.
In one possible implementation, as shown in fig. 6, the first writing module 540 further includes:
and an updating unit 542 configured to update the first version number of the second target data written into the cache to a third version number.
In a possible implementation manner, as shown in fig. 5, the marking module 520 is further configured to read the second target data in the persistent memory and mark the second target data with a second version number if the first target data does not exist;
The second determining module 530 is configured to determine, based on the target object, whether third target data that matches the second target data exists in the cache;
the first writing module 540 is further configured to refuse to write the second target data into the cache if the third target data exists.
In one possible implementation, as shown in fig. 5, the first writing module 540 is further configured to:
and if the third target data does not exist, writing the second target data into the cache, and updating the second version number of the second target data written into the cache into a fourth version number.
In one possible implementation manner, as shown in fig. 7, the processing device 500 for a data read request further includes:
and a second writing module 550, configured to read the first target data in the cache if the first target data exists and the first target data is in a valid state.
In an embodiment of the disclosure, if first target data corresponding to a target object exists in a cache and the first target data is in an invalid state in response to a data reading request based on the target object, second target data corresponding to the target object is read in a persistent memory, the second target data is marked with a first version number of the first target data, and if a version number of third target data matching the second target data exists in the cache is the first version number, the third target data is replaced with the second target data and written into the cache. The data stored in the cache of the present disclosure has a version number, and further, when the version number of the data requested to be written is the same as the version number of the corresponding data in the current cache, the data is allowed to be written into the cache, so that the data stored in the cache and the data stored in the persistent memory can be kept consistent.
Example IV
Referring to fig. 8 and 9, fig. 8 is a schematic diagram of a processing apparatus 800 for a data write request according to an embodiment of the disclosure; fig. 9 shows a specific schematic diagram of the second writing module 840 in the apparatus 800 for processing a data writing request according to an embodiment of the disclosure.
As shown in fig. 8, the processing device 800 for a data writing request includes:
a first determining module 810, configured to respond to a data writing request based on a target object, and determine, based on first target data in the data writing request and the target object, whether second target data matching the first target data exists in a cache;
a first writing module 820, configured to mark the first target data with a first version number and write the first target data into a persistent memory if the second target data exists; the first version number is the version number of the second target data in the cache;
a second determining module 830, configured to determine, based on the target object, whether third target data that matches the first target data exists in the cache;
the second writing module 840 is configured to determine whether the version number of the third target data is the first version number if the third target data exists, and if so, replace the third target data with the first target data and write the third target data into the cache.
In one possible implementation, as shown in fig. 9, the second writing module 840 includes:
a setting unit 841, configured to reject writing of the first target data into the cache if the first version number is not the first version number, and set the third target data in the cache to an invalid state.
In one possible implementation, as shown in fig. 9, the second writing module 840 further includes:
an updating unit 842 is configured to update the first version number of the first target data in the cache to a third version number.
In a possible implementation manner, as shown in fig. 8, the first writing module 820 is further configured to mark a version number of the first target data as a second version number if the second target data does not exist;
the second determining module 830 is further configured to determine, based on the target object, whether third target data that matches the first target data exists in the cache;
the second writing module 840 is further configured to write the first target data into the cache if the third target data does not exist, and update the second version number of the first target data written into the cache to a fourth version number.
In one possible implementation, as shown in fig. 8, the second writing module 840 is further configured to:
and if the third target data exists, refusing to write the first target data into the cache.
In an embodiment of the disclosure, if there is second target data matching first target data in a data write request in a cache, a version number of the first target data is marked with a first version number of the second target data, and the first target data is written into a persistent memory, and if there is third target data matching the first target data in the cache and the version number of the third target data is the first version number, the third target data is replaced with the first target data and written into the cache. The data stored in the cache of the present disclosure has a version number, and further, when the version number of the data requested to be written is the same as the version number of the corresponding data in the current cache, the data is allowed to be written into the cache, so that the data stored in the cache and the data stored in the persistent memory can be kept consistent.
The process flow of each module in the apparatus and the interaction flow between the modules may be described with reference to the related descriptions in the above method embodiments, which are not described in detail herein.
Example five
Based on the same technical concept, the embodiment of the disclosure also provides computer equipment. Referring to fig. 10, a schematic diagram of a computer device 1000 according to an embodiment of the disclosure includes a processor 1100, a memory 1200, and a bus 1300. The memory 1200 is used for storing execution instructions, including a memory 1210 and an external memory 1220; the memory 1210 is also referred to as an internal memory, and is used for temporarily storing operation data in the processor 1100 and data exchanged with the external memory 1220 such as a hard disk, and the processor 1100 exchanges data with the external memory 1220 through the memory 1210, and when the computer device 1000 operates, the processor 1100 and the memory 1200 communicate with each other through the bus 1300, so that the processor 1100 executes the following instructions:
responding to a data reading request based on a target object, and judging whether first target data corresponding to the target object exists in a cache;
if the first target data exist and are in an invalid state, reading second target data corresponding to the target object in a persistent memory, and marking the second target data with a first version number; the first version number is the version number of the first target data in the cache;
Judging whether third target data matched with the second target data exists in the cache or not based on the target object;
if the third target data exist, judging whether the version number of the third target data is the first version number, if so, replacing the third target data with the second target data, and writing the second target data into the cache.
Here, the processor 1100 may also be caused to perform the following instructions:
responding to a data writing request based on a target object, and judging whether second target data matched with first target data exists in a cache or not based on the first target data and the target object in the data writing request;
if the second target data exists, marking the first target data with a first version number, and writing the first target data into a persistent memory; the first version number is the version number of the second target data in the cache;
judging whether third target data matched with the first target data exists in the cache or not based on the target object;
if the third target data exist, judging whether the version number of the third target data is the first version number, if so, replacing the third target data with the first target data, and writing the first target data into the cache.
Example six
The disclosed embodiments also provide a computer-readable storage medium, on which a computer program is stored, which when executed by a processor performs the steps of the method for processing a data read request described in the method embodiments described above, and/or performs the steps of the method for processing a data write request described in the method embodiments described above. Wherein the storage medium may be a volatile or nonvolatile computer readable storage medium.
The computer program product of the method for processing a data read request and a data write request provided in the embodiments of the present disclosure includes a computer readable storage medium storing program codes, where the program codes include instructions for executing the steps of the method for processing a data read request described in the embodiments of the method and/or executing the steps of the method for processing a data write request described in the embodiments of the method, and details of the method embodiments are not described herein.
The disclosed embodiments also provide a computer program which, when executed by a processor, implements any of the methods of the previous embodiments. The computer program product may be realized in particular by means of hardware, software or a combination thereof. In an alternative embodiment, the computer program product is embodied as a computer storage medium, and in another alternative embodiment, the computer program product is embodied as a software product, such as a software development kit (Software Development Kit, SDK), or the like.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described system and apparatus may refer to corresponding procedures in the foregoing method embodiments, which are not described herein again. In the several embodiments provided in the present disclosure, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. The above-described apparatus embodiments are merely illustrative, for example, the division of the units is merely a logical function division, and there may be other manners of division in actual implementation, and for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be through some communication interface, device or unit indirect coupling or communication connection, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in each embodiment of the present disclosure may be integrated in one processing unit, or each unit may be physically stored separately, or two or more units may be integrated in one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer readable storage medium executable by a processor. Based on such understanding, the technical solution of the present disclosure may be embodied in essence or a part contributing to the prior art or a part of the technical solution, or in the form of a software product stored in a storage medium, including several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in the embodiments of the present disclosure. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
Finally, it should be noted that: the foregoing examples are merely specific embodiments of the present disclosure, and are not intended to limit the scope of the disclosure, but the present disclosure is not limited thereto, and those skilled in the art will appreciate that while the foregoing examples are described in detail, it is not limited to the disclosure: any person skilled in the art, within the technical scope of the disclosure of the present disclosure, may modify or easily conceive changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features thereof; such modifications, changes or substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the disclosure, and are intended to be included within the scope of the present disclosure. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.

Claims (14)

1. A method of processing a data read request, the method comprising:
responding to a data reading request based on a target object, and judging whether first target data corresponding to the target object exists in a cache;
if the first target data exist and are in an invalid state, reading second target data corresponding to the target object in a persistent memory, and marking the second target data with a first version number; the first version number is the version number of the first target data in the cache;
judging whether third target data matched with the second target data exists in the cache or not based on the target object;
if the third target data exist, judging whether the version number of the third target data is the first version number, if so, replacing the third target data with the second target data, and writing the second target data into the cache; updating the first version number of the second target data written into the cache to a third version number.
2. The processing method according to claim 1, wherein after said determining whether the version number of the third target data is the first version number, the processing method further comprises:
And if the first version number is not the first version number, refusing to write the second target data into the cache, and setting the third target data in the cache into an invalid state.
3. The processing method according to claim 1, wherein after determining whether first target data corresponding to the target object exists in the cache, the processing method further comprises:
if the first target data does not exist, reading the second target data in the persistent memory, and marking the second target data with a second version number;
judging whether third target data matched with the second target data exists in the cache or not based on the target object;
and if the third target data exists, refusing to write the second target data into the cache.
4. A processing method according to claim 3, wherein after said determining whether there is third target data in said cache that matches said second target data, said processing method further comprises:
and if the third target data does not exist, writing the second target data into the cache, and updating the second version number of the second target data written into the cache into a fourth version number.
5. The processing method according to claim 1, wherein after determining whether first target data corresponding to the target object exists in the cache, the processing method further comprises:
and if the first target data exist and are in a valid state, reading the first target data in the cache.
6. A method of processing a data write request, the method comprising:
responding to a data writing request based on a target object, and judging whether second target data matched with first target data exists in a cache or not based on the first target data and the target object in the data writing request;
if the second target data exists, marking the first target data with a first version number, and writing the first target data into a persistent memory; the first version number is the version number of the second target data in the cache;
judging whether third target data matched with the first target data exists in the cache or not based on the target object;
if the third target data exist, judging whether the version number of the third target data is the first version number, if so, replacing the third target data with the first target data, and writing the first target data into the cache.
7. The processing method according to claim 6, wherein after said determining whether the version number of the third target data is the first version number, the processing method further comprises:
and if the first version number is not the first version number, refusing to write the first target data into the cache, and setting the third target data in the cache into an invalid state.
8. The processing method according to claim 6, wherein after said replacing the third target data with the first target data and writing to the cache, the processing method further comprises:
and updating the first version number of the first target data in the cache to a third version number.
9. The processing method according to claim 6, wherein after determining whether there is second target data in the cache that matches the first target data, the processing method further comprises:
if the second target data does not exist, marking the version number of the first target data as a second version number;
judging whether third target data matched with the first target data exists in the cache or not based on the target object;
And if the third target data does not exist, writing the first target data into the cache, and updating the second version number of the first target data written into the cache into a fourth version number.
10. The processing method according to claim 9, wherein after said determining whether there is third target data in the cache that matches the first target data, the processing method further comprises:
and if the third target data exists, refusing to write the first target data into the cache.
11. A processing apparatus for a data read request, the processing apparatus comprising:
the first judging module is used for responding to a data reading request based on a target object and judging whether first target data corresponding to the target object exists in a cache;
the marking module is used for reading second target data corresponding to the target object from the persistent memory if the first target data exist and are in an invalid state, and marking the second target data by using a first version number; the first version number is the version number of the first target data in the cache;
The second judging module is used for judging whether third target data matched with the second target data exists in the cache or not based on the target object;
the writing module is used for judging whether the version number of the third target data is the first version number if the third target data exists, and if so, replacing the third target data with the second target data and writing the second target data into the cache; updating the first version number of the second target data written into the cache to a third version number.
12. A processing apparatus for a data write request, the processing apparatus comprising:
the first judging module is used for responding to a data writing request based on a target object, and judging whether second target data matched with the first target data exists in a cache or not based on the first target data in the data writing request and the target object;
the first writing module is used for marking the first target data with a first version number and writing the first target data into a persistent memory if the second target data exists; the first version number is the version number of the second target data in the cache;
The second judging module is used for judging whether third target data matched with the first target data exists in the cache or not based on the target object of the first target data;
and the second writing module is used for judging whether the version number of the third target data is the first version number if the third target data exists, and if so, replacing the third target data with the first target data and writing the first target data into the cache.
13. A computer device, comprising: a processor, a memory and a bus, said memory storing machine readable instructions executable by said processor, said processor and said memory communicating via the bus when the computer device is running, said machine readable instructions when executed by said processor performing the steps of the method of processing a data read request according to any of claims 1 to 5 and/or the steps of the method of processing a data write request according to any of claims 6 to 10.
14. A computer-readable storage medium, on which a computer program is stored, which computer program, when being executed by a processor, performs the steps of the method of processing a data read request according to any one of claims 1 to 5 and/or performs the steps of the method of processing a data write request according to any one of claims 6 to 10.
CN202010551153.0A 2020-06-16 2020-06-16 Data reading request and data writing request processing method and device Active CN111752977B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010551153.0A CN111752977B (en) 2020-06-16 2020-06-16 Data reading request and data writing request processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010551153.0A CN111752977B (en) 2020-06-16 2020-06-16 Data reading request and data writing request processing method and device

Publications (2)

Publication Number Publication Date
CN111752977A CN111752977A (en) 2020-10-09
CN111752977B true CN111752977B (en) 2024-01-19

Family

ID=72675733

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010551153.0A Active CN111752977B (en) 2020-06-16 2020-06-16 Data reading request and data writing request processing method and device

Country Status (1)

Country Link
CN (1) CN111752977B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106557278A (en) * 2015-09-30 2017-04-05 腾讯科技(深圳)有限公司 A kind of method of data cached persistence
CN107577775A (en) * 2017-09-08 2018-01-12 北京奇艺世纪科技有限公司 One kind reads data method, device, electronic equipment and readable storage medium storing program for executing
CN109558421A (en) * 2018-10-29 2019-04-02 中国建设银行股份有限公司 Data processing method, system, device and storage medium based on caching

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106557278A (en) * 2015-09-30 2017-04-05 腾讯科技(深圳)有限公司 A kind of method of data cached persistence
CN107577775A (en) * 2017-09-08 2018-01-12 北京奇艺世纪科技有限公司 One kind reads data method, device, electronic equipment and readable storage medium storing program for executing
CN109558421A (en) * 2018-10-29 2019-04-02 中国建设银行股份有限公司 Data processing method, system, device and storage medium based on caching

Also Published As

Publication number Publication date
CN111752977A (en) 2020-10-09

Similar Documents

Publication Publication Date Title
CN107273455B (en) Block chain data access method and device
CN109076021B (en) Data processing method and device
CN109358874B (en) Business rule updating method, business rule updating device, computer equipment and storage medium
CN110109958B (en) Cache processing method, device, equipment and computer readable storage medium
CN105512222A (en) Data query method and system, and data reading method and system
CN109213450B (en) Associated metadata deleting method, device and equipment based on flash memory array
CN104978278B (en) Data processing method and device
CN111752977B (en) Data reading request and data writing request processing method and device
CN113254470B (en) Data modification method, device, computer equipment and storage medium
CN108228842B (en) Docker mirror image library file storage method, terminal, device and storage medium
CN111694703A (en) Cache region management method and device and computer equipment
CN113885801A (en) Memory data processing method and device
CN111752919A (en) Data writing method, data reading method and device
CN108984124B (en) Method and device for reducing write amplification, computer equipment and storage medium
CN109542872B (en) Data reading method and device, computer equipment and storage medium
CN116633616A (en) Data access method, system, equipment and storage medium
CN108804342B (en) Method and system for writing and reading data to and from a persistent storage device
CN116233254A (en) Business cut-off method, device, computer equipment and storage medium
CN113342275B (en) Method, apparatus and computer readable storage medium for accessing data at block link points
CN115712584A (en) Data storage method and device, electronic equipment and storage medium
CN112800123B (en) Data processing method, device, computer equipment and storage medium
CN112685064B (en) Processing method and device for equipment identification, storage medium and electronic device
CN109299067B (en) Page access method, device and storage medium
CN113157603A (en) Data reading device, method, chip, computer equipment and storage medium
CN111131051A (en) Route issuing method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information
CB02 Change of applicant information

Address after: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant after: Douyin Vision Co.,Ltd.

Address before: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant before: Tiktok vision (Beijing) Co.,Ltd.

Address after: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant after: Tiktok vision (Beijing) Co.,Ltd.

Address before: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant before: BEIJING BYTEDANCE NETWORK TECHNOLOGY Co.,Ltd.

GR01 Patent grant
GR01 Patent grant