-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement an idle task to garbage collect stale install bases.
The `--experimental_install_base_gc_max_age` flag determines the criteria for considering an install base stale; zero disables garbage collection. The default will be replaced with a suitable nonzero value in a future CL. Progress on #2109. PiperOrigin-RevId: 705874241 Change-Id: I3c8526a4a0e20a12d52c08cb282f24e268cbc633
- Loading branch information
1 parent
16f08cb
commit c89f8cf
Showing
9 changed files
with
163 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/com/google/devtools/build/lib/server/InstallBaseGarbageCollectorIdleTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2024 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.google.devtools.build.lib.server; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.flogger.GoogleLogger; | ||
import com.google.devtools.build.lib.vfs.Path; | ||
import java.io.IOException; | ||
import java.time.Duration; | ||
|
||
/** An {@link IdleTask} to run a {@link InstallBaseGarbageCollector}. */ | ||
public final class InstallBaseGarbageCollectorIdleTask implements IdleTask { | ||
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass(); | ||
|
||
private final InstallBaseGarbageCollector gc; | ||
|
||
private InstallBaseGarbageCollectorIdleTask(InstallBaseGarbageCollector gc) { | ||
this.gc = gc; | ||
} | ||
|
||
/** | ||
* Creates a new {@link InstallBaseGarbageCollectorIdleTask} according to the options. | ||
* | ||
* @param installBase the server install base | ||
* @param maxAge how long an install base must remain unused to be considered stale | ||
* @return the idle task | ||
*/ | ||
public static InstallBaseGarbageCollectorIdleTask create(Path installBase, Duration maxAge) { | ||
return new InstallBaseGarbageCollectorIdleTask( | ||
new InstallBaseGarbageCollector(installBase.getParentDirectory(), installBase, maxAge)); | ||
} | ||
|
||
@VisibleForTesting | ||
public InstallBaseGarbageCollector getGarbageCollector() { | ||
return gc; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
logger.atInfo().log("Install base garbage collection started"); | ||
gc.run(); | ||
} catch (IOException e) { | ||
logger.atInfo().withCause(e).log("Install base garbage collection failed"); | ||
} catch (InterruptedException e) { | ||
logger.atInfo().withCause(e).log("Install base garbage collection interrupted"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters