summaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2018-02-16 11:27:33 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2018-02-16 11:27:33 +0100
commitd3612c8b4abdd2583f841bef01073f8aaf1a00f7 (patch)
treef44c24281f8b8197ac7e97b5df3879b9ec921366 /config
parent87a68b75d729960da7fcada2fc3a7c30119074ed (diff)
Let RawConfig be a ConfigInstance
Diffstat (limited to 'config')
-rw-r--r--config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java14
-rw-r--r--config/src/main/java/com/yahoo/config/subscription/impl/ConfigSubscription.java10
-rw-r--r--config/src/main/java/com/yahoo/config/subscription/impl/GenericJRTConfigSubscription.java12
3 files changed, 16 insertions, 20 deletions
diff --git a/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java b/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java
index 5873d726857..bf8b9372d58 100644
--- a/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java
+++ b/config/src/main/java/com/yahoo/config/subscription/ConfigSubscriber.java
@@ -230,7 +230,7 @@ public class ConfigSubscriber {
boolean anyConfigChanged = false;
boolean allGenerationsChanged = true;
boolean allGenerationsTheSame = true;
- Long currentGenChecker = null;
+ Long currentGen = null;
for (ConfigHandle<? extends ConfigInstance> h : subscriptionHandles) {
h.setChanged(false); // Reset this flag, if it was set, the user should have acted on it the last time this method returned true.
}
@@ -245,8 +245,8 @@ public class ConfigSubscriber {
}
throwIfExceptionSet(subscription);
ConfigSubscription.ConfigState<? extends ConfigInstance> config = subscription.getConfigState();
- if (currentGenChecker == null) currentGenChecker = config.getGeneration();
- if (!currentGenChecker.equals(config.getGeneration())) allGenerationsTheSame = false;
+ if (currentGen == null) currentGen = config.getGeneration();
+ if (!currentGen.equals(config.getGeneration())) allGenerationsTheSame = false;
allGenerationsChanged = allGenerationsChanged && config.isGenerationChanged();
if (config.isConfigChanged()) anyConfigChanged = true;
timeLeftMillis = timeLeftMillis - (System.currentTimeMillis() - started);
@@ -259,8 +259,8 @@ public class ConfigSubscriber {
if (reconfigDue) {
// This indicates the clients will possibly reconfigure their services, so "reset" changed-logic in subscriptions.
// Also if appropriate update the changed flag on the handler, which clients use.
- markSubsChangedSeen();
- generation = currentGenChecker;
+ markSubsChangedSeen(currentGen);
+ generation = currentGen;
}
return reconfigDue;
}
@@ -286,10 +286,10 @@ public class ConfigSubscriber {
}
}
- private void markSubsChangedSeen() {
+ private void markSubsChangedSeen(Long requiredGen) {
for (ConfigHandle<? extends ConfigInstance> h : subscriptionHandles) {
ConfigSubscription<? extends ConfigInstance> sub = h.subscription();
- h.setChanged(sub.isConfigChangedAndReset());
+ h.setChanged(sub.isConfigChangedAndReset(requiredGen));
}
}
diff --git a/config/src/main/java/com/yahoo/config/subscription/impl/ConfigSubscription.java b/config/src/main/java/com/yahoo/config/subscription/impl/ConfigSubscription.java
index 8408fddba2d..6fd157ee67f 100644
--- a/config/src/main/java/com/yahoo/config/subscription/impl/ConfigSubscription.java
+++ b/config/src/main/java/com/yahoo/config/subscription/impl/ConfigSubscription.java
@@ -96,7 +96,8 @@ public abstract class ConfigSubscription<T extends ConfigInstance> {
* @param subscriber the subscriber for this subscription
* @return a subclass of a ConfigsSubscription
*/
- public static <T extends ConfigInstance> ConfigSubscription<T> get(ConfigKey<T> key, ConfigSubscriber subscriber, ConfigSource source, TimingValues timingValues) {
+ public static <T extends ConfigInstance> ConfigSubscription<T> get(ConfigKey<T> key, ConfigSubscriber subscriber,
+ ConfigSource source, TimingValues timingValues) {
String configId = key.getConfigId();
if (source instanceof RawSource || configId.startsWith("raw:")) return getRawSub(key, subscriber, source);
if (source instanceof FileSource || configId.startsWith("file:")) return getFileSub(key, subscriber, source);
@@ -163,12 +164,13 @@ public abstract class ConfigSubscription<T extends ConfigInstance> {
/**
* Called from {@link ConfigSubscriber} when the changed status of this config is propagated to the clients
*/
- public boolean isConfigChangedAndReset() {
+ public boolean isConfigChangedAndReset(Long requiredGen) {
ConfigState<T> prev = config.get();
- while ( !config.compareAndSet(prev, prev.createUnchanged())) {
+ while ( prev.getGeneration().equals(requiredGen) && !config.compareAndSet(prev, prev.createUnchanged())) {
prev = config.get();
}
- return prev.isConfigChanged();
+ // A false positive is a lot better than a false negative
+ return !prev.getGeneration().equals(requiredGen) || prev.isConfigChanged();
}
void setConfig(Long generation, T config) {
diff --git a/config/src/main/java/com/yahoo/config/subscription/impl/GenericJRTConfigSubscription.java b/config/src/main/java/com/yahoo/config/subscription/impl/GenericJRTConfigSubscription.java
index 3caface8aa4..068b24cdf1a 100644
--- a/config/src/main/java/com/yahoo/config/subscription/impl/GenericJRTConfigSubscription.java
+++ b/config/src/main/java/com/yahoo/config/subscription/impl/GenericJRTConfigSubscription.java
@@ -3,7 +3,6 @@ package com.yahoo.config.subscription.impl;
import java.util.List;
-import com.yahoo.config.ConfigInstance;
import com.yahoo.config.subscription.ConfigSource;
import com.yahoo.config.subscription.ConfigSubscriber;
import com.yahoo.log.LogLevel;
@@ -19,23 +18,18 @@ import com.yahoo.vespa.config.protocol.JRTClientConfigRequest;
* @author vegardh
*
*/
-@SuppressWarnings("rawtypes")
public class GenericJRTConfigSubscription extends JRTConfigSubscription<RawConfig> {
private final List<String> defContent;
- @SuppressWarnings("unchecked")
- public GenericJRTConfigSubscription(ConfigKey<RawConfig> key,
- List<String> defContent,
- ConfigSubscriber subscriber,
- ConfigSource source,
- TimingValues timingValues) {
+ public GenericJRTConfigSubscription(ConfigKey<RawConfig> key, List<String> defContent, ConfigSubscriber subscriber,
+ ConfigSource source, TimingValues timingValues)
+ {
super(key, subscriber, source, timingValues);
this.defContent = defContent;
}
@Override
- @SuppressWarnings("unchecked")
protected void setNewConfig(JRTClientConfigRequest jrtReq) {
setConfig(jrtReq.getNewGeneration(), RawConfig.createFromResponseParameters(jrtReq) );
if (log.isLoggable(LogLevel.DEBUG)) {