CN107577775B - Data reading method and device, electronic equipment and readable storage medium - Google Patents

Data reading method and device, electronic equipment and readable storage medium Download PDF

Info

Publication number
CN107577775B
CN107577775B CN201710805732.1A CN201710805732A CN107577775B CN 107577775 B CN107577775 B CN 107577775B CN 201710805732 A CN201710805732 A CN 201710805732A CN 107577775 B CN107577775 B CN 107577775B
Authority
CN
China
Prior art keywords
data
version information
database
cache
data version
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
CN201710805732.1A
Other languages
Chinese (zh)
Other versions
CN107577775A (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.)
Beijing QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and Technology 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 Beijing QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN201710805732.1A priority Critical patent/CN107577775B/en
Publication of CN107577775A publication Critical patent/CN107577775A/en
Application granted granted Critical
Publication of CN107577775B publication Critical patent/CN107577775B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention provides a data reading method and device, electronic equipment and a computer readable storage medium. The method comprises the following steps: receiving a reading instruction corresponding to first target data; acquiring the current first database data version information of a database, the second database data version information of the last version data stored in the database and the current first cache data version information of a cache region; generating second cache data version information according to the first database data version information and the second database data version information; judging whether the first cache data version information is the same as the second cache data version information; and if the first cache data version information is different from the second cache data version information, reading the first target data from the database. By applying the data reading method provided by the embodiment of the invention, the read data is the same as the data currently stored in the database, so that the accuracy of the read data can be improved.

Description

Data reading method and device, electronic equipment and readable storage medium
Technical Field
The present invention relates to the field of data reading technologies, and in particular, to a method and an apparatus for reading data, an electronic device, and a computer-readable storage medium.
Background
With the rapid development of network technology, in order to increase the speed of accessing data, frequently accessed data in a database is usually stored in a cache area. The read instruction starts a thread to read a cache region first, if data to be read does not exist in the cache region, a database is read to obtain the data, and then the data is written into the cache region. The data reading speed of the cache area is faster than that of the data directly read from the database. When data in a database is modified, in order to ensure that data read from a buffer area is the same as data in the database, the existing data reading method specifically comprises the following steps: when data is modified, a write-in instruction starts a thread to delete corresponding data in a cache region, and then updated data is written into a database; when data is read, because the data does not exist in the cache region, the reading instruction starts the thread to read the database to obtain updated data, and the updated data is written into the cache region, and the data obtained by reading the cache region next time is the same as the data stored in the database.
However, the inventor finds that the prior art has at least the following problems in the process of implementing the invention:
in the thread concurrency scenario, if A, B both threads are simultaneously about to modify a data item in the database, and both thread a and thread B have deleted the corresponding data in the cache. Next, the thread a modifies the content of the data item in the database into data a, at this time, another thread C needs to read the data item, because the data item does not exist in the cache region, the database is read to obtain the data a, and the data a is written into the cache region, and then, the thread B modifies the content of the data item in the database into data B. At this time, the content of the data item in the cache area is data a, and the content of the data item in the database is data B, so that when the data item is read again, the data a is read from the cache area, and the read data is different from the data in the database, which may result in low accuracy of reading the data.
Disclosure of Invention
Embodiments of the present invention provide a method, an apparatus, an electronic device, and a computer-readable storage medium for reading data, so as to ensure that the read data is the same as the data in a database, and improve the accuracy of the read data. The specific technical scheme is as follows:
in a first aspect, to achieve the above object, an embodiment of the present invention discloses a method for reading data, where the method includes:
receiving a reading instruction corresponding to first target data;
acquiring the current first database data version information of a database, the second database data version information of the last version data stored in the database and the current first cache data version information of a cache region;
generating second cache data version information according to the first database data version information and the second database data version information;
judging whether the first cache data version information is the same as the second cache data version information;
and if the first cache data version information is different from the second cache data version information, reading the first target data from the database.
Optionally, the method further includes:
and if the first cache data version information is the same as the second cache data version information, reading the first target data from the cache region.
Optionally, after the reading the first target data from the database, the method further includes:
and writing the data currently stored in the database into the cache region.
Optionally, the method further includes:
receiving a write-in instruction corresponding to second target data;
acquiring current third cache data version information and fourth cache data version information of the cache region, wherein the fourth cache data version information is generated according to the current third database data version information of the database and fourth database data version information of the last version data stored in the database;
writing the second target data into the database and generating fifth database data version information;
setting the fifth database data version information as the current version information of the database;
and writing the second target data into the cache region.
Optionally, before the writing the second target data into the cache region, the method further includes:
judging whether the third cache data version information is the same as the fourth cache data version information;
if the third cache data version information is the same as the fourth cache data version information, executing the step of writing the second target data into the cache region;
or if the third cache data version information is different from the fourth cache data version information, keeping the data in the cache region unchanged.
Optionally, after the writing the second target data into the cache region, the method further includes:
generating fifth cache data version information according to the third database data version information and the fifth database data version information;
and setting the version information of the fifth cache data as the current version information of the cache region.
In a second aspect, to achieve the above object, an embodiment of the present invention further discloses a data reading apparatus, including:
the first receiving module is used for receiving a reading instruction corresponding to the first target data;
the first obtaining module is used for obtaining the current first database data version information of the database, the second database data version information of the last version data stored in the database and the current first cache data version information of the cache region;
the first generation module is used for generating second cache data version information according to the first database data version information and the second database data version information;
the first judging module is used for judging whether the first cache data version information is the same as the second cache data version information; if the first cache data version information is different from the second cache data version information, triggering a first reading module;
the first reading module is used for reading the first target data from the database.
Optionally, the apparatus further comprises:
and the second reading module is used for reading the first target data from the cache region if the first cache data version information is the same as the second cache data version information.
Optionally, the apparatus further comprises:
and the first writing module is used for writing the data currently stored in the database into the cache region.
Optionally, the apparatus further comprises:
the second receiving module is used for receiving a write-in instruction corresponding to second target data;
a second obtaining module, configured to obtain current third cache data version information and fourth cache data version information of the cache area, where the fourth cache data version information is generated according to the current third database data version information of the database and fourth database data version information of a previous version data stored in the database;
the second generation module is used for writing the second target data into the database and generating fifth database data version information;
the first setting module is used for setting the version information of the fifth database data as the current version information of the database;
and the second writing module is used for writing the second target data into the cache region.
Optionally, the apparatus further comprises:
the second judging module is used for judging whether the third cache data version information is the same as the fourth cache data version information;
if the third cache data version information is the same as the fourth cache data version information, executing the step of writing the second target data into the cache region;
or if the third cache data version information is different from the fourth cache data version information, keeping the data in the cache region unchanged.
Optionally, the apparatus further comprises:
a third generating module, configured to generate fifth cache data version information according to the third database data version information and the fifth database data version information;
and the second setting module is used for setting the version information of the fifth cache data as the current version information of the cache region.
In order to achieve the above object, an embodiment of the present invention further discloses an electronic device, where the electronic device includes a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus;
the memory is used for storing a computer program;
the processor is configured to implement the steps of the method for reading data according to the first aspect when executing the program stored in the memory.
In a fourth aspect, to achieve the above object, an embodiment of the present invention further discloses a computer-readable storage medium, in which a computer program is stored, and when the computer program is executed by a processor, the steps of the method for reading data according to the first aspect are implemented.
According to the method, after a reading instruction corresponding to first target data is received, when current first cache data version information and second cache data version information of a cache area are different, the first target data can be read from a database, wherein the second cache data version information is calculated according to the current first database data version information of the database and the second database data version information of the last version data of the database. Therefore, whether the data in the database is the same as the data in the cache area or not can be judged, if not, the data is read from the database, the read data is enabled to be the same as the data currently stored in the database, and the accuracy of the read data can be improved. Of course, it is not necessary for any product or method of practicing the invention to achieve all of the above-described advantages at the same time.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below.
Fig. 1 is a schematic flowchart of a method for reading data according to an embodiment of the present invention;
fig. 2 is a schematic flowchart of a method for modifying data stored in a database according to an embodiment of the present invention;
FIG. 3 is a schematic structural diagram of a data reading apparatus according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be described below with reference to the drawings in the embodiments of the present invention.
As the amount of data stored in the database is increasing, frequently accessed data in the database may be stored in a cache area in order to increase the speed of accessing the data. When the data to be accessed does not exist in the cache area, the database is read again to obtain the data. When data in the database needs to be modified, the write-in instruction starts a thread to delete corresponding data in the cache region firstly, and then the updated data is written into the database; at this time, since the corresponding data in the cache area has been deleted, the read instruction may start the thread to directly read the database, obtain the updated data, and write the updated data into the cache area. The next time the data needs to be read, the read instruction starting thread can directly read the cache area, and the read data is the same as the data in the database. However, in the case of concurrent threads, the thread a deletes data in the cache region first, before the thread a writes updated data into the database, another thread B reads the database to obtain old data and writes the old data into the cache region, and then the thread a writes the updated data into the database, so that the data obtained when the cache region is read next time is different from the data currently stored in the database.
Based on this, the inventors consider that the data stored in the database and the data stored in the cache area can be marked. And selecting different reading modes according to the marks of the data currently stored in the cache area and the marks of the data stored in the database, so that the read data is the same as the data currently stored in the database.
Based on the above consideration, the invention provides a data reading method, a data reading device, an electronic device and a computer readable storage medium. The method can be applied to a terminal and can also be applied to a server. The present invention is described by taking the application to a server as an example, and the other cases are similar. After receiving a reading instruction corresponding to first target data, a server (hereinafter referred to as a target server) applied to the method may read the first target data from the database when current first cache data version information of the cache region is different from second cache data version information, where the second cache data version information is calculated according to current first database data version information of the database and second database data version information of last version data of the database. Based on the scheme, the read data can be the same as the data currently stored in the database, and the accuracy of the read data can be improved.
The present invention will be described in detail with reference to specific examples. Referring to fig. 1, fig. 1 is a schematic flow chart of a method for reading data according to an embodiment of the present invention, including:
s101: a read command corresponding to the first target data is received.
The database is a set of data stored according to a certain rule, and the database can be used for realizing data sharing. In order to increase the speed of accessing data, frequently accessed data stored in the database is usually written into a cache area for storage.
The reading instruction is one of the main instructions for operating data, and the reading instruction can be sent to the target server by the terminal.
When the terminal needs to read some data (i.e. the first target data), a read instruction corresponding to the first target data may be sent to the target server, where the read instruction includes a data item corresponding to the first target data. After receiving the reading instruction, the target server may analyze the reading instruction to obtain the data item, so that a subsequent target server obtains the first target data according to the data item.
S102: the method comprises the steps of obtaining the current first database data version information of a database, the second database data version information of the last version data stored in the database and the current first cache data version information of a cache region.
In one implementation, the target server may modify the data stored in the database according to the received instruction, including updating the data or adding new data. After the data stored in the database is modified, the data stored in the cache area is modified synchronously so as to keep the data stored in the cache area identical to the data stored in the database.
After the data stored in the database is modified, the modified data in the database can be called as the data currently stored in the database, and the data before modification can be called as the last version data stored in the database; similarly, when the synchronous modification of the data stored in the cache region is completed, the modified data in the cache region may be referred to as the data currently stored in the cache region, and the data before modification may be referred to as the last version data stored in the cache region. The target server can distinguish the data stored in the database before and after modification according to the database data version information; and distinguishing the data stored in the cache regions before and after modification according to the cache data version information.
The first database data version information is version information of data currently stored in the database, and the first cache data version information is version information of data currently stored in the cache area.
In general, the target server may keep the data in the database the same as the data in the cache region, that is, the data in the database corresponding to the first database data version information is the same as the data in the cache region corresponding to the first cache data version information. However, in the case of a data modification failure or other abnormality in the cache region, the data corresponding to the first database data version information will not be the same as the data corresponding to the first cache data version information.
In one implementation, the target server mayThe UUID (universal Unique Identifier) is used as version information of the data stored in the database. The UUID may be a character string generated by the target server, and the generated UUID is not repeated each time, that is, the UUID has a unique identification characteristic. The target server may use the generated UUID as version information of each version data of the database (i.e., database data version information). Because each UUID has a unique identification characteristic, every two UUIDs can be combined to obtain a new unique identification, namely, a cacheUUID. The cacheUUID can be used as version information of data in a cache region corresponding to the database (i.e., cache data version information). In this embodiment, the database data version information is UUID, and the cache data version information is cacheUUID, which are similar to other cases and are not described again. For convenience of description, the first database data version information may be denoted as UUID1The second database data version information can be recorded as UUID2The first cache data version information may be recorded as cacheUUID1
The target server can store the UUID and the cacheUUID generated each time, and after the target server receives the instruction, the locally stored UUID and the cacheUUID can be directly obtained.
S103: and generating second cache data version information according to the first database data version information and the second database data version information.
In one implementation, the target server may pre-store a generation algorithm for caching data version information, where the generation algorithm may be a string generation algorithm. The target server can be based on UUID1、UUID2And a character string generating algorithm for generating second cache data version information which can be recorded as cacheUUID2
Exemplary, UUID1Is 8FE345, UUID2665BC9, generating cache data version information by means of character string splicing, and then generating second cache data version information cacheUUID2May be 8 FE345.665BC9. The embodiment of the invention is only explained by taking the case that the CacheUUID is generated by splicing the UUIDs, and other modes of generating the CacheUUID according to the UUID belong to the same sourceWithin the scope of the embodiments of the invention.
S104: and judging whether the first cache data version information is the same as the second cache data version information.
If the first cache data version information is the same as the second cache data version information, executing S105;
if the first cache data version information is not the same as the second cache data version information, S106 is executed.
S105: first target data is read from a database.
In one implementation, if cacheUUID1And cacheUUID2The first target data can be read from the database by the target server, so that the read data is identical to the data in the database, and the accuracy of the read data is improved.
Optionally, after the target server obtains the first target data from the database, the data in the cache region may be updated. Correspondingly, the method further comprises the following steps: and writing the data currently stored in the database into the cache region.
In one implementation, the target server determines the cacheUUID1And cacheUUID2After the difference, the data currently stored in the database can be written into the cache region, so that the data stored in the cache region is the same as the data stored in the database. The data stored in the cache region may not set an expiration time, so as to improve a hit rate of reading the cache region.
S106: the first target data is read from the cache area.
In practice, if the cacheUUID1And cacheUUID2If the data stored in the cache region is the same as the data stored in the database, the target server may read the first target data from the cache region, and at this time, the data read from the cache region is the same as the data in the database, so that the accuracy of the read data may be improved.
In an embodiment of the present invention, the target server may further receive a write command of the data, and modify the data stored in the database. Referring to fig. 2, the specific processing procedure may be:
s201: and receiving a write command corresponding to the second target data.
The write command is also one of the main commands for operating data, and the write command may be a command sent by a terminal corresponding to the target server.
When the terminal needs to write some data (i.e. the second target data), a write instruction corresponding to the second target data may be sent to the target server, where the write instruction includes the second target data. After receiving the write-in instruction, the target server may analyze the write-in instruction to obtain second target data, so that subsequent target servers may modify data in the database and the cache region according to the second target data.
After the data stored in the database is modified, the modified data in the database can be called as the data currently stored in the database, and the data before modification can be called as the last version data stored in the database; similarly, when the synchronous modification of the data stored in the cache region is completed, the modified data in the cache region may be referred to as the data currently stored in the cache region, and the data before modification may be referred to as the last version data stored in the cache region. The target server can distinguish the data stored in the database before and after modification according to the database data version information; and distinguishing the data stored in the cache regions before and after modification according to the cache data version information.
S202: and acquiring the current third cache data version information and the fourth cache data version information of the cache region.
The fourth cache data version information is generated according to the current third database data version information of the database and the fourth database data version information of the last version data stored in the database.
The third database data version information is version information of data currently stored in the database, the fourth database data version information is version information of last version data stored in the database, and the third cache data version information is version information of data currently stored in the cache area.
For ease of description, the third cache data version information may be denoted as cacheUUID3The fourth cache data version information may be recorded as cacheUUID4The third database data version information can be recorded as UUID3The fourth database data version information can be recorded as UUID4
In one implementation, the target server may directly obtain the locally stored cacheUUID3、UUID3And UUID4. According to UUID3And UUID4Generating a cacheUUID4And stored.
Wherein, according to UUID3And UUID4Generating a cacheUUID4The specific steps in (1) may refer to the step of generating a cacheUUID, which is not described herein again.
S203: and writing the second target data into the database, and generating fifth database data version information.
According to one implementation mode, the target server can write the second target data into the database and delete the data in the cache region asynchronously, and failure of writing the second target data into the database due to cache abnormality is avoided. Target server generates and stores new UUID5
S204: and setting the fifth database data version information as the current version information of the database.
In one implementation, the target server may associate the UUID with the target server5And fifth database data version information as data stored in the database after the second target data is written into the database.
S205: and writing the second target data into the cache region.
Therefore, after the target server receives the write-in instruction corresponding to the second target data, the data stored in the database can be modified, and the data stored in the cache region can be synchronously modified, so that the data stored in the cache region is the same as the data stored in the database, and the accuracy of reading the data obtained in the cache region can be improved.
Optionally, before writing the second target data into the cache region (i.e., S205), the method further includes:
and judging whether the third cache data version information is the same as the fourth cache data version information.
And if the third cache data version information is the same as the fourth cache data version information, executing the step of writing the second target data into the cache region.
Or if the third cache data version information is different from the fourth cache data version information, keeping the data in the cache region unchanged.
In one implementation, the cacheUUID3And cacheUUID4The same, that is, the data stored in the cache area is the same as the data stored in the database. After the target server writes the second target data into the database, the second target data may be written into the cache area, so that the data stored in the cache area is the same as the data stored in the database.
cacheUUID3And cacheUUID4The data stored in the cache area is different from the data stored in the database. At this time, the target server does not modify the data in the cache region, and keeps the data in the cache region unchanged, so that the number of times of updating the cache region can be reduced, and the updating load of the target server can be reduced.
Optionally, after writing the second target data into the cache region, the method further includes:
and generating fifth cache data version information according to the third database data version information and the fifth database data version information.
And setting the version information of the fifth cache data as the current version information of the cache region.
In one implementation, the cacheUUID can be used5And the version information of the fifth cache data is stored.
Wherein, according to UUID3And UUID5Generating a cacheUUID5The first step may be referred to above as the step of generating a cacheUUID, whereAnd will not be described in detail.
After the target server writes the second target data into the cache region, the version information of the currently stored data in the cache region is set as cacheUUID5So that the current version information of the cache area is the same as the current version information of the database.
Since the target server may receive the read command corresponding to the first target data and the write command corresponding to the second target data synchronously, the UUID in this embodiment is implemented3UUID as in the above embodiments1The same; similarly, UUID4Can be matched with UUID2Same, cacheUUID3Can be associated with cacheUUID1Same, cacheUUID4Can be associated with cacheUUID2The same is true.
As can be seen from the above, the data reading method according to the embodiment of the present invention may read the first target data from the database when the current first cache data version information of the cache area is different from the second cache data version information after receiving the reading instruction corresponding to the first target data, where the second cache data version information is calculated according to the current first database data version information of the database and the second database data version information of the last version data of the database. Therefore, whether the data in the database is the same as the data in the cache area or not can be judged, if not, the data is read from the database, the read data is enabled to be the same as the data currently stored in the database, and the accuracy of the read data can be improved.
Corresponding to the above method embodiment, referring to fig. 3, fig. 3 is a schematic structural diagram of a data reading apparatus according to an embodiment of the present invention, including:
a first receiving module 301, configured to receive a reading instruction corresponding to first target data;
a first obtaining module 302, configured to obtain current version information of a first database data of a database, second database data version information of a last version data stored in the database, and current version information of a first cache data in a cache region;
a first generating module 303, configured to generate second cache data version information according to the first database data version information and the second database data version information;
a first determining module 304, configured to determine whether the first cache data version information is the same as the second cache data version information; if the first cache data version information is different from the second cache data version information, triggering a first reading module 305;
the first reading module 305 is configured to read the first target data from the database.
In a specific embodiment of the present invention, the apparatus further comprises:
and the second reading module is used for reading the first target data from the cache region if the first cache data version information is the same as the second cache data version information.
In a specific embodiment of the present invention, the apparatus further comprises:
and the first writing module is used for writing the data currently stored in the database into the cache region.
In a specific embodiment of the present invention, the apparatus further comprises:
the second receiving module is used for receiving a write-in instruction corresponding to second target data;
a second obtaining module, configured to obtain current third cache data version information and fourth cache data version information of the cache area, where the fourth cache data version information is generated according to the current third database data version information of the database and fourth database data version information of a previous version data stored in the database;
the second generation module is used for writing the second target data into the database and generating fifth database data version information;
the first setting module is used for setting the version information of the fifth database data as the current version information of the database;
and the second writing module is used for writing the second target data into the cache region.
In a specific embodiment of the present invention, the apparatus further comprises:
the second judging module is used for judging whether the third cache data version information is the same as the fourth cache data version information;
if the third cache data version information is the same as the fourth cache data version information, executing the step of writing the second target data into the cache region;
or if the third cache data version information is different from the fourth cache data version information, keeping the data in the cache region unchanged.
In a specific embodiment of the present invention, the apparatus further comprises:
a third generating module, configured to generate fifth cache data version information according to the third database data version information and the fifth database data version information;
and the second setting module is used for setting the version information of the fifth cache data as the current version information of the cache region.
As can be seen from the above description, the data reading apparatus according to the embodiments of the present invention may read the first target data from the database when the current first cache data version information of the cache region is different from the second cache data version information after receiving the reading instruction corresponding to the first target data, where the second cache data version information is calculated according to the current first database data version information of the database and the second database data version information of the last version data of the database. Therefore, whether the data in the database is the same as the data in the cache area or not can be judged, if not, the data is read from the database, the read data is enabled to be the same as the data currently stored in the database, and the accuracy of the read data can be improved.
An embodiment of the present invention further provides an electronic device, as shown in fig. 4, including a processor 401, a communication interface 402, a memory 403, and a communication bus 404, where the processor 401, the communication interface 402, and the memory 403 complete mutual communication through the communication bus 404,
a memory 403 for storing a computer program;
the processor 401 is configured to implement the data reading method provided in the embodiment of the present invention when executing the program stored in the memory 403.
Specifically, the method for reading data includes:
receiving a reading instruction corresponding to first target data;
acquiring the current first database data version information of a database, the second database data version information of the last version data stored in the database and the current first cache data version information of a cache region;
generating second cache data version information according to the first database data version information and the second database data version information;
judging whether the first cache data version information is the same as the second cache data version information;
and if the first cache data version information is different from the second cache data version information, reading the first target data from the database.
It should be noted that other implementation manners of the above data reading method are partially the same as those of the foregoing method embodiments, and are not described herein again.
The electronic device provided by the embodiment of the invention can read the first target data from the database when receiving the reading instruction corresponding to the first target data and when the current first cache data version information of the cache area is different from the second cache data version information after receiving the reading instruction corresponding to the first target data, wherein the second cache data version information is calculated according to the current first database data version information of the database and the second database data version information of the last version data of the database. The read data is the same as the data currently stored in the database, and the accuracy of the read data can be improved.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the Integrated Circuit may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, a discrete Gate or transistor logic device, or a discrete hardware component.
The embodiment of the present invention further provides a computer-readable storage medium, where instructions are stored in the computer-readable storage medium, and when the instructions are run on a computer, the computer is caused to execute the data reading method provided by the embodiment of the present invention.
Specifically, the method for reading data includes:
receiving a reading instruction corresponding to first target data;
acquiring the current first database data version information of a database, the second database data version information of the last version data stored in the database and the current first cache data version information of a cache region;
generating second cache data version information according to the first database data version information and the second database data version information;
judging whether the first cache data version information is the same as the second cache data version information;
and if the first cache data version information is different from the second cache data version information, reading the first target data from the database.
It should be noted that other implementation manners of the above data reading method are partially the same as those of the foregoing method embodiments, and are not described herein again.
By executing the instruction stored in the computer-readable storage medium provided by the embodiment of the present invention, when reading data, after receiving a read instruction corresponding to first target data, when current first cache data version information of a cache region is different from second cache data version information, the first target data may be read from a database, where the second cache data version information is calculated according to current first database data version information of the database and second database data version information of last version data of the database. The read data is the same as the data currently stored in the database, and the accuracy of the read data can be improved.
Embodiments of the present invention further provide a computer program product including instructions, which when run on a computer, cause the computer to execute the method for reading data provided by embodiments of the present invention.
Specifically, the method for reading data includes:
receiving a reading instruction corresponding to first target data;
acquiring the current first database data version information of a database, the second database data version information of the last version data stored in the database and the current first cache data version information of a cache region;
generating second cache data version information according to the first database data version information and the second database data version information;
judging whether the first cache data version information is the same as the second cache data version information;
and if the first cache data version information is different from the second cache data version information, reading the first target data from the database.
It should be noted that other implementation manners of the above data reading method are partially the same as those of the foregoing method embodiments, and are not described herein again.
By operating the computer program product provided by the embodiment of the invention, when data is read, after a reading instruction corresponding to first target data is received, when the current first cache data version information of the cache region is different from the second cache data version information, the first target data can be read from the database, wherein the second cache data version information is calculated according to the current first database data version information of the database and the second database data version information of the last version data of the database. The read data is the same as the data currently stored in the database, and the accuracy of the read data can be improved.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the apparatus, the electronic device, the computer-readable storage medium, and the computer program product embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and for the relevant points, reference may be made to the partial description of the method embodiments.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.

Claims (14)

1. A data reading method is characterized in that the method is applied to a server, when a writing instruction is received, the server starts a thread to delete corresponding data in a cache region, and the updated data is written into a database; when a reading instruction is received, the server starts a thread to read the database to obtain updated data and writes the updated data into a cache region, and the method comprises the following steps:
receiving a reading instruction corresponding to first target data;
acquiring the current first database data version information of a database, the second database data version information of the last version data stored in the database and the current first cache data version information of a cache region; the version information of the data stored in the database is represented by a universal unique identifier UUID; the version information of the data stored in the cache region is represented by a combination of UUIDs;
generating second cache data version information according to the first database data version information and the second database data version information;
judging whether the first cache data version information is the same as the second cache data version information;
and if the first cache data version information is different from the second cache data version information, reading the first target data from the database.
2. The method of claim 1, further comprising:
and if the first cache data version information is the same as the second cache data version information, reading the first target data from the cache region.
3. The method of claim 1, wherein after said reading said first target data from said database, said method further comprises:
and writing the data currently stored in the database into the cache region.
4. The method of claim 1, further comprising:
receiving a write-in instruction corresponding to second target data;
acquiring current third cache data version information and fourth cache data version information of the cache region, wherein the fourth cache data version information is generated according to the current third database data version information of the database and fourth database data version information of the last version data stored in the database;
writing the second target data into the database and generating fifth database data version information;
setting the fifth database data version information as the current version information of the database;
and writing the second target data into the cache region.
5. The method of claim 4, wherein prior to said writing said second target data to said cache region, said method further comprises:
judging whether the third cache data version information is the same as the fourth cache data version information;
if the third cache data version information is the same as the fourth cache data version information, executing the step of writing the second target data into the cache region;
or if the third cache data version information is different from the fourth cache data version information, keeping the data in the cache region unchanged.
6. The method of claim 4, wherein after the writing the second target data to the cache region, the method further comprises:
generating fifth cache data version information according to the third database data version information and the fifth database data version information;
and setting the version information of the fifth cache data as the current version information of the cache region.
7. A data reading device is characterized in that the data reading device is applied to a server, when a writing instruction is received, the server starts a thread to delete corresponding data in a cache region, and the updated data is written into a database; when receiving a read instruction, the server starts a thread to read the database to obtain updated data, and writes the updated data into a cache area, and the device comprises:
the first receiving module is used for receiving a reading instruction corresponding to the first target data;
the first obtaining module is used for obtaining the current first database data version information of the database, the second database data version information of the last version data stored in the database and the current first cache data version information of the cache region; the version information of the data stored in the database is represented by a universal unique identifier UUID; the version information of the data stored in the cache region is represented by a combination of UUIDs;
the first generation module is used for generating second cache data version information according to the first database data version information and the second database data version information;
the first judging module is used for judging whether the first cache data version information is the same as the second cache data version information; if the first cache data version information is different from the second cache data version information, triggering a first reading module;
the first reading module is used for reading the first target data from the database.
8. The apparatus of claim 7, further comprising:
and the second reading module is used for reading the first target data from the cache region if the first cache data version information is the same as the second cache data version information.
9. The apparatus of claim 7, further comprising:
and the first writing module is used for writing the data currently stored in the database into the cache region.
10. The apparatus of claim 7, further comprising:
the second receiving module is used for receiving a write-in instruction corresponding to second target data;
a second obtaining module, configured to obtain current third cache data version information and fourth cache data version information of the cache area, where the fourth cache data version information is generated according to the current third database data version information of the database and fourth database data version information of a previous version data stored in the database;
the second generation module is used for writing the second target data into the database and generating fifth database data version information;
the first setting module is used for setting the version information of the fifth database data as the current version information of the database;
and the second writing module is used for writing the second target data into the cache region.
11. The apparatus of claim 10, further comprising a second determining module configured to:
judging whether the third cache data version information is the same as the fourth cache data version information;
if the third cache data version information is the same as the fourth cache data version information, executing the step of writing the second target data into the cache region;
or if the third cache data version information is different from the fourth cache data version information, keeping the data in the cache region unchanged.
12. The apparatus of claim 10, further comprising:
a third generating module, configured to generate fifth cache data version information according to the third database data version information and the fifth database data version information;
and the second setting module is used for setting the version information of the fifth cache data as the current version information of the cache region.
13. An electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
the memory is used for storing a computer program;
the processor, when executing the program stored in the memory, implementing the method steps of any of claims 1-6.
14. A computer-readable storage medium, characterized in that a computer program is stored in the computer-readable storage medium, which computer program, when being executed by a processor, carries out the method steps of any one of claims 1 to 6.
CN201710805732.1A 2017-09-08 2017-09-08 Data reading method and device, electronic equipment and readable storage medium Active CN107577775B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710805732.1A CN107577775B (en) 2017-09-08 2017-09-08 Data reading method and device, electronic equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710805732.1A CN107577775B (en) 2017-09-08 2017-09-08 Data reading method and device, electronic equipment and readable storage medium

Publications (2)

Publication Number Publication Date
CN107577775A CN107577775A (en) 2018-01-12
CN107577775B true CN107577775B (en) 2021-12-10

Family

ID=61032927

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710805732.1A Active CN107577775B (en) 2017-09-08 2017-09-08 Data reading method and device, electronic equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN107577775B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109542872B (en) * 2018-10-26 2021-01-22 金蝶软件(中国)有限公司 Data reading method and device, computer equipment and storage medium
CN109766361B (en) * 2018-12-19 2023-08-04 中国平安人寿保险股份有限公司 Cache data reading method, device, computer equipment and storage medium
CN111752977B (en) * 2020-06-16 2024-01-19 抖音视界有限公司 Data reading request and data writing request processing method and device
CN111752919A (en) * 2020-06-16 2020-10-09 北京字节跳动网络技术有限公司 Data writing method, data reading method and device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1522409A (en) * 2001-06-09 2004-08-18 存储交易株式会社 Cache-conscious concurrency control scheme for database systems
CN101464895A (en) * 2009-01-21 2009-06-24 阿里巴巴集团控股有限公司 Method, system and apparatus for updating internal memory data
CN104573035A (en) * 2015-01-16 2015-04-29 杭州犀照科技有限公司 Caching service method and device and news information obtaining method and system

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9501368B2 (en) * 2008-09-30 2016-11-22 Veritas Technologies Llc Backing up and restoring selected versioned objects from a monolithic database backup
US10747746B2 (en) * 2013-04-30 2020-08-18 Amazon Technologies, Inc. Efficient read replicas

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1522409A (en) * 2001-06-09 2004-08-18 存储交易株式会社 Cache-conscious concurrency control scheme for database systems
CN101464895A (en) * 2009-01-21 2009-06-24 阿里巴巴集团控股有限公司 Method, system and apparatus for updating internal memory data
CN104573035A (en) * 2015-01-16 2015-04-29 杭州犀照科技有限公司 Caching service method and device and news information obtaining method and system

Also Published As

Publication number Publication date
CN107577775A (en) 2018-01-12

Similar Documents

Publication Publication Date Title
CN107577775B (en) Data reading method and device, electronic equipment and readable storage medium
CN110162525B (en) B+ tree-based read-write conflict resolution method, device and storage medium
US10394797B2 (en) Method and computing apparatus for managing main memory database
US9620227B1 (en) Characterizing and operating a non-volatile memory device
CN110008758B (en) ID obtaining method and device, electronic equipment and storage medium
CN111831915A (en) Method, device, electronic equipment and storage medium for responding to data query request
CN111159160A (en) Version rollback method and device, electronic equipment and storage medium
CN109062602B (en) Data processing method and device for application program and electronic equipment
CN113407376A (en) Data recovery method and device and electronic equipment
US9535713B2 (en) Manipulating rules for adding new devices
CN113127438B (en) Method, apparatus, server and medium for storing data
CN111090701B (en) Service request processing method, device, readable storage medium and computer equipment
CN112115521B (en) Data access method and device
CN108399076A (en) A kind of firmware update and device based on UEFI
CN108491160B (en) Data writing method and device
WO2020029588A1 (en) Data reading method, device, system, and distributed system
CN111078418A (en) Operation synchronization method and device, electronic equipment and computer readable storage medium
CN110083509B (en) Method and device for arranging log data
CN115712397A (en) Cache verification device, method and system
US10678453B2 (en) Method and device for checking false sharing in data block deletion using a mapping pointer and weight bits
CN112214178B (en) Storage system, data reading method and data writing method
CN115630026A (en) File reading and writing method and system, computer equipment and storage medium
CN110888643A (en) Page processing method and device
CN107305582B (en) Metadata processing method and device
WO2019219021A1 (en) Index data updating method and device in stream-oriented file system

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
GR01 Patent grant
GR01 Patent grant