Skip to content

Commit

Permalink
UpgradeTracker: use List<String> as HashMap key instead of String[]
Browse files Browse the repository at this point in the history
Signed-off-by: b.abdukakharov <[email protected]>
  • Loading branch information
b.abdukakharov committed Jun 28, 2024
1 parent af8c300 commit 435c48b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/com/ibm/watson/modelmesh/UpgradeTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import org.eclipse.collections.impl.factory.primitive.ObjectLongMaps;
import org.eclipse.collections.impl.map.mutable.primitive.ObjectLongHashMap;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
Expand Down Expand Up @@ -64,7 +66,7 @@ public PerTypeLabelStats() {
}

// This is accessed only by instance updater thread
private final Map<String[], PerTypeLabelStats> upgradeTracker = new HashMap<>(1);
private final Map<List<String>, PerTypeLabelStats> upgradeTracker = new HashMap<>(1);

// Map from replicaset to expiry time, updated via copy-on-write by instance updater thread.
// Copy-on-write since updates will be be rare and we want to optimize for reads.
Expand All @@ -86,7 +88,7 @@ void instanceRemoved(String iid, InstanceRecord ir) {
if (iid.length() < 7) {
return; // instance ids must be of non-standard format
}
PerTypeLabelStats ptls = upgradeTracker.get(ir.getLabels());
PerTypeLabelStats ptls = upgradeTracker.get(Arrays.asList(ir.getLabels()));
if (ptls == null) {
return;
}
Expand Down Expand Up @@ -121,9 +123,9 @@ void instanceAdded(String iid, InstanceRecord ir) {
if (iid.length() < 7) {
return; // instance ids must be of non-standard format
}
PerTypeLabelStats ptls = upgradeTracker.get(ir.getLabels());
PerTypeLabelStats ptls = upgradeTracker.get(Arrays.asList(ir.getLabels()));
if (ptls == null) {
upgradeTracker.put(ir.getLabels(), ptls = new PerTypeLabelStats());
upgradeTracker.put(Arrays.asList(ir.getLabels()), ptls = new PerTypeLabelStats());
}
long now = System.currentTimeMillis();
// First 6 chars of instance id comes from replicaset name
Expand Down

0 comments on commit 435c48b

Please sign in to comment.