Disclosure of Invention
In order to solve the above problems, the present invention provides a data deleting method, apparatus, device and storage medium, which can delete a field in a database for a document, that is, a document field, and effectively avoid that the document field occupies a storage space for a long time.
In a first aspect, an embodiment of the present application provides a data deletion method, including:
detecting a field failure characteristic of a target document field from a distributed document storage database, wherein the target document field is a field set by the distributed document storage database for a stored document;
judging whether the field failure characteristics of the target document field meet the field failure rule or not;
and deleting the target document field after determining that the field failure characteristics of the target document field meet the field failure rule.
Here, since the embodiment of the present application is provided with the field-level failure feature information, that is, the field failure feature is provided for the document field, in this way, the corresponding document field is deleted when it is determined that the field failure feature satisfies the field failure rule, so that the document field is prevented from occupying the storage space for a long time, and a foundation is laid for improving the utilization rate of the storage space.
In a specific embodiment, before the detecting the field failure feature of the target document field from the distributed document storage database, the method further includes:
detecting a target failure characteristic corresponding to a stored document from a distributed document storage database, wherein the target failure characteristic is determined based on a field failure characteristic of a document field corresponding to the document;
judging whether the target failure characteristics meet a document failure rule or not;
and after determining that the target failure characteristics meet the document failure rule, executing the field failure characteristics of the target document field detected from the distributed document storage database.
In the specific embodiment, the target failure characteristics are set for the document and are determined based on the field failure characteristics of the document field corresponding to the document, so that the field failure characteristics of the document field in the document are represented by the target failure characteristics, a foundation is laid for effectively screening out the document needing document field deletion processing, and a foundation is laid for subsequently deleting the document field.
Furthermore, the embodiment can effectively screen out the document which needs to be subjected to the document field deleting operation, and simultaneously can screen out the target document field which needs to be subjected to the deleting operation so as to delete the target document field, so that the document field is prevented from occupying the storage space for a long time, and a foundation is laid for improving the utilization rate of the storage space.
In another specific embodiment, the field failure characteristics indicate the failure time of the document field, and the target failure characteristics are the minimum value of the failure times of all document fields corresponding to the document.
Here, this embodiment provides a specific way to determine the target failure feature, that is, the minimum value of the failure time of all document fields in the document is used as the target failure feature, so that a simple and easy-to-implement method is provided for effectively screening out documents requiring document field deletion operation.
In another specific embodiment, the detecting field failure characteristics of the target document field from the distributed document storage database includes: and detecting the sub-field of the target document field from the distributed document storage database to obtain the field failure characteristic of the target document field.
In another specific embodiment, the detecting the target failure characteristics corresponding to the stored documents from the distributed document storage database includes: and detecting a characteristic field corresponding to the document from the distributed document storage database to obtain a target failure characteristic corresponding to the document.
The specific embodiment takes the field failure characteristics as the sub-fields of the document field, namely, the field failure characteristics are characterized by the field; or the target failure characteristics are used as the characteristic fields of the document, namely the characteristic fields are used for representing the target failure characteristics, so that the foundation is laid for maximizing the function improvement realization efficiency compatible with the existing database, the method is simple and convenient to realize, and the foundation is laid for the subsequent engineering application.
In another specific embodiment, the method further comprises: detecting an update operation for the target document field; and after the update operation is determined to be completed, updating the target failure characteristics of the document corresponding to the target document field, so that the updated target failure characteristics of the document are matched with the updated field failure characteristics of the target document field.
The target failure characteristics can be updated correspondingly according to the deletion operation of the target document field, so that the accuracy of the target failure characteristics is ensured, and a foundation is laid for effectively locking the document needing document field deletion again and deleting the target document field to the maximum extent and most accurately.
In another specific embodiment, the detecting the target failure characteristics corresponding to the stored documents from the distributed document storage database includes: and traversing the index of the distributed document storage database to obtain the target failure characteristics corresponding to the document.
In the method, the index aiming at the target failure characteristics is generated, so that the possibility is provided for quickly detecting the document needing to be subjected to document field deletion, and a foundation is laid for quickly realizing the scheme of the application.
In a second aspect, an embodiment of the present application provides a data deleting device, including:
a detection unit, configured to detect a field failure feature of a target document field from a distributed document storage database, where the target document field is a field set by the distributed document storage database for a stored document;
the judging unit is used for judging whether the field failure characteristics of the target document field meet the field failure rules or not;
and the deleting unit is used for deleting the target document field after determining that the field failure characteristics of the target document field meet the field failure rule.
The detection unit is further used for detecting a target failure characteristic corresponding to a stored document from a distributed document storage database, wherein the target failure characteristic is determined based on a field failure characteristic of a document field corresponding to the document;
the judging unit is also used for judging whether the target failure characteristics meet the document failure rule or not;
the detection unit is further configured to execute the field failure feature of the target document field detected from the distributed document storage database after determining that the target failure feature satisfies the document failure rule.
In a specific embodiment, the field failure characteristics indicate failure times of the document fields, and the target failure characteristics are a minimum value of the failure times of all document fields corresponding to the document.
In a specific embodiment, the detecting unit is further configured to detect a subfield of the target document field from the distributed document storage database, and obtain a field failure feature of the target document field.
In a specific embodiment, the detecting unit is further configured to detect a feature field corresponding to the document from the distributed document storage database, so as to obtain a target failure feature corresponding to the document.
In a specific embodiment, the detection unit is further configured to:
detecting an update operation for the target document field;
and after the update operation is determined to be completed, updating the target failure characteristics of the document corresponding to the target document field, so that the updated target failure characteristics of the document are matched with the updated field failure characteristics of the target document field.
In a specific embodiment, the detection unit is further configured to traverse an index of the distributed document storage database to obtain a target failure feature corresponding to the document.
In a third aspect, an embodiment of the present application provides a data deleting device, including:
one or more processors;
a memory communicatively coupled to the one or more processors;
one or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, the one or more programs configured to perform the methods described above.
In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the computer program implements the method described above.
In this way, since the embodiment of the application is provided with the field-level failure feature information, that is, the field failure feature is set for the document field, in this way, the corresponding document field is deleted under the condition that the field failure feature is determined to meet the field failure rule, so that the document field is prevented from occupying the storage space for a long time, and a foundation is laid for improving the utilization rate of the storage space.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
In some of the flows described in the specification and claims of the present application and in the above-described figures, a number of operations are included that occur in a particular order, but it should be clearly understood that the flows may include more or less operations, and that the operations may be performed sequentially or in parallel.
In an actual scene, when a large number of temporary attributes need to be stored for an object, a temporary field is set, but in the prior art, deletion operation for a field level cannot be supported, that is, an effective mechanism cannot be set to delete a document field, so that a problem that the temporary field occupies a storage space for long-term storage exists, at this time, if the temporary field is deleted, a user needs to implement a system to complete cleaning work, obviously, extra workload is increased, and efficiency is reduced.
Based on this, the embodiment of the application provides a data deleting method, device, equipment and storage medium; specifically, fig. 1 is a schematic flow chart of an implementation process of a data deletion method according to an embodiment of the present invention, and as shown in fig. 1, the method includes:
step 101: detecting a field failure characteristic of a target document field from a distributed document storage database, wherein the target document field is a field set by the distributed document storage database for a stored document.
In a specific example, before detecting a field failure feature of a document field from a distributed document storage database, a target failure feature may be set for a document, where the target failure feature is determined based on the field failure feature of the document field corresponding to the document, and then the target failure feature corresponding to the stored document is detected from the distributed document storage database, and whether the target failure feature satisfies a document failure rule is determined, and after determining that the target failure feature satisfies the document failure rule, the field failure feature of the target document field is detected from the distributed document storage database. Here, a document whose target failure characteristics satisfy the document failure rule may be used as a target document, and then it may be detected whether field failure characteristics of a field of the target document in the target document satisfy the field failure rule.
In practical applications, the field failure feature may specifically include at least one of the following information: time to failure, timing of failure (e.g., failure conditions, etc.), manner of failure, etc. Accordingly, the target failure characteristics may also include at least one of the following information: time to failure, timing of failure (e.g., failure conditions, etc.), manner of failure, etc. Of course, in practical application, the target failure characteristics can be set according to actual requirements.
In a specific example, the field failure characteristics indicate failure times of the document fields, and the target failure characteristics are the minimum value of the failure times of all document fields corresponding to the document. Therefore, the method lays a foundation for maximizing and locking the target document field most quickly. At this time, the field failure rule may specifically be a preset failure time, and the document failure rule may specifically be a preset failure time, and in a specific example, the preset failure time indicated by the field failure rule is the same as the preset failure time indicated by the document failure rule.
In a specific example, the field failure feature may be characterized by a field, or the target failure feature may be characterized by a field, and specifically, the field failure feature is used as a subfield of a document field, so that the subfield can characterize the failure feature of the document field, at this time, the detecting the field failure feature of the target document field from the distributed document storage database includes: and detecting the sub-field of the target document field from the distributed document storage database to obtain the field failure characteristic of the target document field. Therefore, a specific feasible scheme is provided, a foundation is laid for subsequent engineering application, meanwhile, the functions of the existing database can be maximally compatible, the implementation efficiency is improved, and the method is simple and convenient to implement.
In another specific example, the target failure characteristics may be used as a characteristic field of the document, so that the characteristic field can characterize the failure characteristics of the document field in the document. At this time, the detecting the target failure characteristics corresponding to the stored documents from the distributed document storage database includes: and detecting a characteristic field corresponding to the document from the distributed document storage database to obtain a target failure characteristic corresponding to the document. Therefore, a specific feasible scheme is provided, a foundation is laid for subsequent engineering application, meanwhile, the functions of the existing database can be maximally compatible, the implementation efficiency is improved, and the method is simple and convenient to implement.
In practical application, considering that there is an operation of modifying a field failure feature of a document field, or adding or deleting a document field, at this time, in order to improve accuracy of the scheme of the present application, it is necessary to update the field failure feature synchronously, specifically, an update operation for a document is detected, where the update operation for the document includes: updating field failure characteristics of at least one document field corresponding to the document (for example, modifying, deleting or adding information and the like), and/or deleting or adding operation (for example, deleting a certain document field corresponding to the document or adding a document field newly); and then, after the update operation aiming at the document is determined to be completed, the target failure characteristics of the document are updated, so that the target failure characteristics of the updated document can be matched with the field failure characteristics of the document field corresponding to the updated document, and thus, a foundation is laid for deleting the target document field to the maximum extent and most accurately.
In practical application, there is also an updating operation for the document field, for example, deleting the target document field, on the basis of which, the method and the device for detecting the target document field to be deleted can ensure that the scheme of the application can continuously detect one or more (two or more) target document fields to be deleted, update the target failure characteristics of the target document, thus ensure the accuracy of the target failure characteristics, and lay the foundation for maximally and most accurately deleting the target document field. The specific implementation mode comprises the following steps: detecting an update operation for the target document field; and after the update operation is determined to be completed, updating the target failure characteristics of the document corresponding to the target document field, so that the updated target failure characteristics of the document are matched with the updated field failure characteristics of the target document field.
Step 102: and judging whether the field failure characteristics of the target document field meet the field failure rule.
Step 103: and deleting the target document field after determining that the field failure characteristics of the target document field meet the field failure rule.
In a specific example, the determining whether the field failure characteristics of the target document field satisfy the field failure rules may specifically be: judging whether the failure time of the target document field is less than the current time, if so, determining that a field failure rule is met, and deleting the target document field; otherwise, the field invalidation rule is not satisfied.
Of course, in another example, the determining whether the target failure feature satisfies the document failure rule may specifically be: judging whether the failure time indicated by the target failure feature is less than the current time, if so, determining that a document failure rule is met, taking the document corresponding to the target failure feature meeting the document failure rule as a target document, and further executing the step 101 to detect a target document field in the target document; otherwise, the document invalidation rules are not considered satisfied. In the process, the document field needing to be deleted can be quickly found by searching all documents with the minimum failure time and then judging whether the target failure characteristics of the document with the minimum failure time meet the document failure rule.
In a specific example, the scheme of the application can also consider deletion operation for the document, specifically, detect the document failure characteristics of the document in the distributed document storage database to obtain the document meeting the preset failure rule, and delete the document meeting the preset failure rule. Wherein the document failure characteristics may include at least one of the following information: time to failure, timing of failure (e.g., failure conditions, etc.), manner of failure, etc. Here, taking the case that the document expiration feature includes expiration time as an example, at this time, the expiration time of the document may be compared with the current expiration time, and the document whose expiration time is less than the current expiration time may be regarded as a document to be deleted and subjected to deletion processing.
In practical application, the index can be used to improve the detection efficiency, that is: generating an index aiming at the characteristic field of the document, thus, the document which accords with the document failure rule can be quickly detected by using the index; or generating an index aiming at the target failure characteristics, and traversing the index of the distributed document storage database, so as to quickly obtain the target failure characteristics corresponding to the document.
In this way, since the embodiment of the application is provided with the field-level failure feature information, that is, the field failure feature is set for the document field, in this way, the corresponding document field is deleted under the condition that the field failure feature is determined to meet the field failure rule, so that the document field is prevented from occupying the storage space for a long time, and a foundation is laid for improving the utilization rate of the storage space.
MongoDB is taken as an example below, and the TTL function of the document field level is provided by using the scheme of the application; in particular, the amount of the solvent to be used,
for a document field needing setting field failure characteristics, such as TTL, adding an associated hidden field (the hidden field is invisible to a user) during storage, namely an expiration timestamp (expired _ at), wherein the data type is int 64; when a document field is set, the associated hidden field, that is, the expired timestamp (expired _ at) ═ current time + TTL.
Setting a target failure characteristic for a document, namely adding an associated hidden field, such as a minimum failure timestamp (min _ expired _ at), wherein the minimum failure timestamp is the minimum value of failure timestamps (expired _ at) of all document fields of the document, and the data type is int 64.
Here, in an actual scenario, if all the attributes of the document have no expiration timestamp set, the default value is the maximum value (0x7 fffffffffffffffff) that the type int64 can store.
In practical applications, when it is necessary to update the attribute (i.e. document field) of a document, for example, adding, modifying, or deleting a document field, the min _ amplified _ at value of the document is recalculated and updated.
The set (containing at least two documents) in MongoDB creates a hidden index on min _ highlighted _ at (the hidden index is invisible to the user), so that the document with the minimum min _ highlighted _ at value can be searched within O (1) time complexity by using the hidden index.
After the hidden fields and the hidden indexes are built, the MongoDB starts a background thread, periodically queries a document (namely a target document) with the minimum min _ amplified _ at value, if the min _ amplified _ at value of the document is smaller than the current time, checks the amplified _ at value corresponding to each document field, deletes the document field with the amplified _ at value smaller than the current time, and updates the min _ amplified _ at of the document, thus periodically finishing the work of cleaning the document fields.
In this way, only 8 bytes of storage space need to be added for the temporary fields (i.e. document fields) of the document, and only 8 bytes of storage space need to be added for the document; meanwhile, on the basis of adding a background thread, the following functions can be realized:
firstly, the granularity supported by MongoDB for TTL is refined from the document level to the document field level, so that the improved flexibility greatly expands the use scene.
Secondly, MongoDB can regularly clean out-of-date temporary fields, so that storage space is saved, and development workload of database users is reduced.
An embodiment of the present application further provides a data deleting device, as shown in fig. 2, the device includes:
a detection unit 21 configured to detect a field failure feature of a target document field from a distributed document storage database, wherein the target document field is a field set by the distributed document storage database for a stored document;
a judging unit 22, configured to judge whether a field failure characteristic of the target document field satisfies a field failure rule;
and the deleting unit 23 is configured to delete the target document field after determining that the field failure feature of the target document field meets the field failure rule.
In a specific embodiment, the detecting unit 21 is further configured to detect a target failure feature corresponding to a stored document from a distributed document storage database, where the target failure feature is determined based on a field failure feature of a document field corresponding to the document;
the judging unit 22 is further configured to judge whether the target failure feature satisfies a document failure rule;
the detecting unit 21 is further configured to, after determining that the target failure feature satisfies the document failure rule, execute the field failure feature of the target document field detected from the distributed document storage database.
In a specific embodiment, the field failure characteristics indicate failure times of the document fields, and the target failure characteristics are a minimum value of the failure times of all document fields corresponding to the document.
In a specific embodiment, the detecting unit 21 is further configured to detect a subfield of the target document field from the distributed document storage database, so as to obtain a field failure feature of the target document field.
In a specific embodiment, the detecting unit 21 is further configured to detect a feature field corresponding to the document from the distributed document storage database, so as to obtain a target failure feature corresponding to the document.
In an embodiment, the detecting unit 21 is further configured to:
detecting an update operation for the target document field;
and after the update operation is determined to be completed, updating the target failure characteristics of the document corresponding to the target document field, so that the updated target failure characteristics of the document are matched with the updated field failure characteristics of the target document field.
In a specific embodiment, the detecting unit 21 is further configured to traverse an index of the distributed document storage database to obtain a target failure feature corresponding to the document.
Here, it should be noted that: the descriptions of the embodiments of the apparatus are similar to the descriptions of the methods, and have the same advantages as the embodiments of the methods, and therefore are not repeated herein. For technical details that are not disclosed in the embodiments of the apparatus of the present invention, those skilled in the art should refer to the description of the embodiments of the method of the present invention to understand, and for brevity, will not be described again here.
An embodiment of the present application further provides a data deleting device, including: one or more processors; a memory communicatively coupled to the one or more processors; one or more application programs; wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, the one or more programs configured to perform the method described above.
In a specific example, the data deleting device according to the embodiment of the present application may be embodied as the structure shown in fig. 3, where the data deleting device at least includes a processor 31, a storage medium 32, and at least one external communication interface 33; the processor 31, the storage medium 32, and the external communication interface 33 are all connected by a bus 34. The processor 31 may be a microprocessor, a central processing unit, a digital signal processor, or a programmable logic array, etc. having processing functions. The storage medium has stored therein computer executable code capable of performing the method of any of the above embodiments. In practical applications, the detecting unit 21, the judging unit 22 and the deleting unit 23 can be implemented by the processor 31.
Here, it should be noted that: the description of the above device embodiment is similar to the description of the above method, and has the same beneficial effects as the method embodiment, and therefore, the description thereof is omitted. For technical details that are not disclosed in the embodiment of the data deleting device of the present invention, those skilled in the art should refer to the description of the embodiment of the method of the present invention to understand that, for the sake of brevity, detailed description is not repeated here.
Embodiments of the present application also provide a computer-readable storage medium, which stores a computer program, and when the program is executed by a processor, the computer program implements the method described above.
A computer-readable storage medium can be any means that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection (electronic device) having one or more wires, a portable computer diskette (magnetic device), a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable read-only memory (CDROM). Additionally, the computer-readable storage medium may even be paper or another suitable medium upon which the program is printed, as the program can be electronically captured, via for instance optical scanning of the paper or other medium, then compiled, interpreted or otherwise processed in a suitable manner if necessary, and then stored in a computer memory.
It should be understood that all or part of the steps carried by the method for implementing the above embodiments can be implemented by hardware related to instructions of a program, which can be stored in a computer readable storage medium, and the program includes one or a combination of the steps of the method embodiments when the program is executed.
In addition, functional units in the embodiments of the present invention may be integrated into one processing module, or each unit may exist alone physically, or two or more units are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. The integrated module, if implemented in the form of a software functional module and sold or used as a separate product, may also be stored in a computer readable storage medium. The storage medium may be a read-only memory, a magnetic or optical disk, or the like.
The embodiments described above are only a part of the embodiments of the present invention, and not all of them. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.