|
43 | 43 | import com.google.devtools.build.lib.events.PrintingEventHandler;
|
44 | 44 | import com.google.devtools.build.lib.events.Reporter;
|
45 | 45 | import com.google.devtools.build.lib.events.StoredEventHandler;
|
| 46 | +import com.google.devtools.build.lib.exec.ExecutionOptions; |
46 | 47 | import com.google.devtools.build.lib.profiler.MemoryProfiler;
|
47 | 48 | import com.google.devtools.build.lib.profiler.Profiler;
|
48 | 49 | import com.google.devtools.build.lib.profiler.SilentCloseable;
|
|
54 | 55 | import com.google.devtools.build.lib.util.AnsiStrippingOutputStream;
|
55 | 56 | import com.google.devtools.build.lib.util.DebugLoggerConfigurator;
|
56 | 57 | import com.google.devtools.build.lib.util.DetailedExitCode;
|
| 58 | +import com.google.devtools.build.lib.util.ExitCode; |
57 | 59 | import com.google.devtools.build.lib.util.InterruptedFailureDetails;
|
58 | 60 | import com.google.devtools.build.lib.util.LoggingUtil;
|
59 | 61 | import com.google.devtools.build.lib.util.Pair;
|
@@ -230,18 +232,29 @@ public BlazeCommandResult exec(
|
230 | 232 | return createDetailedCommandResult(
|
231 | 233 | retrievedShutdownReason, FailureDetails.Command.Code.PREVIOUSLY_SHUTDOWN);
|
232 | 234 | }
|
233 |
| - BlazeCommandResult result = |
234 |
| - execExclusively( |
235 |
| - originalCommandLine, |
236 |
| - invocationPolicy, |
237 |
| - args, |
238 |
| - outErr, |
239 |
| - firstContactTimeMillis, |
240 |
| - commandName, |
241 |
| - command, |
242 |
| - waitTimeInMs, |
243 |
| - startupOptionsTaggedWithBazelRc, |
244 |
| - commandExtensions); |
| 235 | + BlazeCommandResult result; |
| 236 | + int attempt = 0; |
| 237 | + while (true) { |
| 238 | + try { |
| 239 | + result = |
| 240 | + execExclusively( |
| 241 | + originalCommandLine, |
| 242 | + invocationPolicy, |
| 243 | + args, |
| 244 | + outErr, |
| 245 | + firstContactTimeMillis, |
| 246 | + commandName, |
| 247 | + command, |
| 248 | + waitTimeInMs, |
| 249 | + startupOptionsTaggedWithBazelRc, |
| 250 | + commandExtensions, |
| 251 | + attempt); |
| 252 | + break; |
| 253 | + } catch (RemoteCacheEvictedException e) { |
| 254 | + outErr.printErrLn("Found remote cache eviction error, retrying the build..."); |
| 255 | + attempt += 1; |
| 256 | + } |
| 257 | + } |
245 | 258 | if (result.shutdown()) {
|
246 | 259 | setShutdownReason(
|
247 | 260 | "Server shut down "
|
@@ -289,7 +302,9 @@ private BlazeCommandResult execExclusively(
|
289 | 302 | BlazeCommand command,
|
290 | 303 | long waitTimeInMs,
|
291 | 304 | Optional<List<Pair<String, String>>> startupOptionsTaggedWithBazelRc,
|
292 |
| - List<Any> commandExtensions) { |
| 305 | + List<Any> commandExtensions, |
| 306 | + int attempt) |
| 307 | + throws RemoteCacheEvictedException { |
293 | 308 | // Record the start time for the profiler. Do not put anything before this!
|
294 | 309 | long execStartTimeNanos = runtime.getClock().nanoTime();
|
295 | 310 |
|
@@ -631,7 +646,18 @@ private BlazeCommandResult execExclusively(
|
631 | 646 | }
|
632 | 647 |
|
633 | 648 | needToCallAfterCommand = false;
|
634 |
| - return runtime.afterCommand(env, result); |
| 649 | + var newResult = runtime.afterCommand(env, result); |
| 650 | + if (newResult.getExitCode().equals(ExitCode.REMOTE_CACHE_EVICTED)) { |
| 651 | + var executionOptions = |
| 652 | + Preconditions.checkNotNull(options.getOptions(ExecutionOptions.class)); |
| 653 | + if (attempt < executionOptions.remoteRetryOnCacheEviction) { |
| 654 | + throw new RemoteCacheEvictedException(); |
| 655 | + } |
| 656 | + } |
| 657 | + |
| 658 | + return newResult; |
| 659 | + } catch (RemoteCacheEvictedException e) { |
| 660 | + throw e; |
635 | 661 | } catch (Throwable e) {
|
636 | 662 | logger.atSevere().withCause(e).log("Shutting down due to exception");
|
637 | 663 | Crash crash = Crash.from(e);
|
@@ -665,6 +691,8 @@ private BlazeCommandResult execExclusively(
|
665 | 691 | }
|
666 | 692 | }
|
667 | 693 |
|
| 694 | + private static class RemoteCacheEvictedException extends IOException {} |
| 695 | + |
668 | 696 | private static void replayEarlyExitEvents(
|
669 | 697 | OutErr outErr,
|
670 | 698 | BlazeOptionHandler optionHandler,
|
|
0 commit comments