diff options
44 files changed, 160 insertions, 195 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomSearchTuningBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomSearchTuningBuilder.java index 25c8a204c26..81f901fc849 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomSearchTuningBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomSearchTuningBuilder.java @@ -24,7 +24,7 @@ public class DomSearchTuningBuilder extends VespaDomBuilder.DomConfigProducerBui if (equals("dispatch", e)) { handleDispatch(e, tuning); } else if (equals("searchnode", e)) { - handleSearchNode(deployState.getDeployLogger(), parent, e, tuning); + handleSearchNode(deployState.getDeployLogger(), e, tuning); } } return tuning; @@ -59,13 +59,13 @@ public class DomSearchTuningBuilder extends VespaDomBuilder.DomConfigProducerBui } } - private void handleSearchNode(DeployLogger deployLogger, AbstractConfigProducer parent, Element spec, Tuning t) { + private void handleSearchNode(DeployLogger deployLogger, Element spec, Tuning t) { t.searchNode = new Tuning.SearchNode(); for (Element e : XML.getChildren(spec)) { if (equals("requestthreads", e)) { handleRequestThreads(e, t.searchNode); } else if (equals("flushstrategy", e)) { - handleFlushStrategy(deployLogger, parent,e, t.searchNode); + handleFlushStrategy(deployLogger,e, t.searchNode); } else if (equals("resizing", e)) { handleResizing(e, t.searchNode); } else if (equals("index", e)) { @@ -73,7 +73,7 @@ public class DomSearchTuningBuilder extends VespaDomBuilder.DomConfigProducerBui } else if (equals("attribute", e)) { handleAttribute(e, t.searchNode); } else if (equals("summary", e)) { - handleSummary(deployLogger, parent, e, t.searchNode); + handleSummary(deployLogger, e, t.searchNode); } else if (equals("initialize", e)) { handleInitialize(e, t.searchNode); } else if (equals("feeding", e)) { @@ -96,15 +96,15 @@ public class DomSearchTuningBuilder extends VespaDomBuilder.DomConfigProducerBui } } - private void handleFlushStrategy(DeployLogger deployLogger, AbstractConfigProducer parent, Element spec, Tuning.SearchNode sn) { + private void handleFlushStrategy(DeployLogger deployLogger, Element spec, Tuning.SearchNode sn) { for (Element e : XML.getChildren(spec)) { if (equals("native", e)) { - handleNativeStrategy(deployLogger, parent, e, sn); + handleNativeStrategy(deployLogger, e, sn); } } } - private void handleNativeStrategy(DeployLogger deployLogger, AbstractConfigProducer parent, Element spec, Tuning.SearchNode sn) { + private void handleNativeStrategy(DeployLogger deployLogger, Element spec, Tuning.SearchNode sn) { sn.strategy = new Tuning.SearchNode.FlushStrategy(); Tuning.SearchNode.FlushStrategy fs = sn.strategy; for (Element e : XML.getChildren(spec)) { @@ -188,7 +188,7 @@ public class DomSearchTuningBuilder extends VespaDomBuilder.DomConfigProducerBui } } - private void handleSummary(DeployLogger deployLogger, AbstractConfigProducer parent, Element spec, Tuning.SearchNode sn) { + private void handleSummary(DeployLogger deployLogger, Element spec, Tuning.SearchNode sn) { sn.summary = new Tuning.SearchNode.Summary(); for (Element e : XML.getChildren(spec)) { if (equals("io", e)) { @@ -201,24 +201,24 @@ public class DomSearchTuningBuilder extends VespaDomBuilder.DomConfigProducerBui } } } else if (equals("store", e)) { - handleSummaryStore(deployLogger, parent, e, sn.summary); + handleSummaryStore(deployLogger, e, sn.summary); } } } - private void handleSummaryStore(DeployLogger deployLogger, AbstractConfigProducer parent, Element spec, Tuning.SearchNode.Summary s) { + private void handleSummaryStore(DeployLogger deployLogger, Element spec, Tuning.SearchNode.Summary s) { s.store = new Tuning.SearchNode.Summary.Store(); for (Element e : XML.getChildren(spec)) { if (equals("cache", e)) { s.store.cache = new Tuning.SearchNode.Summary.Store.Component(); - handleSummaryStoreComponent(deployLogger, parent, e, s.store.cache); + handleSummaryStoreComponent(deployLogger, e, s.store.cache); } else if (equals("logstore", e)) { - handleSummaryLogStore(deployLogger, parent, e, s.store); + handleSummaryLogStore(deployLogger, e, s.store); } } } - private void handleSummaryStoreComponent(DeployLogger deployLogger, AbstractConfigProducer parent, Element spec, Tuning.SearchNode.Summary.Store.Component c) { + private void handleSummaryStoreComponent(DeployLogger deployLogger, Element spec, Tuning.SearchNode.Summary.Store.Component c) { for (Element e : XML.getChildren(spec)) { if (equals("maxsize", e)) { c.maxSize = asLong(e); @@ -245,7 +245,7 @@ public class DomSearchTuningBuilder extends VespaDomBuilder.DomConfigProducerBui } } - private void handleSummaryLogStore(DeployLogger deployLogger, AbstractConfigProducer parent, Element spec, Tuning.SearchNode.Summary.Store s) { + private void handleSummaryLogStore(DeployLogger deployLogger, Element spec, Tuning.SearchNode.Summary.Store s) { s.logStore = new Tuning.SearchNode.Summary.Store.LogStore(); for (Element e : XML.getChildren(spec)) { if (equals("maxfilesize", e)) { @@ -261,7 +261,7 @@ public class DomSearchTuningBuilder extends VespaDomBuilder.DomConfigProducerBui s.logStore.numThreads = asInt(e); } else if (equals("chunk", e)) { s.logStore.chunk = new Tuning.SearchNode.Summary.Store.Component(true); - handleSummaryStoreComponent(deployLogger, parent, e, s.logStore.chunk); + handleSummaryStoreComponent(deployLogger, e, s.logStore.chunk); } } } diff --git a/config/src/tests/configfetcher/configfetcher.cpp b/config/src/tests/configfetcher/configfetcher.cpp index c7a8541e0eb..2a1158de48f 100644 --- a/config/src/tests/configfetcher/configfetcher.cpp +++ b/config/src/tests/configfetcher/configfetcher.cpp @@ -2,6 +2,7 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/config/helper/configfetcher.h> #include <vespa/vespalib/util/exception.h> +#include <vespa/fastos/time.h> #include <fstream> #include "config-my.h" #include <atomic> diff --git a/config/src/tests/configholder/configholder.cpp b/config/src/tests/configholder/configholder.cpp index 2c6fa2016bf..a9b6dafb72a 100644 --- a/config/src/tests/configholder/configholder.cpp +++ b/config/src/tests/configholder/configholder.cpp @@ -1,21 +1,29 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/config/common/configholder.h> +#include <vespa/fastos/time.h> using namespace config; +namespace { + +constexpr double ONE_SEC = 1000.0; +constexpr double ONE_MINUTE = 60 * ONE_SEC; + +} + TEST("Require that element order is correct") { ConfigValue value(std::vector<vespalib::string>(), "foo"); ConfigValue value2(std::vector<vespalib::string>(), "bar"); ConfigHolder holder; - holder.handle(ConfigUpdate::UP(new ConfigUpdate(value, true, 0))); + holder.handle(std::make_unique<ConfigUpdate>(value, true, 0)); std::unique_ptr<ConfigUpdate> update = holder.provide(); ASSERT_TRUE(value == update->getValue()); - holder.handle(ConfigUpdate::UP(new ConfigUpdate(value, false, 1))); - holder.handle(ConfigUpdate::UP(new ConfigUpdate(value2, false, 2))); + holder.handle(std::make_unique<ConfigUpdate>(value, false, 1)); + holder.handle(std::make_unique<ConfigUpdate>(value2, false, 2)); update = holder.provide(); ASSERT_TRUE(value2 == update->getValue()); } @@ -28,13 +36,11 @@ TEST("Require that waiting is done") FastOS_Time timer; timer.SetNow(); holder.wait(1000); - ASSERT_TRUE(timer.MilliSecsToNow() >= 1000); - ASSERT_TRUE(timer.MilliSecsToNow() < 60000); + EXPECT_GREATER_EQUAL(timer.MilliSecsToNow(), ONE_SEC); + EXPECT_LESS(timer.MilliSecsToNow(), ONE_MINUTE); - timer.SetNow(); - holder.handle(ConfigUpdate::UP(new ConfigUpdate(value, true, 0))); - holder.wait(100); - ASSERT_TRUE(timer.MilliSecsToNow() >= 100); + holder.handle(std::make_unique<ConfigUpdate>(value, true, 0)); + ASSERT_TRUE(holder.wait(100)); } TEST("Require that polling for elements work") @@ -43,12 +49,24 @@ TEST("Require that polling for elements work") ConfigHolder holder; ASSERT_FALSE(holder.poll()); - holder.handle(ConfigUpdate::UP(new ConfigUpdate(value, true, 0))); + holder.handle(std::make_unique<ConfigUpdate>(value, true, 0)); ASSERT_TRUE(holder.poll()); holder.provide(); ASSERT_FALSE(holder.poll()); } +TEST("Require that negative time does not mean forever.") { + ConfigHolder holder; + FastOS_Time timer; + timer.SetNow(); + ASSERT_FALSE(holder.poll()); + ASSERT_FALSE(holder.wait(10)); + ASSERT_FALSE(holder.wait(0)); + ASSERT_FALSE(holder.wait(-1)); + ASSERT_FALSE(holder.wait(-7)); + EXPECT_LESS(timer.MilliSecsToNow(), ONE_MINUTE); +} + TEST_MT_F("Require that wait is interrupted", 2, ConfigHolder) { if (thread_id == 0) { @@ -56,8 +74,8 @@ TEST_MT_F("Require that wait is interrupted", 2, ConfigHolder) timer.SetNow(); TEST_BARRIER(); f.wait(1000); - EXPECT_TRUE(timer.MilliSecsToNow() < 60000.0); - EXPECT_TRUE(timer.MilliSecsToNow() > 400.0); + EXPECT_LESS(timer.MilliSecsToNow(), ONE_MINUTE); + EXPECT_GREATER(timer.MilliSecsToNow(), 400.0); TEST_BARRIER(); } else { TEST_BARRIER(); diff --git a/config/src/tests/configretriever/configretriever.cpp b/config/src/tests/configretriever/configretriever.cpp index 107c06a9abf..944b0d45da0 100644 --- a/config/src/tests/configretriever/configretriever.cpp +++ b/config/src/tests/configretriever/configretriever.cpp @@ -10,6 +10,7 @@ #include <vespa/config/common/configholder.h> #include <vespa/config/subscription/configsubscription.h> #include <vespa/config/common/exceptions.h> +#include <vespa/fastos/time.h> #include "config-bootstrap.h" #include "config-foo.h" #include "config-bar.h" diff --git a/config/src/tests/file_subscription/file_subscription.cpp b/config/src/tests/file_subscription/file_subscription.cpp index 27400ce57c9..69090f4bb8e 100644 --- a/config/src/tests/file_subscription/file_subscription.cpp +++ b/config/src/tests/file_subscription/file_subscription.cpp @@ -5,6 +5,7 @@ #include <vespa/config/file/filesource.h> #include <vespa/config/common/exceptions.h> #include <vespa/vespalib/util/sync.h> +#include <vespa/fastos/time.h> #include <fstream> #include <config-my.h> #include <config-foo.h> diff --git a/config/src/tests/subscriber/subscriber.cpp b/config/src/tests/subscriber/subscriber.cpp index 39a537486cd..5663b145100 100644 --- a/config/src/tests/subscriber/subscriber.cpp +++ b/config/src/tests/subscriber/subscriber.cpp @@ -5,6 +5,7 @@ #include <vespa/config/common/configholder.h> #include <vespa/config/subscription/configsubscription.h> #include <vespa/config/common/exceptions.h> +#include <vespa/fastos/time.h> #include <fstream> #include "config-foo.h" #include "config-bar.h" diff --git a/config/src/tests/subscription/subscription.cpp b/config/src/tests/subscription/subscription.cpp index a9e4c923e92..bfa341fa982 100644 --- a/config/src/tests/subscription/subscription.cpp +++ b/config/src/tests/subscription/subscription.cpp @@ -3,6 +3,7 @@ #include <vespa/config/common/misc.h> #include <vespa/config/common/configholder.h> #include <vespa/config/subscription/configsubscription.h> +#include <vespa/fastos/time.h> #include <config-my.h> using namespace config; diff --git a/config/src/vespa/config/common/configholder.cpp b/config/src/vespa/config/common/configholder.cpp index e2e6ae87688..d3d7e8fd5de 100644 --- a/config/src/vespa/config/common/configholder.cpp +++ b/config/src/vespa/config/common/configholder.cpp @@ -10,7 +10,7 @@ ConfigHolder::ConfigHolder() { } -ConfigHolder::~ConfigHolder() {} +ConfigHolder::~ConfigHolder() = default; ConfigUpdate::UP ConfigHolder::provide() @@ -34,7 +34,7 @@ bool ConfigHolder::wait(uint64_t timeoutInMillis) { vespalib::MonitorGuard guard(_monitor); - return guard.wait(timeoutInMillis); + return static_cast<bool>(_current) || guard.wait(timeoutInMillis); } bool diff --git a/config/src/vespa/config/common/configmanager.cpp b/config/src/vespa/config/common/configmanager.cpp index 2fa40b503df..0831853c2b4 100644 --- a/config/src/vespa/config/common/configmanager.cpp +++ b/config/src/vespa/config/common/configmanager.cpp @@ -2,6 +2,7 @@ #include "configmanager.h" #include "exceptions.h" #include "configholder.h" +#include <vespa/fastos/time.h> #include <thread> #include <sstream> diff --git a/config/src/vespa/config/common/trace.cpp b/config/src/vespa/config/common/trace.cpp index 09727d91fd9..2d9b3ce8370 100644 --- a/config/src/vespa/config/common/trace.cpp +++ b/config/src/vespa/config/common/trace.cpp @@ -2,6 +2,7 @@ #include "trace.h" #include <vespa/vespalib/trace/slime_trace_serializer.h> #include <vespa/vespalib/trace/slime_trace_deserializer.h> +#include <vespa/fastos/timestamp.h> using namespace vespalib; using namespace vespalib::slime; diff --git a/config/src/vespa/config/subscription/configsubscriptionset.cpp b/config/src/vespa/config/subscription/configsubscriptionset.cpp index ab38ba18351..f120272edcf 100644 --- a/config/src/vespa/config/subscription/configsubscriptionset.cpp +++ b/config/src/vespa/config/subscription/configsubscriptionset.cpp @@ -3,7 +3,9 @@ #include "configsubscriptionset.h" #include <vespa/config/common/exceptions.h> #include <vespa/config/common/misc.h> +#include <vespa/fastos/time.h> #include <thread> + #include <vespa/log/log.h> LOG_SETUP(".config.subscription.configsubscriptionset"); @@ -29,8 +31,9 @@ ConfigSubscriptionSet::acquireSnapshot(uint64_t timeoutInMillis, bool ignoreChan { if (_state == CLOSED) { return false; - } else if (_state == OPEN) + } else if (_state == OPEN) { _state = FROZEN; + } FastOS_Time timer; timer.SetNow(); @@ -39,7 +42,7 @@ ConfigSubscriptionSet::acquireSnapshot(uint64_t timeoutInMillis, bool ignoreChan bool inSync = false; LOG(debug, "Going into nextConfig loop, time left is %d", timeLeft); - while (_state != CLOSED && timeLeft >= 0 && !inSync) { + while ((_state != CLOSED) && (timeLeft >= 0) && !inSync) { size_t numChanged = 0; size_t numGenerationChanged = 0; bool generationsInSync = true; @@ -64,18 +67,22 @@ ConfigSubscriptionSet::acquireSnapshot(uint64_t timeoutInMillis, bool ignoreChan if (isGenerationNewer(subscription->getGeneration(), _currentGeneration)) { numGenerationChanged++; } - if (generation < 0) + if (generation < 0) { generation = subscription->getGeneration(); - if (subscription->getGeneration() != generation) + } + if (subscription->getGeneration() != generation) { generationsInSync = false; + } // Adjust timeout timeLeft = timeoutInMillis - static_cast<uint64_t>(timer.MilliSecsToNow()); } inSync = generationsInSync && (_subscriptionList.size() == numGenerationChanged) && (ignoreChange || numChanged > 0); lastGeneration = generation; timeLeft = timeoutInMillis - static_cast<uint64_t>(timer.MilliSecsToNow()); - if (!inSync && timeLeft > 0) { - std::this_thread::sleep_for(10ms); + if (!inSync && (timeLeft > 0)) { + std::this_thread::sleep_for(std::chrono::milliseconds(std::min(10, timeLeft))); + } else { + break; } } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigConvergenceChecker.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigConvergenceChecker.java index 113b57328a3..00f4d4be299 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigConvergenceChecker.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigConvergenceChecker.java @@ -7,6 +7,7 @@ import com.yahoo.component.AbstractComponent; import com.yahoo.config.model.api.HostInfo; import com.yahoo.config.model.api.PortInfo; import com.yahoo.config.model.api.ServiceInfo; +import com.yahoo.config.provision.ApplicationId; import com.yahoo.slime.Cursor; import com.yahoo.vespa.config.server.http.JSONResponse; import org.glassfish.jersey.client.ClientProperties; @@ -38,6 +39,8 @@ import java.util.stream.Collectors; */ public class ConfigConvergenceChecker extends AbstractComponent { + private static final ApplicationId routingApplicationId = ApplicationId.from("hosted-vespa", "routing", "default"); + private static final String nodeAdminName = "node-admin"; private static final String statePath = "/state/v1/"; private static final String configSubPath = "config"; private final static Set<String> serviceTypesToCheck = new HashSet<>(Arrays.asList( @@ -66,6 +69,7 @@ public class ConfigConvergenceChecker extends AbstractComponent { application.getModel().getHosts() .forEach(host -> host.getServices().stream() .filter(service -> serviceTypesToCheck.contains(service.getServiceType())) + .filter(service -> ! isHostAdminService(application.getId(), service)) .forEach(service -> getStatePort(service).ifPresent(port -> servicesToCheck.add(service)))); Map<ServiceInfo, Long> currentGenerations = getServiceGenerations(servicesToCheck, timeoutPerService); @@ -169,6 +173,13 @@ public class ConfigConvergenceChecker extends AbstractComponent { return WebResourceFactory.newResource(StateApi.class, target); } + private static boolean isHostAdminService(ApplicationId id, ServiceInfo service) { + return routingApplicationId.equals(id) + && service.getProperty("clustername") + .map("node-admin"::equals) + .orElse(false); + } + private static class ServiceListResponse extends JSONResponse { // Pre-condition: servicesToCheck has a state port diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobType.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobType.java index 5a4086f9abb..cee8d3ddfd9 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobType.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/deployment/JobType.java @@ -79,18 +79,18 @@ public enum JobType { } /** Returns the job type for the given zone */ - public static JobType from(SystemName system, ZoneId zone) { + public static Optional<JobType> from(SystemName system, ZoneId zone) { for (JobType job : values()) if (zone.equals(job.zones.get(system))) - return job; - throw new IllegalArgumentException("No job is known for " + zone + "."); + return Optional.of(job); + return Optional.empty(); } /** Returns the job job type for the given environment and region or null if none */ - public static JobType from(SystemName system, Environment environment, RegionName region) { + public static Optional<JobType> from(SystemName system, Environment environment, RegionName region) { switch (environment) { - case test: return systemTest; - case staging: return stagingTest; + case test: return Optional.of(systemTest); + case staging: return Optional.of(stagingTest); } return from(system, ZoneId.from(environment, region)); } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java index 8def309a2f0..eb86f0c2919 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java @@ -330,7 +330,8 @@ public class ApplicationController { () -> new IllegalArgumentException("Application package must be given when deploying to " + zone)); } else { - JobType jobType = JobType.from(controller.system(), zone); + JobType jobType = JobType.from(controller.system(), zone) + .orElseThrow(() -> new IllegalArgumentException("No job is known for " + zone + ".")); Optional<JobStatus> job = Optional.ofNullable(application.get().deploymentJobs().jobStatus().get(jobType)); if ( ! job.isPresent() || ! job.get().lastTriggered().isPresent() diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentSteps.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentSteps.java index 925f3e5948a..c400ad4c9cc 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentSteps.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentSteps.java @@ -13,6 +13,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -38,8 +39,7 @@ public class DeploymentSteps { /** Returns jobs for this, in the order they are declared */ public List<JobType> jobs() { return spec.steps().stream() - .flatMap(step -> step.zones().stream()) - .map(this::toJob) + .flatMap(step -> toJobs(step).stream()) .collect(collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); } @@ -66,6 +66,7 @@ public class DeploymentSteps { public List<JobType> toJobs(DeploymentSpec.Step step) { return step.zones().stream() .map(this::toJob) + .filter(Optional::isPresent).map(Optional::get) .collect(collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); } @@ -97,7 +98,7 @@ public class DeploymentSteps { } /** Resolve job from deployment zone */ - private JobType toJob(DeploymentSpec.DeclaredZone zone) { + private Optional<JobType> toJob(DeploymentSpec.DeclaredZone zone) { return JobType.from(system.get(), zone.environment(), zone.region().orElse(null)); } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTest.java index c7127567286..25a051e192f 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTest.java @@ -157,7 +157,7 @@ public class ControllerTest { fail("Expected exception due to illegal deployment spec."); } catch (IllegalArgumentException e) { - assertEquals("No job is known for zone prod.deep-space-9 in default.", e.getMessage()); + assertEquals("Zone prod.deep-space-9 in deployment spec was not found in this system!", e.getMessage()); } // prod zone removal is not allowed diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java index 81fa1685702..7dff2667b9f 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/ApplicationSerializerTest.java @@ -89,7 +89,7 @@ public class ApplicationSerializerTest { statusList.add(JobStatus.initial(JobType.stagingTest) .withTriggering(Version.fromString("5.6.6"), ApplicationVersion.unknown, empty(), "Test 2", Instant.ofEpochMilli(5)) .withCompletion(11, Optional.of(JobError.unknown), Instant.ofEpochMilli(6))); - statusList.add(JobStatus.initial(JobType.from(main, zone1)) + statusList.add(JobStatus.initial(JobType.from(main, zone1).get()) .withTriggering(Version.fromString("5.6.6"), ApplicationVersion.unknown, deployments.stream().findFirst(), "Test 3", Instant.ofEpochMilli(6)) .withCompletion(11, empty(), Instant.ofEpochMilli(7))); diff --git a/fnet/src/tests/databuffer/databuffer.cpp b/fnet/src/tests/databuffer/databuffer.cpp index 94b59095be4..4bc3a6cb7a8 100644 --- a/fnet/src/tests/databuffer/databuffer.cpp +++ b/fnet/src/tests/databuffer/databuffer.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/fnet/databuffer.h> +#include <vespa/fastos/time.h> TEST("test resetIfEmpty") { FNET_DataBuffer buf(64); diff --git a/logd/src/tests/forward/forward.cpp b/logd/src/tests/forward/forward.cpp index a8da40555c7..e541297208b 100644 --- a/logd/src/tests/forward/forward.cpp +++ b/logd/src/tests/forward/forward.cpp @@ -2,6 +2,7 @@ #include <vespa/log/log.h> #include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/metrics/dummy_metrics_manager.h> +#include <vespa/fastos/time.h> #include <logd/forward.h> #include <logd/metrics.h> #include <sstream> diff --git a/messagebus/src/vespa/messagebus/routing/resender.h b/messagebus/src/vespa/messagebus/routing/resender.h index b99a3f8f0b3..93752dcfd5c 100644 --- a/messagebus/src/vespa/messagebus/routing/resender.h +++ b/messagebus/src/vespa/messagebus/routing/resender.h @@ -1,12 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once +#include "iretrypolicy.h" #include <vespa/messagebus/queue.h> #include <vespa/messagebus/reply.h> +#include <vespa/vespalib/util/sync.h> +#include <vespa/fastos/time.h> #include <queue> #include <vector> -#include <vespa/vespalib/util/sync.h> -#include "iretrypolicy.h" namespace mbus { diff --git a/searchcommon/src/vespa/searchcommon/common/schema.h b/searchcommon/src/vespa/searchcommon/common/schema.h index f8020d6ed9a..90cf099f2d8 100644 --- a/searchcommon/src/vespa/searchcommon/common/schema.h +++ b/searchcommon/src/vespa/searchcommon/common/schema.h @@ -6,6 +6,7 @@ #include <vespa/vespalib/stllike/string.h> #include <vespa/vespalib/stllike/hash_map.h> #include <vespa/vespalib/util/ptrholder.h> +#include <vespa/fastos/timestamp.h> #include <vector> namespace vespalib { class asciistream; } diff --git a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp index a4992d57df3..fb80f6f55b4 100644 --- a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp +++ b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp @@ -1,14 +1,5 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <map> -#include <vespa/config-attributes.h> -#include <vespa/config-imported-fields.h> -#include <vespa/config-indexschema.h> -#include <vespa/config-rank-profiles.h> -#include <vespa/config-summary.h> -#include <vespa/config-summarymap.h> -#include <vespa/document/repo/documenttyperepo.h> -#include <vespa/fileacquirer/config-filedistributorrpc.h> #include <vespa/searchcore/proton/server/bootstrapconfig.h> #include <vespa/searchcore/proton/server/bootstrapconfigmanager.h> #include <vespa/searchcore/proton/server/documentdbconfigmanager.h> @@ -16,11 +7,21 @@ #include <vespa/searchcore/proton/server/proton_config_snapshot.h> #include <vespa/searchcore/proton/server/i_proton_configurer.h> #include <vespa/searchcore/proton/common/hw_info.h> -#include <vespa/searchsummary/config/config-juniperrc.h> #include <vespa/searchcore/config/config-ranking-constants.h> -#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/searchsummary/config/config-juniperrc.h> +#include <vespa/document/repo/documenttyperepo.h> +#include <vespa/fileacquirer/config-filedistributorrpc.h> #include <vespa/vespalib/util/varholder.h> +#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/fastos/time.h> #include <vespa/config-bucketspaces.h> +#include <vespa/config-attributes.h> +#include <vespa/config-imported-fields.h> +#include <vespa/config-indexschema.h> +#include <vespa/config-rank-profiles.h> +#include <vespa/config-summary.h> +#include <vespa/config-summarymap.h> +#include <map> using namespace config; using namespace proton; @@ -148,14 +149,14 @@ struct ConfigTestFixture { } BootstrapConfig::SP getBootstrapConfig(int64_t generation, const HwInfo & hwInfo) const { - return BootstrapConfig::SP(new BootstrapConfig(generation, - std::make_shared<DocumenttypesConfig>(documenttypesBuilder), - std::make_shared<DocumentTypeRepo>(documenttypesBuilder), - std::make_shared<ProtonConfig>(protonBuilder), - std::make_shared<FiledistributorrpcConfig>(), - std::make_shared<BucketspacesConfig>(bucketspacesBuilder), - std::make_shared<TuneFileDocumentDB>(), - hwInfo)); + return std::make_shared<BootstrapConfig>(generation, + std::make_shared<DocumenttypesConfig>(documenttypesBuilder), + std::make_shared<DocumentTypeRepo>(documenttypesBuilder), + std::make_shared<ProtonConfig>(protonBuilder), + std::make_shared<FiledistributorrpcConfig>(), + std::make_shared<BucketspacesConfig>(bucketspacesBuilder), + std::make_shared<TuneFileDocumentDB>(), + hwInfo); } void reload() { context->reload(); } diff --git a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp index a271e34b6b7..19175d1e2c7 100644 --- a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp @@ -2,6 +2,7 @@ #include "transactionlogmanagerbase.h" #include <vespa/vespalib/util/stringfmt.h> +#include <vespa/fastos/time.h> #include <vespa/log/log.h> LOG_SETUP(".proton.server.transactionlogmanagerbase"); diff --git a/searchcore/src/vespa/searchcore/proton/server/visibilityhandler.h b/searchcore/src/vespa/searchcore/proton/server/visibilityhandler.h index 6ba2b640fce..25add844d25 100644 --- a/searchcore/src/vespa/searchcore/proton/server/visibilityhandler.h +++ b/searchcore/src/vespa/searchcore/proton/server/visibilityhandler.h @@ -7,6 +7,7 @@ #include <vespa/searchcore/proton/server/igetserialnum.h> #include <vespa/searchcorespi/index/ithreadingservice.h> #include <vespa/vespalib/util/varholder.h> +#include <vespa/fastos/timestamp.h> #include <mutex> namespace proton { diff --git a/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp b/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp index 71467519dbd..2f69f0b45cf 100644 --- a/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp +++ b/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp @@ -18,6 +18,7 @@ #include <vespa/searchlib/diskindex/pagedict4file.h> #include <vespa/searchlib/diskindex/pagedict4randread.h> #include <vespa/vespalib/stllike/asciistream.h> +#include <vespa/fastos/time.h> #include <vespa/fastos/app.h> #include <vespa/log/log.h> LOG_SETUP("fieldwriter_test"); diff --git a/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp b/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp index 500a032d967..c789fb582ec 100644 --- a/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp +++ b/searchlib/src/tests/fef/phrasesplitter/benchmark.cpp @@ -1,6 +1,4 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/log/log.h> -LOG_SETUP("phrasesplitter_test"); #include <vespa/vespalib/testkit/testapp.h> #include <iomanip> @@ -8,9 +6,12 @@ LOG_SETUP("phrasesplitter_test"); #include <vespa/searchlib/fef/matchdatalayout.h> #include <vespa/searchlib/fef/phrasesplitter.h> #include <vespa/searchlib/fef/test/queryenvironment.h> +#include <vespa/fastos/time.h> + +#include <vespa/log/log.h> +LOG_SETUP("phrasesplitter_test"); -namespace search { -namespace fef { +namespace search::fef { class Benchmark : public vespalib::TestApp { @@ -80,6 +81,5 @@ Benchmark::Main() } } -} TEST_APPHOOK(search::fef::Benchmark); diff --git a/searchlib/src/tests/postinglistbm/andstress.cpp b/searchlib/src/tests/postinglistbm/andstress.cpp index 40f919509e8..15e56c2d4ef 100644 --- a/searchlib/src/tests/postinglistbm/andstress.cpp +++ b/searchlib/src/tests/postinglistbm/andstress.cpp @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "andstress.h" -#include <vector> #include <vespa/searchlib/common/bitvector.h> #include <vespa/searchlib/test/fakedata/fakeword.h> @@ -13,8 +12,10 @@ #include <vespa/searchlib/test/fakedata/fakezcbfilterocc.h> #include <vespa/searchlib/test/fakedata/fpfactory.h> #include <vespa/fastos/thread.h> +#include <vespa/fastos/time.h> #include <mutex> #include <condition_variable> +#include <vector> #include <vespa/log/log.h> LOG_SETUP(".andstress"); diff --git a/searchlib/src/tests/transactionlogstress/translogstress.cpp b/searchlib/src/tests/transactionlogstress/translogstress.cpp index abba84b75b6..7a7bc410371 100644 --- a/searchlib/src/tests/transactionlogstress/translogstress.cpp +++ b/searchlib/src/tests/transactionlogstress/translogstress.cpp @@ -7,6 +7,7 @@ #include <vespa/searchlib/util/runnable.h> #include <vespa/searchlib/index/dummyfileheadercontext.h> #include <vespa/fastos/app.h> +#include <vespa/fastos/time.h> #include <iostream> #include <stdexcept> #include <sstream> diff --git a/searchlib/src/tests/util/bufferwriter/bm.cpp b/searchlib/src/tests/util/bufferwriter/bm.cpp index 3370860d2b6..b19a7390e9c 100644 --- a/searchlib/src/tests/util/bufferwriter/bm.cpp +++ b/searchlib/src/tests/util/bufferwriter/bm.cpp @@ -1,11 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/log/log.h> -LOG_SETUP("bufferwriter_bm"); -#include <vespa/vespalib/testkit/testapp.h> -#include <iostream> #include "work.h" #include <vespa/searchlib/util/drainingbufferwriter.h> +#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/fastos/timestamp.h> +#include <iostream> + +#include <vespa/log/log.h> +LOG_SETUP("bufferwriter_bm"); using search::DrainingBufferWriter; diff --git a/searchlib/src/vespa/searchlib/docstore/filechunk.h b/searchlib/src/vespa/searchlib/docstore/filechunk.h index 87dc2e018eb..7d79760a61c 100644 --- a/searchlib/src/vespa/searchlib/docstore/filechunk.h +++ b/searchlib/src/vespa/searchlib/docstore/filechunk.h @@ -7,11 +7,12 @@ #include "lid_info.h" #include "randread.h" #include <vespa/searchlib/util/memoryusage.h> +#include <vespa/searchlib/common/tunefileinfo.h> #include <vespa/vespalib/util/ptrholder.h> #include <vespa/vespalib/util/sync.h> #include <vespa/vespalib/stllike/hash_map.h> -#include <vespa/searchlib/common/tunefileinfo.h> #include <vespa/vespalib/util/generationhandler.h> +#include <vespa/fastos/timestamp.h> class FastOS_FileInterface; diff --git a/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp b/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp index 20de658f7f6..99645cc3338 100644 --- a/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp +++ b/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "debug_attribute_wait.h" +#include <vespa/fastos/time.h> #include <thread> using search::attribute::IAttributeVector; diff --git a/searchlib/src/vespa/searchlib/features/debug_wait.cpp b/searchlib/src/vespa/searchlib/features/debug_wait.cpp index 565ca27a759..6a26b24b451 100644 --- a/searchlib/src/vespa/searchlib/features/debug_wait.cpp +++ b/searchlib/src/vespa/searchlib/features/debug_wait.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "debug_wait.h" +#include <vespa/fastos/time.h> #include <thread> namespace search { diff --git a/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp b/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp index b4009f1e6b0..1f8ea9fb2ea 100644 --- a/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp +++ b/searchlib/src/vespa/searchlib/test/fakedata/fakewordset.cpp @@ -2,6 +2,7 @@ #include "fakewordset.h" #include "fakeword.h" +#include <vespa/fastos/time.h> #include <sstream> #include <vespa/log/log.h> diff --git a/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp b/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp index fe708f52a93..2cb546395d3 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp +++ b/searchlib/src/vespa/searchlib/transactionlog/trans_log_server_explorer.cpp @@ -3,6 +3,7 @@ #include "trans_log_server_explorer.h" #include <vespa/vespalib/data/slime/slime.h> #include <vespa/fastos/file.h> +#include <vespa/fastos/timestamp.h> using vespalib::slime::Inserter; diff --git a/staging_vespalib/src/tests/directio/directio.cpp b/staging_vespalib/src/tests/directio/directio.cpp index cca884333f0..04155f71f94 100644 --- a/staging_vespalib/src/tests/directio/directio.cpp +++ b/staging_vespalib/src/tests/directio/directio.cpp @@ -5,7 +5,6 @@ #include <vespa/vespalib/data/databuffer.h> #include <vespa/fastos/file.h> -using namespace fastos; using namespace vespalib; TEST("that DirectIOException propagates the correct information.") { diff --git a/storage/src/vespa/storage/frameworkimpl/status/statuswebserver.cpp b/storage/src/vespa/storage/frameworkimpl/status/statuswebserver.cpp index 1d3827d9971..2f6346c91b9 100644 --- a/storage/src/vespa/storage/frameworkimpl/status/statuswebserver.cpp +++ b/storage/src/vespa/storage/frameworkimpl/status/statuswebserver.cpp @@ -55,8 +55,14 @@ void StatusWebServer::configure(std::unique_ptr<vespa::config::content::core::St std::unique_ptr<WebServer> server; // Negative port number means don't run the web server if (newPort >= 0) { - server.reset(new WebServer(*this, newPort)); - // Now that we know config update went well, update internal state + try { + server.reset(new WebServer(*this, newPort)); + } catch (const vespalib::PortListenException & e) { + LOG(error, "Failed listening to network port(%d) with protocol(%s): '%s', giving up and restarting.", + e.get_port(), e.get_protocol().c_str(), e.what()); + std::quick_exit(17); + } + // Now that we know config update went well, update internal state _port = server->getListenPort(); LOG(config, "Status pages now available on port %u", _port); if (_httpServer) { diff --git a/storage/src/vespa/storage/tools/throttlingsim.cpp b/storage/src/vespa/storage/tools/throttlingsim.cpp index cd3c0c1cea4..97f5af3518e 100644 --- a/storage/src/vespa/storage/tools/throttlingsim.cpp +++ b/storage/src/vespa/storage/tools/throttlingsim.cpp @@ -1,8 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "throttlingsim.h" -#include <algorithm> #include <vespa/vespalib/util/stringfmt.h> +#include <algorithm> #include <unistd.h> bool Receiver::enqueue(const Message& msg) { diff --git a/storage/src/vespa/storage/tools/throttlingsim.h b/storage/src/vespa/storage/tools/throttlingsim.h index c468f1879a3..dc36a5b9206 100644 --- a/storage/src/vespa/storage/tools/throttlingsim.h +++ b/storage/src/vespa/storage/tools/throttlingsim.h @@ -3,6 +3,7 @@ #include <vespa/vespalib/util/sync.h> #include <vespa/vespalib/util/document_runnable.h> #include <vespa/fastos/app.h> +#include <vespa/fastos/time.h> #include <deque> #include <vector> diff --git a/vdslib/src/tests/distribution/distributiontest.cpp b/vdslib/src/tests/distribution/distributiontest.cpp index 7af48c1904b..5408c714eba 100644 --- a/vdslib/src/tests/distribution/distributiontest.cpp +++ b/vdslib/src/tests/distribution/distributiontest.cpp @@ -681,14 +681,11 @@ DistributionTest::testSkew() ClusterState systemState("storage:50"); - Distribution distr( - Distribution::getDefaultDistributionConfig(copies, nodes)); + Distribution distr(Distribution::getDefaultDistributionConfig(copies, nodes)); std::vector<std::pair<uint64_t, std::vector<uint16_t> > > _distribution(buckets); std::vector<int> _nodeCount(nodes, 0); - FastOS_Time start; - start.SetNow(); for (int i = 0; i < buckets; i++) { _distribution[i].first = i * 100; _distribution[i].second = distr.getIdealStorageNodes( @@ -708,9 +705,6 @@ DistributionTest::testSkew() fprintf(stderr, "%d ", _nodeCount[i]); } - double elapsed = start.MilliSecsToNow(); - fprintf(stderr, "%d calcs in %f ms = %f calcs/sec\n", - buckets, elapsed, double(buckets * 1000) / elapsed); */ sort(_nodeCount.begin(), _nodeCount.end()); @@ -859,8 +853,6 @@ DistributionTest::testSkewWithDown() _distribution[i].second.reserve(copies); } - FastOS_Time start; - start.SetNow(); for (int i = 0; i < buckets; i++) { _distribution[i].first = i * 100; _distribution[i].second = distr.getIdealStorageNodes( @@ -875,10 +867,6 @@ DistributionTest::testSkewWithDown() } } /* - double elapsed = start.MilliSecsToNow(); - fprintf(stderr, "%d calcs in %f ms = %f calcs/sec\n", - buckets, elapsed, double(buckets * 1000) / elapsed); - // Check distribution for (int i = 0; i < nodes; i++) { fprintf(stderr, "%d ", _nodeCount[i]); diff --git a/vespalib/src/tests/executor/stress_test.cpp b/vespalib/src/tests/executor/stress_test.cpp index 5c7620afb14..702991fd779 100644 --- a/vespalib/src/tests/executor/stress_test.cpp +++ b/vespalib/src/tests/executor/stress_test.cpp @@ -4,6 +4,7 @@ #include <vespa/vespalib/util/executor.h> #include <vespa/vespalib/util/threadstackexecutor.h> #include <vespa/vespalib/locale/c.h> +#include <vespa/fastos/time.h> using namespace vespalib; using namespace std::literals; diff --git a/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp b/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp index dd031f0c2ce..e6fdab7d773 100644 --- a/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp +++ b/vespalib/src/tests/left_right_heap/left_right_heap_bench.cpp @@ -3,6 +3,7 @@ #include <vespa/vespalib/util/left_right_heap.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/inline.h> +#include <vespa/fastos/time.h> using namespace vespalib; diff --git a/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp b/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp index 688261af3e7..b113e7a2284 100644 --- a/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp +++ b/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp @@ -2,6 +2,7 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/simple_thread_bundle.h> #include <vespa/vespalib/util/box.h> +#include <vespa/fastos/time.h> using namespace vespalib; diff --git a/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp b/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp index df5b239e341..2a58f1df382 100644 --- a/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp +++ b/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp @@ -2,6 +2,7 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/data/slime/slime.h> +#include <vespa/fastos/time.h> using namespace vespalib; using namespace vespalib::slime::convenience; diff --git a/vespalib/src/vespa/vespalib/util/sync.h b/vespalib/src/vespa/vespalib/util/sync.h index e3f3d44122c..6461eaf9c3f 100644 --- a/vespalib/src/vespa/vespalib/util/sync.h +++ b/vespalib/src/vespa/vespalib/util/sync.h @@ -2,13 +2,11 @@ #pragma once -#include <vespa/fastos/time.h> #include <cassert> #include <mutex> #include <condition_variable> #include <chrono> - namespace vespalib { /** @@ -362,13 +360,12 @@ public: void unlock() { assert(_guard); _guard.unlock(); - _cond = NULL; + _cond = nullptr; } /** * @brief Wait for a signal on the underlying Monitor. **/ void wait() { - assert(_cond != NULL); _cond->wait(_guard); } /** @@ -379,7 +376,6 @@ public: * @return true if a signal was received, false if the wait timed out. **/ bool wait(int msTimeout) { - assert(_cond != NULL); return _cond->wait_for(_guard, std::chrono::milliseconds(msTimeout)) == std::cv_status::no_timeout; } /** @@ -387,14 +383,12 @@ public: * Monitor. **/ void signal() { - assert(_cond != NULL); _cond->notify_one(); } /** * @brief Send a signal to all waiters on the underlying Monitor. **/ void broadcast() { - assert(_cond != NULL); _cond->notify_all(); } /** @@ -406,10 +400,9 @@ public: * will live long enough to be signaled. **/ void unsafeSignalUnlock() { - assert(_cond != NULL); _guard.unlock(); _cond->notify_one(); - _cond = NULL; + _cond = nullptr; } /** * @brief Send a signal to all waiters on the underlying Monitor, @@ -420,10 +413,9 @@ public: * will live long enough to be signaled. **/ void unsafeBroadcastUnlock() { - assert(_cond != NULL); _guard.unlock(); _cond->notify_all(); - _cond = NULL; + _cond = nullptr; } /** * @brief Release the lock held by this object if unlock has not @@ -436,94 +428,7 @@ public: * guard ref as input, ensuring that the caller have grabbed a lock. */ bool monitors(const Monitor& m) const { - return (_cond != NULL && _cond == &m._cond); - } -}; - - -/** - * Helper class that can be used to wait for a condition when having a - * constraint on how long you want to wait. The usage is best - * explained with an example: - * - * <pre> - * bool waitForWantedState(int maxwait) { - * MonitorGuard guard(_monitor); - * TimedWaiter waiter(guard, maxwait); - * while (!wantedState && waiter.hasTime()) { - * waiter.wait(); - * } - * return wantedState; - * } - * </pre> - * - * The example code will limit the total wait time to maxwait - * milliseconds across all blocking wait operations on the underlying - * monitor guard. - **/ -class TimedWaiter -{ -private: - MonitorGuard &_guard; - FastOS_Time _start; - int _maxwait; - int _remain; - bool _timeout; - - TimedWaiter(const TimedWaiter&); - TimedWaiter &operator=(const TimedWaiter&); -public: - - /** - * Create a new instance using the given monitor guard and wait - * time limit. If the maximum time is less than or equal to 0, the - * wait will time out immediately and no low-level wait operations - * will be performed. - * - * @param guard the underlying monitor guard used to perform the actual wait operation. - * @param maxwait maximum time to wait in milliseconds. - **/ - TimedWaiter(MonitorGuard &guard, int maxwait) - : _guard(guard), _start(), _maxwait(maxwait), _remain(0), _timeout(false) - { - if (_maxwait > 0) { - _start.SetNow(); - } else { - _timeout = true; - } - } - - /** - * Check if this object has any time left until the time limit is - * exceeded. - * - * @return true if there is time left. - **/ - bool hasTime() const { - return !_timeout; - } - - /** - * Perform low-level wait in such a way that we do not exceed the - * maximum total wait time. This method also performs the needed - * book-keeping to keep track of elapsed time between invocations. - * - * @return true if we woke up due to a signal, false if we timed out. - **/ - bool wait() { - if (!_timeout) { - if (_remain > 0) { - _remain = (_maxwait - (int)_start.MilliSecsToNow()); - } else { - _remain = _maxwait; - } - if (_remain > 0) { - _timeout = !_guard.wait(_remain); - } else { - _timeout = true; - } - } - return !_timeout; + return (_cond != nullptr && _cond == &m._cond); } }; |