diff options
author | Håkon Hallingstad <hakon@oath.com> | 2019-01-14 15:40:53 +0100 |
---|---|---|
committer | Håkon Hallingstad <hakon@oath.com> | 2019-01-14 15:40:53 +0100 |
commit | eeeff8ac4f7dcd58aaa5f7301d79bbc09f10c680 (patch) | |
tree | b1dec9d6f6ea6435b66be3ad3981f5b99d1610bd /flags | |
parent | 60b1ce20e9c1c44c92e178a79f8c58e0fccdab7f (diff) |
Allow different drop caches strategies
Diffstat (limited to 'flags')
-rw-r--r-- | flags/src/main/java/com/yahoo/vespa/flags/Flags.java | 6 | ||||
-rw-r--r-- | flags/src/main/java/com/yahoo/vespa/flags/InMemoryFlagSource.java | 46 |
2 files changed, 37 insertions, 15 deletions
diff --git a/flags/src/main/java/com/yahoo/vespa/flags/Flags.java b/flags/src/main/java/com/yahoo/vespa/flags/Flags.java index 64112a29a59..9a4f1faed03 100644 --- a/flags/src/main/java/com/yahoo/vespa/flags/Flags.java +++ b/flags/src/main/java/com/yahoo/vespa/flags/Flags.java @@ -29,6 +29,12 @@ public class Flags { "Takes effect only at bootstrap of config server/controller", HOSTNAME); + public static final UnboundIntFlag DROP_CACHES = defineIntFlag("drop-caches", 3, + "The int value to write into /proc/sys/vm/drop_caches for each tick. " + + "1 is page cache, 2 is dentries inodes, 3 is both page cache and dentries inodes, etc.", + "Takes effect on next tick.", + HOSTNAME); + public static final UnboundBooleanFlag ENABLE_CROWDSTRIKE = defineFeatureFlag( "enable-crowdstrike", true, "Whether to enable CrowdStrike.", "Takes effect on next host admin tick", diff --git a/flags/src/main/java/com/yahoo/vespa/flags/InMemoryFlagSource.java b/flags/src/main/java/com/yahoo/vespa/flags/InMemoryFlagSource.java index 5e2afe39dd8..5ed1859b89b 100644 --- a/flags/src/main/java/com/yahoo/vespa/flags/InMemoryFlagSource.java +++ b/flags/src/main/java/com/yahoo/vespa/flags/InMemoryFlagSource.java @@ -1,11 +1,6 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.flags; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.DoubleNode; -import com.yahoo.vespa.flags.json.FlagData; -import com.yahoo.vespa.flags.json.Rule; - import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; @@ -13,29 +8,50 @@ import java.util.concurrent.ConcurrentHashMap; /** * Basic in-memory flag source useful for testing * + * Creates an empty flag source that will make all flags return their default values (from {@code value()}). + * The with* methods can be used to set a different return value. + * * @author freva */ public class InMemoryFlagSource implements FlagSource { - private final Map<FlagId, FlagData> flagDataById = new ConcurrentHashMap<>(); + private final Map<FlagId, RawFlag> rawFlagsById = new ConcurrentHashMap<>(); - public InMemoryFlagSource withFlag(FlagId flagId) { - flagDataById.put(flagId, new FlagData(flagId)); - return this; + public InMemoryFlagSource withBooleanFlag(FlagId flagId, boolean value) { + return withRawFlag(flagId, new UnboundBooleanFlag(flagId, value).serializer().serialize(value)); + } + + public InMemoryFlagSource withStringFlag(FlagId flagId, String value) { + return withRawFlag(flagId, new UnboundStringFlag(flagId, value).serializer().serialize(value)); + } + + public InMemoryFlagSource withIntFlag(FlagId flagId, int value) { + return withRawFlag(flagId, new UnboundIntFlag(flagId, value).serializer().serialize(value)); + } + + public InMemoryFlagSource withLongFlag(FlagId flagId, long value) { + return withRawFlag(flagId, new UnboundLongFlag(flagId, value).serializer().serialize(value)); } public InMemoryFlagSource withDoubleFlag(FlagId flagId, double value) { - return withRawFlag(flagId, new DoubleNode(value)); + return withRawFlag(flagId, new UnboundDoubleFlag(flagId, value).serializer().serialize(value)); + } + + public <T> InMemoryFlagSource withJacksonFlag(FlagId flagId, T value, Class<T> jacksonClass) { + return withRawFlag(flagId, new UnboundJacksonFlag<>(flagId, value, jacksonClass).serializer().serialize(value)); + } + + public InMemoryFlagSource removeFlag(FlagId flagId) { + rawFlagsById.remove(flagId); + return this; } - private InMemoryFlagSource withRawFlag(FlagId flagId, JsonNode rawFlag) { - Rule rule = new Rule(Optional.of(JsonNodeRawFlag.fromJsonNode(rawFlag))); - flagDataById.put(flagId, new FlagData(flagId, new FetchVector(), rule)); + private InMemoryFlagSource withRawFlag(FlagId flagId, RawFlag rawFlag) { + rawFlagsById.put(flagId, rawFlag); return this; } @Override public Optional<RawFlag> fetch(FlagId id, FetchVector vector) { - return Optional.ofNullable(flagDataById.get(id)) - .flatMap(flagData -> flagData.resolve(vector)); + return Optional.ofNullable(rawFlagsById.get(id)); } } |