@@ -26,9 +26,9 @@ static NativeMemoryCapacity from(NativeMemoryCapacity capacity) {
26
26
return new NativeMemoryCapacity (capacity .tierMlNativeMemoryRequirement , capacity .nodeMlNativeMemoryRequirement , capacity .jvmSize );
27
27
}
28
28
29
- private long tierMlNativeMemoryRequirement ;
30
- private long nodeMlNativeMemoryRequirement ;
31
- private Long jvmSize ;
29
+ private final long tierMlNativeMemoryRequirement ;
30
+ private final long nodeMlNativeMemoryRequirement ;
31
+ private final Long jvmSize ;
32
32
33
33
public NativeMemoryCapacity (long tierMlNativeMemoryRequirement , long nodeMlNativeMemoryRequirement , Long jvmSize ) {
34
34
this .tierMlNativeMemoryRequirement = tierMlNativeMemoryRequirement ;
@@ -39,17 +39,22 @@ public NativeMemoryCapacity(long tierMlNativeMemoryRequirement, long nodeMlNativ
39
39
NativeMemoryCapacity (long tierMlNativeMemoryRequirement , long nodeMlNativeMemoryRequirement ) {
40
40
this .tierMlNativeMemoryRequirement = tierMlNativeMemoryRequirement ;
41
41
this .nodeMlNativeMemoryRequirement = nodeMlNativeMemoryRequirement ;
42
+ this .jvmSize = null ;
42
43
}
43
44
44
- NativeMemoryCapacity merge (NativeMemoryCapacity nativeMemoryCapacity ) {
45
- this .tierMlNativeMemoryRequirement += nativeMemoryCapacity .tierMlNativeMemoryRequirement ;
46
- if (nativeMemoryCapacity .nodeMlNativeMemoryRequirement > this .nodeMlNativeMemoryRequirement ) {
47
- this .nodeMlNativeMemoryRequirement = nativeMemoryCapacity .nodeMlNativeMemoryRequirement ;
48
- // If the new node size is bigger, we have no way of knowing if the JVM size would stay the same
49
- // So null out
50
- this .jvmSize = null ;
51
- }
52
- return this ;
45
+ /**
46
+ * Merges the passed capacity with the current one. A new instance is created and returned
47
+ * @param nativeMemoryCapacity the capacity to merge with
48
+ * @return a new instance with the merged capacity values
49
+ */
50
+ NativeMemoryCapacity merge (final NativeMemoryCapacity nativeMemoryCapacity ) {
51
+ if (this == nativeMemoryCapacity ) return this ;
52
+ long tier = this .tierMlNativeMemoryRequirement + nativeMemoryCapacity .tierMlNativeMemoryRequirement ;
53
+ long node = Math .max (nativeMemoryCapacity .nodeMlNativeMemoryRequirement , this .nodeMlNativeMemoryRequirement );
54
+ // If the new node size is bigger, we have no way of knowing if the JVM size would stay the same
55
+ // So null out
56
+ Long jvmSize = nativeMemoryCapacity .nodeMlNativeMemoryRequirement > this .nodeMlNativeMemoryRequirement ? null : this .jvmSize ;
57
+ return new NativeMemoryCapacity (tier , node , jvmSize );
53
58
}
54
59
55
60
public AutoscalingCapacity autoscalingCapacity (int maxMemoryPercent , boolean useAuto ) {
0 commit comments