Data storage method and device, equipment, medium and product
By rewriting data keys using data version mark value in key-value storage system and storing rewritten data in distributed storage, the problem of inconsistency between distributed technology and data version in the existing technology is solved, and the data version is realized consistency and storage efficiency.
Patent Information
- Application Number
- CN202411486812.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-23
- Publication Date
- 2025-02-14
AI Technical Summary
When the prior art realizes the update of the data version of the key-value storage system, it is impossible to effectively utilize distributed technology, resulting in excessive storage pressure on a single storage device and inconsistent data versions in business scenarios with high data demand.
By obtaining the mark value corresponding to the data version, change the original key of the key-value pair in the data to a new key, and store the rewritten key-value pairs on the basis of the new key, ensuring that each key-value pair is in the rewritten new key. Contains data version information.
It realizes the construction of new keys through mark values and original keys during reading, ensuring that the read data is the same version, and maintaining the consistency of data in distributed storage.
Smart Images

Figure CN119441219A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data storage method, device, equipment, medium and product. Background Art
[0002] Key-Value Store is a non-relational database that stores data in the form of key-value pairs. In this database, each data item consists of a unique key and a corresponding value. Key-value databases store data in key-value pairs by matching the key of a data item with its value, thereby achieving data storage and management.
[0003] In some business scenarios, the data that needs to be read comes from the same data version. For example, the feature data read during the inference of the machine learning model needs to belong to the same data version. In related technologies, the hash table data structure of the key-value storage system (such as redis) is used to write the same version of data into the same table. The reader ensures that the read data version is consistent by reading the table. When updating the data version of the table (table name 1), first write the new data into a temporary table (table name 2). After all the data is written, rename the temporary table from table name 2 to table name 1 to achieve data overwrite.
[0004] However, during the implementation of the above solution, a renaming operation is required when switching between new and old data, which requires that all data in the hash table be on the same node. Therefore, distributed technology cannot be used, resulting in excessive storage pressure on a single storage device in business scenarios with high data demand. Summary of the invention
[0005] The present application provides a data storage method, device, equipment, medium and product. The technical solution is as follows:
[0006] In one aspect, a method for storing data is provided, the method comprising:
[0007] Acquire first data, where the first data includes multiple sets of key-value pairs;
[0008] Acquire a first tag key corresponding to the first data, and acquire a first tag value corresponding to a data version of the first data;
[0009] For a first key-value pair in the multiple groups of key-value pairs, combine the first tag value with the first key in the first key-value pair to generate a second key corresponding to the first key-value pair;
[0010] Based on the second key and the first value in the first key-value pair, generating a target key-value pair after rewriting the first key-value pair;
[0011] The target key-value pairs after the multiple groups of key-value pairs are rewritten are stored, and the target version key-value pairs consisting of the first tag key and the first tag value are stored.
[0012] In another aspect, a data storage device is provided, the device comprising:
[0013] An acquisition module, configured to acquire first data, wherein the first data includes a plurality of key-value pairs;
[0014] The acquisition module is further used to acquire a first tag key corresponding to the first data, and acquire a first tag value corresponding to a data version of the first data;
[0015] a generating module, configured to combine the first tag value with the first key in the first key-value pair for a first key-value pair in the plurality of key-value pairs, to generate a second key corresponding to the first key-value pair;
[0016] The generating module is further configured to generate a target key-value pair after rewriting the first key-value pair based on the second key and the first value in the first key-value pair;
[0017] The storage module is used to store target key-value pairs after rewriting the multiple groups of key-value pairs respectively, and to store target version key-value pairs consisting of the first tag key and the first tag value.
[0018] On the other hand, a computer device is provided, comprising a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the data storage method as described in any of the above-mentioned embodiments of the present application.
[0019] On the other hand, a computer-readable storage medium is provided, wherein at least one instruction, at least one program, a code set or an instruction set is stored in the storage medium, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by a processor to implement a data storage method as described in any of the above-mentioned embodiments of the present application.
[0020] On the other hand, a computer program product or a computer program is provided, the computer program product or the computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the data storage method described in any of the above embodiments.
[0021] The technical solution provided by this application includes at least the following beneficial effects:
[0022] In the process of storing the first data, the original key of the key-value pair in the first data is changed to a new key through the first tag value corresponding to the data version, and the rewritten key-value pair is stored based on the new key, so that the stored rewritten first data can carry the data version information, so that when reading, the new key for query is constructed through the tag value corresponding to the known required version and the known original key of the data to be read, so as to ensure that the read data is of the same version. In addition, since the data version information follows each key-value pair, that is, each key-value pair contains the data version information in the rewritten new key, even if multiple groups of key-value pairs in the first data are distributedly stored, it can still be ensured that the data read from different storage devices in the distributed storage system belong to the same data version, so as to maintain data consistency. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0024] Figure 1 It is a schematic diagram of an implementation scheme of a non-distributed key-value storage system in the related art;
[0025] Figure 2 It is a schematic diagram of the application of key-value storage in related technologies to distributed technology;
[0026] Figure 3 is a structural block diagram of a computer system provided by an exemplary embodiment of the present application;
[0027] Figure 4 is a flow chart of a data storage method provided by an exemplary embodiment of the present application;
[0028] Figure 5 is a flow chart of a data storage method provided by an exemplary embodiment of the present application;
[0029] Figure 6 is a schematic diagram of a data storage process provided by an exemplary embodiment of the present application;
[0030] Figure 7 is a flow chart of a data storage method provided by an exemplary embodiment of the present application;
[0031] Figure 8is a schematic diagram of a data reading process provided by an exemplary embodiment of the present application;
[0032] Fig. 9 is a structural block diagram of a data storage device provided by an exemplary embodiment of the present application;
[0033] Fig.10 is a structural block diagram of a data storage device provided by an exemplary embodiment of the present application;
[0034] Fig.11 It is a schematic diagram of the structure of a server provided by an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0035] In order to make the purpose, technical solution and advantages of the present application clearer, the implementation mode of the present application will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present application.
[0036] In this application, the terms "first", "second", etc. are used to distinguish identical items or similar items with substantially the same effects and functions. It should be understood that there is no logical or temporal dependency between "first" and "second", nor are there any limitations on quantity and execution order.
[0037] First, a brief introduction is given to the terms involved in the embodiments of the present application.
[0038] Key-value storage: also known as key-value database or key-value database, is a non-relational database that uses key-value pairs to store data. In this database, each data item consists of a key and a value. The key is unique and is used to identify and retrieve the corresponding value. Key-value storage has the characteristics of simplicity, high performance, scalability, high flexibility, and persistence.
[0039] Distributed technology: a system architecture that distributes computing tasks to multiple computer nodes, which are connected through a network and work together to complete common tasks. The core advantage of this technology is to improve the scalability, reliability and performance of the system. By distributing data processing and storage on multiple nodes, distributed systems can effectively cope with large-scale data and high-concurrency requests while providing load balancing and fault tolerance. Communication between nodes is usually achieved through network protocols, while data consistency, transaction management and distributed locks are key technologies to ensure system stability and data accuracy. Distributed technology is widely used in cloud computing, big data processing and high-performance computing. It allows resources to be allocated on demand, services to be continuously available, and to flexibly respond to changing business needs.
[0040] Distributed system: Distributed refers to an architecture in which the components in a computer system are distributed on different computer nodes to achieve collaborative work and shared resources. A distributed system is a computer system built on a distributed architecture. A distributed system consists of multiple independent computer nodes (usually servers or virtual machines) that are interconnected through a network and work together. The design goals of a distributed system usually include improving the reliability, scalability, and performance of the computer system. In a distributed system, each computer node can process tasks independently and communicate and coordinate through the network to form an overall system. The key advantages of a distributed system include scalability, which is to improve system performance by adding nodes; fault tolerance, which means that the system can continue to operate even if some nodes fail; and high availability, which ensures that services are always available.
[0041] In the related art, in key-value storage, the implementation scheme of using a non-distributed key-value storage system is: using the hash table data structure of the key-value storage system (for example, redis), write the same version of data into the same table. Assuming the table name is FeatureTable, the reader can ensure that the data version read is consistent by reading the table. When updating the data version, first write the new data into a temporary table. Assuming the table name is FeatureTableTemp, after all the data is written, rename the temporary table FeatureTableTemp to FeatureTable, and the reader will automatically switch to the new version of the data. Figure 1 As shown, new data is written into the new table 101, and the new table 101 is renamed to replace the old table 102, thereby implementing the update of the data version and ensuring that when multiple keys are read at the same time, the read values are data of the same version.
[0042] In the above solution, because a rename operation is required when switching between old and new data, this usually requires that all data in the hash table be on the same node, which makes it impossible to use distributed technology, and it is not possible to achieve good disaster recovery and capacity expansion. At the same time, if the amount of data is large (more than tens of millions of keys), the rename operation will cause a large delay, and even cause the system to freeze for a long time.
[0043] When key-value storage is applied to distributed technology, the solution in the related technology is: all key-value data is scattered and written into the distributed storage system, and an expiration time is set for each. When updating data, the same key will overwrite the data and refresh the expiration time. If a key no longer exists in the new data, it will be automatically cleared when the expiration time is reached. Figure 2 As shown, when the version one data 201 stored in the distributed storage system updates the data version, since the amount of data in the new version is less than that in the original version and the expiration time corresponding to the version one data 201 has not yet arrived, the version two data 202 obtained after the data version update in the distributed storage system contains non-new version data. As shown in the figure, Key2-Value2 is dirty data. If the reader reads both Key1 and Key2 data, two different versions of data will be read.
[0044] In the above solution, after the new version of the data is updated and before the old version of the data expires, some of the unexpired old version of the data will be read by the reader, resulting in inconsistent data versions, which will affect data usage. Therefore, when using distributed technology to implement key-value storage, the consistency of data versions is a problem to be solved.
[0045] In an example scenario, the feature data used in the reasoning of a machine learning model is usually large-scale, that is, this is a large-scale (hundreds of millions) key-value pair writing and reading scenario, and multiple features during batch reasoning are usually required to come from the same data version, otherwise the model prediction will not meet expectations. The solutions in the above two related technologies cannot meet the above requirements in this scenario.
[0046] In the data storage method provided in the embodiment of the present application, in the process of storing the first data, the original key of the key-value pair in the first data is changed to a new key through the first tag value corresponding to the data version, and the rewritten key-value pair is stored based on the new key, so that the stored rewritten first data can carry the data version information, so that when reading, the new key for query is constructed by the tag value corresponding to the known required version and the original key of the known data to be read, so as to ensure that the read data is of the same version. In addition, since the data version information follows each key-value pair, that is, each key-value pair contains the data version information in the rewritten new key, even if multiple groups of key-value pairs in the first data are distributedly stored, it can still be ensured that the data read from different storage devices in the distributed storage system belong to the same data version, so as to maintain data consistency.
[0047] Figure 3 The structure block diagram of a computer system provided by an exemplary embodiment of the present application is shown. The computer system 300 includes: a data writer 310 , a data storage system 320 , and a data reader 330 .
[0048] The data writer 310 is a data writing device that writes data into the data storage system 320 during the data storage process. The data storage system 320 is a device that stores the written data. The data reader 330 is a device that reads the data in the data storage system 320 for data processing.
[0049] Optionally, the data writer 310 can be implemented as a terminal or a server. When the data writer 310 is implemented as a terminal, the terminal installs and runs an application that supports the data upload function, and optionally, the application can be implemented as a video application, a social application, an e-commerce application, a game application, etc.
[0050] Optionally, the data storage system 320 may be implemented as a single server or a distributed server.
[0051] Optionally, the data reader 330 can be implemented as a terminal or a server. When the data writer 310 is implemented as a terminal, the terminal installs and runs an application that supports data uploading function, and optionally, the application can be implemented as a video application, a social application, an e-commerce application, a game application, etc.
[0052] Optionally, the device types of the above-mentioned terminal include: at least one of: a game console, a desktop computer, a smart phone, a tablet computer, an e-book reader, a Moving Picture Experts Group Audio Layer III (MP3) player, a Moving Picture Experts Group Audio Layer IV (MP4) player and a laptop computer.
[0053] Those skilled in the art will appreciate that the number of the above devices may be more or less. For example, the above device may be only one, or the above devices may be dozens or hundreds, or more. The embodiment of the present application does not limit the number and type of devices.
[0054] Optionally, the server includes at least one of a server, multiple servers, a cloud computing platform, a virtualization center, and a node in a blockchain system. It is worth noting that the above server can be implemented as a physical server or as a cloud server in the cloud.
[0055] Illustratively, the data writer 310 is connected to the data storage system 320 via a wireless network or a wired network, and the data reader 330 is connected to the data storage system 320 via a wireless network or a wired network.
[0056] Schematically, the data writer 310 obtains the first data, the first data includes multiple groups of key-value pairs to be written into the data storage system 320, and the data writer 310 rewrites the first data, and the rewriting process includes: obtaining a first tag key corresponding to the first data, and obtaining a first tag value corresponding to the data version of the first data, for the first key-value pair in the multiple groups of key-value pairs, combining the first tag value with the first key in the first key-value pair to generate a second key corresponding to the first key-value pair, and generating a target key-value pair after rewriting the first key-value pair based on the second key and the first value in the first key-value pair. The data writer 310 stores the rewritten target key-value pair in the data storage system 320, and stores / updates the target version key-value pair composed of the first tag key and the first tag value in the data storage system 320.
[0057] Combined with the above-mentioned noun introduction and implementation environment, the data storage method provided by this application is explained. Figure 3 The data writing method 310 in FIG. Figure 4 As shown, the method includes the following steps 410 to 450.
[0058] Step 410: Acquire first data, where the first data includes multiple sets of key-value pairs.
[0059] Illustratively, the first data is data to be stored in a data storage system. The first data is a data set formed by multiple sets of key-value pairs. The key-value pair includes a key (Key) and a value (Value), wherein the key is unique in the first data and is used to identify and retrieve the corresponding value.
[0060] Step 420: Obtain a first tag key corresponding to the first data, and obtain a first tag value corresponding to the data version of the first data.
[0061] In the embodiment of the present application, the first marking key is a key for marking the first data. Optionally, the first marking key may be preset or generated in the current storage process.
[0062] In some embodiments, the first tag key is identification data associated with a target business corresponding to the first data. Schematically, the target business corresponding to the first data is determined, and the first tag key corresponding to the target business is obtained.
[0063] In some embodiments, when the first data is data stored by the first storage task corresponding to the target business, a first tag key corresponding to the target business is created based on the target business.
[0064] Illustratively, data corresponding to multiple candidate businesses are stored in the data storage system. When the target business is one of the multiple candidate businesses, optionally, the data writer obtains a business version storage table corresponding to the multiple candidate businesses. The business version storage table includes business version key-value pairs with the business identifier as the key and the tag key corresponding to the business as the value. By obtaining the business identifier of the target business, the first tag key can be queried in the business version storage table; or, the business version storage table stores a key-value pair with the business identifier as the first tag key and the current data version of the business as the value, and the data writer directly uses the business identifier of the target business as the first tag key.
[0065] Illustratively, the data storage system stores data corresponding to multiple candidate services. When the target service is not among the multiple candidate services, that is, when the target service is a newly created service, the data writer generates a first tag key according to a preset tag key generation rule. In one example, the tag keys corresponding to the existing candidate services are "SVC1, SVC2, SVC3...SVCn", and the first tag key of the generated target service is "SVCn+1".
[0066] In the embodiment of the present application, the first marking value is data for marking the data version to which the first data belongs.
[0067] In some embodiments, the data writer or the data storage system stores an original version key-value pair. In an illustrative manner, a first tag key corresponding to the first data is obtained, a second tag value is obtained by querying the original version key-value pair based on the first tag key, and a first tag value is generated based on a preset generation rule and the second tag value. The second tag value in the original version key-value pair is an identifier for indicating the data version of the second data currently stored in the data storage system before the first data is updated to the data storage system. In some embodiments, the second data and the first data belong to the same business.
[0068] Optionally, the first tag value may be generated in at least one of the following ways:
[0069] The first method is to generate the first tag value through a preset version naming rule.
[0070] In some embodiments, the target business corresponds to a preset version naming rule. After determining the target business corresponding to the first data, the preset version naming rule of the target business is obtained, and the first tag value is generated according to the preset version naming rule. In one example, the preset version naming rule of the target business is named "V1, V2, V3..." in sequence according to the order in which the data is updated. For example, when the second tag value corresponding to the second data is "V5", the first tag value corresponding to the first data is "V6".
[0071] In some embodiments, when there is no historically stored data for the target business, that is, when the first data is the data stored for the first time by the target business in the data storage system, in this case, the obtained second tag value is empty, and the first tag value is generated as the first tag value according to the preset version naming rule, for example, the first tag value is "V1".
[0072] The second method is to generate the first tag value through a preconfigured dictionary sequence table.
[0073] Among them, lexicographical order, also known as dictionary sorting or dictionary order, is a comparison method based on the order in which characters appear in a dictionary.
[0074] In an illustrative manner, a dictionary sequence table corresponding to a target business is obtained, the dictionary sequence table is used to indicate the naming rule of the data version of the target business, the dictionary sequence table includes a plurality of candidate character strings arranged in order, a first character string corresponding to a second tag value is searched from the plurality of candidate character strings, and a second character string located after the first character string in the dictionary sequence table is determined as the first tag value. Exemplarily, the dictionary sequence table is {VA, VB, VC, VD...}, when the second tag value corresponding to the second data is "VB" in the dictionary sequence table, "VC" located after "VB" in the dictionary sequence table is used as the first tag value.
[0075] In some embodiments, the number of strings in the dictionary sequence table is limited. When the second tag value is the last string in the dictionary sequence table, the first string in the dictionary sequence table is determined as the first tag value, that is, the strings in the dictionary sequence table are cyclically used for naming the first tag value.
[0076] In some embodiments, when there is no historically stored data for the target business, that is, when the first data is the data first stored in the data storage system by the target business, in this case, the obtained second tag value is empty, and the first string in the dictionary sequence table is used as the first tag value.
[0077] In some embodiments, when generating a dictionary sequence table, the number of character strings in the dictionary sequence table is determined based on the update frequency and expiration time in the data storage system. Schematically, the data update frequency corresponding to the target business in the data storage system and the set data expiration time are obtained, wherein the data update frequency is used to indicate the update frequency when the data storage system updates the data of the target business in the data writing direction, that is, the update frequency of the data version of the data of the target business stored in the data storage system, and the data expiration time is used to indicate the storage time of the data after being written to the data storage system. The number of character strings in the dictionary sequence table is determined based on the data update frequency and the data expiration time. Illustratively, the number of character strings in the dictionary sequence table is set to be greater than the ratio of the data expiration time to the data update frequency. In one example, the ratio between the data expiration time and the data update frequency is rounded and added to 1 to obtain the number of character strings in the dictionary sequence table. For example, if the data update frequency is 2 months / time and the data expiration time is 6 months, the number of character strings in the dictionary sequence table is 4, thereby avoiding the situation in which different data versions of data use the same first tag value in the data storage system; in another example, the number of character strings in the dictionary sequence table is much greater than the ratio of the data expiration time to the data update frequency. For example, if the data update frequency is 2 months / time and the data expiration time is 6 months, the number of character strings in the dictionary sequence table is 100.
[0078] The third method is to use two preset character strings to name the first tag value.
[0079] Illustratively, a third string and a fourth string corresponding to the target business are obtained, wherein the third string and the fourth string are strings used alternately for naming the first tag value, and when the second tag value obtained is the third string, the fourth string is determined as the first tag value, and when the second tag value obtained is the fourth string, the third string is determined as the first tag value.
[0080] In one example, when the second tag value obtained through the first tag key is "VA", the first tag value corresponding to the first data is determined to be "VB", and when the second tag value obtained through the first tag key is "VB", the first tag value corresponding to the first data is determined to be "VA".
[0081] In some embodiments, when there is no historically stored data for the target business, indicating that the first data is the data first stored by the target business in the data storage system, that is, when the acquired second tag value is empty, the third string is determined as the first tag value.
[0082] Step 430: For a first key-value pair in the plurality of key-value pairs, combine the first tag value with the first key in the first key-value pair to generate a second key corresponding to the first key-value pair.
[0083] In an embodiment of the present application, the first data includes multiple groups of key-value pairs, and the multiple groups of key-value pairs include a first key-value pair, wherein the first key-value pair is any key-value pair in the multiple groups of key-value pairs.
[0084] In an embodiment of the present application, during the storage process of the first data, data rewriting is performed on each group of key-value pairs to obtain target key-value pairs. During the rewriting process of the key-value pairs, the key-value pairs in the first data are rewritten based on the first tag key.
[0085] In some embodiments, the second key is generated based on the first tag key and the first key by using a preset rewriting rule, wherein the preset rewriting rule can be implemented as at least one of the following:
[0086] The first one is the splicing rules:
[0087] Illustratively, the first tag value and the first key are concatenated according to a preset concatenation rule to obtain a second key.
[0088] Optionally, the above-mentioned preset splicing rules can be implemented as direct splicing or symbol splicing. In one example, taking direct splicing as an example, the first tag value is "VA", the first key is "data1003", and the second key obtained by splicing is "VAdata1003" or "data1003VA"; in another example, taking symbol splicing as an example, the first tag value is "VA", the first key is "data1003", and the symbol used to splice the first tag value and the first key is an underscore, then the second key obtained by splicing is "VA_data1003" or "data1003_VA". It is worth noting that the splicing symbol underline used above is only an exemplary description, and the splicing symbol can also be implemented as other symbols, which is not limited here.
[0089] The second type is function concatenation:
[0090] Illustratively, the first tag value and the first key are input into a preset conversion function for concatenation to obtain a second key. Optionally, the preset conversion function can be implemented as a join() function in Python, a concat() function in JavaScript, an & operator in C language, etc., which is not limited here.
[0091] Step 440: Generate a target key-value pair that is a rewrite of the first key-value pair based on the second key and the first value in the first key-value pair.
[0092] In some embodiments, in the rewriting process of the first key-value pair, only the first key is rewritten, that is, the second key and the first value in the first key-value pair are combined to form a target key-value pair. In other embodiments, the first key and the first value in the first key-value pair are rewritten at the same time to obtain the second key and the second value respectively, and the second key and the second value are combined to obtain the target key-value pair.
[0093] In some embodiments, when the first value also needs to be rewritten, optionally, the rewriting of the first value can be implemented as at least one of the following:
[0094] The first one is to overwrite the first value by the first tag value.
[0095] Schematically, the first tag value and the first value in the first key-value pair are combined to generate a second value corresponding to the first key-value pair. Optionally, the second value is generated based on the first tag key and the first value by a preset rewriting rule, wherein the preset rewriting rule can be implemented as at least one of the following: 1. Splicing rule: splicing the first tag value and the first value according to the preset splicing rule to obtain the second value. Optionally, the preset splicing rule can be implemented as direct splicing or symbol splicing; 2. Function splicing: schematically, the first tag value and the first value are input into a preset conversion function for splicing to obtain the second value. Optionally, the preset conversion function can be implemented as Python's join() function, JavaScript's concat() function, the & operator in C language, etc., which are not limited here.
[0096] The second method is to overwrite the first value by storing the timestamp.
[0097] Illustratively, a storage timestamp is obtained, and the storage timestamp is combined with a first value in a first key-value pair to generate a second value corresponding to the first key-value pair.
[0098] The storage timestamp is the time recorded in the process of storing the first data. Optionally, the storage timestamp can be implemented as a timestamp indicating that the first data is stored, or the storage timestamp can also be implemented as a timestamp indicating that the first key-value pair is stored.
[0099] Optionally, when the storage timestamp is a timestamp indicating that the first data is stored, the storage timestamp may be a timestamp recorded when the first data is obtained (step 410) or when the first tag key / first tag value corresponding to the first data is obtained (step 420).
[0100] Optionally, when the storage timestamp is a timestamp indicating that the first key-value pair is stored, the storage timestamp may be a timestamp recorded when the second key is generated (step 430) or before the first value is rewritten into the second value.
[0101] Optionally, a second value is generated based on the storage timestamp and the first value through a preset rewriting rule, wherein the preset rewriting rule can be implemented as at least one of the following: 1. Splicing rule: splicing the storage timestamp and the first value according to the preset splicing rule to obtain the second value. Optionally, the above preset splicing rule can be implemented as direct splicing or symbol splicing. For example, the first value is "valueabc" and the storage timestamp is "T", then the second value is "T_valueabc"; 2. Function splicing: illustratively, the storage timestamp and the first value are input into a preset conversion function for splicing to obtain the second value. Optionally, the above preset conversion function can be implemented as Python's join() function, JavaScript's concat() function, the & operator in C language, etc., which is not limited here.
[0102] Optionally, a second value of the target data structure is constructed based on the storage timestamp and the first value.
[0103] Optionally, the above-mentioned target data structure can be implemented as at least one of a map data structure, a queue data structure, a linked list data structure, an array data structure, etc.
[0104] In one example, taking the map data structure as an example, the first value is "valueabc", the storage timestamp is "1618315200", and the constructed second value is "{"v":"valueabc","ct":T}".
[0105] Step 450: store target key-value pairs after rewriting the multiple groups of key-value pairs, and store target version key-value pairs consisting of the first tag key and the first tag value.
[0106] In an embodiment of the present application, the data writer stores the rewritten target key-value pair in a data storage system. Optionally, the data storage system can be implemented as at least one of Redis, MySQL, Oracle, Hadoop, cloud storage, network attached storage (NAS), etc.
[0107] In some embodiments, the data storage system includes multiple storage nodes, that is, the data storage system is a distributed storage system, and the multiple groups of target key-value pairs after the first data is rewritten are stored in the above-mentioned multiple storage nodes respectively according to storage requirements.
[0108] Optionally, the data writer stores the target version key-value pair consisting of the first tag key and the first tag value locally, or the data writer stores the target version key-value pair in a data storage system that stores the target key-value pairs.
[0109] In some embodiments, the data writer updates the original version key-value pair to a target version key-value pair consisting of a first tag key and a first tag value.
[0110] In some embodiments, after obtaining the target key-value pair rewritten by the first key-value pair, a data expiration time corresponding to the target key-value pair is set when storing the target key-value pair, and the data expiration time is used to determine whether the target key-value pair is expired. In some embodiments, the data storage system regularly clears the stored data according to the set data expiration time.
[0111] In summary, in the process of storing the first data, the original key of the key-value pair in the first data is changed to a new key through the first tag value corresponding to the data version, and the rewritten key-value pair is stored based on the new key, so that the stored rewritten first data can carry the data version information, so that when reading, the new key for query is constructed through the tag value corresponding to the known required version and the known original key of the data to be read, thereby ensuring that the read data is of the same version. In addition, since the data version information follows each key-value pair, that is, each key-value pair contains the data version information in the rewritten new key, even if multiple groups of key-value pairs in the first data are distributedly stored, it can still be ensured that the data read from different storage devices in the distributed storage system belong to the same data version, thereby maintaining data consistency.
[0112] In some optional embodiments, when storing the first data, when constructing the first key-value pair in the first data as the target key-value pair, both the first key and the first value in the first key-value pair are reconstructed. Figure 5 , which shows a flowchart of a data storage method provided by an exemplary embodiment of the present application, the method includes steps 510 to 573.
[0113] Step 510: Acquire first data, where the first data includes multiple groups of key-value pairs.
[0114] Illustratively, the first data is data to be stored in a data storage system. The first data is a data set formed by multiple sets of key-value pairs. The key-value pair includes a key (Key) and a value (Value), wherein the key is unique in the first data and is used to identify and retrieve the corresponding value.
[0115] Step 520: Based on the target business corresponding to the first data, obtain a first tag key corresponding to the target business, and obtain a first tag value corresponding to the data version of the first data.
[0116] In the embodiment of the present application, the first marking key is a key for marking the target business corresponding to the first data. Optionally, the first marking key may be preset or generated in the current storage process.
[0117] In an embodiment of the present application, when the first data is data stored for the nth time by the target business, the first tag key corresponding to the target business and the second tag value found from the original version key-value pair through the first tag key are obtained, and n>1.
[0118] In an embodiment of the present application, when the first data is data stored for the first time by the target business, a first tag key is generated according to a preset tag key generation rule, and the second tag value corresponding to the newly created first tag key is empty.
[0119] In an embodiment of the present application, two preset character strings are used to name the first tag value. Schematically, a third character string and a fourth character string corresponding to the target business are obtained, wherein the third character string and the fourth character string are characters used alternately for naming the first tag value. When the obtained second tag value is the third character string, the fourth character string is determined as the first tag value. When the obtained second tag value is the fourth character string, the third character string is determined as the first tag value.
[0120] In one example, when the second tag value obtained through the first tag key is "VA", the first tag value corresponding to the first data is determined to be "VB", and when the second tag value obtained through the first tag key is "VB", the first tag value corresponding to the first data is determined to be "VA".
[0121] In some embodiments, when there is no historically stored data for the target business, indicating that the first data is the data first stored by the target business in the data storage system, that is, when the acquired second tag value is empty, the third string is determined as the first tag value.
[0122] Step 530, record and store the timestamp.
[0123] In the embodiment of the present application, in the process of storing the first data, the storage timestamp is recorded, that is, the storage timestamp is the time recorded in the process of storing the first data.
[0124] Optionally, the storage timestamp may be a timestamp recorded when the first data is acquired or when the first tag key / first tag value corresponding to the first data is acquired.
[0125] Step 540: For a first key-value pair in the plurality of key-value pairs, combine the first tag value with the first key in the first key-value pair to generate a second key corresponding to the first key-value pair.
[0126] In an embodiment of the present application, the first data includes multiple groups of key-value pairs, and the multiple groups of key-value pairs include a first key-value pair, wherein the first key-value pair is any key-value pair in the multiple groups of key-value pairs.
[0127] In an embodiment of the present application, during the storage process of the first data, data is rewritten for each group of key-value pairs to obtain a target key-value pair. During the rewriting process of the key-value pairs, the keys in the key-value pairs are rewritten based on the first tag key, and the values in the key-value pairs are rewritten based on the storage timestamp.
[0128] In the embodiment of the present application, the first tag value and the first key are spliced according to a preset splicing rule to obtain a second key.
[0129] Optionally, the above-mentioned preset splicing rules can be implemented as direct splicing or symbol splicing. In one example, taking direct splicing as an example, the first tag value is "VA", the first key is "data1003", and the second key obtained by splicing is "VAdata1003" or "data1003VA"; in another example, taking symbol splicing as an example, the first tag value is "VA", the first key is "data1003", and the symbol used to splice the first tag value and the first key is an underscore, then the second key obtained by splicing is "VA_data1003" or "data1003_VA". It is worth noting that the splicing symbol underline used above is only an exemplary description, and the splicing symbol can also be implemented as other symbols, which is not limited here.
[0130] Step 550: Combining the stored timestamp as the time value with the first value to obtain a second value.
[0131] Optionally, a second value is generated based on the storage timestamp and the first value through a preset rewriting rule, wherein the preset rewriting rule can be implemented as at least one of the following: 1. Splicing rule: splicing the storage timestamp and the first value according to the preset splicing rule to obtain the second value. Optionally, the above preset splicing rule can be implemented as direct splicing or symbol splicing. For example, the first value is "valueabc" and the storage timestamp is "T", then the second value is "T_valueabc"; 2. Function splicing: illustratively, the storage timestamp and the first value are input into a preset conversion function for splicing to obtain the second value. Optionally, the above preset conversion function can be implemented as Python's join() function, JavaScript's concat() function, the & operator in C language, etc., which is not limited here.
[0132] Optionally, a second value of the target data structure is constructed based on the storage timestamp and the first value.
[0133] Optionally, the above-mentioned target data structure can be implemented as at least one of a map data structure, a queue data structure, a linked list data structure, an array data structure, etc.
[0134] In one example, taking the map data structure as an example, the first value is "valueabc", the storage timestamp is "1618315200", and the constructed second value is "{"v":"valueabc","ct":T}".
[0135] Step 560: Combine the second key and the second value to generate a target key-value pair.
[0136] In the embodiment of the present application, the first key in the first key-value pair is rewritten as the second key, and the first value is rewritten as the second value to obtain a target key-value pair.
[0137] Step 571, storing the target key-value pairs after rewriting the multiple groups of key-value pairs.
[0138] In an embodiment of the present application, the data writer stores the rewritten target key-value pair in a data storage system. Optionally, the data storage system can be implemented as at least one of Redis, MySQL, Oracle, Hadoop, cloud storage, NAS, etc.
[0139] In some embodiments, the data storage system includes multiple storage nodes, that is, the data storage system is a distributed storage system, and the multiple groups of target key-value pairs after the first data is rewritten are stored in the above-mentioned multiple storage nodes respectively according to storage requirements.
[0140] Step 572, update the value in the stored time key-value pair to the stored timestamp.
[0141] In an embodiment of the present application, the target business corresponds to a time key-value pair, and the time key-value pair is used to record the moment when the stored data is updated, that is, the value in the time key-value pair is used to indicate the latest update time of the data of the target business stored in the data storage system. When storing the target key-value pairs after rewriting multiple groups of key-value pairs respectively, or after completing the storage, the time key-value pair corresponding to the target business is updated using the recorded storage timestamp.
[0142] In an illustrative example, a time key-value pair is obtained, and the value in the time key-value pair is updated to a storage timestamp. In one example, the obtained time key-value pair is {ValidCt, T1}, and the storage timestamp corresponding to the data update is T2, then the updated time key-value pair is {ValidCt, T2}.
[0143] In some embodiments, the key in the time key-value pair is associated with the first tag value, that is, different time key-value pairs are constructed for different first tag values. Illustratively, when the first tag value is a third string, the corresponding key in the time key-value pair is acquired / generated based on the third string, and when the first tag value is a fourth string, the corresponding key in the time key-value pair is acquired / generated based on the fourth string. For example, the two preset strings are "VA" and "VB", then when the first tag value is "VA", the key of the time key-value pair is "VA_ValidCt", and when the first tag value is "VB", the key of the time key-value pair is "VB_ValidCt".
[0144] Optionally, the data writer stores the time key-value pair locally, or the data writer stores the time key-value pair in a data storage system that stores the target key-value pair.
[0145] Step 573: Store the target version key-value pair consisting of the first tag key and the first tag value.
[0146] Optionally, the data writer stores the target version key-value pair consisting of the first tag key and the first tag value locally, or the data writer stores the target version key-value pair in a data storage system that stores the target key-value pairs.
[0147] In some embodiments, the data writer updates the original version key-value pair to a target version key-value pair consisting of a first tag key and a first tag value.
[0148] In some embodiments, after obtaining the target key-value pair rewritten by the first key-value pair, a data expiration time corresponding to the target key-value pair is set when storing the target key-value pair, and the data expiration time is used to determine whether the target key-value pair is expired. In some embodiments, the data storage system regularly clears the stored data according to the set data expiration time.
[0149] In one example, if Figure 6 As shown, it shows a schematic diagram of a data storage process provided by an exemplary embodiment of the present application, the data storage party 610 obtains the first data 611 to be updated of the target business, the original version key-value pair 612 corresponding to the target business, reads the corresponding second tag value (VB) from the first tag key (Version) in the original version key-value pair 612, and obtains the first tag value (VA) 613 based on the second tag value (VB). After the data storage party 610 records the current timestamp T614, it rewrites the key-value pair "123-value123" 615 in the first data 611 to obtain the target key-value pair 616, wherein a new "VA_{123}" is constructed according to the original key "123" and the first tag value (VA) 613, and a new value "{"v":"value123","ct":T}" is constructed according to the original value "value123" and the current timestamp T614, and an expiration time is set for the target key-value pair 616, wherein the expiration time is greater than the update time interval of the adjacent data versions of the target business. After all the key-value pairs of the first data 611 are rewritten and written into the data storage system 620, a time key-value pair 617 is written to record the above timestamp T614. In an example, the key of the time key-value pair 617 is "VA_ValidCt" and the value is "T".
[0150] In some embodiments, before the first data 611 is written, the data storage system 620 has stored historical data 621 of the previous data version, and the historical data 621 has not expired. After the data storage party 610 rewrites and writes the first data 611, the data storage system 620 stores the historical data 621 and the rewritten first data 622.
[0151] In summary, in the process of storing the first data, the original key of the key-value pair in the first data is changed to a new key through the first tag value corresponding to the data version, and the rewritten key-value pair is stored based on the new key, so that the stored rewritten first data can carry the data version information, so that when reading, the new key for query is constructed through the tag value corresponding to the known required version and the known original key of the data to be read, thereby ensuring that the read data is of the same version. In addition, since the data version information follows each key-value pair, that is, each key-value pair contains the data version information in the rewritten new key, even if multiple groups of key-value pairs in the first data are distributedly stored, it can still be ensured that the data read from different storage devices in the distributed storage system belong to the same data version, thereby maintaining data consistency.
[0152] In an embodiment of the present application, in the process of storing the first data, in addition to rewriting the original key into a new key through the first tag value, the original value is also rewritten into a new value by updating the storage timestamp recorded when the first data is updated, so that when reading, the time value parsed from the read value (i.e., the new value constructed during the storage process) is compared with the storage timestamp in the time key-value pair stored when the data was last updated, thereby ensuring that the read value is the latest version of the data. Under this scheme, when configuring the first tag value corresponding to different data versions, data of different generations can use the same first tag value, so that the data can directly overwrite the previously stored non-expired data when stored, thereby reducing the storage space occupied and reducing the storage cost requirements.
[0153] In some optional embodiments, when reading data from a data storage system, a second key is constructed based on the first key corresponding to the first key-value pair to be read and the first tag key in the target version key-value pair, and the required data is obtained by querying the data storage system through the second key. Figure 7 , which shows a flow chart of a data reading method provided by an exemplary embodiment of the present application. The method is executed by a data reader, and the method includes steps 710 to 760.
[0154] Step 710: When there is a data reading requirement to read a first value, obtain a first key.
[0155] In the embodiment of the present application, when the data reader has a data reading requirement to read the first value, the data reader obtains the first key as an index of the first value, that is, the first key can be directly obtained by the data reader.
[0156] Optionally, the data reader and the data storage may be implemented as different hardware devices or as the same hardware device, which is not limited here.
[0157] Step 720: Obtain a first tag value from the target version key-value pair.
[0158] Schematically, a data reader obtains a first tag key corresponding to a target business, and queries a corresponding first tag value from a target version key-value pair stored in a data storage system through the first tag key, wherein the first tag key is identification data associated with the target business, and the first tag value is data for marking a data version of the first data to which the first value belongs.
[0159] Step 730: Combine the first key and the first tag value to obtain a second key.
[0160] In the embodiment of the present application, the first tag value and the first key are spliced according to a preset splicing rule to obtain a second key.
[0161] Optionally, the above-mentioned preset splicing rules can be implemented as direct splicing or symbol splicing. In one example, taking direct splicing as an example, the first tag value is "VA", the first key is "data1003", and the second key obtained by splicing is "VAdata1003" or "data1003VA"; in another example, taking symbol splicing as an example, the first tag value is "VA", the first key is "data1003", and the symbol used to splice the first tag value and the first key is an underscore, then the second key obtained by splicing is "VA_data1003" or "data1003_VA". It is worth noting that the splicing symbol underline used above is only an exemplary description, and the splicing symbol can also be implemented as other symbols, which is not limited here.
[0162] Step 740: query and obtain a second value from a plurality of target key-value pairs based on the second key.
[0163] In an embodiment of the present application, the data reader uses the constructed second key as an index to query and obtain the second value that forms a target key-value pair with the second key from multiple target key-value pairs stored in the data storage system.
[0164] In the embodiment of the present application, the second value in the target key-value pair includes a first value and a time value. Schematically, the second value is parsed to obtain the first value and the time value, wherein the first value is the data that the data reader needs to read, and the time value is used to indicate the storage time of the target key-value pair.
[0165] Step 750, obtain the storage timestamp in the time key-value pair.
[0166] In an embodiment of the present application, the data storage system stores data for recording the time when the target business execution data is updated, and the time key-value pair includes a time query key and a storage timestamp.
[0167] In some embodiments, the data reader can directly obtain the time query key, and read the corresponding storage timestamp from the time key-value pair in the data storage system through the time query key. In other embodiments, the data reader generates a corresponding time query key based on the first tag value, and reads the corresponding storage timestamp from the time key-value pair in the data storage system through the generated time query key. In one example, when the first tag value is "VA", the time query key "VA_ValidCt" is constructed according to the preset time key construction rule.
[0168] Step 760: When the time value is greater than or equal to the stored timestamp, the first value is used as the read data.
[0169] In an embodiment of the present application, whether the first value is the latest version of the target business data is determined by comparing the time value corresponding to the read first value with the storage timestamp stored in the time key-value pair. That is, when the time value is greater than or equal to the storage timestamp, it means that the first value is the latest version of the target business data, and it is determined that the first value has been read successfully.
[0170] In some embodiments, when the time value is less than the stored timestamp, the first value is discarded. That is, when the time value is less than the stored timestamp, it means that the first value read is the data of the target business historical data version, so the data is discarded.
[0171] In one example, if Figure 8 As shown, it shows a schematic diagram of the data reading process provided by an exemplary embodiment of the present application, in which the rewritten first data 811, the target version key-value pair 812 and the time key-value pair 813 are stored in the data storage system 810, and the data reader 820 queries the first tag value (VA) in the time key-value pair 813 from the target version key-value pair 812 according to the known first tag key (Version), and uses the first tag value (VA) and the known multiple first keys 814 to construct multiple second keys 815, and uses the multiple second keys 815 as indexes to query from the data storage system 810 to obtain second values 816 corresponding to the multiple second keys 815, and reads the corresponding storage timestamp 818 from the time key-value pair 813 through the known time query key 817, and determines whether to retain or discard the first value corresponding to the second value 816 by comparing the time value in the second value 816 with the storage timestamp 818.
[0172] In summary, in the process of storing the first data, the original key of the key-value pair in the first data is changed to a new key through the first tag value corresponding to the data version, and the rewritten key-value pair is stored based on the new key, so that the stored rewritten first data can carry the data version information, so that when reading, the new key for query is constructed through the tag value corresponding to the known required version and the known original key of the data to be read, thereby ensuring that the read data is of the same version. In addition, since the data version information follows each key-value pair, that is, each key-value pair contains the data version information in the rewritten new key, even if multiple groups of key-value pairs in the first data are distributedly stored, it can still be ensured that the data read from different storage devices in the distributed storage system belong to the same data version, thereby maintaining data consistency.
[0173] It should be noted that before collecting relevant data of users and during the process of collecting relevant data of users, this application can display a prompt interface, pop-up window or output voice prompt information, and the prompt interface, pop-up window or voice prompt information is used to prompt the user that its relevant data is currently being collected, so that this application only starts to execute the relevant steps of obtaining relevant data of users after obtaining the confirmation operation issued by the user to the prompt interface or pop-up window, otherwise (that is, when the confirmation operation issued by the user to the prompt interface or pop-up window is not obtained), the relevant steps of obtaining relevant data of users are terminated, that is, the relevant data of users are not obtained. In other words, all user data collected by this application are collected with the consent and authorization of the user, and the collection, use and processing of relevant user data need to comply with the relevant laws, regulations and standards of relevant countries and regions.
[0174] Please refer to Fig. 9 , which shows a structural block diagram of a data storage device 900 provided by an exemplary embodiment of the present application, the device 900 includes the following modules:
[0175] A first acquisition module 910 is used to acquire first data, where the first data includes multiple groups of key-value pairs;
[0176] The first acquisition module 910 is further configured to acquire a first tag key corresponding to the first data, and acquire a first tag value corresponding to a data version of the first data;
[0177] A first generating module 920, configured to combine the first tag value with the first key in the first key-value pair for a first key-value pair in the plurality of key-value pairs, to generate a second key corresponding to the first key-value pair;
[0178] The first generating module 920 is further configured to generate a target key-value pair after rewriting the first key-value pair based on the second key and the first value in the first key-value pair;
[0179] The storage module 930 is used to store target key-value pairs after the multiple groups of key-value pairs are rewritten respectively, and to store target version key-value pairs consisting of the first tag key and the first tag value.
[0180] In some optional embodiments, the first acquisition module 910 is further configured to acquire a first tag key corresponding to the first data;
[0181] like Fig.10 As shown, the first acquisition module 910 includes:
[0182] A reading unit 911 is used to query an original version key-value pair based on the first tag key to obtain a second tag value, where the original version key-value pair is used to indicate a data version before the data is updated;
[0183] The first generating module 920 is further configured to generate the first tag value based on a preset generating rule and the second tag value;
[0184] The storage module 930 is further configured to update the original version key-value pair to the target version key-value pair consisting of the first tag key and the first tag value.
[0185] In some optional embodiments, the device 900 further includes:
[0186] A first determination module 940, configured to determine a target business corresponding to the first data;
[0187] The first acquisition module 910 is further configured to acquire the first marking key corresponding to the target service.
[0188] In some optional embodiments, the first acquisition module 910 is further used to acquire a dictionary sequence table corresponding to the target service, the dictionary sequence table is used to indicate a naming rule of a data version of the target service, and the dictionary sequence table includes a plurality of candidate character strings arranged in sequence;
[0189] The reading unit 911 is further configured to search for a first character string corresponding to the second tag value from a plurality of candidate character strings;
[0190] The reading unit 911 is further configured to determine a second character string located after the first character string in the dictionary sequence table as the first tag value.
[0191] In some optional embodiments, the first acquisition module 910 is further used to acquire a third character string and a fourth character string corresponding to the target service, where the third character string and the fourth character string are character strings used in turn for naming the first tag value;
[0192] The first determining module 940 is further configured to determine the third character string as the first tag value when the acquired second tag value is empty;
[0193] The first determining module 940 is further configured to determine the fourth string as the first tag value when the acquired second tag value is the third string;
[0194] The first determining module 940 is further configured to determine the third string as the first tag value when the acquired second tag value is the fourth string.
[0195] In some optional embodiments, the first generating module 920 is further configured to concatenate the first tag value and the first key according to a preset concatenation rule to obtain the second key.
[0196] In some optional embodiments, the storage module 930 is further configured to record a storage timestamp during the process of storing the first data;
[0197] The first generating module 920 is further configured to construct a second value by combining the stored timestamp as a time value and the first value;
[0198] The first generating module 920 is further configured to combine the second key and the second value to generate the target key-value pair.
[0199] In some optional embodiments, the first acquisition module 910 is further used to acquire a time key-value pair, where the time key-value pair is used to record the time when the stored data is updated;
[0200] The storage module 930 is further configured to update the value in the time key-value pair to the storage timestamp.
[0201] In some optional embodiments, the device 900 further includes:
[0202] A second acquisition module 950 is used to acquire the first key when there is a data reading requirement to read the first value;
[0203] The second acquisition module 950 is further configured to acquire the first tag value from the target version key-value pair;
[0204] A second generating module 960, configured to combine the first key and the first tag value to obtain the second key;
[0205] A reading module 970, configured to query and obtain the second value from a plurality of target key-value pairs based on the second key, where the second value includes the first value and the time value;
[0206] The reading module 970 is further used to obtain the storage timestamp in the time key-value pair;
[0207] The second determining module 980 is configured to use the first value as the read data when the time value is greater than or equal to the stored timestamp.
[0208] It should be noted that the data storage device provided in the above embodiment is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the data storage device provided in the above embodiment and the data storage method embodiment belong to the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0209] Fig.11 The schematic diagram of the structure of a server provided by an exemplary embodiment of the present application is shown, which specifically includes the following structure.
[0210] The server 1100 includes a central processing unit (CPU) 1101, a system memory 1104 including a random access memory (RAM) 1102 and a read only memory (ROM) 1103, and a system bus 1105 connecting the system memory 1104 and the central processing unit 1101. The server 1100 also includes a mass storage device 1106 for storing an operating system 1113, application programs 1114, and other program modules 1115.
[0211] The mass storage device 1106 is connected to the central processing unit 1101 through a mass storage controller (not shown) connected to the system bus 1105. The mass storage device 1106 and its associated computer-readable media provide non-volatile storage for the server 1100. That is, the mass storage device 1106 may include a computer-readable medium (not shown) such as a hard disk or a compact disc read only memory (CD-ROM) drive.
[0212] Without loss of generality, computer-readable media may include computer storage media and communication media. Computer storage media include volatile and non-volatile, removable and non-removable media implemented by any method or technology for storing information such as computer-readable instructions, data structures, program modules or other data. Computer storage media include RAM, ROM, Erasable Programmable Read Only Memory (EPROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other solid-state memory technology, CD-ROM, Digital Versatile Disc (DVD) or other optical storage, cassettes, tapes, disk storage or other magnetic storage devices. Of course, those skilled in the art will appreciate that computer storage media are not limited to the above. The above-mentioned system memory 1104 and mass storage device 1106 can be collectively referred to as memory.
[0213] According to various embodiments of the present application, the server 1100 can also be connected to a remote computer on the network through a network such as the Internet. That is, the server 1100 can be connected to the network 1112 through the network interface unit 1111 connected to the system bus 1105, or the network interface unit 1111 can be used to connect to other types of networks or remote computer systems (not shown).
[0214] The above-mentioned memory also includes one or more programs, and the one or more programs are stored in the memory and configured to be executed by the CPU.
[0215] The embodiment of the present application also provides a computer device, which includes a processor and a memory, wherein at least one instruction, at least one program, code set or instruction set is stored in the memory, and the at least one instruction, at least one program, code set or instruction set is loaded and executed by the processor to implement the data storage method provided by the above-mentioned method embodiments. Optionally, the computer device can be a terminal or a server.
[0216] An embodiment of the present application also provides a computer-readable storage medium, on which is stored at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded and executed by a processor to implement the data storage method provided by the above-mentioned method embodiments.
[0217] The embodiments of the present application also provide a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the data storage method described in any of the above embodiments.
[0218] Optionally, the computer readable storage medium may include: a read-only memory (ROM), a random access memory (RAM), a solid state drive (SSD), or an optical disk. Among them, the random access memory may include a resistance random access memory (ReRAM) and a dynamic random access memory (DRAM). The serial numbers of the above embodiments of the present application are only for description and do not represent the advantages and disadvantages of the embodiments.
[0219] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0220] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A data storage method, characterized in that: The method comprises: Acquire first data, where the first data includes multiple sets of key-value pairs; Acquire a first tag key corresponding to the first data, and acquire a first tag value corresponding to a data version of the first data; For a first key-value pair in the multiple groups of key-value pairs, combine the first tag value with the first key in the first key-value pair to generate a second key corresponding to the first key-value pair; Based on the second key and the first value in the first key-value pair, generating a target key-value pair after rewriting the first key-value pair; The target key-value pairs after the multiple groups of key-value pairs are rewritten are stored, and the target version key-value pairs consisting of the first tag key and the first tag value are stored.
2. The method according to claim 1, characterized in that The obtaining of a first tag key corresponding to the first data and obtaining of a first tag value corresponding to a data version of the first data include: Obtain a first tag key corresponding to the first data; Based on the first tag key, query the original version key-value pair to obtain a second tag value, where the original version key-value pair is used to indicate the data version before the data is updated; Generate the first tag value based on a preset generation rule and the second tag value; The storing of the target version key-value pair consisting of the first tag key and the first tag value includes: The original version key-value pair is updated to the target version key-value pair consisting of the first tag key and the first tag value.
3. The method according to claim 2, characterized in that The obtaining a first tag key corresponding to the first data includes: Determining a target business corresponding to the first data; Obtain the first marking key corresponding to the target business.
4. The method according to claim 2 or 3, characterized in that: The generating the first tag value based on a preset generation rule and the second tag value includes: Acquire a dictionary sequence table corresponding to the target service, wherein the dictionary sequence table is used to indicate a naming rule of a data version of the target service, and the dictionary sequence table includes a plurality of candidate character strings arranged in sequence; Searching for a first character string corresponding to the second tag value from a plurality of candidate character strings; A second character string located after the first character string in the dictionary sequence table is determined as the first tag value.
5. The method according to claim 2 or 3, characterized in that: The generating the first tag value based on a preset generation rule and the second tag value includes: Acquire a third character string and a fourth character string corresponding to the target service, where the third character string and the fourth character string are character strings used in turn for naming the first tag value; When the acquired second tag value is empty, determining the third character string as the first tag value; When the acquired second tag value is the third string, determining the fourth string as the first tag value; When the acquired second tag value is the fourth character string, the third character string is determined as the first tag value.
6. The method according to any one of claims 1 to 3, characterized in that: The combining the first tag value with the first key in the first key-value pair to generate a second key corresponding to the first key-value pair includes: The first tag value and the first key are concatenated according to a preset concatenation rule to obtain the second key.
7. The method according to any one of claims 1 to 3, characterized in that: The generating, based on the second key and the first value in the first key-value pair, a target key-value pair that is rewritten from the first key-value pair includes: In the process of storing the first data, recording the storage timestamp; Combining the stored timestamp as a time value with the first value to obtain a second value; The second key and the second value are combined to generate the target key-value pair.
8. The method according to claim 7, characterized in that The method further comprises: Obtain a time key-value pair, where the time key-value pair is used to record the time when the stored data is updated; The value in the time key-value pair is updated to the storage timestamp.
9. The method according to claim 8, characterized in that The method further comprises: In case there is a data reading demand for reading the first value, obtaining the first key; Obtain the first tag value from the target version key-value pair; Combining the first key and the first tag value to obtain the second key; Based on the second key, query from multiple target key-value pairs to obtain the second value, where the second value includes the first value and the time value; Obtaining the storage timestamp in the time key-value pair; When the time value is greater than or equal to the storage timestamp, the first value is used as the read data.
10. A data storage device, characterized in that: The device comprises: An acquisition module, configured to acquire first data, wherein the first data includes a plurality of key-value pairs; The acquisition module is further used to acquire a first tag key corresponding to the first data, and acquire a first tag value corresponding to a data version of the first data; a generating module, configured to combine the first tag value with the first key in the first key-value pair for a first key-value pair in the plurality of key-value pairs, to generate a second key corresponding to the first key-value pair; The generating module is further configured to generate a target key-value pair after rewriting the first key-value pair based on the second key and the first value in the first key-value pair; The storage module is used to store target key-value pairs after rewriting the multiple groups of key-value pairs respectively, and to store target version key-value pairs consisting of the first tag key and the first tag value.
11. A computer device, characterized in that: The computer device includes a processor and a memory, wherein the memory stores at least one program, and the at least one program is loaded and executed by the processor to implement the data storage method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one program code, and the program code is loaded and executed by a processor to implement the data storage method according to any one of claims 1 to 9.
13. A computer program product, characterized in that The method comprises a computer program or an instruction, wherein when the computer program or the instruction is executed by a processor, the method for storing data as claimed in any one of claims 1 to 9 is implemented.