clean up chunk build outputs and renderer resources after job failures #54

Merged
embeddedt merged 2 commits from rdh/celeritas:thingy into stonecutter 2026-11-24 09:02:00 -05:00
2 changed files with 32 additions and 10 deletions
Showing only changes of commit 9da6f8984c - Show all commits

No files matched your search

@@ -789,24 +789,45 @@ public abstract class RenderSectionManager {
}
private ArrayList<ChunkJobResult.Success<? extends ChunkTaskOutput>> collectChunkBuildResults() {
ArrayList<ChunkJobResult.Success<? extends ChunkTaskOutput>> results = new ArrayList<>();
ChunkJobResult<? extends ChunkTaskOutput> result;
var results = drainChunkBuildResults(this.buildResults);
while ((result = this.buildResults.poll()) != null) {
if (result instanceof ChunkJobResult.Success<? extends ChunkTaskOutput> successfulResult) {
for (var successfulResult : results) {
this.jobMetricsTracker.collectMetrics(successfulResult);
if (successfulResult.output() instanceof ChunkSortOutput sort && sort.render.isTreeSorted() && successfulResult.executionTimeNanos() >= 0) {
this.treeSortMetrics.collect(successfulResult.executionTimeNanos());
}
}
return results;
}
static ArrayList<ChunkJobResult.Success<? extends ChunkTaskOutput>> drainChunkBuildResults(Queue<ChunkJobResult<? extends ChunkTaskOutput>> buildResults) {
ArrayList<ChunkJobResult.Success<? extends ChunkTaskOutput>> results = new ArrayList<>();
RuntimeException firstFailure = null;
ChunkJobResult<? extends ChunkTaskOutput> result;
while ((result = buildResults.poll()) != null) {
if (result instanceof ChunkJobResult.Success<? extends ChunkTaskOutput> successfulResult) {
results.add(successfulResult);
} else if (result instanceof ChunkJobResult.Failure<? extends ChunkTaskOutput> failure) {
failure.abort();
if (firstFailure == null) {
firstFailure = failure.asException();
} else if (firstFailure != failure.throwable()) {
firstFailure.addSuppressed(failure.throwable());
}
} else {
throw new AssertionError();
}
}
if (firstFailure != null) {
for (var successfulResult : results) {
successfulResult.output().delete();
}
throw firstFailure;
}
return results;
}
@@ -917,10 +938,11 @@ public abstract class RenderSectionManager {
this.builder.shutdown(); // stop all the workers, and cancel any tasks
try {
for (var result : this.collectChunkBuildResults()) {
result.output().delete(); // delete resources for any pending tasks (including those that were cancelled)
}
} finally {
this.renderListManager.destroy();
if (this.shadowRenderListManager != null) {
this.shadowRenderListManager.destroy();
@@ -937,6 +959,7 @@ public abstract class RenderSectionManager {
this.sectionsWithGlobalEntities.clear();
}
}
public int getTotalSections() {
return this.sectionByPosition.size();
@@ -12,12 +12,11 @@ public sealed interface ChunkJobResult<OUTPUT> permits ChunkJobResult.Success, C
Objects.requireNonNull(throwable);
}
public void abort() {
public RuntimeException asException() {
if (this.throwable instanceof RuntimeException crashException) {
// Propagate RuntimeExceptions directly to provide extra information if they are a vanilla crash exception
throw crashException;
return crashException;
} else {
throw new RuntimeException("Exception thrown while executing job", this.throwable);
return new RuntimeException("Exception thrown while executing job", this.throwable);
}
}
}