Optimize volatile flags for logging audit (elastic/x-pack-elasticsearch#4265)

Remove unnecessary volatile qualifier.

Original commit: elastic/x-pack-elasticsearch@2889bc40e7
This commit is contained in:
Albert Zaharovits 2018-04-05 13:35:32 +03:00 committed by GitHub
parent f709fcd083
commit f3a7c58413
1 changed files with 10 additions and 10 deletions

View File

@ -116,10 +116,10 @@ public class LoggingAuditTrail extends AbstractComponent implements AuditTrail,
private final Logger logger; private final Logger logger;
final EventFilterPolicyRegistry eventFilterPolicyRegistry; final EventFilterPolicyRegistry eventFilterPolicyRegistry;
private final ThreadContext threadContext; private final ThreadContext threadContext;
// protected for testing // package for testing
volatile EnumSet<AuditLevel> events; volatile EnumSet<AuditLevel> events;
volatile boolean includeRequestBody; boolean includeRequestBody;
volatile LocalNodeInfo localNodeInfo; LocalNodeInfo localNodeInfo;
@Override @Override
public String name() { public String name() {
@ -139,17 +139,17 @@ public class LoggingAuditTrail extends AbstractComponent implements AuditTrail,
this.localNodeInfo = new LocalNodeInfo(settings, null); this.localNodeInfo = new LocalNodeInfo(settings, null);
this.eventFilterPolicyRegistry = new EventFilterPolicyRegistry(settings); this.eventFilterPolicyRegistry = new EventFilterPolicyRegistry(settings);
clusterService.addListener(this); clusterService.addListener(this);
clusterService.getClusterSettings().addSettingsUpdateConsumer(newSettings -> {
this.includeRequestBody = INCLUDE_REQUEST_BODY.get(newSettings);
}, Arrays.asList(INCLUDE_REQUEST_BODY));
clusterService.getClusterSettings().addSettingsUpdateConsumer(newSettings -> {
this.events = parse(INCLUDE_EVENT_SETTINGS.get(newSettings), EXCLUDE_EVENT_SETTINGS.get(newSettings));
}, Arrays.asList(INCLUDE_EVENT_SETTINGS, EXCLUDE_EVENT_SETTINGS));
clusterService.getClusterSettings().addSettingsUpdateConsumer(newSettings -> { clusterService.getClusterSettings().addSettingsUpdateConsumer(newSettings -> {
final LocalNodeInfo localNodeInfo = this.localNodeInfo; final LocalNodeInfo localNodeInfo = this.localNodeInfo;
final Settings.Builder builder = Settings.builder().put(localNodeInfo.settings).put(newSettings, false); final Settings.Builder builder = Settings.builder().put(localNodeInfo.settings).put(newSettings, false);
this.localNodeInfo = new LocalNodeInfo(builder.build(), localNodeInfo.localNode); this.localNodeInfo = new LocalNodeInfo(builder.build(), localNodeInfo.localNode);
}, Arrays.asList(HOST_ADDRESS_SETTING, HOST_NAME_SETTING, NODE_NAME_SETTING)); this.includeRequestBody = INCLUDE_REQUEST_BODY.get(newSettings);
// `events` is a volatile field! Keep `events` write last so that
// `localNodeInfo` and `includeRequestBody` writes happen-before! `events` is
// always read before `localNodeInfo` and `includeRequestBody`.
this.events = parse(INCLUDE_EVENT_SETTINGS.get(newSettings), EXCLUDE_EVENT_SETTINGS.get(newSettings));
}, Arrays.asList(HOST_ADDRESS_SETTING, HOST_NAME_SETTING, NODE_NAME_SETTING, INCLUDE_EVENT_SETTINGS, EXCLUDE_EVENT_SETTINGS,
INCLUDE_REQUEST_BODY));
clusterService.getClusterSettings().addAffixUpdateConsumer(FILTER_POLICY_IGNORE_PRINCIPALS, (policyName, filtersList) -> { clusterService.getClusterSettings().addAffixUpdateConsumer(FILTER_POLICY_IGNORE_PRINCIPALS, (policyName, filtersList) -> {
final Optional<EventFilterPolicy> policy = eventFilterPolicyRegistry.get(policyName); final Optional<EventFilterPolicy> policy = eventFilterPolicyRegistry.get(policyName);
final EventFilterPolicy newPolicy = policy.orElse(new EventFilterPolicy(policyName, settings)) final EventFilterPolicy newPolicy = policy.orElse(new EventFilterPolicy(policyName, settings))