Data storage method, device, electronic device and computer readable medium

Through keyword mapping and metadata management, the data consistency problem between the cache and the database is solved, real-time updating and caching of data are realized, the real-time performance and reliability of the system are improved, and it is suitable for high concurrency environments.

CN110362599BActive Publication Date: 2024-10-18BEIJING JINGDONG SHANGKE INFORMATION TECH CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN201810305102.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2018-04-08
Publication Date
2024-10-18
Estimated Expiration
2038-04-08

AI Technical Summary

Technical Problem

In the existing technology, the data consistency problem between the cache and the database is difficult to effectively solve, especially in high concurrency situations, resulting in consistency problems when data is updated and read, affecting the real-time and reliability of the system.

Method used

The data to be processed is identified through the keyword mapping relationship, the read and write operations of metadata are logically controlled, and the data version is updated and cached to ensure data consistency between the cache and the database and shorten the final consistency time.

Benefits of technology

It achieves data consistency between the cache and the database, improves the real-time and reliability of the data, reduces the database load, and enhances the system's universality and load stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110362599B_ABST
    Figure CN110362599B_ABST
Patent Text Reader

Abstract

The present disclosure provides a data storage method, device, electronic device and computer-readable medium, which belongs to the field of Internet technology. The data storage method includes: according to the keyword mapping relationship, using keywords to identify the data to be processed to obtain metadata; performing logical control of read operations and write operations on the metadata to complete the update and cache of the data to be processed; and updating and caching the version according to the metadata. By using keywords to identify the data to be processed and then performing corresponding read and write operations, the consistency problem of the data in the cache and the database can be solved, the version of the data can be updated and cached, the time for the data to reach final consistency can be shortened, and the real-time and reliability of the data can be guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure generally relates to the field of Internet technology, and in particular, to a data storage method, device, electronic device, and computer-readable medium. Background Art

[0002] Internet systems often choose a data access method that combines traditional databases with distributed caches, taking advantage of their respective strengths. Traditional databases have the advantage of structured SQL (Structured Query Language) queries, while distributed caches are used as high-performance caches.

[0003] However, the cache-db (cache-database) data access method also has many problems in use, such as the problem of data consistency in cache and db. Data consistency in multiple storage media is very important for each system. According to the application environment of the system, it is divided into strong consistency and eventual consistency. The requirements for strong consistency are very high, and it is often difficult to achieve due to various complex factors. Most systems only need to meet the eventual consistency. However, under the premise of eventual consistency, the shorter the time it takes to reach data consistency, the better. The shorter the time, the faster the data user can load the latest data.

[0004] Therefore, there are data consistency issues in the technical solutions in the prior art, and there is still room for improvement.

[0005] The above information disclosed in this Background section is only for enhancement of understanding of the background of the present disclosure and therefore it may contain information that does not constitute the prior art that is already known to one of ordinary skill in the art. Summary of the invention

[0006] The present disclosure provides a data storage method, device, electronic device and computer-readable medium to solve the above technical problems.

[0007] Other features and advantages of the present disclosure will become apparent from the following detailed description, or may be learned in part by the practice of the present disclosure.

[0008] According to one aspect of the present disclosure, there is provided a data storage method, comprising:

[0009] According to the keyword mapping relationship, the data to be processed is identified using the keywords to obtain metadata;

[0010] Performing logical control of read and write operations on the metadata to complete the update and cache of the data to be processed;

[0011] The version is updated and cached according to the metadata.

[0012] In one embodiment of the present disclosure, the metadata obtained by using keywords to identify the data to be processed includes:

[0013] Mapping the keyword set with the data set to be processed, using the keywords in the keyword set to identify the data to be processed in the data set to be processed one by one, to obtain metadata;

[0014] The data set to be processed includes M parameters, the keyword set includes N keywords, and the metadata includes: a primary version key set, and the primary version key node set includes M version keys, M≤N.

[0015] In one embodiment of the present disclosure, the logical control of writing the metadata includes:

[0016] The metadata is written into a database, the update of the to-be-processed data in the database is completed, and a response is given that the interface write operation is successful.

[0017] In one embodiment of the present disclosure, after writing the metadata into the database, the method further includes:

[0018] The primary version key set is supplemented with version keys according to the updated data of the database to obtain a complete version key set.

[0019] In one embodiment of the present disclosure, the complete version key set also includes:

[0020] The complete version key set is stored in the database.

[0021] In one embodiment of the present disclosure, performing version update according to the metadata includes:

[0022] The version key and the value corresponding to the version key are updated according to the complete version key set and cached in a cache area.

[0023] In one embodiment of the present disclosure, the logical control of the read operation on the metadata includes:

[0024] Read cache data for the metadata from the cache area;

[0025] A version comparison is performed based on the metadata and the cached data. If the value V1 corresponding to the version key of the cached data is greater than or equal to the value V2 corresponding to the version key of the metadata, the cached data is directly returned; if the value V1 corresponding to the version key of the cached data is less than or equal to the value V2 corresponding to the version key of the metadata, data for the metadata is obtained from the database and cached in the cache area.

[0026] According to another aspect of the present disclosure, there is provided a data storage device, comprising:

[0027] A keyword mapping unit, configured to store a mapping relationship of keywords;

[0028] A metadata constructor is configured to identify the data to be processed by using a keyword set to obtain metadata;

[0029] A logic controller configured to control read operations and write operations of the metadata;

[0030] A data buffer, configured to update and cache the data to be processed according to the control of the logic control unit;

[0031] A version cache is configured to update and cache versions according to the metadata.

[0032] According to yet another aspect of the present disclosure, an electronic device is provided, comprising a processor; and a memory storing instructions for the processor to control the method steps as described above.

[0033] According to another aspect of the present disclosure, a computer-readable medium is provided, on which computer-executable instructions are stored. When the executable instructions are executed by a processor, the method steps described above are implemented.

[0034] According to the data storage method, device, electronic device and computer-readable medium provided by the embodiments of the present disclosure, on the one hand, by using keywords to identify the data to be processed and then performing corresponding read and write operations, the consistency problem existing in the cache and database data can be solved; on the other hand, in addition to caching and updating the data, the version of the data is further updated and cached, which shortens the time it takes for the data to reach final consistency and ensures the real-time and reliability of the data.

[0035] It is to be understood that the foregoing general description and the following detailed description are exemplary only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] The above and other objects, features and advantages of the present disclosure will become more apparent by describing in detail example embodiments thereof with reference to the attached drawings.

[0037] Figure 1 A flow chart of a data storage method provided in one embodiment of the present disclosure is shown.

[0038] Figure 2 Shown is an overall framework diagram for implementing the data storage method in the embodiment of the present disclosure.

[0039] Figure 3 A schematic diagram of a flow chart of a write operation in an embodiment of the present disclosure is shown.

[0040] Figure 4 A schematic diagram of a flow chart of a read operation in an embodiment of the present disclosure is shown.

[0041] Figure 5 A schematic diagram of a data storage device provided by another embodiment of the present disclosure is shown.

[0042] Figure 6 A schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure and suitable for implementing the embodiment of the present application is shown. DETAILED DESCRIPTION

[0043] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that the present disclosure will be more comprehensive and complete and fully convey the concepts of the example embodiments to those skilled in the art. The accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted.

[0044] In addition, the described features, structures or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known structures, methods, devices, implementations, materials or operations are not shown or described in detail to avoid obscuring various aspects of the present disclosure.

[0045] Some of the blocks shown in the accompanying drawings are functional entities that do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.

[0046] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with specific embodiments and with reference to the accompanying drawings.

[0047] With the explosive development of the Internet, the concurrency of the system often plays a vital role. There are many technologies and methods to improve the concurrency of the system, from load balancing to the front end, to the application background, and to storage. Among them, distributed cache technology is a key technology to improve concurrency. Distributed cache pursues high performance and often does not support structured queries like SQL, but stores in a simple k / v manner.

[0048] In the relevant embodiments of the present disclosure, cache-db is generally used in two ways:

[0049] (1) Low concurrency:

[0050] Write: write to db->write to db successfully, then write to cache (ttl);

[0051] Read: read cache->if there is no data in cache, read db->write db data back to cache; if there is data in cache, read directly from cache;

[0052] In this case, there will be consistency issues: after writing to the db successfully, when preparing to write to the cache, in many cases, writing a piece of data in the db will have countless uses, which means there are countless cache keys. Even if the cache keys are registered and managed, there is still the question of whether all keys need to be updated. Even if the service has the ability to asynchronously complete the update of all keys, the value of all updated keys is not necessarily just this complete data. In most cases, this data is just one of the cached ones. In addition, arbitrarily updating the data in the cache means that the business is not decoupled, and various emergencies will cause data anomalies, and the updated data in the cache may have problems. In short, it is not a good practice to directly update the user's cache while updating the db.

[0053] (2) High concurrency situation:

[0054] Write: If it is asynchronous writing, it will be written to the cache first, and then returned directly; the worker will save the data to the db periodically or in a specific action;

[0055] Read: read cache->if there is no data in cache, read db->write db data back to cache; if there is data in cache, take it directly from cache.

[0056] In this case, there will also be consistency issues: read data from the cache first, because the cache is written first and then written to the database, it is guaranteed to obtain the latest data, but when the cache is synchronized to the database, it relies on other high-performance workers. This processing method is usually prone to congestion, resulting in more and more caches, and the time for the data in the database and the data in the cache to be consistent is getting longer and longer. In addition, directly reading data from the same cache does not take advantage of the SQL structure at all. Therefore, the application scope of this design method is relatively small.

[0057] Of course, in addition to the above two methods, there is a third commonly used method, which is to use the method of notifying after successfully writing data to the DB to inform the subscriber that the data has changed. After receiving the notification, the subscriber should make the associated cache expire, so that the next time the data is loaded, the latest data can be directly loaded from the DB and then cached. This method has significantly improved both the low coupling between producers and consumers and the universal scope. However, because the subscriber often has no effective management of the cache key, when receiving the change notification, they do not know which keys to update, and the update notification may fail, resulting in consumers not being able to use the latest data for a long time.

[0058] Based on the above, a better way is still needed to support and solve the data consistency problem between cache and database.

[0059] Figure 1 A flowchart of a data storage method provided in an embodiment of the present disclosure is shown, comprising the following steps:

[0060] like Figure 1 As shown, in step S110, the data to be processed are identified using the keywords according to the keyword mapping relationship to obtain metadata.

[0061] like Figure 1 As shown, in step S120, logical control of read and write operations is performed on the metadata to complete the update and cache of the data to be processed.

[0062] like Figure 1 As shown, in step S130, the version is updated and cached according to the metadata.

[0063] The data storage method provided by the embodiment of the present disclosure can, on the one hand, solve the consistency problem of cache and database data by using keywords to identify the data to be processed and then performing corresponding read and write operations; on the other hand, in addition to caching and updating the data, the data version is further updated and cached, which shortens the time for the data to reach final consistency and ensures the real-time and reliability of the data.

[0064] Figure 2 The overall framework diagram for implementing the data storage method in the embodiment of the present disclosure is shown as follows: Figure 2 As shown, it includes: logic control layer, data cache layer, version cache layer, persistence layer and keyword mapping unit, through which data read service and write service are realized. The functions of each layer are:

[0065] The logic control unit layer is mainly responsible for the logic control of reading and writing data and the switching logic between cache and db; the data cache layer is mainly responsible for caching the data read from the db to make the interface respond faster; the version cache layer is mainly responsible for caching the version keys and version key values ​​corresponding to various keywords (the version key value is represented by the time stamp); the persistence layer is the db layer, which is mainly responsible for reading and writing data to the db; the keyword mapping unit is mainly responsible for identifying the data tables in the db with keywords for use in subsequent version caching processes.

[0066] The following combination Figure 2 The overall framework diagram shown in the figure introduces the data storage method provided by the present disclosure in detail, as follows:

[0067] In step S110, the data to be processed is identified using the keywords according to the keyword mapping relationship to obtain metadata.

[0068] In one embodiment of the present disclosure, the keyword mapping relationship is provided by a keyword mapping unit, wherein the keyword may be a field name. Taking employee information management data as an example, the keyword may include but is not limited to name, work number, telephone number, etc. The work number is immutable and unique, while the name and telephone number are variable and non-unique. Accordingly, the fields of the keyword mapping unit include {'work number', 'telephone number'}. The data to be processed may be data to be written or data to be read.

[0069] In one embodiment of the present disclosure, the step is specifically:

[0070] According to the mapping between the keyword set and the data set to be processed, the keywords in the keyword set are used to identify the data to be processed in the data set to be processed one by one, so as to obtain metadata;

[0071] The data set to be processed includes M parameters, and paramSet is used to represent the data set to be processed, paramSet = {param1 = value1, param2 = value2, ..., paramM = valueM};

[0072] The keyword set includes N keywords, and KeySet is used to represent the keyword set, KeySet = {key1, key2, ..., keyN}.

[0073] It should be noted that the metadata constructor in the disclosed embodiment constructs metadata required for various subsequent steps, such as version key, database query metadata, and prefix metadata of data cache key, etc., based on the data set to be processed and the keyword set.

[0074] Based on each version key, the version key set is:

[0075] versionKeySet = {versionKey1, versionKey2, ..., versionKeyN}, where the version key is determined by param and key. That is, any version key in the version key set is:

[0076] versionKeyX='paramA=valueA'+'paramB=valueB'+……

[0077] Among them, paramA, valueA, paramB, and valueB are all elements in the data set paramSet to be processed.

[0078] It should be noted that the field names in the to-be-processed data set paramSet, the keyword set KeySet, and the version key set versionKeySet are consistent with the keyword field names to ensure that the mapping is completed smoothly. The version keys generated when reading and writing data are stored in the same cache shard, which can be replaced by inter-process communication, such as MQ / Kafka.

[0079] It should also be noted that the data set {paramX} to be processed is a subset of the keyword set {KeyX}. Usually, the number of valid paramX elements in paramSet is less than the number of elements in the KeySet set, that is, M≤N. The number of primary version key set elements actually constructed by the metadata constructor is the same as the number of elements in the data set to be processed, that is, the number of primary version key set elements is also M. The number of primary version key set elements must be less than N. The primary version key set is represented by subVersionKeySet.

[0080] In step S120, logical control of read and write operations is performed on the metadata to complete the update and cache of the data to be processed.

[0081] The following describes how metadata is read or written to the data to be processed via the logic control bus:

[0082] Figure 3 A flowchart of a write operation is shown in FIG. Figure 3 As shown, before the logic control bus, the metadata constructor constructs metadata based on the data set to be written by the write data entry unit (ie, the data to be processed) and the keyword mapping unit in combination with the mapping relationship.

[0083] In one embodiment of the present disclosure, the control logic of the logic control bus when writing data includes:

[0084] First, the metadata is written to the database, the update of the pending data in the database is completed, and the interface write operation is responded to successfully. When writing to the database, the SQL statement is queried and stored accordingly.

[0085] Then, the primary version key set is completed according to the updated data in the database to obtain a complete version key set. Since the primary version key set obtained by the metadata constructor in step S110 is incomplete, in order to achieve the purpose of notifying all version keys of the data update, the corresponding version key needs to be completed. Therefore, the asynchronous thread prioritizes retrieving the fields with complete updated data from the database, recorded as fieldSet = {field1 = value1, field2 = value2, ..., fieldT}. In general, the size T of filedSet should be larger than the number N of the keyword set KeySet, that is, T>N>M. After obtaining the complete data, the subVersionKeySet can be completed, that is, the completed version key set is recorded as diffVersionKeySet, so the following relationship exists:

[0086] versionKeySet=subVersionKey+diffVerisonKey.

[0087] Finally, the complete set of version keys is stored in the database. Specifically, all version keys can be updated through asynchronous updates. Figure 3 As shown, specifically, after all version keys are updated, they are cached in the cache area Redis through the version cache executor to complete the data writing operation.

[0088] Figure 4 A flowchart of a read operation is shown in FIG. Figure 3 As shown, before the logic control bus, the metadata constructor constructs metadata based on the data set to be read by the write data entry unit (ie, the data to be processed) and the keyword mapping unit in combination with the mapping relationship.

[0089] In one embodiment of the present disclosure, the control logic of the logic control bus when reading data includes:

[0090] First of all, unlike writing data, when reading data, if you want to read data from the database, you need to read the cache first.

[0091] Specifically, Figure 4 As shown in the figure, reading data from the cache area Redis specifically includes:

[0092] The first step is to read the cache data for the metadata from the cache area through the data cache executor;

[0093] The second step is to compare the versions of the metadata and cached data. If the value V1 corresponding to the version key of the cached data is greater than or equal to the value V2 corresponding to the version key of the metadata, the cached data is returned directly; if the value V1 corresponding to the version key of the cached data is less than or equal to the value V2 corresponding to the version key of the metadata, the data for the metadata is obtained from the database and cached in the cache area.

[0094] It should be noted that there is another difference from writing data: in the data reading process, a version key unique to this read operation will be constructed, recorded as readVersionKey. The construction method of readVersionKey is the same as that of subVersionKeySet in the data writing process, so it will not be repeated here.

[0095] For the second step above, data DataX is read from the cache area first (the data version number of DataX is temporarily recorded as V1. At this time, the read data DataX cannot be returned directly, and the version number needs to be compared, that is, the version number V2 corresponding to the readVersionKey generated by reading the data from the database is extracted. If the comparison result is V1≥V2, the read data DataX is returned immediately; if V2>V1, it means that the data in the cache area has deployed the latest data, and the latest data DataY needs to be reloaded from the database, and DataY is stored in the cache area so that the next time the data is read, the latest data can be read. In this way, the latest real-time data can be directly and quickly read from the cache area when reading data, ensuring real-time caching of data and enhancing reliability.

[0096] Then, the primary version key set is completed according to the updated data in the database to obtain a complete version key set.

[0097] Similar to the process of writing data, when reading data, since the primary version key set obtained by the metadata builder in step S110 is incomplete, in order to achieve the purpose of notifying all version keys of data updates, the corresponding version keys need to be completed. Therefore, the asynchronous thread first retrieves the updated data fields from the database again, which are recorded as

[0098] fieldSet = {field1 = value1, field2 = value2, ..., fieldT}, generally, the size T of fieldSet should be larger than the number N of keyword set KeySet, that is, T>N>M. After obtaining the complete data, subVersionKeySet can be completed, that is, the completed version key set is recorded as diffVersionKeySet, so the following relationship exists:

[0099] versionKeySet=subVersionKey+diffVerisonKey.

[0100] Finally, the complete version key set is stored in the database. Specifically, all version keys can be updated through asynchronous updates.

[0101] At this point, the version numbers in all version keys are asynchronously updated. After the version key is completed, there is no need to visit the database again, because DataY is already the latest data and has all the fields in fieldSet.

[0102] In step S130, the version is updated and cached according to the metadata.

[0103] In one embodiment of the present disclosure, the step specifically includes:

[0104] According to the complete version key set, the version key and the value corresponding to the version key are updated and cached in the cache area. Specifically, after all version keys are updated, they are cached in the cache area Redis through the version cache executor to complete the data reading operation.

[0105] It should be noted that in the embodiment of the present disclosure, Redis and MySQL are used to replace cache and db respectively.

[0106] The following example introduces the data reading and writing operations:

[0107] Assume that employee information = {'employee number', 'name', 'telephone number'}, the employee number is immutable and unique, the name and telephone number are mutable and non-unique, and the fields of the keyword mapping unit are {'employee number', 'telephone number'}.

[0108] During a write operation:

[0109] When updating an employee's name (from 'zhangsan1' to zhangsan2'), the data submitted is the pending data set paramSet = {'employee number': 1005, 'name': 'zhangsan2'}. The full set of the original version key set should be

[0110] versionKey1 = 'Working Number = 1005'

[0111] versionKey2 = 'phone number = xxx',

[0112] However, since the data to be processed only includes the employee number and name, the metadata constructor can only construct a primary version key set, namely subVersionKeySet, by mapping with the keyword mapping unit. The subVersionKeySet only contains versionKey1, and the missing versionKey2 can only be completed by the subsequent database data. The complete information of the employee queried from the database by the employee number is {'employee number': 1005, 'name': 'zhangsan1', 'telephone number': xxx}, and the completed version key set diffversionKey, namely versionKey2 = 'telephone number = xxx'.

[0113] After updating the database, you also need to update the value of the version key. Suppose the value before this update = v20180226, and the value of this update = v20180227.

[0114] Therefore, at this time, the notification updates versionKey1='employee number=1005' and versionKey2='telephone number=xxx', and the version number value is both v20180227.

[0115] During a read operation:

[0116] When querying employee information by employee number or phone number, the only parameter submitted is the employee number. The employee information data is read from the cache and the data version is v20180226, while the value in the version key is v20180227. By comparing the versions, it is found that the data is no longer the latest. At this time, the latest data is read from the database and returned, and then the latest data in the cache is asynchronously updated. In addition, the version key can also be updated in the same way as the above write operation, which will not be repeated here.

[0117] By providing a unified internal logic for reading and writing, each data change has a unique version key, and the consistency problem between cache and database can be solved by marking keywords. In addition, this method has the following advantages:

[0118] 1) Reliability: If the notification of writing data fails, you may be notified when reading data, which enhances reliability;

[0119] 2) Real-time: The data of the read / write port is the latest real-time data, with strong real-time performance;

[0120] 3) DB load: Since the read interface has high reliability in obtaining real-time data, the TTL (Time To Live) of the data cache can theoretically be set very long, thus avoiding fewer DB accesses;

[0121] 4) DB load stability: Since the TTL of the data cache can be set longer in theory, it means that there will no longer be a collective failure of the cache when the traffic is low, which will cause the database load to increase sharply when the traffic suddenly peaks next time, making the DB load more stable;

[0122] 5) Final consistency time: Due to the high real-time performance, the final consistency time is significantly shortened;

[0123] 6) Universality: Under the premise of ensuring consistency, the complex and tedious read and write processes are encapsulated, so the application only needs to pass parameters to call the real-time cache component, which has stronger universality and is applicable to the cache-db structure.

[0124] In summary, the data storage method provided in the embodiment of the present disclosure, on the one hand, can solve the consistency problem of cache and database data by using keywords to identify the data to be processed and then performing corresponding read and write operations; on the other hand, in addition to caching and updating the data, the data version is further updated and cached, shortening the time for the data to reach final consistency, ensuring the real-time and reliability of the data, and based on the above, it also has strong universality and db load stability, reducing the db load.

[0125] Figure 5 A schematic diagram of a data storage device provided by another embodiment of the present disclosure is shown as follows: Figure 5 As shown, the device 500 includes: a keyword mapping unit 510, a metadata constructor 520, a logic controller 530, a data buffer 540 and a version buffer 550.

[0126] The keyword mapping unit 510 is configured to store mapping relationships of keywords; the metadata constructor 520 is configured to use a keyword set to identify the data to be processed and obtain metadata; the logic controller 530 is configured to control the read operation and the write operation of the metadata; the data cache 540 is configured to update and cache the data to be processed according to the control of the logic control unit; the version cache 550 is configured to update and cache the version according to the metadata.

[0127] In one embodiment of the present disclosure, the mapping relationship of keywords in the keyword mapping unit 510 is provided by the keyword mapping unit, wherein the keywords may be field names. Taking employee information management data as an example, the keywords may include but are not limited to name, work number, telephone number, etc. The work number is immutable and unique, while the name and telephone number are variable and non-unique. Accordingly, the fields of the keyword mapping unit include {'work number', 'telephone number'}. The data to be processed may be data to be written or data to be read.

[0128] In one embodiment of the present disclosure, the metadata constructor 520 maps the keyword set with the to-be-processed data set, and identifies the to-be-processed data in the to-be-processed data set one by one using the keywords in the keyword set to obtain metadata.

[0129] The data set to be processed includes M parameters, and paramSet is used to represent the data set to be processed, paramSet = {param1 = value1, param2 = value2, ..., paramM = valueM};

[0130] The keyword set includes N keywords, and KeySet is used to represent the keyword set, KeySet = {key1, key2, ..., keyN}.

[0131] It should be noted that the metadata constructor in the disclosed embodiment constructs metadata required for various subsequent steps, such as version key, database query metadata, and prefix metadata of data cache key, etc., based on the data set to be processed and the keyword set.

[0132] Based on each version key, the version key set is:

[0133] versionKeySet = {versionKey1, versionKey2, ..., versionKeyN}, where the version key is determined by param and key. That is, any version key in the version key set is:

[0134] versionKeyX='paramA=valueA'+'paramB=valueB'+……

[0135] Among them, paramA, valueA, paramB, and valueB are all elements in the data set paramSet to be processed.

[0136] It should be noted that the field names in the to-be-processed data set paramSet, the keyword set KeySet, and the version key set versionKeySet are consistent with the keyword field names to ensure that the mapping is completed smoothly. The version keys generated when reading and writing data are stored in the same cache shard, which can be replaced by inter-process communication, such as MQ / Kafka.

[0137] It should also be noted that the data set {paramX} to be processed is a subset of the keyword set {KeyX}. Usually, the number of valid paramX elements in paramSet is less than the number of elements in the KeySet set, that is, M≤N. The number of primary version key set elements actually constructed by the metadata constructor is the same as the number of elements in the data set to be processed, that is, the number of primary version key set elements is also M. The number of primary version key set elements must be less than N. The primary version key set is represented by subVersionKeySet.

[0138] In one embodiment of the present disclosure, the logic controller 530 performs the corresponding read operation or write operation on the data to be processed as follows:

[0139] 1) The control logic of the logic control bus when writing data includes:

[0140] First, the metadata is written to the database, the update of the pending data in the database is completed, and the interface write operation is responded to successfully. When writing to the database, the SQL statement is queried and stored accordingly.

[0141] Then, the primary version key set is completed according to the updated data in the database to obtain a complete version key set. Since the primary version key set obtained by the metadata constructor in step S110 is incomplete, in order to achieve the purpose of notifying all version keys of the data update, the corresponding version key needs to be completed. Therefore, the asynchronous thread prioritizes retrieving the fields with complete updated data from the database, recorded as fieldSet = {field1 = value1, field2 = value2, ..., fieldT}. In general, the size T of filedSet should be larger than the number N of the keyword set KeySet, that is, T>N>M. After obtaining the complete data, the subVersionKeySet can be completed, that is, the completed version key set is recorded as diffVersionKeySet, so the following relationship exists:

[0142] versionKeySet=subVersionKey+diffVerisonKey.

[0143] Finally, the complete set of version keys is stored in the database. Specifically, all version keys can be updated through asynchronous updates. Figure 3 As shown, specifically, after all version keys are updated, they are cached in the cache area Redis through the version cache executor to complete the data writing operation.

[0144] 2) The control logic of the logic control bus when reading data includes:

[0145] First of all, unlike writing data, when reading data, if you want to read data from the database, you need to read the cache first.

[0146] Specifically, reading data from the cache area Redis includes:

[0147] The first step is to read the cache data for the metadata from the cache area through the data cache executor;

[0148] The second step is to compare the versions of the metadata and cached data. If the value V1 corresponding to the version key of the cached data is greater than or equal to the value V2 corresponding to the version key of the metadata, the cached data is returned directly; if the value V1 corresponding to the version key of the cached data is less than or equal to the value V2 corresponding to the version key of the metadata, the data for the metadata is obtained from the database and cached in the cache area.

[0149] It should be noted that there is another difference from writing data: in the data reading process, a version key unique to this read operation will be constructed, recorded as readVersionKey. The construction method of readVersionKey is the same as that of subVersionKeySet in the data writing process, so it will not be repeated here.

[0150] For the second step above, data DataX is read from the cache area first (the data version number of DataX is temporarily recorded as V1. At this time, the read data DataX cannot be returned directly, and the version number needs to be compared, that is, the version number V2 corresponding to the readVersionKey generated by reading the data from the database is extracted. If the comparison result is V1≥V2, the read data DataX is returned immediately; if V2>V1, it means that the data in the cache area has deployed the latest data, and the latest data DataY needs to be reloaded from the database, and DataY is stored in the cache area so that the next time the data is read, the latest data can be read. In this way, the latest real-time data can be directly and quickly read from the cache area when reading data, ensuring real-time caching of data and enhancing reliability.

[0151] Then, the primary version key set is completed according to the updated data in the database to obtain a complete version key set.

[0152] Similar to the process of writing data, when reading data, since the primary version key set obtained by the metadata builder in step S110 is incomplete, in order to achieve the purpose of notifying all version keys of data updates, the corresponding version keys need to be completed. Therefore, the asynchronous thread first retrieves the updated data fields from the database again, which are recorded as

[0153] fieldSet = {field1 = value1, field2 = value2, ..., fieldT}, generally, the size T of fieldSet should be larger than the number N of keyword set KeySet, that is, T>N>M. After obtaining the complete data, subVersionKeySet can be completed, that is, the completed version key set is recorded as diffVersionKeySet, so the following relationship exists:

[0154] versionKeySet=subVersionKey+diffVerisonKey.

[0155] Finally, the complete version key set is stored in the database. Specifically, all version keys can be updated through asynchronous updates.

[0156] At this point, the version numbers in all version keys are asynchronously updated. After the version key is completed, there is no need to visit the database again, because DataY is already the latest data and has all the fields in fieldSet.

[0157] In one embodiment of the present disclosure, the data buffer 540 updates and caches the data to be processed according to the control of the logic control unit, wherein the update and cache of the write data and the read data refer to the introduction of the above logic control process and will not be repeated here.

[0158] In one embodiment of the present disclosure, the version cache 550 updates the version key and the value corresponding to the version key according to the complete version key set and caches them in the cache area. Specifically, after all version keys are updated, they are cached in the cache area Redis through the version cache executor to complete the data reading operation.

[0159] In one embodiment of the present disclosure, the data storage device can be Figure 2 The layers in the overall architecture shown above correspond to each other, and in addition, the database ( Figure 5 (not shown) to complete data writing and reading operations.

[0160] The functions of each module in the device refer to the relevant description in the above method embodiment, which will not be repeated here.

[0161] On the other hand, the present disclosure further provides an electronic device, including a processor and a memory, wherein the memory stores an operation instruction for the processor to control the following method:

[0162] According to the keyword mapping relationship, the data to be processed is identified by using the keyword to obtain metadata; logical control of read and write operations is performed on the metadata to complete the update and cache of the data to be processed; and version update and cache are performed according to the metadata.

[0163] Reference below Figure 6 , which shows a schematic diagram of the structure of a computer system 600 suitable for implementing an electronic device of an embodiment of the present application. Figure 6 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0164] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 607 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0165] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.

[0166] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication part 609, and / or installed from a removable medium 611. When the computer program is executed by a central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present application are executed.

[0167] It should be noted that the computer-readable medium shown in the present application may be a computer-readable signal medium or a computer-readable medium or any combination of the above two. The computer-readable medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium may also be any computer-readable medium other than a computer-readable medium that can send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0168] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0169] The units involved in the embodiments described in the present application may be implemented by software or by hardware. The described units may also be provided in a processor, for example, may be described as: a processor including a sending unit, an acquisition unit, a determination unit, and a first processing unit. Among them, the names of these units do not constitute a limitation on the units themselves in certain circumstances, for example, the sending unit may also be described as a "unit that sends a picture acquisition request to the connected server".

[0170] On the other hand, the present disclosure also provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes the following method steps:

[0171] According to the keyword mapping relationship, the data to be processed is identified by using the keyword to obtain metadata; logical control of read and write operations is performed on the metadata to complete the update and cache of the data to be processed; and version update and cache are performed according to the metadata.

[0172] It should be clearly understood that the present disclosure describes how to form and use specific examples, but the principles of the present disclosure are not limited to any details of these examples. On the contrary, based on the teachings of the contents disclosed in the present disclosure, these principles can be applied to many other embodiments.

[0173] The exemplary embodiments of the present disclosure are specifically shown and described above. It should be understood that the present disclosure is not limited to the detailed structures, configurations or implementations described herein; on the contrary, the present disclosure is intended to cover various modifications and equivalent configurations included in the spirit and scope of the appended claims.

Claims

1. A data storage method, characterized in that: include: According to the keyword mapping relationship, the data to be processed is identified using the keyword to obtain metadata, wherein the metadata includes a version set; Performing logical control of read and write operations on the metadata to complete the update and cache of the data to be processed; Updating and caching versions according to the metadata; Performing a read operation on the metadata includes: reading cache data for the metadata from a cache area; performing version comparison between the metadata and the cache data, and determining a data storage location based on the version comparison result to return corresponding data; Among them, the data set to be processed includes M data to be processed, the keyword set includes N keywords, and the metadata includes: a primary version key set, and the primary version key set includes M version keys, M≤N; a read operation is performed on the metadata, including: if the value V1 corresponding to the version key of the cached data is greater than or equal to the value V2 corresponding to the version key of the metadata, then the cached data is directly returned; if the value V1 corresponding to the version key of the cached data is less than or equal to the value V2 corresponding to the version key of the metadata, then the data for the metadata is obtained from the database and cached to the cache area; and the updated version key of the metadata is obtained.

2. The data storage method according to claim 1, characterized in that: Keywords are used to identify the data to be processed, and the metadata obtained includes: Mapping is performed between the keyword set and the data set to be processed, and the data to be processed in the data set to be processed are identified one by one using the keywords in the keyword set to obtain metadata.

3. The data storage method according to claim 2, characterized in that: The logical control of writing the metadata includes: The metadata is written into a database, the update of the to-be-processed data in the database is completed, and a response is given that the interface write operation is successful.

4. The data storage method according to claim 1, characterized in that: After the metadata is written into the database, the following steps are also included: The primary version key set is supplemented with version keys according to the updated data of the database to obtain a complete version key set.

5. The data storage method according to claim 4, characterized in that: The complete version key set also includes: The complete version key set is stored in the database.

6. The data storage method according to claim 4, characterized in that: Updating the version according to the metadata includes: The version key and the value corresponding to the version key are updated according to the complete version key set and cached in a cache area.

7. A data storage device, characterized in that: include: A keyword mapping unit configured to store a mapping relationship of keywords; A metadata constructor configured to identify the data to be processed by using a keyword set to obtain metadata, wherein the metadata includes a version set; A logic controller configured to control read operations and write operations of the metadata; A data buffer, configured to update and cache the data to be processed according to the control of the logic control unit; A version cache, configured to update and cache versions according to the metadata; The logic controller is further configured to read cache data for the metadata from the cache area; perform version comparison according to the metadata and the cache data, and determine a data storage location based on the version comparison result to return corresponding data; Among them, the data set to be processed includes M data to be processed, the keyword set includes N keywords, and the metadata includes: a primary version key set, and the primary version key set includes M version keys, M≤N; the logic controller is also configured to directly return the cached data if the value V1 corresponding to the version key of the cached data is greater than or equal to the value V2 corresponding to the version key of the metadata; if the value V1 corresponding to the version key of the cached data is less than or equal to the value V2 corresponding to the version key of the metadata, obtain the data for the metadata from the database and cache it to the cache area; obtain the updated version key of the metadata.

8. An electronic device, characterized in that: include: processor; A memory storing the method steps for the processor to control according to any one of claims 1 to 6.

9. A computer-readable medium having computer-executable instructions stored thereon, characterized in that: When the executable instructions are executed by a processor, the method steps according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Device and method for visiting data recording stored in cache on server

    CN104123235A