Skip to content

Commit

Permalink
Avoid repeated calls to getState in AbstractDependentConfig
Browse files Browse the repository at this point in the history
The getState method was called repeatedly in various AbstractDependentConfig methods, which could
incur repeated volatile reads or correctness issues in edge cases.
  • Loading branch information
kilink committed Sep 23, 2024
1 parent e9bbde9 commit 4e92434
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.netflix.archaius.config;

import com.netflix.archaius.api.Config;
import com.netflix.archaius.api.PropertyDetails;

import java.util.Iterator;
Expand Down Expand Up @@ -27,9 +28,11 @@ public AbstractDependentConfig() {

@Override
public Object getRawProperty(String key) {
Object value = getState().getData().get(key);
if (getState().getInstrumentedKeys().containsKey(key)) {
getState().getInstrumentedKeys().get(key).recordUsage(createPropertyDetails(key, value));
CachedState state = getState();
Object value = state.getData().get(key);
Config config = state.getInstrumentedKeys().get(key);
if (config != null) {
config.recordUsage(createPropertyDetails(key, value));
}
return value;
}
Expand All @@ -52,9 +55,11 @@ public Iterable<String> keys() {

@Override
public void forEachProperty(BiConsumer<String, Object> consumer) {
getState().getData().forEach((k, v) -> {
if (getState().getInstrumentedKeys().containsKey(k)) {
getState().getInstrumentedKeys().get(k).recordUsage(createPropertyDetails(k, v));
CachedState state = getState();
state.getData().forEach((k, v) -> {
Config config = state.getInstrumentedKeys().get(k);
if (config != null) {
config.recordUsage(createPropertyDetails(k, v));
}
consumer.accept(k, v);
});
Expand All @@ -77,8 +82,10 @@ public boolean isEmpty() {

@Override
public void recordUsage(PropertyDetails propertyDetails) {
if (getState().getInstrumentedKeys().containsKey(propertyDetails.getKey())) {
getState().getInstrumentedKeys().get(propertyDetails.getKey()).recordUsage(createPropertyDetails(propertyDetails.getKey(), propertyDetails.getValue()));
CachedState state = getState();
Config config = state.getInstrumentedKeys().get(propertyDetails.getKey());
if (config != null) {
config.recordUsage(createPropertyDetails(propertyDetails.getKey(), propertyDetails.getValue()));
}
}

Expand Down

0 comments on commit 4e92434

Please sign in to comment.