clean up chunk build outputs and renderer resources after job failures #54
No files matched your search
+29
-6
@@ -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();
|
||||
|
||||
+3
-4
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user