Garbage cleaning method, device, equipment, and storage medium
By performing dynamic garbage cleaning when the registry service is started, it solves the problem in the existing technology that the storage space cannot be released immediately and the service needs to be stopped for full scanning, achieving an efficient and fast garbage cleaning process, and simplifying the image deletion operation.
Patent Information
- Application Number
- CN201810996685.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-08-29
- Publication Date
- 2025-01-24
- Estimated Expiration
- 2039-05-19
AI Technical Summary
In the prior art, the user cannot immediately release the system storage space after deleting the mirror in the registry, and needs to stop the registry service for full scanning to clean up garbage.
Under the premise of starting the registry service, realize dynamic garbage cleaning. By obtaining the deletion request of the target mirror image in the mirror warehouse, the reference count of the storage block referenced by the target mirror image is reduced. The storage block referenced by the mirror.
It can be cleaned up without the need to stop the registry service, reduce the system burden, increase the cleaning speed, and simplify the mirror deletion operation through the mirror name and TAG interface.
Smart Images

Figure CN110874255B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to computer technology, and in particular to a garbage cleaning method and device, equipment, and storage medium. Background Art
[0002] Docker is an open source application container engine. As one of the core components of Docker, the image repository registry is responsible for the storage of images. An image is the basic unit that can be run in Docker. An image is composed of layers, and each layer of an image is a file system. When the registry stores an image, a blob is allocated for storage for each layer of the image and the description file containing the layer reference relationship of the image. The blob is a storage block. For each blob, the registry will perform a hash calculation based on the stored content, and the hash value will be used as the key value of the blob. The key value of the image is the hash value of the blob where the description file is located. When a new image is pushed to the registry, the registry will determine whether the image layer already exists in the registry based on the hash value. If the image layer already exists in the registry, it will skip the step of uploading through the request and directly establish a reference relationship. This can save registry storage and reduce network traffic.
[0003] As users continue to upload images, the system storage occupied by the registry will gradually increase. However, after users delete images in the registry, the storage space cannot be released immediately. For this reason, the registry provides a garbage cleaning tool. The usage process is to first stop the registry service, then fully scan the existing images and blobs in the system, analyze the blob reference relationship image by image and mark the blobs referenced by the image, and delete the blob storage files for blobs that are not referenced by the image, thereby releasing system storage space. Summary of the invention
[0004] In view of this, the embodiment of the present invention provides a garbage cleaning method, device, equipment, and storage medium to solve at least one problem existing in the prior art. Under the premise of starting a registry service, dynamic garbage cleaning of the registry without stopping service is realized without user triggering. At the same time, image deletion using image name plus Tag is realized, where Tag is a label. In this way, during garbage cleaning, there is no need to stop the registry service, and a full scan is only performed when the service is started. During operation, all operations and records on images and blobs are incremental, the system burden is smaller, and the cleaning speed is faster. The technical solution of the embodiment of the present invention is implemented as follows:
[0005] In a first aspect, an embodiment of the present invention provides a garbage cleaning method, the method comprising:
[0006] Get a deletion request for the target image in the image repository;
[0007] After deleting the target image, according to the reference counting strategy, the reference count of the storage block referenced by the target image is decremented;
[0008] When the reference count is decremented to zero, garbage cleaning is performed according to a preset garbage cleaning strategy to delete the storage block referenced by the target image.
[0009] In a second aspect, an embodiment of the present invention provides a garbage cleaning device, the device comprising: an agent control module, an image management module, a reference counting module and a garbage cleaning control module, wherein:
[0010] The proxy control module is used to obtain a deletion request for a target image in the image repository;
[0011] The image management module is used to delete the target image;
[0012] The reference counting module is used to decrement the reference count of the storage block referenced by the target image according to the reference counting strategy;
[0013] The garbage cleaning control module is used to perform garbage cleaning according to a preset garbage cleaning strategy after the reference count is decremented to zero, and delete the storage block referenced by the target image.
[0014] In a third aspect, an embodiment of the present invention provides a device including a memory and a processor, wherein the memory stores a computer program executable on the processor, and the processor implements the steps in the garbage cleaning method when executing the program.
[0015] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which implements the steps in the garbage cleaning method when executed by a processor.
[0016] In an embodiment of the present invention, a deletion request for a target image in an image repository is obtained; after deleting the target image, according to a reference counting strategy, a reference count of a storage block referenced by the target image is decremented; when the reference count is decremented to zero, according to a preset garbage cleaning strategy, a garbage cleaning is performed to delete the storage block referenced by the target image; in this way, during garbage cleaning, there is no need to stop the registry service, and a full scan is performed only when the service is started. During operation, all operations and records on images and blobs are incremental, the system burden is smaller, the cleaning speed is faster, the cleaning strategy can be customized according to the registry operating environment, the applicability is wider, an interface for deleting images by adding tags to image names is added, and the image deletion operation is simplified. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 A schematic diagram of the implementation flow of the garbage cleaning method according to an embodiment of the present invention;
[0018] Figure 2 A schematic diagram of a processing flow of a request for querying whether a specified storage block exists according to an embodiment of the present invention;
[0019] Figure 3 A schematic diagram of a processing flow of a request for creating a new image according to an embodiment of the present invention;
[0020] Figure 4 A schematic diagram of a processing flow of a request to delete an image by using an image key value according to an embodiment of the present invention;
[0021] Figure 5 A schematic diagram of a processing flow of a request to delete an image through an image tag according to an embodiment of the present invention;
[0022] Figure 6 This is a schematic diagram of the garbage cleaning control process according to an embodiment of the present invention;
[0023] Figure 7 This is a schematic diagram of the structure of a garbage cleaning device according to an embodiment of the present invention;
[0024] Figure 8 A schematic diagram of the structure of a garbage cleaning device and an image repository according to an embodiment of the present invention;
[0025] Fig. 9 It is a schematic diagram of the composition structure of the device according to the embodiment of the present invention. DETAILED DESCRIPTION
[0026] The technical solution of the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments.
[0027] Embodiment 1
[0028] Figure 1FIG. 1 is a schematic diagram of the implementation flow of the garbage cleaning method according to an embodiment of the present invention. Figure 1 As shown, the method includes:
[0029] Step S101, obtaining a deletion request for a target image in an image repository.
[0030] Step S102: after deleting the target image, according to the reference counting strategy, the reference count of the storage block referenced by the target image is decremented.
[0031] Step S103, when the reference count is decremented to zero, garbage cleaning is performed according to a preset garbage cleaning strategy to delete the storage block referenced by the target image.
[0032] for Figure 1 It should be noted that the technical solution shown is to obtain a deletion request for a target image in an image repository; after deleting the target image, according to a reference counting strategy, the reference count of the storage block referenced by the target image is decremented; when the reference count is decremented to zero, according to a preset garbage cleaning strategy, a garbage cleaning is performed to delete the storage block referenced by the target image; on the premise of starting a registry service, dynamic garbage cleaning without user triggering is realized without stopping the registry service, and at the same time, image deletion using image name plus tag is realized, so that during garbage cleaning, there is no need to stop the registry service, and a full scan is performed only when the service is started. During operation, all operations and records on images and blobs are incremental, the system burden is smaller, and the cleaning speed is faster. The cleaning strategy can be customized according to the registry operating environment, which has wider applicability, and an interface for deleting images by adding tags to image names is added to simplify the image deletion operation.
[0033] against Figure 1 The technical solution shown in the figure, in a possible implementation scheme, when the reference count is decremented to zero, a garbage cleaning is performed according to a preset garbage cleaning strategy to delete the storage block referenced by the target image, including:
[0034] If the time interval between the first moment and the last garbage cleaning start moment is equal to the preset first time interval, then within the preset second time interval, a garbage cleaning is performed to delete the storage block referenced by the target image, wherein the first moment includes when the reference count decreases to zero and the count of requests to the image repository decreases to zero; the requests to the image repository include deletion requests, storage block access requests, and image information modification requests. It should be noted that the storage block access request is a HEAD request, and the image information modification request is a PUT request.
[0035] Then, preferably, the method further comprises: performing garbage cleaning once within a preset second time interval, before deleting the storage block referenced by the target image;
[0036] Requests to the image repository after the first moment are cached.
[0037] Then, preferably, after caching the request to the image repository after the first moment, the method further includes:
[0038] When the preset second time interval is exceeded, the cache of requests to the image repository after the current moment is released.
[0039] against Figure 1 In a possible implementation of the technical solution shown in FIG. 1 , after obtaining a deletion request for a target image in the image repository, the method further includes:
[0040] Parse the deletion request for the target image in the image repository and obtain the image name and image tag information.
[0041] Then, preferably, deleting the target image includes:
[0042] Delete the target image according to the image name and the image tag information.
[0043] After deleting the target image, the reference count of the storage block referenced by the target image is decremented according to a preset reference count strategy, including:
[0044] The storage block referenced by the target image is referenced by N images, wherein the N images include the target image, and N is a positive integer greater than or equal to 1;
[0045] When any of the N images is deleted, the reference count is decremented;
[0046] When all the N images are deleted, the reference count is decremented to zero.
[0047] Based on the same inventive concept as the above-mentioned embodiments, this embodiment illustrates the technical solutions of the above-mentioned embodiments through specific examples. Figure 2 FIG. 1 is a schematic diagram of a processing flow of a request for querying whether a specified storage block exists according to an embodiment of the present invention. Figure 2 As shown, specifically including:
[0048] Step S201, obtaining a HEAD request.
[0049] It should be noted that the server receives the HEAD request sent by the docker daemon, and the HEAD request URL carries the name of the uploaded image and the ID information of the image layer, wherein the docker daemon is the server of the docker. The HEAD request is a request for the image repository.
[0050] Step S202, determine whether the HEAD request needs to be cached. If the HEAD request does not need to be cached, go to step S203 for processing.
[0051] Step S203, increment the request counter, and then forward the HEAD request to the image repository registry.
[0052] Step S204, based on the current image repository registry storage blob situation, determine whether the image layer needs to be uploaded. If not, go to step S205 for processing; if necessary, go to step S208 for processing.
[0053] It should be noted that the blob is a storage block.
[0054] Step S205: Send a message OK in response to the HEAD request to the docker daemon, and the request counter is decremented.
[0055] Step S206: if it is identified that there is a reference relationship of a storage block, a reference operation is performed on the storage block.
[0056] It should be noted that the reference operation performed on the storage block is to count the reference of the storage block referenced by the image to be uploaded, and the reference count is incremented.
[0057] Step S207, after waiting for the reference cycle, erase the reference relationship to the storage block.
[0058] It should be noted that step S207 can prevent the failure of the entire upload action due to garbage cleaning deleting the layer before the image is successfully uploaded; at the same time, if the upload request is interrupted, the uploaded storage blocks need to rely on this mechanism to be cleaned up in time. The reference count of the storage block is decremented. The reference period is a preset value, preferably, the reference period is set to 10 minutes. Erasing the reference relationship to the storage block means that the reference count of the storage block is decremented.
[0059] It should be noted that, in step S206 and step S207, the reference count of the storage block is incremented, and after the preset reference cycle, the reference count of the storage block is decremented accordingly regardless of whether the uploaded image is successfully uploaded. When the storage block is successfully referenced, the reference count of the storage block is further incremented.
[0060] Step S208, replying a failure message FAIL to the docker daemon for the HEAD request, and the request counter is decremented.
[0061] Based on the same inventive concept as the above-mentioned embodiments, this embodiment illustrates the technical solutions of the above-mentioned embodiments through specific examples. Figure 3 A schematic diagram of the processing flow of a request for creating a new image according to an embodiment of the present invention is shown in FIG. Figure 3 As shown, specifically including:
[0062] Step S301, obtaining a PUT request.
[0063] It should be noted that the PUT request URL contains the image name and image tag, or the PUT request URL contains the image key value information, and the PUT request body contains detailed image description information. After dockerdaemon has uploaded all image layers, it needs to send a PUT request to upload the image configuration file to complete the entire upload process. Among them, the image configuration file is a description file containing the layer reference relationship of the image. The PUT request is a request for the image repository.
[0064] Step S302, determine whether the PUT request needs to be cached. If the PUT request does not need to be cached, go to step S303 for processing.
[0065] Step S303: increment the request counter and then forward the PUT request to the image repository registry.
[0066] Step S304, determining whether the image is successfully saved, if the image is successfully saved, proceeding to step S305 for processing, if the image is not successfully saved, proceeding to step S308 for processing.
[0067] Step S305: Send a message SUCC in response to the PUT request to the docker daemon, and the request counter is decremented.
[0068] It should be noted that the registry successfully processes the PUT request, indicating that the registry has successfully saved the image and replies with a SUCC message. The server sends a SUCC message in response to the PUT request to the docker daemon, and the request counter is decremented.
[0069] Step S306, identifying that the registry storage image is successful, and judging whether to update the original image or to add a new image according to the image information input.
[0070] Step S307, updating the reference relationship of the corresponding storage block for the storage block reference change caused by the mirror change.
[0071] It should be noted that the reference relationship of the corresponding storage block is updated, that is, the reference count of the storage block referenced by the image is increased or decreased.
[0072] Step S308: Send a message FAIL in response to the PUT request to the docker daemon, and the request counter is decremented.
[0073] It should be noted that, due to some reasons, the PUT request fails, the registry fails to save the image successfully, and replies with a FAIL message. The server sends the FAIL message in reply to the PUT request to the docker daemon, and the request counter is decremented.
[0074] It should be noted that when uploading an image through Docker, the Docker daemon will first obtain the image layer information from the local computer, and then determine whether the image layers need to be uploaded. If they need to be uploaded, the upload operation will be performed, otherwise the upload operation will be skipped. After all layers are uploaded, the Docker daemon will send a new manifests request to upload the relationship between the image layers, and the image upload operation is completed. Among them, manifests exist in the registry as the metadata file of the Docker image.
[0075] Based on the same inventive concept as the above-mentioned embodiments, this embodiment illustrates the technical solutions of the above-mentioned embodiments through specific examples. Figure 4 FIG. 1 is a schematic diagram of a processing flow of a request to delete an image by using an image key value according to an embodiment of the present invention. Figure 4 As shown, specifically including:
[0076] Step S401, obtaining a DELETE request.
[0077] It should be noted that users delete images through the native registry interface. The deletion request is a DELETE request, and the DELETE request URL carries the image name and image key information. The native registry interface for deleting images sends a DELETE request. Deleting the key information of an image will cause the risk that all tags that reference the key of the image will become unavailable. The DELETE request is a request to the image repository.
[0078] Step S402, determine whether the DELETE request needs to be cached. If the DELETE request does not need to be cached, go to step S403 for processing.
[0079] Step S403: increment the request counter and forward the DELETE request to the image repository registry.
[0080] Step S404, determining whether the image is successfully deleted, if the image is successfully deleted, proceeding to step S405 for processing, if the image is not successfully deleted, proceeding to step S408 for processing.
[0081] Step S405: Send a message SUCC in response to the DELETE request to the user, and the request counter is decremented.
[0082] It should be noted that the registry successfully deletes the specified image and replies with a success SUCC message. The server sends a SUCC message in response to the DELETE request to the user, and the request counter is decremented.
[0083] Step S406: upon receiving the registry message SUCC, delete the mirror record specified by the user.
[0084] Step S407: decrement the reference count of the storage block referenced by the image.
[0085] It should be noted that the reference count of the storage block referenced by the image is decremented, that is, the storage block is dereferenced.
[0086] Step S408: Send a message NOT FOUND in reply to the DELETE request to the user, and the request counter is decremented.
[0087] It should be noted that the registry believes that the image being deleted by the user does not exist, or that the image deletion fails due to other reasons. The registry will reply with a NOT FOUND message indicating the deletion failed, along with the reason for the failure. The server will send a NOT FOUND message to the user in response to the DELETE request, and the request counter will be decremented.
[0088] Based on the same inventive concept as the above-mentioned embodiments, this embodiment illustrates the technical solutions of the above-mentioned embodiments through specific examples. Figure 5 FIG. 1 is a schematic diagram of a processing flow of a request to delete an image through an image tag according to an embodiment of the present invention. Figure 5 As shown, specifically including:
[0089] Step S501, obtaining a DELETE request.
[0090] It should be noted that the user deletes the image through the image name plus tag deletion interface, where the tag is a label. The user sends a DELETE request to delete the image. The DELETE request URL needs to carry the image name and image tag information, and the DELETE request is sent to the proxy control module. The newly added deletion interface allows the user to specify the image name and tag in the URL to delete the specified image. The DELETE request is a request to the image repository.
[0091] Step S502: When it is identified that the DELETE request carries Tag information, the process goes to step S503 for processing. If the image specified by the user cannot be found, the process goes to step S506 for processing.
[0092] Step S503: Delete the specified image.
[0093] Step S504: decrement the reference count of the storage block of the specified image.
[0094] Step S505: reply a deletion success SUCC message to the user.
[0095] Step S506: If the image specified by the user cannot be found, a deletion failure NOT FOUND message is sent to the user.
[0096] Based on the same inventive concept as the above-mentioned embodiments, this embodiment illustrates the technical solutions of the above-mentioned embodiments through specific examples. Figure 6 FIG. 1 is a schematic diagram of a garbage cleaning control process according to an embodiment of the present invention. Figure 6 As shown, specifically including:
[0097] Step S601, when the request counter is decremented, determine whether the current service volume of the registry is 0, if it is 0, go to step S602 for processing.
[0098] It should be noted that when the reference count of the storage block is decremented to zero, it is determined whether the current business volume of the registry is 0, wherein the current business volume of the registry is the total number of various requests to the image repository, including DELETE requests, HEAD requests, and PUT requests.
[0099] Step S602, determine whether the immediate cleaning condition is met at the first moment, if the immediate cleaning condition is met, go to step S603 for processing, if not, go to step S604 for processing.
[0100] It should be noted that when the current business volume of the registry is 0, whether garbage cleaning can be performed at the first moment is determined based on whether the interval between the first moment and the start time of the last garbage cleaning is equal to the preset first time interval; immediate cleaning condition: the interval between the first moment and the start time of the last garbage cleaning is equal to the preset first time interval; when the cleaning condition is met, garbage cleaning is performed, otherwise wait for the next moment when the registry business volume is 0.
[0101] Step S603, when the requirement for immediate cleaning is met, enter the HOLD mode.
[0102] It should be noted that the HOLD mode caches the various requests received to the image repository registry and starts a cache request timeout timer, wherein the HOLD mode is a service suspension mode.
[0103] Step S604: The garbage cleaning requirement is not met at the first moment, and the entire cleaning process ends, waiting for the next registry idle event to be triggered.
[0104] Step S605, obtaining all storage blocks to be cleared.
[0105] Step S606, obtain one from all storage blocks to be cleaned, if the acquisition is successful, go to step S608 for processing, if it fails, indicating that there is no storage block that can be cleaned, then go to step S607 for processing.
[0106] Step S607, exiting the HOLD mode.
[0107] It should be noted that exiting HOLD mode will release all cached requests and clear the cached request timeout timer.
[0108] Step S608, after obtaining the storage block information that can be cleared, determine whether the cache request timeout timer is triggered by timeout. If it is triggered by timeout, go to step S607 for processing; if it is not triggered by timeout, go to step S609 for processing.
[0109] Step S609, deleting the storage block and the record information of the storage block.
[0110] It should be noted that after the deletion is completed, the process proceeds to step S606 to apply for the next storage block information to be deleted until all the storage block information to be deleted is cleared.
[0111] Embodiment 2
[0112] Based on the same inventive concept as the above embodiments, Figure 7 FIG. 1 is a schematic diagram of the structure of a garbage cleaning device according to an embodiment of the present invention. Figure 7As shown, the garbage cleaning device 700 includes: an agent control module 701, an image management module 702, a reference counting module 703 and a garbage cleaning control module 704, wherein:
[0113] The proxy control module 701 is used to obtain a deletion request for a target image in the image repository;
[0114] The image management module 702 is used to delete the target image;
[0115] The reference counting module 703 is used to decrement the reference count of the storage block referenced by the target image according to the reference counting strategy;
[0116] The garbage cleaning control module 704 is used to perform garbage cleaning according to a preset garbage cleaning strategy when the reference count is decremented to zero, and delete the storage block referenced by the target image.
[0117] In the above scheme, preferably, the garbage cleaning control module 704 is used to perform a garbage cleaning within a preset second time interval to delete the storage block referenced by the target image when the time interval between the first moment and the last garbage cleaning start moment is equal to the preset first time interval, wherein the first moment includes when the reference count decreases to zero and the count of requests to the image repository decreases to zero; the requests to the image repository include deletion requests, storage block access requests, and image information modification requests. In the above scheme, preferably, the proxy control module 701 is used to parse the deletion request for the target image in the image repository and obtain the image name and image tag information.
[0118] Preferably, the proxy control module 701 is used to cache requests to the image repository after the first moment.
[0119] Preferably, the proxy control module 701 is used to release the cache of requests to the image repository after the first moment when the preset second time interval is exceeded.
[0120] In the above solution, preferably, the image management module 702 is used to delete the target image according to the image name and image tag information.
[0121] In the above scheme, preferably, the reference counting module 703 is used for the storage block referenced by the target image to be referenced by N images, wherein the N images include the target image, and N is a positive integer greater than or equal to 1; when any of the N images is deleted, the reference count is decremented; when all the N images are deleted, the reference count is decremented to zero.
[0122] It should be noted that the proxy control module 701 is used to forward the registry request, count the current business quantity in real time, cache the business request, identify the business request, and notify other related modules, wherein the registry request is a request to the image warehouse. The image management module 702 is responsible for maintaining the reference relationship of all images and storage blocks in the current registry, and provides interfaces for adding, updating, and deleting image reference relationships. The reference counting module 703 is used to maintain the reference counts of all storage blocks and provide interfaces for adding and deleting reference counts. The garbage cleaning control module 704 is used to decide whether garbage cleaning can be performed at the current moment, and to control the process of garbage cleaning. When the system is powered on, the image management module 702 and the reference counting module 703 perform the operation of initializing data to obtain the reference relationship between the current image and storage block; then the proxy control and registry services are started in turn. The proxy control module 701 will intercept all requests to the registry, thereby identifying the events of adding, deleting images, and accessing storage blocks, and notifying the image management module 702 and the reference counting module 703. When the number of services in the registry is 0, the proxy control module 701 notifies the garbage cleaning control module 704, which decides whether to perform garbage cleaning based on the reference relationship of the current storage block. When performing garbage cleaning, the garbage cleaning control module 704 notifies the proxy control module 701 to cache all requests, and obtains the storage blocks that are not currently referenced from the reference counting module 703, and cleans them one by one.
[0123] Figure 8 FIG. 1 is a schematic diagram of the structure of the garbage cleaning device and the image warehouse according to an embodiment of the present invention. Figure 8 As shown, a garbage cleaning device 700 and an image registry 800, wherein the dynamic garbage cleaning device 700 includes an agent control module 701, an image management module 702, a reference counting module 703 and a garbage cleaning control module 704, and the image registry 800 includes storage blocks (blobs) 801 and images (images) 802.
[0124] It should be noted that the processing of the request to query whether the specified storage block exists:
[0125] S011, the proxy control module 701 receives the message HEAD / v2 / sent by the docker daemon / blobs / <digst>.
[0126] S012, the proxy control module 701 forwards the message HEAD / v2 / / blobs / <digst>To the image repository 800.
[0127] S013, the image repository 800 sends a message OK or FAIL to the proxy control module 701.
[0128] S014, the proxy control module 701 forwards the message OK or FAIL.
[0129] When the proxy control module 701 forwards the message OK, the following processing is continued:
[0130] S015, the proxy control module 701 sends message blobs <digst>head succ to the reference counting module 703.
[0131] S016, after waiting for the reference cycle, the proxy control module 701 sends a message erase blob <digst>head history to the reference counting module 703, wherein the reference period is a preset value, and preferably, the reference period is set to 10 minutes.
[0132] It should be noted that the processing of the request to create a new image:
[0133] S021, the proxy control module 701 receives the message PUT / v2 / sent by the docker daemon / manifests / <reference>.
[0134] S022, the proxy control module 701 forwards the message PUT / v2 / / manifests / <reference>To the image repository 800.
[0135] S023 , the image repository 800 sends a message SUCC or FAIL to the proxy control module 701 .
[0136] S024, the proxy control module 701 forwards the message SUCC or FAIL.
[0137] When the proxy control module 701 forwards the message SUCC, the following processing is continued:
[0138] S025, the proxy control module 701 sends a message add image <reference>To the image management module 702.
[0139] S026 , the image management module 702 sends a message ref by image to the reference counting module 703 .
[0140] It should be noted that the processing of the request to delete an image by image key value:
[0141] S031, the proxy control module 701 receives the message DELETE / v2 / / manifests / <digst>.
[0142] S032, the proxy control module 701 forwards the message DELETE / v2 / / manifests / <digst>To the image repository 800.
[0143] S033 , the image repository 800 sends a message SUCC or NOT FOUND to the proxy control module 701 .
[0144] S034, the proxy control module 701 forwards the message SUCC or NOT FOUND.
[0145] When the proxy control module 701 forwards the message SUCC, the following processing is continued:
[0146] S035, the agent control module 701 sends a message delete image by <digst>To the image management module 702.
[0147] S036, the image management module 702 sends a message remove ref by image to the reference counting module 703.
[0148] It should be noted that the processing of the request to delete an image through an image tag is as follows:
[0149] S041, the proxy control module 701 receives the message DELETE / v2 / / manifests / <tag>.
[0150] S042, the proxy control module 701 forwards the message delete image by <tag>To the image management module 702.
[0151] When the proxy control module 701 recognizes that the DELETE request carries Tag information, it performs the following processing:
[0152] S043, the image management module 702 sends a message remove ref by image to the reference counting module 703.
[0153] S044 , the image management module 702 sends a message SUCC to the proxy control module 701 .
[0154] S045, the proxy control module 701 forwards the message SUCC.
[0155] When the proxy control module 701 cannot find the image specified by the user, the following processing is performed:
[0156] S046, the image management module 702 sends a message NOT FOUND to the proxy control module 701.
[0157] S047, the proxy control module 701 forwards the message NOT FOUND. It should be noted that the Tag is a label.
[0158] The description of the above device embodiment is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment. For technical details not disclosed in the device embodiment of the present invention, please refer to the description of the method embodiment of the present invention for understanding.
[0159] It should be noted that, in the embodiment of the present invention, if the above-mentioned garbage cleaning method is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention can be essentially or partly reflected in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions for a device to execute all or part of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk. In this way, the embodiment of the present invention is not limited to any specific combination of hardware and software.
[0160] Correspondingly, an embodiment of the present invention provides a device, including a memory and a processor, wherein the memory stores a computer program that can be executed on the processor, and the processor implements the steps in the garbage cleaning method when executing the program.
[0161] Generally speaking, during the implementation process, the device may be various types of devices with information processing capabilities, for example, the device may include a server, etc.
[0162] Correspondingly, an embodiment of the present invention provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps in the garbage cleaning method are implemented.
[0163] It should be noted that the description of the above storage medium and device embodiments is similar to the description of the above method embodiments, and has similar beneficial effects as the method embodiments. For technical details not disclosed in the storage medium and device embodiments of the present invention, please refer to the description of the method embodiments of the present invention for understanding.
[0164] Based on the above-mentioned garbage cleaning device 700 and computer-readable storage medium, an embodiment of the present invention provides a device, Fig. 9 Schematic diagram of the structure of the device according to the embodiment of the present invention. Fig. 9 As shown, the device 900 includes at least one processor 901, at least one communication bus 902, a user interface 903, at least one external communication interface 904 and a memory 905. The communication bus 902 is configured to realize the connection and communication between these components. The user interface 903 may include a display screen, and the external communication interface 904 may include a standard wired interface and a wireless interface. The memory 905 is configured to store instructions and applications executable by the processor 901, and can also cache data to be processed or processed by the processor 901 and each module in the device 900, which can be implemented by flash memory (FLASH) or random access memory (Random Access Memory, RAM).
[0165] The processor 901 is configured to execute, when running the computer program:
[0166] Get a deletion request for the target image in the image repository;
[0167] After deleting the target image, according to the reference counting strategy, the reference count of the storage block referenced by the target image is decremented;
[0168] When the reference count is decremented to zero, garbage cleaning is performed according to a preset garbage cleaning strategy to delete the storage block referenced by the target image.
[0169] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present invention. Therefore, "in one embodiment" or "in an embodiment" appearing in various places throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present invention, the size of the serial number of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention. The serial numbers of the above-mentioned embodiments of the present invention are only for description and do not represent the advantages and disadvantages of the embodiments.
[0170] It should be noted that, in this article, the term "includes", "comprising" or any other variation thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0171] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0172] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0173] In addition, all functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0174] A person skilled in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM), magnetic disks or optical disks, etc., various media that can store program codes.
[0175] Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a device to execute all or part of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks or optical disks.
[0176] The above is only an embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.< / tag> < / tag> < / digst> < / digst> < / digst> < / reference> < / reference> < / reference> < / digst> < / digst> < / digst> < / digst>
Claims
1. A garbage cleaning method, characterized in that: The method comprises: Get a deletion request for the target image in the image repository; After deleting the target image, according to the reference counting strategy, the reference count of the storage block referenced by the target image is decremented; When the reference count is decremented to zero, a garbage cleaning is performed according to a preset garbage cleaning strategy to delete the storage block referenced by the target image, including: if the time interval between the first moment and the start time of the last garbage cleaning is equal to the preset first time interval, then within the preset second time interval, a garbage cleaning is performed to delete the storage block referenced by the target image, wherein the first moment includes when the reference count is decremented to zero and the count of requests to the image repository is decremented to zero; the request to the image repository includes a deletion request, a storage block access request, and an image information modification request.
2. The method according to claim 1, characterized in that After obtaining the deletion request for the target image in the image repository, the method further includes: Parse the deletion request for the target image in the image repository and obtain the image name and image tag information.
3. The method according to claim 2, characterized in that The deleting the target image includes: Delete the target image according to the image name and the image tag information.
4. The method according to claim 1, characterized in that: The step of decrementing the reference count of the storage block referenced by the target image according to the reference count strategy includes: The storage block referenced by the target image is referenced by N images, wherein the N images include the target image, and N is a positive integer greater than or equal to 1; When any of the N images is deleted, the reference count is decremented; When all the N images are deleted, the reference count is decremented to zero.
5. The method according to claim 1, characterized in that The method further comprises: performing garbage cleaning within a preset second time interval, before deleting the storage block referenced by the target image; Requests to the image repository after the first moment are cached.
6. The method according to claim 5, characterized in that After caching the request to the image repository after the first moment, the method further includes: When the preset second time interval is exceeded, the cache of requests to the image repository after the first moment is released.
7. A dynamic garbage cleaning device, characterized in that: The device comprises: an agent control module, an image management module, a reference counting module and a garbage cleaning control module, wherein: The proxy control module is used to obtain a deletion request for a target image in the image repository; The image management module is used to delete the target image; The reference counting module is used to decrement the reference count of the storage block referenced by the target image according to the reference counting strategy; The garbage cleaning control module is used to perform a garbage cleaning according to a preset garbage cleaning strategy after the reference count is decremented to zero, and delete the storage block referenced by the target image; wherein, when the reference count is decremented to zero, a garbage cleaning is performed according to a preset garbage cleaning strategy, and the storage block referenced by the target image is deleted, including: if the time interval between the first moment and the start moment of the last garbage cleaning is equal to the preset first time interval, then within the preset second time interval, a garbage cleaning is performed to delete the storage block referenced by the target image, wherein the first moment includes when the reference count is decremented to zero and the count of requests to the image repository is decremented to zero; the request to the image repository includes a deletion request, a storage block access request, and an image information modification request.
8. A garbage cleaning device, comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, characterized in that: When the processor executes the program, the steps of the garbage cleaning method described in any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the garbage cleaning method described in any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Image management method, device and system
CN105740048A