From 7725c92530ab7b751fe9e5bf294fc153a1e10693 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Mon, 25 Mar 2024 21:47:13 -0700 Subject: [PATCH 1/3] Mark the immutable class final Necessary for true immutability. --- .../java/io/trino/execution/resourcegroups/ResourceUsage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/trino-main/src/main/java/io/trino/execution/resourcegroups/ResourceUsage.java b/core/trino-main/src/main/java/io/trino/execution/resourcegroups/ResourceUsage.java index bb9c13f56298..bd708acd64fc 100644 --- a/core/trino-main/src/main/java/io/trino/execution/resourcegroups/ResourceUsage.java +++ b/core/trino-main/src/main/java/io/trino/execution/resourcegroups/ResourceUsage.java @@ -21,7 +21,7 @@ import static com.google.common.math.LongMath.saturatedSubtract; @Immutable -class ResourceUsage +final class ResourceUsage { private final long cpuUsageMillis; private final long memoryUsageBytes; From 36839b8d6da1c526a54bd6ba2417e8c11878afa6 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Mon, 25 Mar 2024 21:45:48 -0700 Subject: [PATCH 2/3] Remove redundant clone method The class is immutable. --- .../execution/resourcegroups/InternalResourceGroup.java | 2 +- .../io/trino/execution/resourcegroups/ResourceUsage.java | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/execution/resourcegroups/InternalResourceGroup.java b/core/trino-main/src/main/java/io/trino/execution/resourcegroups/InternalResourceGroup.java index 81198805c32c..6fcc6c6616db 100644 --- a/core/trino-main/src/main/java/io/trino/execution/resourcegroups/InternalResourceGroup.java +++ b/core/trino-main/src/main/java/io/trino/execution/resourcegroups/InternalResourceGroup.java @@ -954,7 +954,7 @@ public Collection subGroups() ResourceUsage getResourceUsageSnapshot() { synchronized (root) { - return cachedResourceUsage.clone(); + return cachedResourceUsage; } } diff --git a/core/trino-main/src/main/java/io/trino/execution/resourcegroups/ResourceUsage.java b/core/trino-main/src/main/java/io/trino/execution/resourcegroups/ResourceUsage.java index bd708acd64fc..98fc16d26b10 100644 --- a/core/trino-main/src/main/java/io/trino/execution/resourcegroups/ResourceUsage.java +++ b/core/trino-main/src/main/java/io/trino/execution/resourcegroups/ResourceUsage.java @@ -32,12 +32,6 @@ public ResourceUsage(long cpuUsageMillis, long memoryUsageBytes) this.memoryUsageBytes = memoryUsageBytes; } - @Override - public ResourceUsage clone() - { - return new ResourceUsage(cpuUsageMillis, memoryUsageBytes); - } - public ResourceUsage add(ResourceUsage other) { long newCpuUsageMillis = saturatedAdd(this.cpuUsageMillis, other.cpuUsageMillis); From 69219ff2a59697dde6657ce87bc8c50e313408a9 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Mon, 25 Mar 2024 22:22:18 -0700 Subject: [PATCH 3/3] =?UTF-8?q?empty:=20roll=20the=20dice=20=F0=9F=8E=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit