A file cleaning method and apparatus
By using the asynchronous component sharing variable mechanism in the file cleanup server, the executable cleanup time is dynamically identified, which solves the problem of file cleanup competing for system resources during peak business periods and achieves efficient file cleanup during system idle time.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-17
- Publication Date
- 2026-03-17
AI Technical Summary
Existing file cleanup solutions can easily lead to resource contention during peak business periods, resulting in decreased system performance and impacting business continuity.
A file cleanup server is used. By setting a shared variable that can be accessed by asynchronous components, the cleanup status at the current time is detected, and the system determines whether to perform file cleanup based on the status, utilizing system idle time for file cleanup.
By effectively utilizing system idle time for file cleanup, the impact of cleaning up a large number of files during peak business periods on actual business operations has been reduced, thus maintaining the efficient operation of the system.
Smart Images

Figure CN116266172B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data cleaning technology, and in particular to a file cleaning method and apparatus. Background Technology
[0002] With the rapid growth of business volume in the financial sector, the generation and modification of various data files are also increasing. Especially in distributed business scenarios, the file system generates a large number of data files every day. When the number of these files exceeds the system's carrying capacity, the overall performance of the system will drop significantly. Therefore, it is necessary to clean up these files regularly.
[0003] However, the inventors discovered that the existing file cleanup solutions face high business risks and can easily affect business continuity. Summary of the Invention
[0004] This application provides a file cleaning method and apparatus to reduce the impact of file cleaning on actual business operations.
[0005] The embodiments of this application adopt the following technical solutions:
[0006] In a first aspect, embodiments of this application provide a file cleanup method, executed by a file cleanup server, wherein the method includes:
[0007] Set up a shared variable that can be accessed by both the first component and the second component, where the first component and the second component are asynchronous components;
[0008] The first component detects the cleanup status at the current time and determines the value of the shared variable based on the detected cleanup status at the current time.
[0009] The second component reads the value of the shared variable and determines, based on the read value of the shared variable, whether to clean up the file to be cleaned according to a preset file cleanup strategy.
[0010] Optionally, the step of having the first component detect the cleanup status at the current time includes:
[0011] The evaluation metrics for the cleanup status are obtained, including hardware resource metrics and the time period corresponding to the peak business period.
[0012] The current cleaning status is determined based on the evaluation indicators of the cleaning status.
[0013] Optionally, determining the current cleaning status based on the evaluation index of the cleaning status includes:
[0014] If the hardware resource indicators do not meet the preset indicator threshold requirements, and the current time is not within the time period corresponding to the business peak period, then the cleanup status of the current time is determined to be a cleanupable status.
[0015] If the hardware resource indicators reach the preset threshold requirements, and / or the current time is within the time period corresponding to the peak business period, then the cleanup status of the current time is determined to be an uncleanable state.
[0016] Optionally, determining the value of the shared variable based on the cleanup status detected at the current time includes:
[0017] If the cleanup status at the current time is a cleanupable status, then the value of the shared variable is determined to be true;
[0018] If the current time's cleanup status is an uncleanable status, then the value of the shared variable is determined to be false.
[0019] Optionally, the evaluation metrics for obtaining the cleanup status include:
[0020] The steps for obtaining evaluation indicators of the cleanup status are executed according to the first preset time interval.
[0021] Optionally, after setting shared variables that can be accessed by both the first and second components, the method further includes:
[0022] Get information about the files to be cleaned;
[0023] The number of files to be cleaned is determined based on the information of the files to be cleaned.
[0024] If the number of files to be cleaned exceeds a preset threshold, then the second component reads the value of the shared variable;
[0025] If the number of files to be cleaned is not higher than the preset number threshold, the second component will not read the value of the shared variable.
[0026] Optionally, determining whether to clean up the files to be cleaned according to a preset file cleanup strategy based on the value of the read shared variable includes:
[0027] If the value of the shared variable read is true, then the file to be cleaned will be cleaned according to the preset file cleanup strategy;
[0028] If the value of the shared variable read is false, then the file to be cleaned will not be cleaned.
[0029] Optionally, after cleaning the files to be cleaned according to a preset file cleanup strategy, the method further includes:
[0030] Get the cleanup results of the files to be cleaned;
[0031] If the cleaning result of the file to be cleaned is "cleaning complete", then the current file cleaning will end.
[0032] If the cleaning result of the file to be cleaned is that the cleaning is not complete, then the step of making the second component read the value of the shared variable is executed again.
[0033] Optionally, if the value of the shared variable read is false, the method further includes:
[0034] After the second preset time interval, the step of causing the second component to read the value of the shared variable is executed again.
[0035] Secondly, embodiments of this application also provide a file cleaning device applied to a file cleaning server, wherein the device is used to implement any of the methods described above.
[0036] Thirdly, embodiments of this application also provide an electronic device, including:
[0037] Processor; and
[0038] A memory configured to store computer-executable instructions, which, when executed, cause the processor to perform any of the methods described above.
[0039] Fourthly, embodiments of this application also provide a computer-readable storage medium that stores one or more programs, which, when executed by an electronic device including multiple applications, cause the electronic device to perform any of the methods described above.
[0040] The at least one technical solution adopted in this application embodiment can achieve the following beneficial effects: The file cleanup method of this application embodiment can be executed by a file cleanup server. When performing file cleanup, a shared variable that can be accessed by both the first component and the second component is first set. Here, the first component and the second component are asynchronous components. Then, the first component detects the cleanup status at the current time and determines the value of the shared variable based on the detected cleanup status at the current time. Finally, the second component reads the value of the shared variable and determines whether to clean up the files to be cleaned according to the preset file cleanup strategy based on the read value of the shared variable. By introducing the cleanup status at the current time as a shared variable, the file cleanup method of this application embodiment can dynamically identify the time when a cleanup operation can be performed, effectively utilize system idle time for file cleanup, and reduce the impact of cleaning up a large number of files during peak business periods on actual business. In addition, the first component and the second component used in this application embodiment are two asynchronous components. The cleanup status at the current time is detected through an asynchronous thread, which does not affect the execution efficiency of the main process. Attached Figure Description
[0041] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0042] Figure 1 This is a flowchart illustrating a file cleaning method according to an embodiment of this application;
[0043] Figure 2 This is a schematic diagram of a file cleanup process in an embodiment of this application;
[0044] Figure 3 This is a schematic diagram of the structure of a file cleaning device according to an embodiment of this application;
[0045] Figure 4 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. Detailed Implementation
[0046] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0047] The technical solutions provided by the various embodiments of this application are described in detail below with reference to the accompanying drawings.
[0048] Existing file cleanup solutions mainly employ a timed execution of cleanup programs, such as periodically scanning Changelog files, filtering files to be cleaned, and deleting them until the deletion is complete.
[0049] However, this cleanup method has a problem: during peak business periods, when the number of files to be cleaned on a single day is large, the cleanup process of a single batch of files will occupy the core business resources of the system and take too long, which will lead to a decline in the overall performance of the system. If a large number of files are written during peak business periods, performing a deletion operation at this time will cause the actual business to face a significant risk.
[0050] Based on this, this application provides a file cleanup method, executed by a file cleanup server, such as... Figure 1 The diagram shows a flowchart of a file cleaning method according to an embodiment of this application. The method includes at least the following steps S110 to S130:
[0051] Step S110: Set a shared variable that can be accessed by both the first component and the second component, wherein the first component and the second component are asynchronous components.
[0052] The file cleaning method in this application embodiment can be executed by a file cleaning server. The file cleaning server can be a database server, or any other server with file cleaning needs, or another server that performs file cleaning on machines with file cleaning needs. Of course, those skilled in the art can flexibly adjust the specific settings according to the actual business scenario, and no specific limitation is made here.
[0053] In this embodiment of the application, when performing file cleanup, a shared variable Runnable is set in the configuration file in advance. This shared variable can be accessed by both the first component and the second component. It can be used to characterize the cleanup status of the machine where the file to be cleaned is located at the current time.
[0054] The aforementioned "first component" and "second component" can be viewed as carriers of two asynchronously executed threads. Their execution processes are independent of each other, but they can establish a connection through shared variables.
[0055] Step S120: The first component detects the cleanup status at the current time and determines the value of the shared variable based on the detected cleanup status at the current time.
[0056] The thread executed by the aforementioned "first component" can be viewed as a detection thread. Specifically, after setting the shared variables, the first component needs to detect the cleanup status of the machine containing the files to be cleaned at the current time. This current cleanup status can be used to indicate whether the files to be cleaned on the machine can be cleaned at the current time. Then, the value of the shared variables can be determined based on the detected current cleanup status, which will serve as the basis for subsequent file cleanup.
[0057] Step S130: The second component reads the value of the shared variable and determines whether to clean up the file to be cleaned according to the read value of the shared variable.
[0058] The thread executed by the aforementioned "second component" can be viewed as a cleanup thread. Specifically, it needs to read the values of shared variables based on the actual cleanup requirements, determine the current cleanup status based on the values of the shared variables, and then determine whether the files to be cleaned can be cleaned according to the preset file cleanup strategy at the current time based on the current cleanup status.
[0059] Considering that file cleanup is limited during peak business periods, this application introduces a shared variable—the current cleanup status—to dynamically identify when cleanup operations can be performed. This effectively utilizes system idle time for file cleanup, reducing the impact of cleaning up large numbers of files during peak periods on actual business operations. Furthermore, the first and second components used in this application are asynchronous components. The current cleanup status is detected via asynchronous threads, without affecting the execution efficiency of the main process.
[0060] In one embodiment of this application, the step of enabling the first component to detect the cleanup status at the current time includes: obtaining an evaluation index of the cleanup status, wherein the evaluation index of the cleanup status includes hardware resource indicators and time periods corresponding to peak business periods; and determining the cleanup status at the current time based on the evaluation index of the cleanup status.
[0061] In this embodiment of the application, when detecting the cleanup status at the current time, two-dimensional evaluation indicators are used to evaluate the cleanup status at the current time, which may specifically include hardware resource indicators and time period indicators corresponding to peak business periods.
[0062] Hardware resource metrics can specifically include CPU utilization, load status, and the number of active connections for the service. These hardware resource metrics can be obtained in real time when the cleanup status is detected. Specifically, since some servers have monitoring programs deployed to monitor the hardware operating status of the devices, this embodiment can obtain the above-mentioned different types of hardware resource metrics from the monitoring programs deployed on the machine to be cleaned. Of course, in addition to obtaining the above monitoring metrics from the monitoring programs, the machine where the files to be cleaned are located also has these hardware resource metrics configured.
[0063] It should be noted that, in addition to the hardware resource indicators listed above, those skilled in the art can flexibly select other indicators according to actual business needs, and no specific restrictions are imposed here.
[0064] The peak business periods are pre-set timeframes for different business applications and can be pre-written into configuration files. For example, the peak period for deposit transactions is typically between t1 and t2, while for transaction reconciliation, it's usually between t3 and t4. Those skilled in the art can flexibly adjust the peak periods for different business applications based on actual business scenarios; no specific limitations are imposed here.
[0065] After obtaining evaluation indicators such as hardware resource metrics and the time periods corresponding to peak business periods, the current cleanup status can be determined based on the cleanup status evaluation indicators, i.e., whether file cleanup can be performed at the current time.
[0066] In one embodiment of this application, determining the cleanup status of the current time based on the evaluation index of the cleanup status includes: if the hardware resource index does not reach the preset index threshold requirement and the current time is not within the time period corresponding to the business peak period, then the cleanup status of the current time is determined to be a cleanable status; if the hardware resource index reaches the preset index threshold requirement, and / or the current time is within the time period corresponding to the business peak period, then the cleanup status of the current time is determined to be an uncleanable status.
[0067] When determining the current cleanup status based on evaluation metrics, if hardware resource metrics do not meet preset threshold requirements (e.g., CPU utilization and load do not exceed preset thresholds), then the current hardware resources are considered not to be saturated. Furthermore, if the current time is not within a peak business period, it indicates that the system is relatively idle and can provide sufficient resources for file cleanup. Therefore, the current cleanup status can be determined as "ready to clean."
[0068] If hardware resource metrics meet preset threshold requirements, such as CPU utilization exceeding a preset threshold or load exceeding a preset threshold, then the current hardware resource operation can be considered saturated. Furthermore, if the current time falls within a peak business period, it indicates that the system is generally busy and cannot provide sufficient resources for file cleanup. Therefore, the current cleanup status can be determined as "uncleanable."
[0069] It should be noted that the values of the aforementioned hardware resource indicators are generally positively correlated with the determination of whether the current time is a peak business period. For example, if the value of a hardware resource indicator exceeds a corresponding preset threshold, then the current time is usually a peak business period; conversely, if the current time is a peak business period, then the value of the hardware resource indicator will usually also exceed the corresponding preset threshold. This embodiment uses both indicators to assist in the determination, aiming to improve the accuracy of the current cleanup status assessment. Of course, to simplify the determination process, either indicator can be chosen.
[0070] In one embodiment of this application, determining the value of the shared variable based on the cleanup status of the detected current time includes: if the cleanup status of the current time is a cleanupable state, then determining the value of the shared variable to be true; if the cleanup status of the current time is a cleanup-uncleanable state, then determining the value of the shared variable to be false.
[0071] If the current cleanup status is detected as cleanable, the value of the shared variable can be set to true to indicate that file cleanup can be performed at the current time. If the current cleanup status is detected as uncleanable, the value of the shared variable can be set to false to indicate that file cleanup cannot be performed at the current time.
[0072] In one embodiment of this application, the evaluation index for obtaining the cleanup status includes: executing the evaluation index for obtaining the cleanup status according to a first preset time interval.
[0073] In this embodiment of the application, when obtaining the evaluation index of the cleanup status, it can be obtained once every certain period of time according to the first preset time interval. The purpose of setting the first preset time interval is mainly to control the detection frequency of the cleanup status at the current time. The value can be flexibly set according to the actual business needs. For example, it can be set to be obtained once every 10 seconds. No specific limitation is made here.
[0074] In one embodiment of this application, after setting a shared variable that can be accessed by both the first component and the second component, the method further includes: obtaining information about files to be cleaned; determining the number of files to be cleaned based on the information about the files to be cleaned; and determining whether to allow the second component to read the value of the shared variable based on the number of files to be cleaned.
[0075] In real-world applications, there may be situations where the number of files to be cleaned is small, such as only a few or a dozen files on a particular day. Compared to the resources provided by the system to the actual business, the system resources required to clean up these few files are minimal. Therefore, there will be no situation where resources are contested with the core business, and the risks to the actual business are within a controllable range.
[0076] Considering the aforementioned special circumstances, this embodiment of the application, after setting shared variables, can first obtain information about the files to be cleaned. This information can be a list of files to be cleaned, including basic information such as file paths and creation times. Then, based on this information, the number of files to be cleaned can be determined. Furthermore, based on the number of files to be cleaned, it can be determined whether further consideration of the current cleanup status is needed to determine whether file cleanup operations can be performed.
[0077] In one embodiment of this application, determining whether to allow the second component to read the value of the shared variable based on the number of files to be cleaned includes: if the number of files to be cleaned is higher than a preset number threshold, then allowing the second component to read the value of the shared variable; if the number of files to be cleaned is not higher than the preset number threshold, then not allowing the second component to read the value of the shared variable.
[0078] After obtaining the number of files to be cleaned, compare the number of files to be cleaned with a preset number threshold. If the number of files to be cleaned exceeds the number threshold, it means that the number of files to be cleaned is large, and it is necessary to further consider the current cleanup status to determine whether cleanup can be carried out. If the number of files to be cleaned does not exceed the number threshold, it means that the number of files to be cleaned is small, and cleaning them directly will not have a substantial impact on the actual business. Therefore, it is not necessary to consider the current cleanup status, and the files to be cleaned can be cleaned directly.
[0079] This application embodiment takes into account the cleaning needs when the number of files to be cleaned is small, flexibly adjusts the cleaning strategy, and simplifies the file cleaning process.
[0080] In one embodiment of this application, determining whether to clean the file to be cleaned according to a preset file cleanup strategy based on the value of the read shared variable includes: if the value of the read shared variable is true, then the file to be cleaned is cleaned according to the preset file cleanup strategy; if the value of the read shared variable is false, then the file to be cleaned is not cleaned.
[0081] As mentioned above, the second component in this application embodiment is mainly a thread used to perform specific cleanup operations. For the second component, when Runnable=true is read, it means that the cleanup status at the current time is a cleanupable state. At this time, the files to be cleaned can be cleaned according to the preset file cleanup strategy. However, if Runnable=false is read, it means that the cleanup status at the current time is an uncleanupable state. At this time, the files to be cleaned cannot be cleaned, otherwise it may cause uncontrollable risks to the actual business.
[0082] In real-world business scenarios, cleaning up a large number of files at once can easily impact server response speed, thereby affecting actual business operations. Therefore, the preset file cleaning strategy used in this embodiment can be to clean up the files one by one. Of course, for cases where the number of files to be cleaned is small, they can also be cleaned up in batches at once. How to set the file cleaning strategy is flexible and can be adjusted by those skilled in the art according to actual needs, and is not specifically limited here.
[0083] In one embodiment of this application, after cleaning the file to be cleaned according to a preset file cleaning strategy, the method further includes: obtaining the cleaning result of the file to be cleaned; if the cleaning result of the file to be cleaned is that the cleaning is complete, then ending the current file cleaning; if the cleaning result of the file to be cleaned is that the cleaning is incomplete, then executing the step of having the second component read the value of the shared variable again.
[0084] In this embodiment of the application, after cleaning the files to be cleaned according to the preset file cleaning strategy, the cleaning result of the files to be cleaned can be further obtained. If the cleaning result is that the cleaning is completed, it means that the current file cleaning task has been completed and the current file cleaning can be ended. If the cleaning result is that the cleaning is not completed, then for the files that have not been cleaned, the above-mentioned step of reading the value of the shared variable can be repeated to determine whether the file can be cleaned based on the value of the shared variable, until all files to be cleaned are cleaned, and then the current loop ends.
[0085] In one embodiment of this application, if the value of the shared variable read is false, the method further includes: after a second preset time interval, performing the step of causing the second component to read the value of the shared variable again.
[0086] In this embodiment, when Runnable = false, meaning the current cleanup status is uncleaned, the step of reading the shared variable value can be executed again after waiting for a second preset time interval. This second preset time interval is primarily used to control the cleanup speed of the files to be cleaned. Its value can be flexibly set according to actual cleanup needs; for example, it can be set to 10 seconds. When rapid cleanup of files is required, this second preset time interval can be appropriately shortened so that when the value of the shared variable becomes true, the change can be quickly detected, allowing for timely cleanup operations.
[0087] like Figure 2 The diagram illustrates a file cleanup process according to an embodiment of this application. First, a shared variable `Runnable` is set that can be accessed by both the first and second components. Then, the initial state of `Runnable` is set to `Runnable = true`.
[0088] The first component is then activated, checking the cleanup status every 10 seconds and updating the Runnable value accordingly. Simultaneously, the second component first retrieves information about the files to be cleaned, then reads the Runnable value to determine the current cleanup status. If Runnable = false, it waits 10 seconds, retrieves the Runnable value again, and checks the cleanup status. If Runnable = true, the cleanup operation can be performed directly. Finally, it checks if the cleanup is complete. If not, it repeats the steps of retrieving file information and reading the Runnable value. If cleanup is complete, the current loop ends, completing the file cleanup task.
[0089] The aforementioned file cleanup process, by introducing the cleanup status of the current time as a shared variable, can dynamically identify the time when cleanup operations can be performed, effectively utilizing system idle time for file cleanup and reducing the impact of cleaning up a large number of files during peak business periods on actual business operations. Furthermore, the first and second components used in this embodiment are two asynchronous components, detecting the cleanup status of the current time through asynchronous threads, without affecting the execution efficiency of the main process.
[0090] This application also provides a file cleaning device 300, applied to a file cleaning server, such as... Figure 3 The diagram shows a structural schematic of a file cleaning device according to an embodiment of this application. The device includes: a setting unit 310, a detection unit 320, and a cleaning unit 330, wherein:
[0091] Setting unit 310 is used to set shared variables that can be accessed by both the first component and the second component, wherein the first component and the second component are asynchronous components;
[0092] The detection unit 320 is used to enable the first component to detect the cleanup status at the current time, and to determine the value of the shared variable based on the detected cleanup status at the current time.
[0093] The cleaning unit 330 is used to enable the second component to read the value of the shared variable, and to determine whether to clean the file to be cleaned according to the read value of the shared variable.
[0094] In one embodiment of this application, the detection unit 320 is specifically used to: obtain evaluation indicators of the cleanup status, wherein the evaluation indicators of the cleanup status include hardware resource indicators and time periods corresponding to peak business periods; and determine the cleanup status of the current time based on the evaluation indicators of the cleanup status.
[0095] In one embodiment of this application, the detection unit 320 is specifically used to: if the hardware resource index does not reach the preset index threshold requirement and the current time is not within the time period corresponding to the business peak period, then determine that the cleanup status of the current time is a cleanable status; if the hardware resource index reaches the preset index threshold requirement, and / or the current time is within the time period corresponding to the business peak period, then determine that the cleanup status of the current time is an uncleanable status.
[0096] In one embodiment of this application, the detection unit 320 is specifically used to: determine the value of the shared variable as true if the cleanup status of the current time is a cleanupable state; and determine the value of the shared variable as false if the cleanup status of the current time is a cleanup-uncleanable state.
[0097] In one embodiment of this application, the detection unit 320 is specifically used to: perform the step of acquiring evaluation indicators of the cleaning status according to a first preset time interval.
[0098] In one embodiment of this application, the apparatus further includes: a first acquisition unit, configured to acquire information about files to be cleaned; a first determination unit, configured to determine the number of files to be cleaned based on the information about the files to be cleaned; and a second determination unit, configured to determine whether to cause the second component to read the value of the shared variable based on the number of files to be cleaned.
[0099] In one embodiment of this application, the second determining unit is specifically used to: if the number of files to be cleaned is higher than a preset number threshold, then cause the second component to read the value of the shared variable; if the number of files to be cleaned is not higher than the preset number threshold, then do not cause the second component to read the value of the shared variable.
[0100] In one embodiment of this application, the cleaning unit 330 is specifically used to: if the value of the read shared variable is true, then clean the file to be cleaned according to a preset file cleaning strategy; if the value of the read shared variable is false, then do not clean the file to be cleaned.
[0101] In one embodiment of this application, the apparatus further includes: a second acquisition unit, configured to acquire the cleaning result of the file to be cleaned; an end unit, configured to end the current file cleaning if the cleaning result of the file to be cleaned is that the cleaning is complete; and a first execution unit, configured to execute the step of causing the second component to read the value of the shared variable again if the cleaning result of the file to be cleaned is that the cleaning is incomplete.
[0102] In one embodiment of this application, the apparatus further includes: a first execution unit, configured to, if the value of the shared variable read is false, execute again, after a second preset time interval, the step of causing the second component to read the value of the shared variable.
[0103] It is understood that the above-mentioned file cleaning device can implement each step of the file cleaning method executed by the file cleaning server provided in the foregoing embodiments. The relevant explanations of the file cleaning method are applicable to the file cleaning device and will not be repeated here.
[0104] Figure 4 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. Please refer to it. Figure 4 At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and memory. The memory may include main memory, such as high-speed random-access memory (RAM), or non-volatile memory, such as at least one disk drive. Of course, the electronic device may also include other hardware required for other business operations.
[0105] The processor, network interface, and memory can be interconnected via an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. This bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 4 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0106] Memory is used to store programs. Specifically, programs may include program code, which includes computer operation instructions. Memory may include main memory and non-volatile memory, and provides instructions and data to the processor.
[0107] The processor reads the corresponding computer program from non-volatile memory into main memory and then runs it, forming a file cleanup mechanism at the logical level. The processor executes the program stored in memory and specifically performs the following operations:
[0108] Set up a shared variable that can be accessed by both the first component and the second component, where the first component and the second component are asynchronous components;
[0109] The first component detects the cleanup status at the current time and determines the value of the shared variable based on the detected cleanup status at the current time.
[0110] The second component reads the value of the shared variable and determines, based on the read value of the shared variable, whether to clean up the file to be cleaned according to a preset file cleanup strategy.
[0111] The above is as stated in this application. Figure 1The file cleaning device method disclosed in the illustrated embodiments can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by integrated logic circuits in the processor's hardware or by instructions in software form. The processor can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this application can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. The software module can reside in a mature storage medium in the field, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method.
[0112] The electronic device can also perform Figure 1 The method for executing the file cleanup device, and the implementation of the file cleanup device in... Figure 1 The functions of the embodiments shown are not described in detail here.
[0113] This application also proposes a computer-readable storage medium that stores one or more programs, the programs including instructions that, when executed by an electronic device including multiple applications, enable the electronic device to perform... Figure 1 The method executed by the file cleaning device in the illustrated embodiment is specifically used to perform the following:
[0114] Set up a shared variable that can be accessed by both the first component and the second component, where the first component and the second component are asynchronous components;
[0115] The first component detects the cleanup status at the current time and determines the value of the shared variable based on the detected cleanup status at the current time.
[0116] The second component reads the value of the shared variable and determines, based on the read value of the shared variable, whether to clean up the file to be cleaned according to a preset file cleanup strategy.
[0117] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0118] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0119] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0120] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0121] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0122] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0123] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0124] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0125] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0126] The above description is merely an embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principle of this application should be included within the scope of the claims of this application.
Claims
1. A file cleaning method executed by a file cleaning server, wherein, The method comprises: setting a shared variable accessible by a first component and a second component, wherein the first component and the second component are asynchronous components; causing the first component to detect a cleaning state of a current time, and determining a value of the shared variable according to the detected cleaning state of the current time; causing the second component to read the value of the shared variable, and determining whether to clean the to-be-cleaned file according to a preset file cleaning strategy according to the read value of the shared variable; the first component and the second component are carriers of two asynchronously executed threads, the thread executed by the first component is a detection thread, and the thread executed by the second component is a cleaning thread; after setting the shared variable accessible by the first component and the second component, the method further comprises: obtaining information of the to-be-cleaned file; determining the number of to-be-cleaned files according to the information of the to-be-cleaned file; if the number of to-be-cleaned files is higher than a preset number threshold, causing the second component to read the value of the shared variable; if the number of to-be-cleaned files is not higher than the preset number threshold, not causing the second component to read the value of the shared variable.
2. The method of claim 1, wherein, The causing the first component to detect the cleaning state of the current time comprises: obtaining an evaluation index of the cleaning state, wherein the evaluation index of the cleaning state comprises a hardware resource index and a time period corresponding to a business peak period; determining the cleaning state of the current time according to the evaluation index of the cleaning state.
3. The method of claim 2, wherein, The determining the cleaning state of the current time according to the evaluation index of the cleaning state comprises: if the hardware resource index does not reach a preset index threshold, and the current time is not located in the time period corresponding to the business peak period, determining that the cleaning state of the current time is a cleanable state; if the hardware resource index reaches a preset index threshold, and / or the current time is located in the time period corresponding to the business peak period, determining that the cleaning state of the current time is an uncleanable state.
4. The method of claim 3, wherein, The determining the value of the shared variable according to the detected cleaning state of the current time comprises: if the cleaning state of the current time is a cleanable state, determining that the value of the shared variable is true; if the cleaning state of the current time is an uncleanable state, determining that the value of the shared variable is false.
5. The method of claim 2, wherein, The obtaining the evaluation index of the cleaning state comprises: performing the step of obtaining the evaluation index of the cleaning state according to a first preset time interval.
6. The method of claim 1, wherein, The determining whether to clean the to-be-cleaned file according to the preset file cleaning strategy according to the read value of the shared variable comprises: if the read value of the shared variable is true, cleaning the to-be-cleaned file according to the preset file cleaning strategy; if the read value of the shared variable is false, not cleaning the to-be-cleaned file.
7. The method of claim 6, wherein, After cleaning the to-be-cleaned file according to the preset file cleaning strategy, the method further comprises: obtaining a cleaning result of the to-be-cleaned file; if the cleaning result of the to-be-cleaned file is cleaning completion, ending this file cleaning. If the cleaning result of the file to be cleaned is not completed, the step of reading the value of the shared variable by the second component is executed again.
8. The method of claim 6, wherein, If the value of the shared variable read is false, the method further comprises: After a second preset time interval, the step of reading the value of the shared variable by the second component is executed again.
9. A file cleaning apparatus applied to a file cleaning server, wherein, The device comprises: a setting unit configured to set a shared variable accessible by a first component and a second component, wherein the first component and the second component are asynchronous components; a detection unit configured to enable the first component to detect a cleaning state of a current time, and determine a value of the shared variable according to the detected cleaning state of the current time; a cleaning unit configured to enable the second component to read the value of the shared variable, and determine whether to clean the file to be cleaned according to a preset file cleaning strategy according to the value of the shared variable read; The first component and the second component are carriers of two threads executed asynchronously, the thread executed by the first component is a detection thread, and the thread executed by the second component is a cleaning thread. The device further comprises: a first acquisition unit configured to acquire information of a file to be cleaned; a first determination unit configured to determine a number of files to be cleaned according to the information of the file to be cleaned; a second determination unit configured to enable the second component to read the value of the shared variable if the number of files to be cleaned is higher than a preset number threshold, and not enable the second component to read the value of the shared variable if the number of files to be cleaned is not higher than the preset number threshold.
Citation Information
Patent Citations
Data cleaning method and device, electronic equipment and computer readable storage medium
CN112925745A