Skip to content
Permalink
Browse files
Fix issue #2117: improve efficiency of ClusterStatusMonitor and PerIn…
…stanceResourceMonitor, plus misc code cleanup (#2118)
  • Loading branch information
richardstartin committed Jun 2, 2022
1 parent 0efa9cf commit 6524a34a3d79b41d80cc1efa09b6a16d0f3ec31e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
@@ -459,10 +459,7 @@ public void setPerInstanceResourceStatus(BestPossibleStateOutput bestPossibleSta
String state = instanceStateMap.get(instance);
PerInstanceResourceMonitor.BeanName beanName =
new PerInstanceResourceMonitor.BeanName(_clusterName, instance, resource);
if (!beanMap.containsKey(beanName)) {
beanMap.put(beanName, new HashMap<Partition, String>());
}
beanMap.get(beanName).put(partition, state);
beanMap.computeIfAbsent(beanName, k -> new HashMap<>()).put(partition, state);
}
}
}
@@ -70,8 +70,7 @@ public String resourceName() {

public ObjectName objectName() {
try {
return new ObjectName(String.format("%s:%s", MonitorDomainNames.ClusterStatus.name(),
new BeanName(_clusterName, _instanceName, _resourceName).toString()));
return new ObjectName(MonitorDomainNames.ClusterStatus.name() + ":" + this);
} catch (MalformedObjectNameException e) {
LOG.error("Failed to create object name for cluster: {}, instance: {}, resource: {}.",
_clusterName, _instanceName, _resourceName);
@@ -81,7 +80,7 @@ public ObjectName objectName() {

@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof BeanName)) {
if (!(obj instanceof BeanName)) {
return false;
}

@@ -92,14 +91,16 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
return toString().hashCode();
return 31 * 31 * _clusterName.hashCode()
+ 31 * _instanceName.hashCode()
+ _resourceName.hashCode();
}

@Override
public String toString() {
return String.format("%s=%s,%s=%s,%s=%s", ClusterStatusMonitor.CLUSTER_DN_KEY, _clusterName,
ClusterStatusMonitor.INSTANCE_DN_KEY, _instanceName, ClusterStatusMonitor.RESOURCE_DN_KEY,
_resourceName);
return ClusterStatusMonitor.CLUSTER_DN_KEY + "=" + _clusterName + ","
+ ClusterStatusMonitor.INSTANCE_DN_KEY + "=" + _instanceName + ","
+ ClusterStatusMonitor.RESOURCE_DN_KEY + "=" + _resourceName;
}
}

@@ -115,18 +116,18 @@ public PerInstanceResourceMonitor(String clusterName, String participantName,
_tags = ImmutableList.of(ClusterStatusMonitor.DEFAULT_TAG);
_participantName = participantName;
_resourceName = resourceName;
_partitions = new SimpleDynamicMetric("PartitionGauge", 0L);
_partitions = new SimpleDynamicMetric<>("PartitionGauge", 0L);
}

@Override
public String getSensorName() {
return Joiner.on('.').join(ImmutableList
.of(ClusterStatusMonitor.PARTICIPANT_STATUS_KEY, _clusterName, serializedTags(),
_participantName, _resourceName)).toString();
_participantName, _resourceName));
}

private String serializedTags() {
return Joiner.on('|').skipNulls().join(_tags).toString();
return Joiner.on('|').skipNulls().join(_tags);
}

public String getInstanceName() {
@@ -161,7 +162,7 @@ public synchronized void update(Map<Partition, String> stateMap, Set<String> tag
}
cnt++;
}
_partitions.updateValue(Long.valueOf(cnt));
_partitions.updateValue((long) cnt);
}

@Override

0 comments on commit 6524a34

Please sign in to comment.