Skip to content

Commit

Permalink
Merge pull request #32833 from vespa-engine/hmusum/support-setting-zo…
Browse files Browse the repository at this point in the history
…okeeper-pre-alloc-size

Support setting zookeeper preAllocSize with feature flag
  • Loading branch information
hmusum authored Nov 12, 2024
2 parents 3852913 + 665e7b4 commit e3e2386
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 9 deletions.
7 changes: 4 additions & 3 deletions config-model-api/abi-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -758,10 +758,10 @@
"public static final enum com.yahoo.config.application.api.ValidationId accessControl",
"public static final enum com.yahoo.config.application.api.ValidationId globalEndpointChange",
"public static final enum com.yahoo.config.application.api.ValidationId zoneEndpointChange",
"public static final enum com.yahoo.config.application.api.ValidationId redundancyIncrease",
"public static final enum com.yahoo.config.application.api.ValidationId redundancyOne",
"public static final enum com.yahoo.config.application.api.ValidationId pagedSettingRemoval",
"public static final enum com.yahoo.config.application.api.ValidationId certificateRemoval"
"public static final enum com.yahoo.config.application.api.ValidationId certificateRemoval",
"public static final enum com.yahoo.config.application.api.ValidationId redundancyIncrease"
]
},
"com.yahoo.config.application.api.ValidationOverrides$Allow" : {
Expand Down Expand Up @@ -1341,7 +1341,8 @@
"public boolean enforceStrictlyIncreasingClusterStateVersions()",
"public boolean distributionConfigFromClusterController()",
"public boolean useLegacyWandQueryParsing()",
"public boolean forwardAllLogLevels()"
"public boolean forwardAllLogLevels()",
"public long zookeeperPreAllocSize()"
],
"fields" : [ ]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ interface FeatureFlags {
@ModelFeatureFlag(owners = {"vekterli"}) default boolean distributionConfigFromClusterController() { return false; }
@ModelFeatureFlag(owners = {"arnej"}) default boolean useLegacyWandQueryParsing() { return true; }
@ModelFeatureFlag(owners = {"hmusum"}) default boolean forwardAllLogLevels() { return true; }
@ModelFeatureFlag(owners = {"hmusum"}) default long zookeeperPreAllocSize() { return 65536L; }
}

/** Warning: As elsewhere in this package, do not make backwards incompatible changes that will break old config models! */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.cloud.config.CuratorConfig;
import com.yahoo.cloud.config.ZookeeperServerConfig;

import com.yahoo.config.model.producer.TreeConfigProducer;
import com.yahoo.config.provision.Environment;
import com.yahoo.config.provision.RegionName;
Expand All @@ -20,6 +21,8 @@
import java.util.Optional;
import java.util.stream.IntStream;

import static com.yahoo.config.model.api.ModelContext.FeatureFlags;

/**
* Represents a config server cluster.
*
Expand All @@ -34,11 +37,13 @@ public class ConfigserverCluster extends TreeConfigProducer
ZookeeperServerConfig.Producer {

private final ConfigOptions options;
private final FeatureFlags featureFlags;
private ContainerCluster<?> containerCluster;

public ConfigserverCluster(TreeConfigProducer<?> parent, String subId, ConfigOptions options) {
public ConfigserverCluster(TreeConfigProducer<?> parent, String subId, ConfigOptions options, FeatureFlags featureFlags) {
super(parent, subId);
this.options = options;
this.featureFlags = featureFlags;
}

public void setContainerCluster(ContainerCluster<?> containerCluster) {
Expand Down Expand Up @@ -87,6 +92,7 @@ public void getConfig(ZookeeperServerConfig.Builder builder) {
builder.reconfigureEnsemble(!isHostedVespa);
builder.snapshotMethod(options.zooKeeperSnapshotMethod());
builder.juteMaxBuffer(options.zookeeperJuteMaxBuffer());
builder.preAllocSizeKb(featureFlags.zookeeperPreAllocSize());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ConfigServerContainerModelBuilder(ConfigOptions options) {
@Override
public void doBuild(ContainerModel model, Element spec, ConfigModelContext modelContext) {
ConfigserverCluster cluster = new ConfigserverCluster(modelContext.getParentProducer(), "configserver",
options);
options, modelContext.featureFlags());
super.doBuild(model, spec, modelContext.withParent(cluster));
cluster.setContainerCluster(model.getCluster());
}
Expand Down
4 changes: 4 additions & 0 deletions configdefinitions/src/vespa/zookeeper-server.def
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ learnerAsyncSending bool default=false
# Whether the ZooKeeper ensemble should be reconfigured automatically if servers change. This only has an effect if
# dynamicReconfiguration=true.
reconfigureEnsemble bool default=true

# To avoid seeks ZooKeeper allocates space in the transaction log file in blocks of preAllocSize kilobytes. The default block size is 64M
# Can/should be reduced for tests
preAllocSizeKb long default=65536
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public static class FeatureFlags implements ModelContext.FeatureFlags {
private final boolean distributionConfigFromClusterController;
private final boolean useLegacyWandQueryParsing;
private final boolean forwardAllLogLevels;
private final long zookeeperPreAllocSize;

public FeatureFlags(FlagSource source, ApplicationId appId, Version version) {
this.defaultTermwiseLimit = Flags.DEFAULT_TERM_WISE_LIMIT.bindTo(source).with(appId).with(version).value();
Expand Down Expand Up @@ -258,7 +259,7 @@ public FeatureFlags(FlagSource source, ApplicationId appId, Version version) {
this.sortBlueprintsByCost = Flags.SORT_BLUEPRINTS_BY_COST.bindTo(source).with(appId).with(version).value();
this.persistenceThreadMaxFeedOpBatchSize = Flags.PERSISTENCE_THREAD_MAX_FEED_OP_BATCH_SIZE.bindTo(source).with(appId).with(version).value();
this.logserverOtelCol = Flags.LOGSERVER_OTELCOL_AGENT.bindTo(source).with(appId).with(version).value();
this.sharedHosts = PermanentFlags.SHARED_HOST.bindTo(source).with( appId).with(version).value();
this.sharedHosts = PermanentFlags.SHARED_HOST.bindTo(source).with(appId).with(version).value();
this.adminClusterArchitecture = Architecture.valueOf(PermanentFlags.ADMIN_CLUSTER_NODE_ARCHITECTURE.bindTo(source).with(appId).with(version).value());
this.logserverNodeMemory = PermanentFlags.LOGSERVER_NODE_MEMORY.bindTo(source).with(appId).with(version).value();
this.symmetricPutAndActivateReplicaSelection = Flags.SYMMETRIC_PUT_AND_ACTIVATE_REPLICA_SELECTION.bindTo(source).with(appId).with(version).value();
Expand All @@ -267,6 +268,7 @@ public FeatureFlags(FlagSource source, ApplicationId appId, Version version) {
this.distributionConfigFromClusterController = Flags.DISTRIBUTION_CONFIG_FROM_CLUSTER_CONTROLLER.bindTo(source).with(appId).with(version).value();
this.useLegacyWandQueryParsing = Flags.USE_LEGACY_WAND_QUERY_PARSING.bindTo(source).with(appId).with(version).value();
this.forwardAllLogLevels = PermanentFlags.FORWARD_ALL_LOG_LEVELS.bindTo(source).with(appId).with(version).value();
this.zookeeperPreAllocSize = Flags.ZOOKEEPER_PRE_ALLOC_SIZE_KIB.bindTo(source).value();
}

@Override public int heapSizePercentage() { return heapPercentage; }
Expand Down Expand Up @@ -324,6 +326,7 @@ public FeatureFlags(FlagSource source, ApplicationId appId, Version version) {
@Override public boolean distributionConfigFromClusterController() { return distributionConfigFromClusterController; }
@Override public boolean useLegacyWandQueryParsing() { return useLegacyWandQueryParsing; }
@Override public boolean forwardAllLogLevels() { return forwardAllLogLevels; }
@Override public long zookeeperPreAllocSize() { return zookeeperPreAllocSize; }
}

public static class Properties implements ModelContext.Properties {
Expand Down
7 changes: 7 additions & 0 deletions flags/src/main/java/com/yahoo/vespa/flags/Flags.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,13 @@ public class Flags {
"Whether node snapshots should be created when host storage is discarded",
"Takes effect immediately");

public static final UnboundLongFlag ZOOKEEPER_PRE_ALLOC_SIZE_KIB = defineLongFlag(
"zookeeper-pre-alloc-size", 65536,
List.of("hmusum"), "2024-11-11", "2025-01-11",
"Setting for zookeeper.preAllocSize flag in KiB, can be reduced from default value "
+ "e.g. when running tests to avoid writing a large, sparse, mostly unused file",
"Takes effect on restart of Docker container");

/** WARNING: public for testing: All flags should be defined in {@link Flags}. */
public static UnboundBooleanFlag defineFeatureFlag(String flagId, boolean defaultValue, List<String> owners,
String createdAt, String expiresAt, String description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public Configurator(ZookeeperServerConfig zookeeperServerConfig) {
System.setProperty("zookeeper.learner.asyncSending", String.valueOf(zookeeperServerConfig.learnerAsyncSending()));
// Enable creation of TTL Nodes.
System.setProperty("zookeeper.extendedTypesEnabled", "true");
// Space in the transaction log file in kilobytes.
System.setProperty("zookeeper.preAllocSize", String.valueOf(zookeeperServerConfig.preAllocSizeKb()));
}

void writeConfigToDisk() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public void config_is_written_correctly_with_one_server() {
}

@Test
public void config_is_written_correctly_with_multiple_servers() throws IOException {
public void config_is_written_correctly_with_multiple_servers() {
three_config_servers(false);
}

@Test
public void config_is_written_correctly_with_multiple_servers_on_hosted_vespa() throws IOException {
public void config_is_written_correctly_with_multiple_servers_on_hosted_vespa() {
three_config_servers(true);
}

Expand Down Expand Up @@ -155,7 +155,7 @@ public void test_parsing_config() throws IOException {
Files.readString(cfgFile.toPath()));
}

private void three_config_servers(boolean hosted) throws IOException {
private void three_config_servers(boolean hosted) {
ZookeeperServerConfig.Builder builder = new ZookeeperServerConfig.Builder();
builder.zooKeeperConfigFile(cfgFile.getAbsolutePath());
builder.server(newServer(0, "foo", 123, 321, false));
Expand Down

0 comments on commit e3e2386

Please sign in to comment.