Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpgradeTracker: use List<String> as HashMap key instead of String[] #144

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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