Data deletion method, device, apparatus and medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- DUXIAOMAN TECH (BEIJING) CO LTD
- Filing Date
- 2023-08-30
- Publication Date
- 2026-06-02
Smart Images

Figure CN117216324B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of kv database technology, and in particular relates to a data deletion method, apparatus, device and medium. Background Technology
[0002] CKV database is a memory-compressed key-value storage database that uses a path-compressed trie implementation principle to perform prefix compression on both the key and value datasets, resulting in high concurrency, low latency, and high compression ratio. Currently, CKV databases employ a marker-based deletion strategy for data deletion, assigning a deletion flag to each data item. However, this method cannot physically delete the data to be deleted, leaving it to continue occupying memory and causing a continuous increase in memory usage. Physically deleting the data requires a full data load, which necessitates a service restart, incurring significant system overhead and potentially causing system stability issues. Therefore, the data deletion methods in CKV databases have significant limitations and low flexibility. Summary of the Invention
[0003] This application provides an implementation scheme that differs from related technologies, in order to solve the technical problem that the data deletion method of CKV database in related technologies has significant limitations and low flexibility.
[0004] Firstly, this application provides a data deletion method, including:
[0005] Get the string to be deleted; where the string to be deleted is the content corresponding to the key;
[0006] Check if there exists an identifier for the key node corresponding to the string to be deleted, and an identifier for the value node corresponding to the key node;
[0007] If there are identifiers for key nodes and value nodes, set the first deletion identifier corresponding to the key node identifier to a first identifier used to indicate that the information corresponding to the key node can be deleted;
[0008] Control the information corresponding to the delete key node;
[0009] Determine whether the identifier of the value node is not referenced by other key nodes. If so, set the second deletion identifier corresponding to the value node identifier to a second identifier used to indicate that the information corresponding to the value node can be deleted.
[0010] Control the information corresponding to the deleted value node.
[0011] Secondly, this application provides a data erasure device, comprising:
[0012] The retrieval unit is used to retrieve the string to be deleted; where the string to be deleted is the content corresponding to the key.
[0013] The search unit is used to search for the existence of the identifier of the key node corresponding to the string to be deleted and the identifier of the value node corresponding to the key node;
[0014] The setting unit is used to set the first deletion flag corresponding to the key node flag to a first flag indicating that the information corresponding to the key node can be deleted if there are key node flags and value node flags.
[0015] The deletion unit is used to control the deletion of information corresponding to the key node;
[0016] The determining unit is used to determine whether the identifier of the value node is not referenced by other key nodes. If so, the second deletion identifier corresponding to the value node identifier is set to a second identifier used to indicate that the information corresponding to the value node can be deleted.
[0017] The deletion unit is also used to control the information corresponding to the deleted value node.
[0018] Thirdly, this application provides an electronic device, comprising:
[0019] Processor; and
[0020] Memory is used to store the processor's executable instructions;
[0021] The processor is configured to execute the first aspect, or any method in any possible implementation of the first aspect, by executing executable instructions.
[0022] Fourthly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the first aspect, or any method in any possible implementation of the first aspect.
[0023] This application provides a scheme for obtaining a string to be deleted; wherein the string to be deleted is the content corresponding to a key; checking whether there is an identifier for the key node corresponding to the string to be deleted and an identifier for the value node corresponding to the key node; if there are identifiers for the key node and the value node, setting the first deletion identifier corresponding to the key node identifier to a first identifier used to indicate that the information corresponding to the key node can be deleted; controlling the deletion of the information corresponding to the key node; determining whether the identifier of the value node is not referenced by other key nodes, and if so, setting the second deletion identifier corresponding to the value node identifier to a second identifier used to indicate that the information corresponding to the value node can be deleted; and controlling the deletion of the information corresponding to the value node. This scheme can maintain the deletion status of nodes by setting deletion identifiers for nodes, thereby achieving the purpose of immediately releasing memory. It can also determine whether the value node can be safely deleted based on whether the value node is referenced by other nodes, thereby achieving the technical effect of improving the flexibility of the data deletion method of the CKV database. Attached Figure Description
[0024] To more clearly illustrate the technical solutions in the embodiments or related technologies of this application, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings:
[0025] Figure 1 A schematic flowchart illustrating a data deletion method provided in an embodiment of this application;
[0026] Figure 2a A schematic diagram of the logical storage structure of a key-Trie provided in an embodiment of this application;
[0027] Figure 2b A schematic diagram of the structure of a second storage area, HashTire, provided in an embodiment of this application;
[0028] Figure 2c This is a schematic diagram of the structure of the first storage area of a key-Trie provided in an embodiment of this application;
[0029] Figure 3 This is another schematic flowchart illustrating a data deletion method provided in an embodiment of this application;
[0030] Figure 4 This is a flowchart illustrating a recursive deletion operation on a node according to an embodiment of this application.
[0031] Figure 5 This is a schematic diagram of the structure of a data deletion device provided in an embodiment of this application;
[0032] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0033] The embodiments of this application are described in detail below, with examples of these embodiments illustrated in the accompanying drawings. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this application, and should not be construed as limiting this application.
[0034] The terms "first" and "second," etc., used in the specification, claims, and drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the solution can be implemented in a different order than that illustrated or described in this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0035] Currently, CKV databases employ a mark-to-delete strategy when performing data deletion operations, assigning a deletion marker to each piece of data to be deleted. However, this method cannot physically remove the data to be deleted, as it continues to occupy memory, causing memory usage to rise continuously. Physically deleting the data requires a full data load, which necessitates a service restart, incurring significant system overhead and potentially causing system stability issues. Therefore, CKV database data deletion methods in related technologies have significant limitations and low flexibility.
[0036] To address this technical problem, this application provides a data deletion method, apparatus, device, and medium to resolve the limitations and low flexibility of data deletion methods for CKV databases in related technologies.
[0037] The technical solution of this application and how it solves the above-mentioned technical problems will be described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.
[0038] Figure 1 This is a flowchart illustrating a data deletion method provided as an exemplary embodiment of this application. This method can be applied to terminal devices that have permission to access and modify the CKV database.
[0039] In some embodiments, the CKV database is used to store key-value pair data, where the key and value are stored using path-compressed trie key-Trie and value-Trie respectively, and the two path-compressed trie are associated with each other by the id identifier of the value node.
[0040] Figure 2aThis is a schematic diagram of the logical storage structure of a key-Trie provided for an exemplary embodiment of this application. The key-Trie stores seven key data, corresponding to seven nodes k1-k7 respectively. The first key data corresponding to k1 is abc, the second key data corresponding to k2 is abcpqq, the third key data corresponding to k3 is abfxl, the fourth key data corresponding to k4 is aefgh, the fifth key data corresponding to k5 is abcpqdfgh, the sixth key data corresponding to k6 is abfa345, and the seventh key data corresponding to k7 is ae / 111.
[0041] Each key data item can be represented by several nodes in a key-Trie. Each node consists of two parts: the node's association information and the node's label substring. Specifically, the node's association information is the association information between the node and its parent node.
[0042] In some embodiments, the association information of a node is the topological structure information between the node and its parent node. Specifically, the topological structure information can be a triplet: (parent node id, the character 'c' that does not match the parent node's label for the first time, and the maximum length of the match that matches the parent node's label).
[0043] For example in Figure 2a In the diagram, k1's label is "abc," and since k1 has no parent node, its association information is empty. k2's label is "qq," and its association information is (k1, p, 3), where k1 represents the node ID of k2's parent node, p indicates that the first mismatch between k2 and its parent node's label is "p," and 3 indicates that the maximum length of the key string corresponding to k2 matching the parent node's label is 3. The storage structure for the remaining k3-k7 follows the same principle as k1 and k2, and will not be elaborated upon here.
[0044] In some embodiments, the physical storage structure of the key-Trie and value-Trie is identical, both consisting of a first storage area (LabelStore) and a second storage area (HashTrie), wherein:
[0045] The information stored in the second storage area HashTrie of key-Trie and value-Trie is completely identical. For each node of key-Trie and value-Trie, the second storage area HashTrie stores the association information of that node and the overwrite identifier. The overwrite identifier is used to identify whether the storage unit where the association information of each node is located can be overwritten or rewritten.
[0046] In some embodiments, the second storage area, HashTrie, can be a hash table structure. Each non-empty position in the HashTrie represents an existing node. The parent node of a specified node can be calculated using a hash algorithm.
[0047] like Figure 2b As shown, Figure 2b This is a schematic diagram of the structure of a second storage area provided for an exemplary embodiment of this application. The second storage area HashTrie stores the association information and overlay identifier of each of the seven nodes k1-k7.
[0048] In some embodiments, the node association information occupies 8 bits of storage space, and the overwrite identifier occupies 1 bit of storage space.
[0049] In some embodiments, the overwrite flag can be 0 or 1. 0 or 1 can be used to indicate whether the association information of a node at this location has been deleted. Specifically, when the overwrite flag is 0, it indicates that the storage unit containing the corresponding association information cannot be overwritten or rewritten; when the flag is 1, it indicates that the storage unit containing the corresponding association information can be overwritten or rewritten. For example, in... Figure 2b In the data, the relationship information between k1 and k7 has not been deleted, and the storage unit where the relationship information between k1 and k7 is located cannot be overwritten or written.
[0050] The underlying data structure of the first storage area LabelStore for both key-Trie and value-Trie is a chunk array and a pointer array. The chunk array is used to identify whether a node exists and whether the information corresponding to the node can be safely deleted, while the pointer array is used to store the label information of the node.
[0051] For the first storage area of the key-Trie, LabelStore, LabelStore stores the substring label of each node, the length of the label, the node ID of the value corresponding to the key of the node, the existence identifier of each node, and the deletion identifier of each node.
[0052] The substring label, the length of the label, and the node ID of the value corresponding to the key of the node are all stored in the pointer array in LabelStore. The existence flag and the deletion flag are both stored in the chunk array in LabelStore.
[0053] In some embodiments, an existence flag is used to indicate whether the node exists. When the existence flag of a node indicates that the node does not exist, it means that the string corresponding to the node has been completely deleted and the node no longer exists.
[0054] In some embodiments, a deletion flag is used to indicate whether the information corresponding to the node can be deleted. When the deletion flag of a node indicates that the information of the node can be deleted, it means that the string corresponding to the node can be safely deleted. However, since the substring of the node may be referenced by the child nodes of the node, the information of the node cannot be completely deleted at this time. The node still exists, and only part of the information of the node has been deleted.
[0055] For the first storage area of the value-Trie, LabelStore, LabelStore stores the substring label of each node, the length of the label, the reference count of the value corresponding to the node, the existence identifier of each node, and the deletion identifier of each node.
[0056] The substring label, the length of the label, and the reference count of the value corresponding to the node are all stored in a pointer array in LabelStore. The existence flag and the deletion flag are both stored in a chunk array in LabelStore. The reference count indicates the number of times the value is referenced by different keys. The existence flag is used to indicate whether the node exists, and the deletion flag is used to indicate whether the information corresponding to the node can be deleted.
[0057] Figure 2c A schematic diagram of the structure of the first storage area of a key-Trie provided for an exemplary embodiment of this application, wherein:
[0058] The first part belongs to the aforementioned chunk array and is used to store the existence flags of each node. Corresponding to the nodes in the first storage area of the key-Trie, when the existence flag of a certain bit is 1, it indicates that the node exists; when the existence flag of a certain bit is 0, it indicates that the node does not exist.
[0059] The second part belongs to the chunk array mentioned above and is used to store the deletion flags of each node. When a bit is 0, it indicates that the information of the node corresponding to that bit has not been deleted. When a bit is 1, it indicates that the information of the node corresponding to that bit can be deleted.
[0060] The pointer array part is used to store the substring label of each node, the length of the label, and the node ID of the value corresponding to the key of the node.
[0061] For example in Figure 2cIn the diagram, the deletion flag corresponding to k1 is 0, indicating that the information corresponding to k1 has not been deleted. From the pointer content stored in the pointer array, we know that the label of k1 is abc, the length is 3, and the node id of the corresponding value is v1. The label of k2 is qq, the length is 2, and the node id of the corresponding value is v2. The storage principle of the remaining k3-k7 is the same as that of k1 and k2, and this application will not elaborate on it.
[0062] This data deletion method includes at least the following S11-S16:
[0063] S11. Obtain the string to be deleted; where the string to be deleted is the content corresponding to the key;
[0064] In some embodiments, the string to be deleted is the key data in a key-value pair that needs to be deleted from the CKV database.
[0065] S12. Check if there is an identifier for the key node corresponding to the string to be deleted and an identifier for the value node corresponding to the key node;
[0066] In some embodiments, checking whether there exists an identifier for the key node corresponding to the string to be deleted and an identifier for the value node corresponding to the key node specifically includes the following steps S121-S124:
[0067] S121. In the key-Trie, match the substring of the node at the current position (when this step is executed for the first time, the node at the current position is the root node of the key-Trie) with the string to be deleted;
[0068] S122. Determine whether the two are completely matched. If they are, the identifier of the key node corresponding to the string to be deleted is successfully found. Use the id of the node at the current position as the identifier of the key node corresponding to the string to be deleted. If the two are not completely matched, execute S123.
[0069] S123. Determine if there is a branch that matches the current position of the string to be deleted. If it exists, obtain the child node through the branch and use the child node as the node at the current position, then return to execute S121. If it does not exist, the search fails.
[0070] S124. If the search is successful, extract the corresponding value node ID from the string of the node at the current position, and use the corresponding value node ID as the identifier of the value node corresponding to the key node of the string to be deleted. Otherwise, the search for the identifier of the key node and the identifier of the value node corresponding to the key node of the string to be deleted fails.
[0071] S13. If there are identifiers for key nodes and value nodes, set the first deletion identifier corresponding to the key node identifier to a first identifier used to indicate that the information corresponding to the key node can be deleted.
[0072] In some embodiments, setting the first deletion identifier corresponding to the key node identifier as a first identifier for indicating that the information corresponding to the key node can be deleted specifically involves: using the deletion identifier in the first storage area of the key node corresponding to the key node identifier as the first deletion identifier, and setting the first deletion identifier as a first identifier for indicating that the information corresponding to the key node can be deleted.
[0073] In some embodiments, the first identifier can be 1.
[0074] In some embodiments, setting the first deletion identifier to the first identifier can be achieved by performing bitwise operations on the chunk array in the first storage area LabelStore.
[0075] By setting a deletion flag for key nodes, the deletion status of key nodes can be maintained, recording whether each key node can be deleted and when it should be deleted.
[0076] S14. Control the information corresponding to the delete key node;
[0077] In some embodiments, the information corresponding to the key node includes the substring corresponding to the key node, and the first association relationship information between the key node and its first parent node.
[0078] Then, in S14, the information corresponding to the key node to be deleted is controlled, including the following S141-S143:
[0079] S141. Determine whether the key node is a leaf node and check whether the maximum length of the substring referenced by the child node of the key node is 0;
[0080] In some embodiments, before determining whether the maximum length of the substring referenced by the child nodes of the key node is 0, the method further includes: obtaining the maximum length of the substring referenced by the child nodes of the key node.
[0081] In some embodiments, obtaining the maximum length of a substring referenced by the child nodes of a key node specifically includes:
[0082] Get the number of characters referenced by each child node of the key node in the substring, and get the total number of characters referenced by the child nodes in the substring; take the maximum value of the total number of characters as the maximum length of the substring referenced by the child nodes of the key node.
[0083] Specifically, the number of characters in the substring of the key node that each child node references in the key node can be obtained from the association information between the key node and its child nodes stored in the second storage area HashTrie of the key-Trie to which the key node belongs.
[0084] S142. When the key node is a leaf node, or the key node is not a leaf node, but the maximum length of the substring referenced by the child node of the key node is 0, then control the deletion of the substring stored in the first storage area corresponding to the key node, set the existence flag in the first storage area to a third flag indicating that the key node no longer exists, and set the overwrite flag stored in the second storage area corresponding to the key node to a fourth flag indicating that the first association information can be overwritten.
[0085] In some embodiments, the third identifier is 0.
[0086] In some embodiments, the fourth identifier is 1.
[0087] In some embodiments, setting the presence flag in the first storage area to a third flag indicating that the key node no longer exists can be achieved by performing bitwise operations on the chunk array in the LabelStore of the first storage area.
[0088] In some embodiments, after controlling the substring stored in the first storage area corresponding to the deleted key node, the method further includes: the length of the substring corresponding to the key node stored in the first storage area corresponding to the deleted key node and the identifier of the value node referenced by the key node stored in the first storage area corresponding to the deleted key node.
[0089] If a key node is a leaf node or not a leaf node, but the maximum length of its substring referenced by its child nodes is 0, then the key node can be safely deleted. In this case, the key node information stored in both the first and second storage areas should be deleted. For the first storage area, this can be achieved by deleting the substring of the key node stored there, modifying the key node's existence flag to a third flag indicating that the key node no longer exists, and adjusting the length of the substring corresponding to the key node. For the second storage area, this can be achieved by setting the key node's overwrite flag to a fourth flag indicating that the first association information can be overwritten. When new data needs to be written, if the overwrite flag of the first association information is read as the fourth flag, the new data can be directly written to the storage unit where the first association information is located.
[0090] S143. Determine whether the key node has a parent node. If it does, determine whether the third deletion identifier corresponding to the parent node is the first identifier. If so, use the parent node as the new key node and return to execute the steps of determining whether the key node is a leaf node and determining whether the maximum length of the string referenced by the child node of the key node is 0.
[0091] Specifically, when the third deletion flag of the parent node is the first flag, it means that the information corresponding to the parent node can be deleted, but the parent node still exists. This situation may be because the key node referenced a substring of the parent node before the key node was deleted, resulting in the information corresponding to the parent node not being completely deleted. By recursively deleting the parent node of the key node, it can be ensured that the information corresponding to the parent node can be successfully deleted, thus freeing up memory.
[0092] In some embodiments, in S14, controlling the deletion of information corresponding to the key node further includes: determining whether the key node is a leaf node and determining whether the maximum length of the substring referenced by the child node of the key node is 0. If the key node is not a leaf node and the maximum length of the string referenced by the child node of the key node is not 0, then controlling the deletion of the remaining characters after the maximum length of characters in the substring to obtain the target string, and setting the length of the target string stored in the first storage area to the maximum length.
[0093] In some embodiments, if a key node is not a leaf node and the maximum length of the string referenced by the key node's child nodes is not 0, it means that the substring of the key node is referenced by its child nodes. In this case, the key node cannot be safely deleted; only the remaining characters after the maximum length of the substring can be deleted, that is, the characters not referenced by the key node's child nodes can be deleted to ensure the integrity of the child node's information.
[0094] Since the substring corresponding to the key node has been modified to the target substring, it is also necessary to modify the length of the substring corresponding to the key node stored in the first storage area to the length (maximum length) of the target substring.
[0095] S15. Determine whether the identifier of the value node is not referenced by other key nodes. If so, set the second deletion identifier corresponding to the value node identifier to a second identifier used to indicate that the information corresponding to the value node can be deleted.
[0096] Among them, the other key nodes in S15 are other key nodes besides the key nodes corresponding to the strings to be deleted mentioned above.
[0097] If the identifier of a value node is not referenced by other key nodes, it means that the information corresponding to the value node can be safely deleted, and therefore the deletion operation on the information corresponding to the value node can be performed.
[0098] In some embodiments, determining whether the identifier of a value node is not referenced by other key nodes in S15 specifically includes the following S151-S153:
[0099] S151, Query the number of times the value node identifier is referenced;
[0100] In some embodiments, the number of times a value node identifier is referenced is the number of times the string corresponding to the value node is referenced by different keys corresponding to different key nodes.
[0101] In some embodiments, the number of times a value node identifier is referenced can be specifically achieved by querying the reference count of the string corresponding to the value node in the first storage area LabelStore of the value-Trie corresponding to the value node. In this case, the number of times the value node identifier is referenced is equal to the reference count of the value node.
[0102] S152, Decrease the control count by one;
[0103] Specifically, decrement the reference count of the value node by one.
[0104] S153. Determine if the number of times is 0. If yes, determine if the identifier of the value node is not referenced by other key nodes. If no, determine if the identifier of the value node is referenced by other key nodes.
[0105] In some embodiments, determining whether the updated number of references is 0 can determine whether the identifier of the value node is referenced by other nodes, and perform corresponding operations on the value node based on the determination result.
[0106] Specifically, when the number of updates is 0, it means that the identifier of the value node is not referenced by any other key node besides being referenced by the key node corresponding to the value node. In this case, the information corresponding to the value node can be safely deleted. When the number of updates is not 0, it means that the identifier of the value node is referenced by other key nodes besides being referenced by the key node corresponding to the value node. In this case, the information corresponding to the value node cannot be deleted.
[0107] S16. Control the information corresponding to the deleted value node.
[0108] Specifically, the method for controlling the information corresponding to the deleted value node is completely consistent with the method for controlling the information corresponding to the deleted key node in S14 above, and this application will not elaborate on it.
[0109] In some embodiments, the method further includes S01-S06:
[0110] S01. Obtain the string to be stored;
[0111] In some embodiments, the string to be stored is the content corresponding to the key to be stored.
[0112] S02. Determine the identifier of the corresponding second key node based on the string to be stored;
[0113] In some embodiments, determining the identifier of the corresponding second key node based on the string to be stored specifically involves: writing the string to be stored into the key-Trie and obtaining the identifier of the second key node corresponding to the string to be stored, as well as the substring corresponding to the second key node.
[0114] S03. Determine the storage information of the second key node in the second storage area. The storage information includes: the second association relationship information between the second key node and its parent node.
[0115] In some embodiments, determining the second association information between the second key node and its parent node specifically includes: determining the id of the parent node of the second key node, the character 'c' that does not match the substring corresponding to the parent node of the second key node for the first time, and the maximum length of the substring corresponding to the parent node of the second key node.
[0116] S04. Determine the storage location of the stored information based on preset rules;
[0117] In some embodiments, the underlying data structure of the second storage area is a hash table structure. The storage units for the association information of the nodes stored in the second storage area are all obtained by performing a preset hash function operation on the node identifier. Therefore, the preset rule is a preset hash algorithm. Since the identifier of the second key node has been determined, the storage location of the storage information of the second key node can be determined by performing a preset hash algorithm operation on the identifier of the second key node.
[0118] S05. If the target overlay identifier corresponding to the storage location is the fourth identifier;
[0119] Specifically, the target overlay identifier corresponding to the storage location is the fourth identifier, which indicates that the second association information can be overlaid.
[0120] S06. Overwrite the existing content at the storage location with the stored information.
[0121] In some embodiments, if the target overwrite identifier corresponding to the storage location is not the fourth identifier, it means that the storage location cannot be written to or overwritten. In this case, a hash collision has occurred, and the storage location of the stored information can be determined by using the open addressing method or other methods to resolve hash collisions.
[0122] By using additional storage units in the second storage area to set overwrite flags for the node association information, when a node does not exist (is completely deleted), the memory occupied by the node in the second storage area can be marked and deleted. When new data needs to be written, the new data can be directly written to the storage unit with the overwrite flag set to the fourth flag, thus realizing the rational use of memory and the physical deletion of the original useless information.
[0123] Figure 3 Another flowchart illustrating a data deletion method provided for an exemplary embodiment of this application specifically includes:
[0124] S31. Obtain the key to be deleted;
[0125] S32. Check if there is a key node and value node corresponding to the key. If there is a key node and value node corresponding to the key, execute S33. If there is no key node and value node corresponding to the key, the process ends.
[0126] S33. Set the deletion flag of the node stored in the first storage area corresponding to the key node to 1, and perform a recursive deletion operation on the key node corresponding to the key.
[0127] In this context, a deletion flag of 1 can be considered the first deletion flag, indicating that the information corresponding to the key node can be deleted.
[0128] S34. Query the reference count (ref_count) of the value node corresponding to the key;
[0129] S35. ref_count=ref_count-1;
[0130] S36. Check if ref_count is equal to 0. If yes, execute S36. If no, the process ends.
[0131] S37. Set the deletion flag of the value node corresponding to the key to 1, and perform a recursive deletion operation on the value node corresponding to the key.
[0132] In this context, a deletion flag of 1 for a value node can be considered as the first deletion flag for the value node, indicating that the information corresponding to the key node corresponding to the value can be deleted.
[0133] Figure 4 The flowchart illustrating a recursive deletion operation on a node, provided as an exemplary embodiment of this application, specifically includes:
[0134] S41. Determine if the node is a leaf node. If the node is a leaf node, jump to and execute S44. If the node is not a leaf node, execute S42.
[0135] S42. Calculate the maximum length (maxlen) of the substring of this node that is referenced by its child nodes;
[0136] S43. Determine if maxlen is equal to 0. If yes, execute S44; otherwise, execute S46.
[0137] S44. Set the existence flag of the node to 0, delete all substrings of the node in the first storage area LabelStore corresponding to the node, and set the overwrite flag in the second storage area hashtire to 1.
[0138] S45. Determine if the parent node of the node exists and if the deletion status flag of the parent node is 1. If so, treat the parent node of the node as the new node and perform a recursive deletion operation, that is, treat the parent node as the new node and return to the new node to execute S41.
[0139] S46. Control the deletion of the remaining characters after the maximum length of characters in the substring of the node to obtain the target string, and set the length of the target string stored in the first storage area to maxlen.
[0140] This application provides a scheme for obtaining a string to be deleted; wherein the string to be deleted is the content corresponding to a key; checking whether there is an identifier for the key node corresponding to the string to be deleted and an identifier for the value node corresponding to the key node; if there are identifiers for the key node and the value node, setting the first deletion identifier corresponding to the key node identifier to a first identifier used to indicate that the information corresponding to the key node can be deleted; controlling the deletion of the information corresponding to the key node; determining whether the identifier of the value node is not referenced by other key nodes, and if so, setting the second deletion identifier corresponding to the value node identifier to a second identifier used to indicate that the information corresponding to the value node can be deleted; and controlling the deletion of the information corresponding to the value node. This scheme can maintain the deletion status of nodes by setting deletion identifiers for nodes, thereby achieving the purpose of immediately releasing memory. It can also determine whether the value node can be safely deleted based on whether the value node is referenced by other nodes, thereby achieving the technical effect of improving the flexibility of the data deletion method of the CKV database.
[0141] Figure 5 A schematic diagram of the structure of a data deletion device provided for an exemplary embodiment of this application;
[0142] The device includes:
[0143] The acquisition unit 51 is used to acquire the string to be deleted; wherein, the string to be deleted is the content corresponding to the key;
[0144] The search unit 52 is used to search for whether there is an identifier for the key node corresponding to the string to be deleted and an identifier for the value node corresponding to the key node;
[0145] Setting unit 53 is used to set the first deletion flag corresponding to the key node flag to a first flag indicating that the information corresponding to the key node can be deleted if there is an identifier for the key node and an identifier for the value node.
[0146] Deletion unit 54 is used to control the information corresponding to the deletion key node;
[0147] The determining unit 55 is used to determine whether the identifier of the value node is not referenced by other key nodes. If so, the second deletion identifier corresponding to the value node identifier is set to a second identifier used to indicate that the information corresponding to the value node can be deleted.
[0148] The deletion unit 54 is also used to control the information corresponding to the deleted value node.
[0149] In some embodiments, the data deletion device is further configured to:
[0150] The query value node identifier is the number of times it has been referenced;
[0151] Decrease the control count by one;
[0152] Check if the number of times is 0. If it is, then the identifier of the value node is not referenced by other key nodes. If not, then the identifier of the value node is referenced by other key nodes.
[0153] In some embodiments, the information corresponding to the key node includes the substring corresponding to the key node and the first association information between the key node and its first parent node. When the data deletion device is used to control the deletion of the information corresponding to the key node, it is specifically used for:
[0154] Determine whether a key node is a leaf node and check whether the maximum length of a substring referenced by a key node's child nodes is 0;
[0155] When the key node is a leaf node, or when the key node is not a leaf node but the maximum length of the substring referenced by the key node's child nodes is 0, the system deletes the substring stored in the first storage area corresponding to the key node, sets the existence flag in the first storage area to a third flag indicating that the key node no longer exists, and sets the overwrite flag stored in the second storage area corresponding to the key node to a fourth flag indicating that the first association information can be overwritten. The system then determines whether the key node has a parent node. If it does, it determines whether the third deletion flag corresponding to the parent node is the first flag. If so, it sets the parent node as the new key node and returns to the steps of determining whether the key node is a leaf node and whether the maximum length of the substring referenced by the key node's child nodes is 0.
[0156] In some embodiments, the data deletion device is further configured to:
[0157] Get the string to be stored;
[0158] The identifier of the corresponding second key node is determined based on the string to be stored;
[0159] Determine the storage information of the second key node in the second storage area. The storage information includes: the second association relationship information between the second key node and its parent node.
[0160] The storage location of the stored information is determined based on preset rules;
[0161] If the target overlay identifier corresponding to the storage location is the fourth identifier;
[0162] The stored information will overwrite the existing content at the storage location.
[0163] In some embodiments, when the data deletion device is used to control the deletion of information corresponding to a key node, it is further used to: determine whether the key node is a leaf node and determine whether the maximum length of the substring referenced by the child node of the key node is 0; when the key node is not a leaf node and the maximum length of the substring referenced by the child node of the key node is not 0, then control the deletion of the remaining characters after the maximum length of characters in the substring to obtain the target substring, and set the length of the target substring stored in the first storage area to the maximum length.
[0164] In some embodiments, the data deletion device is further configured to:
[0165] To obtain the number of characters in a substring referenced by each child node of a key node, we can obtain the total number of characters in the substring referenced by multiple child nodes.
[0166] The maximum value among multiple character counts is used as the maximum length of the substring that can be referenced by the child nodes of the key node.
[0167] It should be understood that the device embodiments and method embodiments can correspond to each other, and similar descriptions can be referred to the method embodiments. To avoid repetition, they will not be repeated here. Specifically, the device can execute the above method embodiments, and the foregoing and other operations and / or functions of each module in the device correspond to the corresponding processes in the various methods in the above method embodiments, which will not be repeated here for the sake of brevity.
[0168] The apparatus of this application embodiment has been described above from the perspective of functional modules in conjunction with the accompanying drawings. It should be understood that this functional module can be implemented in hardware, in software instructions, or in a combination of hardware and software modules. Specifically, the steps of the method embodiments in this application can be completed by integrated logic circuits in the processor's hardware and / or by software instructions. The steps of the method disclosed in this application embodiment can be directly embodied as being executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. Optionally, the software module can reside in a mature storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps in the above method embodiments.
[0169] Figure 6 This is a schematic block diagram of an electronic device provided in an embodiment of this application. The electronic device may include:
[0170] The system includes a memory 601 and a processor 602. The memory 601 stores computer programs and transfers the program code to the processor 602. In other words, the processor 602 can retrieve and run the computer programs from the memory 601 to implement the methods described in the embodiments of this application.
[0171] For example, the processor 602 can be used to execute the above-described method embodiments according to instructions in the computer program.
[0172] In some embodiments of this application, the processor 602 may include, but is not limited to:
[0173] General-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0174] In some embodiments of this application, the memory 601 includes, but is not limited to:
[0175] Volatile memory and / or non-volatile memory. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), and Direct Rambus RAM (DR RAM).
[0176] In some embodiments of this application, the computer program may be divided into one or more modules, which are stored in the memory 601 and executed by the processor 602 to perform the method provided in this application. The one or more modules may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in the electronic device.
[0177] like Figure 6 As shown, the electronic device may also include:
[0178] Transceiver 603, which may be connected to processor 602 or memory 601.
[0179] The processor 602 can control the transceiver 603 to communicate with other devices; specifically, it can send information or data to other devices or receive information or data sent by other devices. The transceiver 603 may include a transmitter and a receiver. The transceiver 603 may further include antennas, and the number of antennas may be one or more.
[0180] It should be understood that the various components in the electronic device are connected through a bus system, which includes a data bus, a power bus, a control bus, and a status signal bus.
[0181] This application also provides a computer storage medium storing a computer program thereon, which, when executed by a computer, enables the computer to perform the methods of the above-described method embodiments. Alternatively, embodiments of this application also provide a computer program product containing instructions that, when executed by a computer, cause the computer to perform the methods of the above-described method embodiments.
[0182] When implemented using software, it can be implemented entirely or partially as a computer program product. This computer program product includes one or more computer instructions. When these computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., digital video disc (DVD)), or a semiconductor medium (e.g., solid-state disk (SSD)).
[0183] Those skilled in the art will recognize that the modules and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0184] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or modules may be electrical, mechanical, or other forms.
[0185] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. For example, the functional modules in the various embodiments of this application may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.
[0186] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A data deletion method, characterized in that, include: Get the string to be deleted; wherein, the string to be deleted is the content corresponding to the key; Check if there exists an identifier for the key node corresponding to the string to be deleted and an identifier for the value node corresponding to the key node; If the identifier of the key node and the identifier of the value node exist, set the first deletion identifier corresponding to the identifier of the key node to a first identifier used to indicate that the information corresponding to the key node can be deleted; Control the deletion of information corresponding to the key node; Determine whether the identifier of the value node is not referenced by other key nodes. If so, set the second deletion identifier corresponding to the identifier of the value node to a second identifier used to indicate that the information corresponding to the value node can be deleted. Control the deletion of information corresponding to the value node; The information corresponding to the key node includes the substring corresponding to the key node, and the first association relationship information between the key node and its first parent node. Controlling the deletion of the information corresponding to the key node includes: Determine whether the key node is a leaf node and determine whether the maximum length of the substring referenced by the child nodes of the key node is 0; When the key node is a leaf node, or when the key node is not a leaf node but the maximum length of the substring referenced by the child nodes of the key node is 0, the system controls the deletion of the substring stored in the first storage area corresponding to the key node, the setting of the existence flag in the first storage area to a third flag indicating that the key node no longer exists, and the setting of the overwrite flag stored in the second storage area corresponding to the key node to a fourth flag indicating that the first association information can be overwritten; it determines whether the key node has a parent node, and if so, determines whether the third deletion flag corresponding to the parent node is the first flag, and if so, sets the parent node as the new key node, and returns to the steps of determining whether the key node is a leaf node and determining whether the maximum length of the substring referenced by the child nodes of the key node is 0.
2. The method according to claim 1, characterized in that, The method further includes: Query the number of times the identifier of the value node is referenced; Decrease the number of times by one; Determine whether the number of times is 0. If it is, determine that the identifier of the value node is not referenced by other key nodes. If not, determine that the identifier of the value node is referenced by other key nodes.
3. The method according to claim 1, characterized in that, The method further includes: Get the string to be stored; The identifier of the corresponding second key node is determined based on the string to be stored; Determine the storage information of the second key node in the second storage area, the storage information including: the second association relationship information between the second key node and the parent node of the second key node; The storage location of the stored information is determined based on preset rules; If the target coverage identifier corresponding to the storage location is the fourth identifier; The stored information overwrites the original content at the storage location.
4. The method according to claim 1, characterized in that, Controlling the deletion of information corresponding to the key node further includes: determining whether the key node is a leaf node and determining whether the maximum length of the substring referenced by the child nodes of the key node is 0. When the key node is not a leaf node and the maximum length of the substring referenced by the child nodes of the key node is not 0, then controlling the deletion of the remaining characters after the maximum length of characters in the substring to obtain the target substring, and setting the length of the target substring stored in the first storage area to the maximum length.
5. The method according to claim 1, characterized in that, The method further includes: Obtain the number of characters referenced by each child node of the key node in the substring, and thus obtain the number of characters referenced by the substring in the multiple child nodes; The maximum value among the multiple character counts is taken as the maximum length of the substring referenced by the child nodes of the key node.
6. A data deletion device, characterized in that, include: The acquisition unit is used to acquire the string to be deleted; wherein the string to be deleted is the content corresponding to the key; The search unit is used to search for whether there is an identifier for the key node corresponding to the string to be deleted and an identifier for the value node corresponding to the key node; The setting unit is configured to, if an identifier for the key node and an identifier for the value node exist, set the first deletion identifier corresponding to the identifier of the key node to a first identifier indicating that the information corresponding to the key node can be deleted; The deletion unit is used to control the deletion of information corresponding to the key node; The determining unit is used to determine whether the identifier of the value node is not referenced by other key nodes. If so, the second deletion identifier corresponding to the identifier of the value node is set to a second identifier used to indicate that the information corresponding to the value node can be deleted. The deletion unit is also used to control the deletion of information corresponding to the value node; The information corresponding to the key node includes the substring corresponding to the key node and the first association relationship information between the key node and the first parent node of the key node. When the data deletion device controls the deletion of the information corresponding to the key node, it is also used to determine whether the key node is a leaf node and to determine whether the maximum length of the substring referenced by the child node of the key node is 0. When the key node is a leaf node, or the key node is not a leaf node, but the maximum length of the substring referenced by the child node of the key node is 0, the device controls the deletion of the substring stored in the first storage area corresponding to the key node, sets the existence identifier in the first storage area to a third identifier to indicate that the key node no longer exists, and sets the overwrite identifier stored in the second storage area corresponding to the key node to a fourth identifier to indicate that the first association relationship information can be overwritten. The device determines whether the key node has a parent node. If it does, it determines whether the third deletion identifier corresponding to the parent node is the first identifier. If it is, the device uses the parent node as a new key node and returns to execute the steps of determining whether the key node is a leaf node and determining whether the maximum length of the substring referenced by the child node of the key node is 0.
7. The data deletion device according to claim 6, characterized in that, The device is also used for: Query the number of times the identifier of the value node is referenced; Decrease the number of times by one; Determine whether the number of times is 0. If it is, determine that the identifier of the value node is not referenced by other key nodes. If not, determine that the identifier of the value node is referenced by other key nodes.
8. An electronic device, characterized in that, include: processor; as well as Memory for storing the executable instructions of the processor; The processor is configured to execute the method of any one of claims 1-5 by executing the executable instructions.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1-5.