Data storage method and device, equipment and storage medium

By processing and encrypting the key-value data stored locally by the browser and storing it with the timestamp as a snapshot, the problem of data rollback cannot be realized in the prior art is solved, and the reliability and security of data storage are improved.

CN119493928APending Publication Date: 2025-02-21CHINA CONSTRUCTION BANK +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411301359.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-18
Publication Date
2025-02-21

AI Technical Summary

Technical Problem

Existing browser local storage technology only stores the latest data and cannot realize data rollback, resulting in low reliability of data storage.

Method used

The data rollback function is realized by processing, encrypting the key-value data to be stored, and storing it with the timestamp as a snapshot in the historical snapshot list.

Benefits of technology

The data rollback function is realized, which improves the reliability, security and flexibility of data storage and avoids the risk of data loss.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119493928A_ABST
    Figure CN119493928A_ABST
Patent Text Reader

Abstract

The invention discloses a data storage method and device, equipment and a storage medium. The invention relates to the technical field of data processing. The method comprises the following steps: processing a first key name of to-be-stored first key value data to obtain a first processed key name; encrypting the first key value data to obtain encrypted first key value data; taking the first processed key name, the encrypted first key value data and the first timestamp as a first snapshot, and updating a historical snapshot list to obtain an updated snapshot list; determining the first snapshot as an effective snapshot; and if a data rollback request is received, according to a target timestamp in the data rollback request, updating the snapshot with the corresponding timestamp in front of the target timestamp and closest to the target timestamp in the updated snapshot list into an effective snapshot. According to the data storage method, the reliability, safety and flexibility of data storage are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a data storage method, device, equipment and storage medium. Background Art

[0002] When users use browsers to obtain data, browser local storage (LocalStorage) technology plays a vital role. LocalStorage is a local storage mechanism introduced by Hyper Text Markup Language 5 (HTML5), which can store data locally in the browser in the form of key-value pairs.

[0003] Currently, only the latest data is stored in the local storage of the browser. For example, if a user enters first data in a webpage at a first moment, the browser can store the first data locally in the browser. If a user enters second data in the same webpage at a second moment after the first moment, the browser will update the first data stored locally in the browser to the second data.

[0004] However, in the above implementation, since only the latest data is stored, when the user needs to restore the historical data stored locally in the browser, that is, when data rollback is required, the historical data cannot be restored, and the reliability of data storage is low. Summary of the invention

[0005] The present application provides a data storage method, device, equipment and storage medium to solve the technical problem of low reliability in data storage in related technologies.

[0006] In a first aspect, the present application provides a data storage method, comprising:

[0007] Processing the first key name of the first key-value data to be stored to obtain a first processed key name;

[0008] Encrypting the first key-value data to obtain encrypted first key-value data;

[0009] Taking the first processed key name, the encrypted first key value data, and the first timestamp as the first snapshot, updating the historical snapshot list to obtain an updated snapshot list; wherein the updated snapshot list includes the first snapshot and at least one historical snapshot, the first timestamp is the timestamp corresponding to the first key value data, and the timestamps corresponding to the first snapshot and at least one historical snapshot are different;

[0010] determining the first snapshot as a valid snapshot;

[0011] If a data rollback request is received, the snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp is updated as the valid snapshot according to the target timestamp in the data rollback request; wherein the target timestamp is less than or equal to the first timestamp.

[0012] In a second aspect, the present application provides a data storage device, the device comprising:

[0013] A first determining module, used for processing a first key name of the first key-value data to be stored to obtain a first processed key name;

[0014] An encryption module, used for encrypting the first key-value data to obtain encrypted first key-value data;

[0015] an updating module, configured to use the first processed key name, the encrypted first key value data, and the first timestamp as a first snapshot, update the historical snapshot list, and obtain an updated snapshot list; wherein the updated snapshot list includes the first snapshot and at least one historical snapshot, the first timestamp is a timestamp corresponding to the first key value data, and the timestamps corresponding to the first snapshot and at least one historical snapshot are different;

[0016] A second determining module, configured to determine the first snapshot as a valid snapshot;

[0017] A rollback module is used to update, if a data rollback request is received, a snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp as the valid snapshot according to the target timestamp in the data rollback request; wherein the target timestamp is less than or equal to the first timestamp.

[0018] In a third aspect, the present application further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the data storage method as described in any one of the present applications is implemented.

[0019] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any data storage method as described in the present application.

[0020] In a fifth aspect, the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements any data storage method as described in the present application.

[0021] The technical solution provided by the present application includes: processing the first key name of the first key-value data to be stored to obtain the first processed key name; encrypting the first key-value data to obtain the encrypted first key-value data; using the first processed key name, the encrypted first key-value data and the first timestamp as the first snapshot, updating the historical snapshot list to obtain the updated snapshot list, wherein the updated snapshot list includes the first snapshot and at least one historical snapshot, the first timestamp is the timestamp corresponding to the first key-value data, and the timestamps corresponding to the first snapshot and at least one historical snapshot are different; determining the first snapshot as a valid snapshot; if a data rollback request is received, according to the target timestamp in the data rollback request, updating the snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp as a valid snapshot, wherein the target timestamp is less than or equal to the first timestamp. On the one hand, by storing the first snapshot and at least one historical snapshot, it is realized that the valid snapshot can be updated according to the target timestamp in the data rollback request later, which is equivalent to realizing the recovery of historical data, avoiding the risk of data loss, and enhancing the fault tolerance of data operations, and improving the reliability, security and flexibility of data storage. On the other hand, by processing the key name, it is ensured that the data stored in multiple users and multiple environments do not conflict, and the consistency of the data is improved. At the same time, the first key value data can be encrypted and stored, further ensuring the security of data storage. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0023] Figure 1 A schematic diagram of an application scenario of the data storage method provided in an embodiment of the present application;

[0024] Figure 2 A schematic diagram of a data storage method provided in an embodiment of the present application;

[0025] Figure 3 is a structural schematic diagram of the first snapshot;

[0026] Figure 4 A schematic diagram of a flow chart of another data storage method provided in an embodiment of the present application;

[0027] Figure 5 Schematic diagram of obtaining the second snapshot in different scenarios;

[0028] Figure 6A flowchart of another data storage method provided in an embodiment of the present application;

[0029] Figure 7 A schematic diagram for obtaining a third snapshot;

[0030] Figure 8 A schematic diagram for obtaining a fourth snapshot;

[0031] Fig. 9 A flowchart of another data storage method provided in an embodiment of the present application;

[0032] Fig.10 A flowchart of another data storage method provided in an embodiment of the present application;

[0033] Fig.11 A schematic diagram of the structure of a data storage device provided in an embodiment of the present application;

[0034] Fig.12 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0035] The present application will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present application, rather than to limit the present application. It should also be noted that, for ease of description, only the parts related to the present application, rather than all structures, are shown in the accompanying drawings.

[0036] It should be noted that similar numbers and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. At the same time, in the description of this application, the terms "first", "second" and "third" are only used to distinguish the description and cannot be understood as indicating or implying relative importance. The acquisition, storage, use, processing, etc. of data in the technical solution of this application comply with the relevant provisions of national laws and regulations. It should be noted that in the embodiments of this application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. The purpose is only to illustrate the feasibility of the implementation of the technical solution of this application, but it does not mean that the applicant has or will necessarily use the solution.

[0037] Figure 1 A schematic diagram of an application scenario of the data storage method provided in the embodiment of the present application. Figure 1 As shown, the data storage method provided in this embodiment can be applied to Figure 1In the electronic device 11 shown. The electronic device 11 in this embodiment can be a computer device, a user equipment (User Equipment, referred to as: UE). The user equipment in this embodiment can be a mobile phone, a tablet computer, a laptop computer, a vehicle terminal or other devices. A browser 13 is installed on the electronic device 11 in this embodiment. The user 12 can obtain data on the Internet through the browser 13 on the electronic device 11. When the user uses the browser, the LocalStorage technology can store the information entered by the user or the information of the web page in the browser locally, that is, locally in the electronic device 11, to improve the efficiency of the user's subsequent acquisition of data.

[0038] LocalStorage technology is a website (Web) storage mechanism that allows web applications to store data in the user's browser. The data will be persisted in the browser until explicitly deleted. LocalStorage provides a simple way to store data and is suitable for non-sensitive information that needs to be saved for a long time, such as user settings, application status, etc. LocalStorage technology has the following characteristics. 1. Persistence: The stored data still exists after the browser session ends unless it is explicitly cleared. 2. Storage capacity: Compared with small text files (Cookies), LocalStorage technology provides a larger storage space, typically 5-10 megabytes (MB). 3. Ease of use: The application programming interface (Application Programming Interface, referred to as: API) is simple, and developers can easily store, read and delete data.

[0039] In the related art, LocalStorage technology only stores the latest data when storing data. When the user needs to restore the historical data stored in the browser locally, that is, when the data needs to be rolled back, the historical data cannot be restored. Therefore, there is a technical problem of low reliability of the stored data. The electronic device 11 in this embodiment can store multiple snapshots by executing the data storage method provided in this embodiment. When the data is rolled back, the specified historical snapshot can be restored, thereby improving the reliability and security of data storage.

[0040] The data storage method of the present application is further described in detail below through several specific embodiments.

[0041] Figure 2 The present invention provides a flow chart of a data storage method according to an embodiment of the present invention. The method can be performed by a data storage device, which can be implemented in the form of hardware and / or software, and can be configured in an electronic device. The electronic device here can be Figure 1 For example, the electronic device in this embodiment may be a computer device. Figure 2 As shown, the data storage method provided in this embodiment includes the following steps.

[0042] Step 201: Process the first key name of the first key-value data to be stored to obtain a first processed key name.

[0043] In this embodiment, the electronic device may execute step 201 under a user's trigger instruction. Alternatively, the electronic device automatically executes step 201 when detecting that the data storage condition is met. Alternatively, the electronic device automatically executes step 201 at a preset frequency. In this embodiment, data can be stored in the form of key-value pairs.

[0044] In the related art, when LocalStorage technology stores data in multiple users and multiple environments, it does not process the key names between different applications or components under the same domain name, which may cause data conflicts. For example, for the domain name www.XXXX.com.cn, the key name of the user data of application A is user, and the key name of the user data of application B is also user, which will cause data conflicts.

[0045] In this embodiment, when storing data, in order to avoid key name conflicts, the first key name of the first key value data to be stored is processed to obtain a first processed key name.

[0046] Optionally, the first key name can be processed in the following manner to obtain a first processed key name: according to the mapping relationship between the preset processing method and the attribute information of the key name, as well as the attribute information of the first key name, determine the first target processing method corresponding to the first key name; according to the first target processing method, process the first key name of the first key value data to obtain the first processed key name. This processing method can determine the first target processing method corresponding to the first key name based on the mapping relationship and the attribute information of the first key name, realize the efficient determination of the target processing method corresponding to the key name, and improve the efficiency of data storage while avoiding key name conflicts.

[0047] Furthermore, the first target processing method includes at least one of the following processing methods: adding a prefix, adding a suffix, changing the characters at the target position, adding characters at the target position, and deleting characters at the target position.

[0048] The attribute information of the key name in this embodiment may include at least one of the following: the application corresponding to the key name, the component corresponding to the key name, the generation time corresponding to the key value data of the key name, etc. Table 1 shows the mapping relationship between the processing method and the attribute information of the key name. Table 1 takes the attribute information of the key name as the application corresponding to the key name and the processing method as adding a prefix as an example for illustration.

[0049] Mapping relationship between the processing methods and the attribute information of the key names in Table 1

[0050] Key attribute information Processing Application A Add prefix APP Application B Add the prefix WEB Application C Add the prefix SERVER

[0051] In this embodiment, adding a prefix means adding a specified character or string before the key name. For example, assuming the key name is user, the key name after adding the prefix APP is APP_user or APPuser.

[0052] Adding a suffix means adding a specified character or string after the key name. For example, assuming the key name is user, the key name after adding the suffix APP is user_APP or userAPP.

[0053] Changing the character at the target position means changing the character at the target position to a different specified character for the key names of different attribute information. For example, for the key name of Application A, changing the first character to a specific character, such as changing it to 1, that is, changing user to 1ser; for the key name of Application B, changing the first character to a specific character, such as changing it to 2, that is, changing user to 2ser.

[0054] Adding a character at the target position means adding a different specified character at the target position for the key names of different attribute information. For example, for the key name of Application A, adding a specific character, such as adding 11, after the third character, that is, changing user to use11r; for the key name of Application B, adding a specific character, such as adding 22, after the third character, that is, changing user to use22r.

[0055] Deleting the character at the target position means deleting the character at different target positions for the key names of different attribute information. For example, for the key name of Application A, deleting the first character, that is, changing user to ser; for the key name of Application B, deleting the second character, that is, changing user to uer.

[0056] In step 201, assume that the first key-value data is: name: 'Zhang San', age: '30'. The first key name of the first key-value data is user. Assume that the first target processing method is to add the prefix APP, then the first processed key name is: APP_user.

[0057] It should be noted that the first key-value data in this embodiment can be newly generated data or data obtained by modifying a certain historical key-value data.

[0058] Step 202: Encrypt the first key-value data to obtain the encrypted first key-value data.

[0059] In the related art, when storing data, it is directly stored in plain text, which leads to security risks in the stored data and may be stolen by malicious code. In this embodiment, in order to improve the security of the stored data, the first key value data is encrypted to obtain the encrypted first key value data.

[0060] Data encryption is the process of converting data into a form that only authorized users can interpret. In this embodiment, the first key value data is encrypted when stored to protect the privacy and security of the data. Encryption ensures that the data is not accessed or leaked by unauthorized users during storage, thereby enhancing the security of the data.

[0061] Optionally, in order to improve encryption efficiency, in this embodiment, the first key value data can be encrypted and stored through a network encryption API (Web Crypto API) to improve data security. Optionally, Web Crypto is a plug-in in a built-in browser. This implementation method can improve encryption efficiency and, in turn, improve data storage efficiency.

[0062] The specific encryption process may include the following processes: key generation: using the Web Crypto API to generate a key, illustratively, the key may be an Advanced Encryption Standard (AES) key; data encryption: using the AES algorithm to encrypt the first key-value data to generate the encrypted first key-value data, i.e., ciphertext, and an initialization vector (IV).

[0063] Step 203: Use the first processed key name, the encrypted first key value data, and the first timestamp as the first snapshot, update the historical snapshot list, and obtain an updated snapshot list.

[0064] The updated snapshot list includes a first snapshot and at least one historical snapshot. The first timestamp is a timestamp corresponding to the first key value data. The timestamps corresponding to the first snapshot and at least one historical snapshot are different.

[0065] In this embodiment, the historical snapshot list and the updated snapshot list are both located in LocalStorage, that is, located locally in the electronic device.

[0066] The data storage method provided in this embodiment can store multiple snapshots to facilitate subsequent data rollback and improve the reliability of data storage. A snapshot refers to a copy of the data state recorded at a certain moment. In this embodiment, the snapshot includes encrypted key value data, processed key name, timestamp and other related information. The snapshot function allows the user to save the current state when the data changes so that it can be viewed, restored or rolled back to this state in the future. This mechanism is very important for version control and historical management of data.

[0067] A timestamp is a number or mark indicating the time when an event occurred. In this embodiment, the timestamp refers to the specific moment corresponding to the key-value data. The timestamp is used to track the historical state of the data, support snapshot sorting and rollback operations, and enable the data recovery process to accurately return to the specified time point.

[0068] In step 203, the first processed key name, the encrypted first key value data, and the first timestamp are used as the first snapshot. The first timestamp in this embodiment is the timestamp corresponding to the first key value data. Optionally, the first timestamp can be the time when the first key value data is generated. Alternatively, the first timestamp can be the time when the first key name of the first key value data is processed. Alternatively, the first timestamp can be the time when the first key value data is encrypted. Figure 3 is a schematic diagram of the structure of the first snapshot. Figure 3 As shown, the first snapshot in this embodiment includes the first processed key name, the encrypted first key value data and the first timestamp. Optionally, the first snapshot may also include other data, for example, the storage address of the first snapshot, the data volume of the first snapshot, etc.

[0069] In this embodiment, the updated snapshot list includes a first snapshot and at least one historical snapshot. The timestamps corresponding to the first snapshot and at least one historical snapshot are different. Table 2 shows the historical snapshot list. Table 3 shows the updated snapshot list. Assume that the first processed key name is APP_user, the encrypted first key value data is XXXX4, and the first timestamp is 2024.8.23, 15:40.

[0070] Table 2 Historical snapshot list

[0071] Processed key name Encrypted key value data Timestamp APP_user XXXX1 2024.8.23,15:25 APP_user XXXX2 2024.8.23,15:32 APP_user XXXX3 2024.8.23,15:37

[0072] Table 3 Updated snapshot list

[0073] Processed key name Encrypted key value data Timestamp APP_user XXXX1 2024.8.23,15:25 APP_user XXXX2 2024.8.23,15:32 APP_user XXXX3 2024.8.23,15:37 APP_user XXXX4 2024.8.23,15:40

[0074] Optionally, in order to improve the updating efficiency of the update history snapshot list, in this embodiment, a predefined data storage API can be used to update the history snapshot list by using the first processed key name, the encrypted first key value data and the first timestamp as the first snapshot to obtain an updated snapshot list. Exemplarily, the data storage API can be named setItem.

[0075] Step 204: Determine the first snapshot as a valid snapshot.

[0076] In this embodiment, the valid snapshot is used to represent the snapshot that can be normally read by the user when the user uses the browser. Taking Table 3 as an example, 4 snapshots are stored in the updated snapshot list. If the user needs to read a snapshot from the updated snapshot list while using the browser, if the valid snapshot is not set, it will cause reading confusion, that is, it is impossible to determine which snapshot should be read from the 4 snapshots.

[0077] In this embodiment, after each new snapshot is stored, that is, after the first snapshot is stored, the latest stored snapshot is set as a valid snapshot, because the latest stored snapshot is generally the latest data. This is also in line with the general rule of users using browsers.

[0078] In the first implementation, the first snapshot corresponds to a flag. The implementation process of step 204 may include: setting the flag of the valid snapshot in the historical snapshot list to an invalid value; setting the flag of the first snapshot to a valid value. For example, 1 represents a valid value and 0 represents an invalid value. Assuming that the valid snapshot in Table 2 is APP_user, XXXX3, 2024.8.23, 15:37, then the flag of the valid snapshot is set from 1 to 0, and the flag of the first snapshot in Table 3 is set to 1.

[0079] In the second implementation, the historical snapshot list corresponds to a valid snapshot identifier. The implementation process of step 204 may include: updating the valid snapshot identifier of the updated snapshot list to the identifier of the first snapshot. This implementation can quickly update the valid snapshot, further improving the data storage efficiency. For example, 1 represents a valid value and 0 represents an invalid value. Assuming that the valid snapshot in Table 2 is APP_user, XXXX3, 2024.8.23, 15:37, the identifier of the snapshot is 0003, and the identifier of the first snapshot in Table 3 is 0004. Update the valid snapshot identifier of the updated snapshot list from 0003 to 0004.

[0080] Step 205: If a data rollback request is received, then according to the target timestamp in the data rollback request, the snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp is updated as a valid snapshot.

[0081] The target timestamp is less than or equal to the first timestamp.

[0082] When a user uses a browser, there may be a scenario where, after an application update or a user erroneous operation, the stored data needs to be restored to historical data, that is, data rollback needs to be implemented.

[0083] Rollback is the process of restoring data to a previous state. In this embodiment, the rollback function enables the user to restore the valid snapshot in the updated snapshot list to a specified historical snapshot. The rollback function is used to correct erroneous operations or restore data to a specific point in time, which helps data recovery and error correction, and improves the flexibility and reliability of data storage.

[0084] In the data storage technology of the related art, the data snapshot function cannot be implemented, which means that once the data is modified or deleted, the existing technology cannot save the previous state. This means that if an error or accident occurs during the data operation of the user or the system, the data cannot be restored to the state before the error occurs, which brings the risk of data loss and reduces the user experience. This makes data operations irreversible, and once modified or deleted, they cannot be restored. When the user needs to restore the stored data to a certain historical time point, the related technology cannot meet this demand. This greatly limits the flexibility of using stored data in application scenarios that require frequent undo operations or restoration to historical versions.

[0085] Snapshot and rollback have the following effects. Ensure data security and reliability: In complex Web applications, the frequency and complexity of data operations increase the possibility of data errors. The snapshot and rollback functions allow the current storage state to be saved after each data operation, and the data can be restored to a specified historical state when needed. This function greatly improves the security and reliability of data operations and avoids data loss or damage caused by operational errors. Optimize user experience: For applications that need to undo operations or restore historical data, such as online editors, form data saving and other scenarios, snapshot and rollback functions can provide a better user experience. Users can roll back to the previous state at any time without worrying about losing data due to misoperation.

[0086] The data rollback request in this embodiment may be triggered by a user or a developer. Alternatively, it may be automatically generated by the electronic device when it detects that the rollback condition is met. The data rollback request in this embodiment includes a target timestamp. It is understood that the target timestamp is less than or equal to the first timestamp.

[0087] When rolling back data, the snapshot whose corresponding timestamp is before the target timestamp and closest to the target timestamp in the updated snapshot list is updated as a valid snapshot. The specific implementation of the valid snapshot update process is similar to the valid snapshot update process in step 204, which will not be repeated here.

[0088] For example, taking Table 3 as an example, assuming that the target timestamp is 2024.8.23, 15:38, then in the updated snapshot list, the snapshot whose corresponding timestamp is before the target timestamp and closest to the target timestamp is APP_user, XXXX3, 2024.8.23, 15:37, and the valid snapshot is updated from the first snapshot to this snapshot.

[0089] Optionally, in order to improve the rollback efficiency, the implementation process of step 205 can be: through a predefined data rollback API, according to the target timestamp in the data rollback request, the snapshot whose corresponding timestamp is before the target timestamp and closest to the target timestamp in the updated snapshot list is updated as a valid snapshot. Exemplarily, the data rollback API can be named rollbackItem.

[0090] Optionally, in order to further improve the security of data, the data storage method provided in this embodiment can perform tamper-proof verification on the data rollback request. Tamper-proof verification is a process of ensuring that data has not been modified or tampered with without authorization by technical means. Optionally, in this embodiment, the data rollback request is verified by means of hash values ​​and the like. Tamper-proof verification ensures the consistency and reliability of the snapshot during the rollback process, protects the data from malicious modification or attack, and ensures the credibility of the data.

[0091] After receiving the data rollback request, before updating the snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp as a valid snapshot according to the target timestamp in the data rollback request, the method further includes the following steps: obtaining verification information of the data rollback request, wherein the verification information includes at least one of the following: source information of the data rollback request and the occurrence frequency of the data rollback request; verifying the security of the data rollback request according to the verification information of the data rollback request, and determining the verification result of the data rollback request; when the verification result of the data rollback request is verification passed, determining to execute the step of "updating the snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp as a valid snapshot according to the target timestamp in the data rollback request". Optionally, when the verification result of the data rollback request is verification failed, refusing to execute the step of "updating the snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp as a valid snapshot according to the target timestamp in the data rollback request".

[0092] Optionally, the implementation process of verifying the security of the data rollback request based on the verification information of the data rollback request and determining the verification result of the data rollback request may include the following process: when it is determined based on the source information of the data rollback request that the data rollback request is from a device that has the permission to roll back, determining whether the frequency of occurrence of the data rollback request is less than a frequency threshold; when it is determined whether the frequency of occurrence of the data rollback request is less than the frequency threshold, determining that the verification result of the data rollback request is a passed verification; when it is determined based on the source information of the data rollback request that the data rollback request is from a device that has no permission to roll back, determining that the verification result of the data rollback request is a failed verification; when it is determined based on the source information of the data rollback request that the data rollback request is from a device that has the permission to roll back, but the frequency of occurrence of the data rollback request is greater than or equal to the frequency threshold, determining that the verification result of the data rollback request is a failed verification.

[0093] Furthermore, when it is determined based on the source information of the data rollback request that the data rollback request comes from a device with permission to roll back, the following process may be included: based on the source information of the data rollback request, determining a hash value of the source information; based on the hash value of the source information, determining whether the data rollback request comes from a device with permission to roll back.

[0094] The data storage method provided in this embodiment has the following effects.

[0095] First, it improves the flexibility of data management. Every time the data changes, the system automatically generates a snapshot to record the current storage status. This allows developers and users to go back, view or restore historical data at any point in time during data operations. The snapshot mechanism greatly improves the flexibility of data management, especially in application scenarios where data needs to be frequently updated or adjusted, and can effectively track and manage data changes. When an erroneous operation or data anomaly occurs, users can use the rollback function to restore the data to a specified historical state. This function not only avoids the risk of data loss, but also enhances the fault tolerance of data operations. The rollback function allows users to easily correct errors and improves the security and reliability of data operations.

[0096] Second, data security and consistency are improved. All key-value data in snapshots are encrypted during storage to prevent unauthorized access and data leakage. This measure ensures the security of data in local storage, especially when processing sensitive data, and can effectively protect user privacy and data confidentiality. Furthermore, during snapshot recovery or rollback, the system will verify the integrity of the data to ensure that it has not been tampered with. Through technical means such as hash verification, external attacks or malicious tampering can be discovered and prevented in a timely manner, ensuring data consistency and reliability.

[0097] Third, friendly operation experience. This embodiment provides a simple and easy-to-use API interface, and developers can easily integrate snapshot and rollback functions without additional complex configuration. Even in complex application scenarios, developers can quickly implement data version control and recovery.

[0098] Fourth, improve the fault tolerance of data operations. With the ability to quickly correct errors, through the snapshot and rollback functions, users can quickly correct errors in operations and restore to the correct data state. This rapid error correction capability enables applications to respond quickly to emergencies, reduces the impact of data corruption, and ensures the stability and continuity of the system. With data version control, the snapshot mechanism is equivalent to introducing a version control function for data, and users can return to a certain version of the data state at any time. This plays an important role in data analysis, debugging, or recovery of historical data, making the management of locally stored data more sophisticated and reliable.

[0099] Fifth, avoid key name conflicts. By processing key names, it ensures that data in multiple users and multiple environments do not conflict and can be effectively managed.

[0100] The data storage method provided in this embodiment includes: processing the first key name of the first key-value data to be stored to obtain the first processed key name; encrypting the first key-value data to obtain the encrypted first key-value data; using the first processed key name, the encrypted first key-value data and the first timestamp as the first snapshot, updating the historical snapshot list to obtain the updated snapshot list, wherein the updated snapshot list includes the first snapshot and at least one historical snapshot, the first timestamp is the timestamp corresponding to the first key-value data, and the timestamps corresponding to the first snapshot and at least one historical snapshot are different; determining the first snapshot as a valid snapshot; if a data rollback request is received, according to the target timestamp in the data rollback request, updating the snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp as a valid snapshot, wherein the target timestamp is less than or equal to the first timestamp. On the one hand, by storing the first snapshot and at least one historical snapshot, it is realized that the valid snapshot can be updated according to the target timestamp in the data rollback request later, which is equivalent to realizing the recovery of historical data, avoiding the risk of data loss, and enhancing the fault tolerance of data operation, and improving the reliability, security and flexibility of data storage. On the other hand, by processing the key name, it is ensured that the data stored in multiple users and multiple environments do not conflict, and the consistency of the data is improved. At the same time, the first key value data can be encrypted and stored, further ensuring the security of data storage.

[0101] Figure 4 A flowchart of another data storage method provided in an embodiment of the present application. Figure 2 Based on the illustrated embodiment and various optional implementations, the steps of how to implement data reading are described in detail. Figure 4 As shown, the data storage method provided in this embodiment includes the following steps.

[0102] Step 401: Process the first key name of the first key-value data to be stored to obtain a first processed key name.

[0103] Step 402: Encrypt the first key value data to obtain encrypted first key value data.

[0104] Step 403: Use the first processed key name, the encrypted first key value data, and the first timestamp as the first snapshot, update the historical snapshot list, and obtain an updated snapshot list.

[0105] The updated snapshot list includes a first snapshot and at least one historical snapshot, the first timestamp is a timestamp corresponding to the first key-value data, and the timestamps corresponding to the first snapshot and the at least one historical snapshot are different.

[0106] Step 404: Determine the first snapshot as a valid snapshot.

[0107] Step 405: If a data rollback request is received, then according to the target timestamp in the data rollback request, the snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp is updated as a valid snapshot.

[0108] The target timestamp is less than or equal to the first timestamp.

[0109] The implementation process and technical principles of step 401 and step 201, step 402 and step 202, step 403 and step 203, step 404 and step 204, and step 405 and step 205 are similar and will not be repeated here.

[0110] Step 406: Receive a data read request.

[0111] The data read request includes the second key name.

[0112] In this embodiment, data can be read from the stored data. The data read request in this embodiment can be triggered by a user or a developer. Or, it can be automatically generated by the electronic device when it detects that the data read condition is met. The second key name in this embodiment refers to the key name corresponding to the data to be read.

[0113] Step 407: Process the second key name to obtain a second processed key name.

[0114] As shown in step 201 and step 401, when storing data, in order to avoid data conflicts, the key name is processed. Therefore, when reading data, in order to ensure that the data can be successfully read, the second key name also needs to be processed first to obtain the second processed key name.

[0115] Optionally, the implementation process of step 407 may be: determining the second target processing method corresponding to the second key name according to the mapping relationship and the attribute information of the second key name; processing the second key name according to the second target processing method to obtain the second processed key name. This processing method can determine the second target processing method corresponding to the second key name based on the mapping relationship and the attribute information of the second key name, realizes efficient determination of the target processing method corresponding to the key name, and improves the efficiency of data reading.

[0116] Optionally, the second target processing method includes at least one of the following processing methods: adding a prefix, adding a suffix, changing the characters at the target position, adding characters at the target position, and deleting characters at the target position.

[0117] The attribute information of the key name in this embodiment is similar to the attribute information of the key name in step 201, and will not be repeated here. The specific implementation of the second target processing method in this embodiment is similar to the specific implementation of the first target processing method in step 201, and will not be repeated here.

[0118] Step 408: Read the second snapshot whose corresponding processed key name is the same as the second processed key name from the updated snapshot list.

[0119] The second snapshot is a valid snapshot.

[0120] After the second processed key name is determined, a second snapshot having the same processed key name as the second processed key name is read from the updated snapshot list. In addition, the second snapshot in this embodiment is a valid snapshot.

[0121] Figure 5 Schematic diagrams of obtaining the second snapshot in different scenarios. Based on the two implementation methods of marking the valid snapshot in step 204, Figure 5 Schematic diagrams showing acquisition of the second snapshot in different scenarios.

[0122] like Figure 5 As shown in the left figure in , in the implementation method where each snapshot has a flag bit corresponding to it, first determine each snapshot whose corresponding processed key name is the same as the second processed key name from the updated snapshot list. Then, traverse the flag bit of each snapshot in the snapshots, determine the snapshot whose corresponding flag bit is a valid value as the second snapshot, and read the second snapshot. In this implementation method, the processed key names corresponding to each snapshot in the updated snapshot list can be the same or different.

[0123] like Figure 5 As shown in the right figure of , in an implementation method in which the historical snapshot list corresponds to a valid snapshot identifier, an updated snapshot list including snapshots corresponding to the same processed key name as the second processed key name is first determined. The snapshot corresponding to the valid snapshot identifier of the updated snapshot list is determined as the second snapshot, and the second snapshot is read. In this implementation method, the processed key names corresponding to the snapshots in the updated snapshot list are the same.

[0124] Step 409: decrypt the encrypted second key-value data in the second snapshot to obtain the second key-value data.

[0125] Since the first key-value data is stored in encrypted form in step 202 , in step 409 , after obtaining the encrypted second key-value data in the second snapshot, the encrypted second key-value data needs to be decrypted to obtain the second key-value data.

[0126] Optionally, in order to improve the efficiency of data reading, steps 407 to 409 may be implemented through a data reading API. Exemplarily, the data reading API may be named getItem.

[0127] The data storage method provided in this embodiment receives a data reading request, wherein the data reading request includes a second key name, processes the second key name to obtain a second processed key name, reads a second snapshot whose corresponding processed key name is the same as the second processed key name from the updated snapshot list, wherein the second snapshot is a valid snapshot, decrypts the encrypted second key value data in the second snapshot to obtain the second key value data, thereby realizing efficient and reliable reading of the correct second key value data.

[0128] Figure 6 A flowchart of another data storage method provided in an embodiment of the present application. The data storage method provided in this embodiment, Figure 2 , Figure 4 Based on the illustrated embodiment and various optional implementations, a detailed description is given of how to obtain an updated snapshot list. Figure 6 As shown, the data storage method provided in this embodiment includes the following steps.

[0129] Step 601: Process the first key name of the first key-value data to be stored to obtain a first processed key name.

[0130] Step 602: Encrypt the first key value data to obtain encrypted first key value data.

[0131] The implementation methods and technical principles of step 601 and step 201, and step 602 and step 202 are similar, and will not be repeated here.

[0132] Step 603: Use the first processed key name, the encrypted first key value data and the first timestamp as the first snapshot, and obtain a third snapshot in the historical snapshot list whose corresponding timestamp is before the first timestamp and closest to the first timestamp.

[0133] In this embodiment, in order to save storage space, when updating the first snapshot to the snapshot list, an incremental storage method is used to record only the data part that is different from the previous snapshot, rather than completely copying all the data of the first snapshot. The previous snapshot in this embodiment refers to the third snapshot in the historical snapshot list, whose corresponding timestamp is before the first timestamp and closest to the first timestamp. Taking Table 3 as an example, the third snapshot includes: APP_user, XXXX3, 2024.8.23, 15:37.

[0134] This storage method can reduce storage space usage. For frequently changing data, this mechanism significantly reduces storage requirements, improves storage efficiency, and can also increase the read speed of snapshots. At the same time, this efficient storage method can maintain low storage usage even in the case of frequent data changes, thereby improving the operating efficiency of electronic devices.

[0135] More specifically, the process of obtaining the third snapshot in the historical snapshot list in step 603, whose corresponding timestamp is before the first timestamp and closest to the first timestamp, may include the following steps 6031 to 6033.

[0136] Step 6031: If the timestamp corresponding to the third snapshot is the earliest timestamp in the historical snapshot list, the third snapshot is acquired.

[0137] The snapshot corresponding to the earliest timestamp in the historical snapshot list must be the fully stored snapshot. Therefore, if the timestamp corresponding to the third snapshot is the earliest timestamp in the historical snapshot list, the third snapshot can be directly obtained.

[0138] Step 6032: If the timestamp corresponding to the third snapshot is not the earliest timestamp in the historical snapshot list, obtain difference information corresponding to each snapshot whose corresponding timestamp is between the timestamp corresponding to the third snapshot and the earliest timestamp.

[0139] If the timestamp corresponding to the third snapshot is not the earliest timestamp in the historical snapshot list, the third snapshot needs to be restored first according to the stored difference information. Therefore, in step 6032, the difference information corresponding to each snapshot whose corresponding timestamp is between the timestamp corresponding to the third snapshot and the earliest timestamp is obtained.

[0140] Step 6033: Determine the third snapshot according to the snapshot corresponding to the earliest timestamp, the difference information corresponding to each snapshot, and the difference information corresponding to the third snapshot.

[0141] After obtaining each difference information, the third snapshot can be determined based on the snapshot corresponding to the earliest timestamp, the difference information corresponding to each snapshot, and the difference information corresponding to the third snapshot. During the recovery process, the recovery can be performed one by one in the order of timestamps: first, based on the difference information of the snapshot corresponding to the earliest timestamp and the snapshot corresponding to the second earliest timestamp, the snapshot corresponding to the second earliest timestamp is determined; then, based on the difference information of the snapshot corresponding to the second earliest timestamp and the snapshot corresponding to the third earliest timestamp, the snapshot corresponding to the third earliest timestamp is determined; and so on, until the third snapshot is determined.

[0142] Figure 7 is a schematic diagram of obtaining the third snapshot. Figure 7 As shown, it is assumed that the historical snapshot list includes 5 snapshots. In order from the front to the back of the timestamp, they are: snapshot 71, snapshot 72, snapshot 73, snapshot 74 and snapshot 75. That is, the timestamp corresponding to snapshot 71 is the earliest, and the timestamp corresponding to snapshot 75 is the latest. When storing, the data stored in the historical snapshot list is: the full information of snapshot 71, the difference information of snapshot 72, the difference information of snapshot 73, the difference information of snapshot 74 and the difference information of snapshot 75. When updating the historical snapshot list, snapshot 75 is the third snapshot in this embodiment. When determining the third snapshot, first obtain the difference information corresponding to each snapshot whose corresponding timestamp is between the timestamp corresponding to the third snapshot and the earliest timestamp, that is, obtain the difference information of snapshot 72, the difference information of snapshot 73 and the difference information of snapshot 74. Then, according to the full information of snapshot 71 and the difference information of snapshot 72, determine the full information of snapshot 72. According to the full information of snapshot 72 and the difference information of snapshot 73, determine the full information of snapshot 73. The full amount information of snapshot 74 is determined based on the full amount information of snapshot 73 and the difference information of snapshot 74. The full amount information of snapshot 74 is determined based on the difference information of snapshot 75 and the difference information of snapshot 75.

[0143] Step 604: Compare the first snapshot with the third snapshot to obtain first difference information corresponding to the first snapshot.

[0144] The first difference information is used to represent the difference between the first snapshot and the third snapshot.

[0145] After the third snapshot is determined, the first snapshot is compared with the third snapshot to obtain first difference information corresponding to the first snapshot, that is, an increment of the first snapshot compared to the third snapshot is determined.

[0146] Step 605: Update the first difference information corresponding to the first snapshot into the historical snapshot list to obtain an updated snapshot list.

[0147] The updated snapshot list includes a first snapshot and at least one historical snapshot. The first timestamp is a timestamp corresponding to the first key value data. The timestamps corresponding to the first snapshot and at least one historical snapshot are different.

[0148] In step 605, the first difference information corresponding to the first snapshot is updated to the historical snapshot list to obtain an updated snapshot list, thereby realizing incremental storage.

[0149] Step 606: Determine the first snapshot as a valid snapshot.

[0150] Step 607: If a data rollback request is received, then according to the target timestamp in the data rollback request, the snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp is updated as a valid snapshot.

[0151] The target timestamp is less than or equal to the first timestamp.

[0152] The implementation process and technical principle of step 606 and step 204, and step 607 and step 205 are similar, and will not be repeated here.

[0153] Step 608: Receive a data read request.

[0154] The data read request includes the second key name.

[0155] The implementation process and technical principle of step 608 are similar to those of step 406 and will not be repeated here.

[0156] Step 609: Process the second key name to obtain a second processed key name.

[0157] The implementation process and technical principle of step 609 are similar to those of step 407 and will not be repeated here.

[0158] Step 610: Read the second snapshot whose corresponding processed key name is the same as the second processed key name from the updated snapshot list.

[0159] The second snapshot is a valid snapshot.

[0160] Optionally, based on the implementation method of incremental storage, the implementation process of step 610 may include the following steps: reading from the updated snapshot list the second difference information corresponding to the second snapshot whose corresponding processed key name is the same as the second processed key name; obtaining from the updated snapshot list the fourth snapshot whose corresponding timestamp is before the second timestamp corresponding to the second snapshot and is closest to the second timestamp; determining the second snapshot based on the fourth snapshot and the second difference information.

[0161] Among them, the implementation method of obtaining the fourth snapshot is similar to the implementation method of obtaining the third snapshot: if the timestamp corresponding to the fourth snapshot is the earliest timestamp in the historical snapshot list, then the fourth snapshot is obtained; if the timestamp corresponding to the fourth snapshot is not the earliest timestamp in the historical snapshot list, then the difference information corresponding to each snapshot whose corresponding timestamp is between the timestamp corresponding to the fourth snapshot and the earliest timestamp is obtained; the fourth snapshot is determined based on the snapshot corresponding to the earliest timestamp, the difference information corresponding to each snapshot, and the difference information corresponding to the fourth snapshot.

[0162] Figure 8 Schematic diagram of obtaining the fourth snapshot. Figure 8 As shown, it is assumed that the updated snapshot list includes 6 snapshots. In order from the front to the back of the timestamp, they are: snapshot 81, snapshot 82, snapshot 83, snapshot 84, snapshot 85 and snapshot 86. When storing, the data stored in the updated snapshot list is: full information of snapshot 81, difference information of snapshot 82, difference information of snapshot 83, difference information of snapshot 84, difference information of snapshot 85 and difference information of snapshot 86. Assuming that the second snapshot is snapshot 85, the fourth snapshot is snapshot 84. When determining snapshot 84, first obtain the difference information corresponding to each snapshot whose corresponding timestamp is between the timestamp corresponding to the fourth snapshot and the earliest timestamp, that is, obtain the difference information of snapshot 82 and the difference information of snapshot 83. Then, according to the full information of snapshot 81 and the difference information of snapshot 82, determine the full information of snapshot 82. According to the full information of snapshot 82 and the difference information of snapshot 83, determine the full information of snapshot 83. According to the full information of snapshot 83 and the difference information of snapshot 84, determine snapshot 84.

[0163] Step 611: decrypt the encrypted second key-value data in the second snapshot to obtain the second key-value data.

[0164] The implementation process and technical principle of step 611 are similar to those of step 409 and will not be repeated here.

[0165] The data storage method provided in this embodiment, when storing a first snapshot, obtains a third snapshot in the historical snapshot list, whose corresponding timestamp is before the first timestamp and closest to the first timestamp, compares the first snapshot with the third snapshot, and obtains first difference information corresponding to the first snapshot, wherein the first difference information is used to characterize the difference between the first snapshot and the third snapshot, updates the first difference information corresponding to the first snapshot to the historical snapshot list, and obtains an updated snapshot list, thereby realizing incremental storage, reducing the occupancy of storage space, and improving storage efficiency.

[0166] Fig. 9 A flowchart of another data storage method provided in an embodiment of the present application. Figure 2 , Figure 4 and Figure 6 Based on the illustrated embodiment and various optional implementations, the implementation after obtaining the updated snapshot list is described in detail. For the sake of simplicity, this embodiment only shows the steps after obtaining the updated snapshot list in step 204. Fig. 9 As shown, the data storage method provided in this embodiment also includes the following steps.

[0167] Step 901: when it is determined that the number of snapshots included in the updated snapshot list is greater than a preset maximum number threshold, obtain the snapshot corresponding to the earliest timestamp and the difference information of the snapshot corresponding to the second earliest timestamp.

[0168] In order to prevent storage resources from being wasted due to excessive number of snapshots, this embodiment provides an automatic cleanup strategy. When the snapshots reach the preset maximum number threshold, the earliest snapshots will be automatically cleaned up according to the strategy to ensure the rational use of storage resources and the continuous availability of local storage.

[0169] In this embodiment, the preset maximum number threshold is used to represent the maximum number of snapshots that can be included in the updated snapshot list. In order to avoid the problem that after deleting the snapshot corresponding to the earliest timestamp, the snapshot cannot be restored based on the difference information of other snapshots, in step 901, when it is determined that the number of snapshots included in the updated snapshot list is greater than the preset maximum number threshold, the snapshot corresponding to the earliest timestamp and the difference information of the snapshot corresponding to the next earliest timestamp are obtained, so as to restore the snapshot corresponding to the next earliest timestamp.

[0170] Step 902: Determine the snapshot corresponding to the next earliest timestamp based on difference information between the snapshot corresponding to the earliest timestamp and the snapshot corresponding to the next earliest timestamp.

[0171] Step 903: Delete the snapshot corresponding to the earliest timestamp.

[0172] In step 902, the snapshot corresponding to the next earliest timestamp is determined, so that after deleting the snapshot corresponding to the earliest timestamp, the updated snapshot list still stores all the snapshots, without affecting the storage process of subsequent snapshots or the subsequent snapshot reading process.

[0173] It should be noted that, in step 901, it may be determined that the snapshot corresponding to the earliest timestamp needs to be deleted when the storage duration of the snapshot corresponding to the earliest timestamp is greater than a preset storage duration threshold.

[0174] In this embodiment, the following method can also be executed at a preset frequency to clear redundant snapshots and save storage space: determine whether there are duplicate snapshots in the updated snapshot list; when it is determined that there are duplicate snapshots, perform a deduplication operation so that there are no duplicate snapshots in the updated snapshot list after the deduplication operation.

[0175] The data storage method provided in this embodiment can prevent waste of storage resources due to excessive number of snapshots, and at the same time, the deletion process will not affect the storage process of subsequent snapshots, nor will it affect the subsequent snapshot reading process, thus having high security.

[0176] Fig.10 A flowchart of another data storage method provided in an embodiment of the present application. Figure 2 , Figure 4 , Figure 6 and Fig. 9 Based on the illustrated embodiment and various optional implementations, a detailed description is given of how to roll back a key name.

[0177] In this embodiment, there are multiple updated snapshot lists. The processed key names of the snapshots in the same updated snapshot list are the same. The processed key names of the snapshots in different updated snapshot lists are different. The data rollback request also includes a rollback key name.

[0178] like Fig.10 As shown, the data storage method provided in this embodiment includes the following steps.

[0179] Step 1001: Process the first key name of the first key-value data to be stored to obtain a first processed key name.

[0180] Step 1002: Encrypt the first key value data to obtain encrypted first key value data.

[0181] Step 1003: Use the first processed key name, the encrypted first key value data, and the first timestamp as the first snapshot, update the historical snapshot list, and obtain an updated snapshot list.

[0182] The updated snapshot list includes a first snapshot and at least one historical snapshot. The first timestamp is a timestamp corresponding to the first key value data. The timestamps corresponding to the first snapshot and at least one historical snapshot are different.

[0183] Step 1004: Determine the first snapshot as a valid snapshot.

[0184] The implementation process and technical principles of step 1001 and step 201, step 1002 and step 202, step 1003 and step 203, and step 1004 and step 204 are similar and will not be repeated here.

[0185] Step 1005: If a data rollback request is received, a third target processing method corresponding to the rollback key name is determined according to the mapping relationship and the attribute information of the rollback key name.

[0186] Step 1006: According to the third target processing method, the rollback key name is processed to obtain a processed rollback key name.

[0187] In this embodiment, based on the mapping relationship and the attribute information of the rollback key name, the third target processing method corresponding to the rollback key name is determined, and the rollback key name is processed according to the third target processing method. The implementation process of obtaining the processed rollback key name is similar to the implementation process of obtaining the first processed key name in step 201, and will not be repeated here.

[0188] Furthermore, the third target processing method includes at least one of the following processing methods: adding a prefix, adding a suffix, changing the characters at the target position, adding characters at the target position, and deleting characters at the target position.

[0189] Step 1007: Determine the target updated snapshot list corresponding to the data rollback request according to the processed rollback key name.

[0190] Since there are multiple updated snapshot lists in this embodiment, it is necessary to first determine the target updated snapshot list corresponding to the data rollback request. The processed key name corresponding to the snapshot in the target updated snapshot list is the same as the processed rollback key name.

[0191] Step 1008: According to the target timestamp in the data rollback request, the snapshot in the target updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp is updated as a valid snapshot.

[0192] The target timestamp is less than or equal to the first timestamp.

[0193] Step 1008 is similar to the implementation process of updating the valid snapshot in step 205, and will not be described again here.

[0194] The data storage method provided in this embodiment can realize the rollback of data with a specific rollback key name, realize refined rollback, avoid unnecessary data changes that may be caused by global rollback, and further improve data reliability.

[0195] Fig.11 A schematic diagram of a data storage device provided in an embodiment of the present application. Fig.11 As shown, the data storage device provided in this embodiment includes the following modules: a first determination module 111 , an encryption module 112 , an update module 113 , a second determination module 114 and a rollback module 115 .

[0196] The first determining module 111 is used to process the first key name of the first key-value data to be stored to obtain a first processed key name.

[0197] The encryption module 112 is used to encrypt the first key-value data to obtain encrypted first key-value data.

[0198] The updating module 113 is configured to update the historical snapshot list by taking the first processed key name, the encrypted first key value data and the first timestamp as the first snapshot to obtain an updated snapshot list.

[0199] The updated snapshot list includes the first snapshot and at least one historical snapshot, the first timestamp is a timestamp corresponding to the first key-value data, and the timestamps corresponding to the first snapshot and at least one historical snapshot are different.

[0200] The second determining module 114 is configured to determine the first snapshot as a valid snapshot.

[0201] The rollback module 115 is configured to update, if a data rollback request is received, a snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp as the valid snapshot according to the target timestamp in the data rollback request.

[0202] The target timestamp is less than or equal to the first timestamp.

[0203] In one embodiment, the device further includes: a receiving module, a third determining module, a reading module and a decryption module.

[0204] The receiving module is used to receive a data reading request, wherein the data reading request includes a second key name.

[0205] The third determining module is used to process the second key name to obtain a second processed key name.

[0206] The reading module is used to read, from the updated snapshot list, a second snapshot whose corresponding processed key name is the same as the second processed key name.

[0207] The second snapshot is a valid snapshot.

[0208] The decryption module is used to decrypt the encrypted second key-value data in the second snapshot to obtain the second key-value data.

[0209] In one embodiment, the first determination module 111 is used to: determine a first target processing method corresponding to the first key name based on a mapping relationship between a preset processing method and attribute information of a key name, and attribute information of the first key name; and process the first key name of the first key value data according to the first target processing method to obtain a first processed key name.

[0210] In one embodiment, the third determination module is used to: determine the second target processing method corresponding to the second key name based on the mapping relationship and the attribute information of the second key name; and process the second key name according to the second target processing method to obtain a second processed key name.

[0211] In one embodiment, the first target processing method and / or the second target processing method includes at least one of the following processing methods: adding a prefix, adding a suffix, changing the characters at the target position, adding characters at the target position, and deleting characters at the target position.

[0212] In one embodiment, in terms of updating the historical snapshot list to obtain the updated snapshot list, the update module 113 is used to: obtain a third snapshot in the historical snapshot list, whose corresponding timestamp is before the first timestamp and closest to the first timestamp; compare the first snapshot with the third snapshot to obtain first difference information corresponding to the first snapshot, wherein the first difference information is used to characterize the difference between the first snapshot and the third snapshot; and update the first difference information corresponding to the first snapshot to the historical snapshot list to obtain the updated snapshot list.

[0213] In one embodiment, the reading module is used to: read from the updated snapshot list the second difference information corresponding to the second snapshot whose corresponding processed key name is the same as the second processed key name; obtain from the updated snapshot list the fourth snapshot whose corresponding timestamp is before the second timestamp corresponding to the second snapshot and is closest to the second timestamp; determine the second snapshot based on the fourth snapshot and the second difference information.

[0214] In one embodiment, in the aspect of obtaining a third snapshot in the historical snapshot list whose corresponding timestamp is before the first timestamp and closest to the first timestamp, the update module 113 is used to: if the timestamp corresponding to the third snapshot is the earliest timestamp in the historical snapshot list, obtain the third snapshot; if the timestamp corresponding to the third snapshot is not the earliest timestamp in the historical snapshot list, obtain difference information corresponding to each snapshot whose corresponding timestamp is between the timestamp corresponding to the third snapshot and the earliest timestamp; determine the third snapshot according to the snapshot corresponding to the earliest timestamp, the difference information corresponding to each snapshot, and the difference information corresponding to the third snapshot.

[0215] In one embodiment, the device further includes: a first acquisition module, a fourth determination module and a deletion module.

[0216] The first acquisition module is configured to acquire difference information between the snapshot corresponding to the earliest timestamp and the snapshot corresponding to the next earliest timestamp when it is determined that the number of snapshots included in the updated snapshot list is greater than a preset maximum number threshold.

[0217] The fourth determining module is used to determine the snapshot corresponding to the next earliest timestamp according to difference information between the snapshot corresponding to the earliest timestamp and the snapshot corresponding to the next earliest timestamp.

[0218] The deletion module is used to delete the snapshot corresponding to the earliest timestamp.

[0219] In one embodiment, the number of the updated snapshot lists is multiple, the processed key names of the snapshots in the same updated snapshot list are the same, and the processed key names of the snapshots in different updated snapshot lists are different. The data rollback request also includes a rollback key name. The device also includes: a fifth determination module, which is used to: if a data rollback request is received, determine the third target processing method corresponding to the rollback key name according to the mapping relationship and the attribute information of the rollback key name; according to the third target processing method, process the rollback key name to obtain the processed rollback key name. The rollback module 115 is used to: determine the target updated snapshot list corresponding to the data rollback request according to the processed rollback key name; according to the target timestamp in the data rollback request, update the snapshot in the target updated snapshot list whose corresponding timestamp is before the target timestamp and is closest to the target timestamp to the valid snapshot.

[0220] In one embodiment, the device further includes: a second acquisition module, a verification module and a sixth determination module.

[0221] The second acquisition module is used to acquire verification information of the data rollback request, wherein the verification information includes at least one of the following: source information of the data rollback request and occurrence frequency of the data rollback request.

[0222] The verification module is used to verify the security of the data rollback request according to the verification information of the data rollback request, and determine the verification result of the data rollback request.

[0223] The sixth determination module is used to determine the step of executing "updating, according to the target timestamp in the data rollback request, the snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp to the valid snapshot" when the verification result of the data rollback request is verification passed.

[0224] In one embodiment, the first snapshot corresponds to a flag. The second determination module 114 is used to: set the flag of the valid snapshot in the historical snapshot list to an invalid value; set the flag of the first snapshot to a valid value. Alternatively, the historical snapshot list corresponds to a valid snapshot identifier. The second determination module 114 is used to: update the valid snapshot identifier of the updated snapshot list to the identifier of the first snapshot.

[0225] In one embodiment, the update module 113 is used to: update the historical snapshot list through a predefined data storage API, using the first processed key name, the encrypted first key value data and the first timestamp as the first snapshot to obtain an updated snapshot list.

[0226] In one embodiment, the rollback module 115 is used to: use a predefined data rollback API to update the snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp to the valid snapshot according to the target timestamp in the data rollback request.

[0227] The data storage device provided in the embodiment of the present application can be used to execute the technical solution of the data storage method in the above embodiment. Its implementation principle and technical effect are similar and will not be repeated here.

[0228] It should be noted that it should be understood that the division of the various modules of the above device is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software called by processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software called by processing elements, and some modules can be implemented in the form of hardware. For example, the first determination module 111, the encryption module 112, the update module 113, the second determination module 114 and the rollback module 115 can be separately established processing elements, or they can be integrated in a chip of the above device. In addition, they can also be stored in the memory of the above device in the form of program code, and a processing element of the above device can call and execute the functions of the first determination module 111, the encryption module 112, the update module 113, the second determination module 114 and the rollback module 115. The implementation of other modules is similar. In addition, all or part of these modules can be integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in a processor element or an instruction in software form.

[0229] Fig.12 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Fig.12 As shown, the electronic device may include: a processor 142 and a memory 143.

[0230] The processor 142 executes the computer execution instructions stored in the memory, so that the processor 142 executes the scheme in the above embodiment. The processor 142 can be a general-purpose processor, including a central processing unit CPU, a network processor (network processor, NP), etc.; it can also be a digital signal processor DSP, an application-specific integrated circuit ASIC, a field programmable gate array FPGA or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.

[0231] The memory 143 is connected to the processor 142 via a system bus and completes communication between them. The memory 143 is used to store computer program instructions.

[0232] Optionally, the electronic device may further include a transceiver 141. The transceiver 141 may be configured to receive at least one of the following: a data rollback request and a data read request.

[0233] The system bus can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The system bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The transceiver is used to realize the communication between the data storage device and other computer devices. The memory may include random access memory (RAM) and may also include non-volatile memory.

[0234] An embodiment of the present application also provides a chip for executing instructions, which is used to execute the technical solution of the data storage method in the above embodiment.

[0235] An embodiment of the present application further provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on a computer, the computer executes the technical solution of the data storage method of the above embodiment.

[0236] An embodiment of the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements the data storage method provided in any embodiment of the present application.

[0237] In the process of implementation, the computer program product can be written in one or more programming languages ​​or a combination thereof to perform the computer program code of the present application, and the programming language includes an object-oriented programming language, such as Java, Smalltalk, C++, and also includes a conventional procedural programming language, such as "C" language or similar programming language. The program code can be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on the remote computer, or completely on the remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).

[0238] Note that the above are only preferred embodiments of the present application and the technical principles used. Those skilled in the art will understand that the present application is not limited to the specific embodiments herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present application. Therefore, although the present application is described in more detail through the above embodiments, the present application is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present application, and the scope of the present application is determined by the scope of the appended claims.

Claims

1. A data storage method, characterized in that: include: Processing the first key name of the first key-value data to be stored to obtain a first processed key name; Encrypting the first key-value data to obtain encrypted first key-value data; Taking the first processed key name, the encrypted first key value data, and the first timestamp as the first snapshot, updating the historical snapshot list to obtain an updated snapshot list; wherein the updated snapshot list includes the first snapshot and at least one historical snapshot, the first timestamp is the timestamp corresponding to the first key value data, and the timestamps corresponding to the first snapshot and at least one historical snapshot are different; determining the first snapshot as a valid snapshot; If a data rollback request is received, the snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp is updated as the valid snapshot according to the target timestamp in the data rollback request; wherein the target timestamp is less than or equal to the first timestamp.

2. The method according to claim 1, characterized in that The method further comprises: Receiving a data read request; wherein the data read request includes a second key name; Processing the second key name to obtain a second processed key name; Reading from the updated snapshot list a second snapshot whose corresponding processed key name is the same as the second processed key name; wherein the second snapshot is a valid snapshot; The encrypted second key-value data in the second snapshot is decrypted to obtain the second key-value data.

3. The method according to claim 2, characterized in that The step of processing the first key name of the first key-value data to be stored to obtain a first processed key name includes: Determine a first target processing method corresponding to the first key name according to a mapping relationship between a preset processing method and attribute information of the key name, and the attribute information of the first key name; According to the first target processing method, the first key name of the first key-value data is processed to obtain a first processed key name; The processing of the second key name to obtain a second processed key name includes: Determine a second target processing method corresponding to the second key name according to the mapping relationship and the attribute information of the second key name; According to the second target processing method, the second key name is processed to obtain a second processed key name.

4. The method according to claim 3, characterized in that The first target processing method and / or the second target processing method include at least one of the following processing methods: Add prefix, add suffix, change characters at target position, add characters at target position, delete characters at target position.

5. The method according to any one of claims 2 to 4, characterized in that: The updating history snapshot list obtains the updated snapshot list, including: Obtain a third snapshot in the historical snapshot list, whose corresponding timestamp is before the first timestamp and closest to the first timestamp; Comparing the first snapshot with the third snapshot to obtain first difference information corresponding to the first snapshot; wherein the first difference information is used to represent the difference between the first snapshot and the third snapshot; The first difference information corresponding to the first snapshot is updated into the historical snapshot list to obtain the updated snapshot list.

6. The method according to claim 5, characterized in that The step of reading from the updated snapshot list a second snapshot whose corresponding processed key name is the same as the second processed key name comprises: Reading, from the updated snapshot list, second difference information corresponding to a second snapshot whose processed key name is the same as the second processed key name; Acquire, from the updated snapshot list, a fourth snapshot whose corresponding timestamp is before the second timestamp corresponding to the second snapshot and which is closest to the second timestamp; The second snapshot is determined according to the fourth snapshot and the second difference information.

7. The method according to claim 5, characterized in that The step of obtaining a third snapshot in the historical snapshot list, whose corresponding timestamp is before the first timestamp and closest to the first timestamp, includes: If the timestamp corresponding to the third snapshot is the earliest timestamp in the historical snapshot list, acquiring the third snapshot; If the timestamp corresponding to the third snapshot is not the earliest timestamp in the historical snapshot list, obtaining difference information corresponding to each snapshot whose timestamp is between the timestamp corresponding to the third snapshot and the earliest timestamp; The third snapshot is determined according to the snapshot corresponding to the earliest timestamp, the difference information corresponding to the snapshots, and the difference information corresponding to the third snapshot.

8. The method according to any one of claims 1 to 4, characterized in that: After obtaining the updated snapshot list, the method further includes: When it is determined that the number of snapshots included in the updated snapshot list is greater than a preset maximum number threshold, obtaining difference information between the snapshot corresponding to the earliest timestamp and the snapshot corresponding to the second earliest timestamp; Determine the snapshot corresponding to the next earliest timestamp according to difference information between the snapshot corresponding to the first earliest timestamp and the snapshot corresponding to the next earliest timestamp; Delete the snapshot corresponding to the earliest timestamp.

9. The method according to claim 3, characterized in that: There are multiple updated snapshot lists, the processed key names of the snapshots in the same updated snapshot list are the same, and the processed key names of the snapshots in different updated snapshot lists are different; the data rollback request also includes a rollback key name; The method further comprises: If a data rollback request is received, determining a third target processing method corresponding to the rollback key name according to the mapping relationship and the attribute information of the rollback key name; According to the third target processing method, the rollback key name is processed to obtain a processed rollback key name; If a data rollback request is received, updating, according to the target timestamp in the data rollback request, a snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp as the valid snapshot, includes: Determining a target updated snapshot list corresponding to the data rollback request according to the processed rollback key name; According to the target timestamp in the data rollback request, a snapshot in the target updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp is updated as the valid snapshot.

10. The method according to any one of claims 1 to 4, characterized in that: After receiving the data rollback request, updating, according to the target timestamp in the data rollback request, the snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp to be before the valid snapshot, the method further includes: Acquire verification information of the data rollback request; wherein the verification information includes at least one of the following: source information of the data rollback request and occurrence frequency of the data rollback request; Verifying the security of the data rollback request according to the verification information of the data rollback request, and determining a verification result of the data rollback request; When the verification result of the data rollback request is that the verification is passed, it is determined to execute the step of "updating, according to the target timestamp in the data rollback request, the snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp as the valid snapshot".

11. The method according to any one of claims 1 to 4, characterized in that: The first snapshot corresponds to a flag bit; determining the first snapshot as a valid snapshot includes: setting the flag bit of the valid snapshot in the historical snapshot list to an invalid value; setting the flag bit of the first snapshot to a valid value; or, The historical snapshot list corresponds to a valid snapshot identifier; and determining the first snapshot as a valid snapshot includes: updating the valid snapshot identifier of the updated snapshot list to the identifier of the first snapshot.

12. The method according to any one of claims 1 to 4, characterized in that: The method of taking the first processed key name, the encrypted first key value data and the first timestamp as the first snapshot, updating the historical snapshot list, and obtaining the updated snapshot list includes: Using a predefined data storage application programming interface API, taking the first processed key name, the encrypted first key value data, and the first timestamp as a first snapshot, updating the historical snapshot list, and obtaining an updated snapshot list; The updating, according to the target timestamp in the data rollback request, of a snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp as the valid snapshot comprises: Through a predefined data rollback API, according to the target timestamp in the data rollback request, the snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp is updated as the valid snapshot.

13. A data storage device, characterized in that: include: A first determining module, used for processing a first key name of the first key-value data to be stored to obtain a first processed key name; An encryption module, used for encrypting the first key-value data to obtain encrypted first key-value data; an updating module, configured to use the first processed key name, the encrypted first key value data, and the first timestamp as a first snapshot, update the historical snapshot list, and obtain an updated snapshot list; wherein the updated snapshot list includes the first snapshot and at least one historical snapshot, the first timestamp is a timestamp corresponding to the first key value data, and the timestamps corresponding to the first snapshot and at least one historical snapshot are different; A second determining module, configured to determine the first snapshot as a valid snapshot; A rollback module is used to update, if a data rollback request is received, a snapshot in the updated snapshot list whose corresponding timestamp is before the target timestamp and closest to the target timestamp as the valid snapshot according to the target timestamp in the data rollback request; wherein the target timestamp is less than or equal to the first timestamp.

14. An electronic device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the data storage method according to any one of claims 1 to 12 when executing the computer program.

15. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the data storage method according to any one of claims 1 to 12 is implemented.

16. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the computer program implements the data storage method according to any one of claims 1 to 12.