aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@oath.com>2018-02-22 12:48:47 +0000
committerTor Egge <Tor.Egge@oath.com>2018-02-22 12:48:47 +0000
commit6cc9ca39379fbd9baf3cb01ef1f2b2cd85a51ed9 (patch)
treee60ef6799946586e1fbe0abe4b3f5d3e59caa00f
parent1e7d98b23ae6b97734e1248c6028075f9b3f5d2e (diff)
Add cluster state bundle which contains a baseline cluster state and
(later) a derived cluster state for each bucket space.
-rw-r--r--storage/src/tests/common/testnodestateupdater.cpp22
-rw-r--r--storage/src/tests/common/testnodestateupdater.h11
-rw-r--r--storage/src/tests/persistence/filestorage/filestormanagertest.cpp5
-rw-r--r--storage/src/tests/storageserver/statemanagertest.cpp7
-rw-r--r--storage/src/vespa/storage/bucketdb/bucketmanager.cpp6
-rw-r--r--storage/src/vespa/storage/common/CMakeLists.txt1
-rw-r--r--storage/src/vespa/storage/common/cluster_state_bundle.cpp34
-rw-r--r--storage/src/vespa/storage/common/cluster_state_bundle.h27
-rw-r--r--storage/src/vespa/storage/common/nodestateupdater.h4
-rw-r--r--storage/src/vespa/storage/frameworkimpl/component/distributorcomponentregisterimpl.cpp9
-rw-r--r--storage/src/vespa/storage/persistence/bucketownershipnotifier.cpp6
-rw-r--r--storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp6
-rw-r--r--storage/src/vespa/storage/storageserver/bouncer.cpp16
-rw-r--r--storage/src/vespa/storage/storageserver/changedbucketownershiphandler.cpp4
-rw-r--r--storage/src/vespa/storage/storageserver/mergethrottler.cpp3
-rw-r--r--storage/src/vespa/storage/storageserver/statemanager.cpp28
-rw-r--r--storage/src/vespa/storage/storageserver/statemanager.h15
17 files changed, 151 insertions, 53 deletions
diff --git a/storage/src/tests/common/testnodestateupdater.cpp b/storage/src/tests/common/testnodestateupdater.cpp
index 58e8c2ea73d..18f296e5583 100644
--- a/storage/src/tests/common/testnodestateupdater.cpp
+++ b/storage/src/tests/common/testnodestateupdater.cpp
@@ -1,14 +1,32 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "testnodestateupdater.h"
+#include <vespa/storage/common/cluster_state_bundle.h>
namespace storage {
TestNodeStateUpdater::TestNodeStateUpdater(const lib::NodeType& type)
: _reported(new lib::NodeState(type, lib::State::UP)),
- _current(new lib::NodeState(type, lib::State::UP))
+ _current(new lib::NodeState(type, lib::State::UP)),
+ _clusterStateBundle(),
+ _listeners()
{ }
-TestNodeStateUpdater::~TestNodeStateUpdater() { }
+TestNodeStateUpdater::~TestNodeStateUpdater() = default;
+
+std::shared_ptr<const ClusterStateBundle>
+TestNodeStateUpdater::getClusterStateBundle() const
+{
+ return _clusterStateBundle;
+}
+
+void
+TestNodeStateUpdater::setClusterState(lib::ClusterState::CSP c)
+{
+ _clusterStateBundle = std::make_shared<const ClusterStateBundle>(*c);
+ for (uint32_t i = 0; i < _listeners.size(); ++i) {
+ _listeners[i]->handleNewState();
+ }
+}
}
diff --git a/storage/src/tests/common/testnodestateupdater.h b/storage/src/tests/common/testnodestateupdater.h
index 3e5dfed560d..daecb45ece4 100644
--- a/storage/src/tests/common/testnodestateupdater.h
+++ b/storage/src/tests/common/testnodestateupdater.h
@@ -16,7 +16,7 @@ struct TestNodeStateUpdater : public NodeStateUpdater
{
lib::NodeState::CSP _reported;
lib::NodeState::CSP _current;
- lib::ClusterState::CSP _cluster;
+ std::shared_ptr<const ClusterStateBundle> _clusterStateBundle;
std::vector<StateListener*> _listeners;
public:
@@ -25,7 +25,7 @@ public:
lib::NodeState::CSP getReportedNodeState() const override { return _reported; }
lib::NodeState::CSP getCurrentNodeState() const override { return _current; }
- lib::ClusterState::CSP getSystemState() const override { return _cluster; }
+ std::shared_ptr<const ClusterStateBundle> getClusterStateBundle() const override;
void addStateListener(StateListener& s) override { _listeners.push_back(&s); }
void removeStateListener(StateListener&) override {}
Lock::SP grabStateChangeLock() override { return Lock::SP(new Lock); }
@@ -33,12 +33,7 @@ public:
void setCurrentNodeState(const lib::NodeState& state) { _current.reset(new lib::NodeState(state)); }
- void setClusterState(lib::ClusterState::CSP c) {
- _cluster = c;
- for (uint32_t i = 0; i < _listeners.size(); ++i) {
- _listeners[i]->handleNewState();
- }
- }
+ void setClusterState(lib::ClusterState::CSP c);
};
} // storage
diff --git a/storage/src/tests/persistence/filestorage/filestormanagertest.cpp b/storage/src/tests/persistence/filestorage/filestormanagertest.cpp
index af0082fa788..2192ae4d634 100644
--- a/storage/src/tests/persistence/filestorage/filestormanagertest.cpp
+++ b/storage/src/tests/persistence/filestorage/filestormanagertest.cpp
@@ -7,6 +7,7 @@
#include <vespa/document/test/make_document_bucket.h>
#include <vespa/storage/storageserver/statemanager.h>
#include <vespa/storage/bucketdb/bucketmanager.h>
+#include <vespa/storage/common/cluster_state_bundle.h>
#include <vespa/storage/persistence/persistencethread.h>
#include <vespa/storage/persistence/filestorage/filestormanager.h>
#include <vespa/storage/persistence/filestorage/modifiedbucketchecker.h>
@@ -177,9 +178,11 @@ struct FileStorManagerTest : public CppUnit::TestFixture {
bool ownsBucket(uint16_t distributorIndex,
const document::BucketId& bucket) const
{
+ auto clusterStateBundle = _node->getStateUpdater().getClusterStateBundle();
+ const auto &clusterState = *clusterStateBundle->getBaselineClusterState();
uint16_t distributor(
_node->getDistribution()->getIdealDistributorNode(
- *_node->getStateUpdater().getSystemState(), bucket));
+ clusterState, bucket));
return distributor == distributorIndex;
}
diff --git a/storage/src/tests/storageserver/statemanagertest.cpp b/storage/src/tests/storageserver/statemanagertest.cpp
index c07c150a520..0676d3684ff 100644
--- a/storage/src/tests/storageserver/statemanagertest.cpp
+++ b/storage/src/tests/storageserver/statemanagertest.cpp
@@ -4,6 +4,7 @@
#include <vespa/metrics/metricmanager.h>
#include <vespa/storageapi/message/bucket.h>
#include <vespa/storageapi/message/state.h>
+#include <vespa/storage/common/cluster_state_bundle.h>
#include <vespa/storage/frameworkimpl/component/storagecomponentregisterimpl.h>
#include <vespa/storage/storageserver/statemanager.h>
#include <tests/common/teststorageapp.h>
@@ -105,7 +106,7 @@ StateManagerTest::testSystemState()
{
std::shared_ptr<api::StorageReply> reply;
// Verify initial state on startup
- ClusterState::CSP currentState = _manager->getSystemState();
+ ClusterState::CSP currentState = _manager->getClusterStateBundle()->getBaselineClusterState();
CPPUNIT_ASSERT_EQUAL(std::string("cluster:d"),
currentState->toString(false));
@@ -118,7 +119,7 @@ StateManagerTest::testSystemState()
_upper->sendDown(cmd);
GET_ONLY_OK_REPLY(reply);
- currentState = _manager->getSystemState();
+ currentState = _manager->getClusterStateBundle()->getBaselineClusterState();
CPPUNIT_ASSERT_EQUAL(sendState, *currentState);
currentNodeState = _manager->getCurrentNodeState();
@@ -225,7 +226,7 @@ StateManagerTest::testReportedNodeState()
void
StateManagerTest::testClusterStateVersion()
{
- ClusterState state(*_manager->getSystemState());
+ ClusterState state(*_manager->getClusterStateBundle()->getBaselineClusterState());
state.setVersion(123);
_manager->setClusterState(state);
diff --git a/storage/src/vespa/storage/bucketdb/bucketmanager.cpp b/storage/src/vespa/storage/bucketdb/bucketmanager.cpp
index 62094bce395..142003735b8 100644
--- a/storage/src/vespa/storage/bucketdb/bucketmanager.cpp
+++ b/storage/src/vespa/storage/bucketdb/bucketmanager.cpp
@@ -7,6 +7,7 @@
#include <iomanip>
#include <vespa/storage/common/content_bucket_space_repo.h>
#include <vespa/storage/common/nodestateupdater.h>
+#include <vespa/storage/common/cluster_state_bundle.h>
#include <vespa/storage/storageutil/distributorstatecache.h>
#include <vespa/storageframework/generic/status/htmlstatusreporter.h>
#include <vespa/storageframework/generic/status/xmlstatusreporter.h>
@@ -517,8 +518,9 @@ BucketManager::processRequestBucketInfoCommands(document::BucketSpace bucketSpac
std::map<uint16_t, RBISP> requests;
auto distribution(_component.getBucketSpaceRepo().get(bucketSpace).getDistribution());
- lib::ClusterState::CSP clusterState(
- _component.getStateUpdater().getSystemState());
+ auto clusterStateBundle(_component.getStateUpdater().getClusterStateBundle());
+ assert(clusterStateBundle);
+ lib::ClusterState::CSP clusterState(clusterStateBundle->getDerivedClusterState(bucketSpace));
assert(clusterState.get());
DistributionHashNormalizer normalizer;
diff --git a/storage/src/vespa/storage/common/CMakeLists.txt b/storage/src/vespa/storage/common/CMakeLists.txt
index c53aead2ba2..d1e819523d7 100644
--- a/storage/src/vespa/storage/common/CMakeLists.txt
+++ b/storage/src/vespa/storage/common/CMakeLists.txt
@@ -3,6 +3,7 @@ vespa_add_library(storage_common OBJECT
SOURCES
bucketmessages.cpp
bucketoperationlogger.cpp
+ cluster_state_bundle.cpp
content_bucket_space.cpp
content_bucket_space_repo.cpp
distributorcomponent.cpp
diff --git a/storage/src/vespa/storage/common/cluster_state_bundle.cpp b/storage/src/vespa/storage/common/cluster_state_bundle.cpp
new file mode 100644
index 00000000000..1793c74d378
--- /dev/null
+++ b/storage/src/vespa/storage/common/cluster_state_bundle.cpp
@@ -0,0 +1,34 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "cluster_state_bundle.h"
+#include <vespa/vdslib/state/clusterstate.h>
+
+namespace storage {
+
+ClusterStateBundle::ClusterStateBundle(const ClusterState &baselineClusterState)
+ : _baselineClusterState(std::make_shared<const ClusterState>(baselineClusterState))
+{
+}
+
+ClusterStateBundle::~ClusterStateBundle() = default;
+
+const std::shared_ptr<const lib::ClusterState> &
+ClusterStateBundle::getBaselineClusterState() const
+{
+ return _baselineClusterState;
+}
+
+const std::shared_ptr<const lib::ClusterState> &
+ClusterStateBundle::getDerivedClusterState(document::BucketSpace) const
+{
+ // For now, just return the baseline cluster state.
+ return _baselineClusterState;
+}
+
+uint32_t
+ClusterStateBundle::getVersion() const
+{
+ return _baselineClusterState->getVersion();
+}
+
+}
diff --git a/storage/src/vespa/storage/common/cluster_state_bundle.h b/storage/src/vespa/storage/common/cluster_state_bundle.h
new file mode 100644
index 00000000000..af4a12a8b3c
--- /dev/null
+++ b/storage/src/vespa/storage/common/cluster_state_bundle.h
@@ -0,0 +1,27 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <vespa/document/bucket/bucketspace.h>
+
+namespace storage {
+
+namespace lib { class ClusterState; }
+
+/**
+ * Class representing the baseline cluster state and the derived cluster
+ * state for each bucket space.
+ */
+class ClusterStateBundle
+{
+ using ClusterState = lib::ClusterState;
+ std::shared_ptr<const ClusterState> _baselineClusterState;
+public:
+ ClusterStateBundle(const ClusterState &baselineClusterState);
+ ~ClusterStateBundle();
+ const std::shared_ptr<const ClusterState> &getBaselineClusterState() const;
+ const std::shared_ptr<const ClusterState> &getDerivedClusterState(document::BucketSpace bucketSpace) const;
+ uint32_t getVersion() const;
+};
+
+}
diff --git a/storage/src/vespa/storage/common/nodestateupdater.h b/storage/src/vespa/storage/common/nodestateupdater.h
index dcfeda3f08e..7fd3dedbcab 100644
--- a/storage/src/vespa/storage/common/nodestateupdater.h
+++ b/storage/src/vespa/storage/common/nodestateupdater.h
@@ -29,6 +29,8 @@
namespace storage {
+class ClusterStateBundle;
+
struct StateListener {
virtual ~StateListener() {}
virtual void handleNewState() = 0;
@@ -41,7 +43,7 @@ struct NodeStateUpdater {
virtual lib::NodeState::CSP getReportedNodeState() const = 0;
virtual lib::NodeState::CSP getCurrentNodeState() const = 0;
- virtual lib::ClusterState::CSP getSystemState() const = 0;
+ virtual std::shared_ptr<const ClusterStateBundle> getClusterStateBundle() const = 0;
virtual void addStateListener(StateListener&) = 0;
virtual void removeStateListener(StateListener&) = 0;
diff --git a/storage/src/vespa/storage/frameworkimpl/component/distributorcomponentregisterimpl.cpp b/storage/src/vespa/storage/frameworkimpl/component/distributorcomponentregisterimpl.cpp
index 22d7239b178..cf290c78acf 100644
--- a/storage/src/vespa/storage/frameworkimpl/component/distributorcomponentregisterimpl.cpp
+++ b/storage/src/vespa/storage/frameworkimpl/component/distributorcomponentregisterimpl.cpp
@@ -2,6 +2,7 @@
#include "distributorcomponentregisterimpl.h"
#include <vespa/vdslib/distribution/idealnodecalculatorimpl.h>
#include <vespa/vespalib/util/exceptions.h>
+#include <vespa/storage/common/cluster_state_bundle.h>
namespace storage {
@@ -16,7 +17,8 @@ DistributorComponentRegisterImpl::~DistributorComponentRegisterImpl() {
void
DistributorComponentRegisterImpl::handleNewState()
{
- _clusterState = *getNodeStateUpdater().getSystemState();
+ auto clusterStateBundle = getNodeStateUpdater().getClusterStateBundle();
+ _clusterState = *clusterStateBundle->getBaselineClusterState();
}
void
@@ -70,8 +72,9 @@ void
DistributorComponentRegisterImpl::setNodeStateUpdater(NodeStateUpdater& updater)
{
StorageComponentRegisterImpl::setNodeStateUpdater(updater);
- if (updater.getSystemState().get() != 0) {
- _clusterState = *updater.getSystemState();
+ auto clusterStateBundle = updater.getClusterStateBundle();
+ if (clusterStateBundle) {
+ _clusterState = *clusterStateBundle->getBaselineClusterState();
}
updater.addStateListener(*this);
}
diff --git a/storage/src/vespa/storage/persistence/bucketownershipnotifier.cpp b/storage/src/vespa/storage/persistence/bucketownershipnotifier.cpp
index 900fa71d7a0..5e561951260 100644
--- a/storage/src/vespa/storage/persistence/bucketownershipnotifier.cpp
+++ b/storage/src/vespa/storage/persistence/bucketownershipnotifier.cpp
@@ -4,6 +4,7 @@
#include <vespa/storage/common/nodestateupdater.h>
#include <vespa/storage/common/bucketoperationlogger.h>
#include <vespa/storage/common/content_bucket_space_repo.h>
+#include <vespa/storage/common/cluster_state_bundle.h>
#include <vespa/storageapi/message/bucket.h>
#include <vespa/vdslib/distribution/distribution.h>
#include <vespa/vespalib/util/backtrace.h>
@@ -21,8 +22,9 @@ BucketOwnershipNotifier::getOwnerDistributorForBucket(
{
try {
auto distribution(_component.getBucketSpaceRepo().get(bucket.getBucketSpace()).getDistribution());
- return (distribution->getIdealDistributorNode(
- *_component.getStateUpdater().getSystemState(), bucket.getBucketId()));
+ const auto clusterStateBundle = _component.getStateUpdater().getClusterStateBundle();
+ const auto &clusterState = *clusterStateBundle->getDerivedClusterState(bucket.getBucketSpace());
+ return (distribution->getIdealDistributorNode(clusterState, bucket.getBucketId()));
// If we get exceptions there aren't any distributors, so they'll have
// to explicitly fetch all bucket info eventually anyway.
} catch (lib::TooFewBucketBitsInUseException& e) {
diff --git a/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp b/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp
index cf41a297541..2773c19eaa1 100644
--- a/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp
+++ b/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp
@@ -6,6 +6,7 @@
#include <vespa/storage/common/bucketmessages.h>
#include <vespa/storage/common/bucketoperationlogger.h>
#include <vespa/storage/common/content_bucket_space_repo.h>
+#include <vespa/storage/common/cluster_state_bundle.h>
#include <vespa/storage/common/messagebucket.h>
#include <vespa/storage/config/config-stor-server.h>
#include <vespa/storage/persistence/bucketownershipnotifier.h>
@@ -574,7 +575,7 @@ FileStorManager::onMergeBucket(const shared_ptr<api::MergeBucketCommand>& cmd)
vespalib::make_string(
"Trying to perform merge %s whose bucket belongs on target disk %d, which is down. Cluster state version of command is %d, our system state version is %d",
cmd->toString().c_str(), entry->disk, cmd->getClusterStateVersion(),
- _component.getStateUpdater().getSystemState()->getVersion()));
+ _component.getStateUpdater().getClusterStateBundle()->getVersion()));
LOGBT(debug, cmd->getBucketId().toString(), "%s", code.getMessage().c_str());
api::MergeBucketReply::SP reply(new api::MergeBucketReply(*cmd));
reply->setResult(code);
@@ -965,7 +966,8 @@ namespace {
void
FileStorManager::updateState()
{
- lib::ClusterState::CSP state(_component.getStateUpdater().getSystemState());
+ auto clusterStateBundle = _component.getStateUpdater().getClusterStateBundle();
+ lib::ClusterState::CSP state(clusterStateBundle->getBaselineClusterState());
lib::Node node(_component.getNodeType(), _component.getIndex());
bool nodeUp = state->getNodeState(node).getState().oneOf("uir");
diff --git a/storage/src/vespa/storage/storageserver/bouncer.cpp b/storage/src/vespa/storage/storageserver/bouncer.cpp
index 7648c07d7da..af274c9b3e6 100644
--- a/storage/src/vespa/storage/storageserver/bouncer.cpp
+++ b/storage/src/vespa/storage/storageserver/bouncer.cpp
@@ -2,6 +2,7 @@
#include "bouncer.h"
#include "bouncer_metrics.h"
+#include <vespa/storage/common/cluster_state_bundle.h>
#include <vespa/storageapi/message/state.h>
#include <vespa/storageapi/message/persistence.h>
#include <vespa/config/subscription/configuri.h>
@@ -289,14 +290,15 @@ Bouncer::handleNewState()
{
vespalib::LockGuard lock(_lock);
_nodeState = *_component.getStateUpdater().getReportedNodeState();
- _clusterState = &_component.getStateUpdater().getSystemState()
- ->getClusterState();
+ const auto clusterStateBundle = _component.getStateUpdater().getClusterStateBundle();
+ const auto &clusterState = *clusterStateBundle->getBaselineClusterState();
+ _clusterState = &clusterState.getClusterState();
if (_config->useWantedStateIfPossible) {
- // If current node state is more strict than our own reported state,
- // set node state to our current state
- lib::NodeState currState = _component.getStateUpdater().getSystemState()
- ->getNodeState(lib::Node(_component.getNodeType(),
- _component.getIndex()));
+ // If current node state is more strict than our own reported state,
+ // set node state to our current state
+ lib::NodeState currState = clusterState.
+ getNodeState(lib::Node(_component.getNodeType(),
+ _component.getIndex()));
if (_nodeState.getState().maySetWantedStateForThisNodeState(
currState.getState()))
{
diff --git a/storage/src/vespa/storage/storageserver/changedbucketownershiphandler.cpp b/storage/src/vespa/storage/storageserver/changedbucketownershiphandler.cpp
index 1a8be145470..cd7be21a369 100644
--- a/storage/src/vespa/storage/storageserver/changedbucketownershiphandler.cpp
+++ b/storage/src/vespa/storage/storageserver/changedbucketownershiphandler.cpp
@@ -3,6 +3,7 @@
#include "changedbucketownershiphandler.h"
#include <vespa/storageapi/message/state.h>
#include <vespa/storage/bucketdb/storbucketdb.h>
+#include <vespa/storage/common/cluster_state_bundle.h>
#include <vespa/storage/common/messagebucket.h>
#include <vespa/storage/common/nodestateupdater.h>
#include <vespa/storage/common/content_bucket_space_repo.h>
@@ -56,7 +57,8 @@ void
ChangedBucketOwnershipHandler::reloadClusterState()
{
vespalib::LockGuard guard(_stateLock);
- lib::ClusterState::CSP newState(_component.getStateUpdater().getSystemState());
+ const auto clusterStateBundle = _component.getStateUpdater().getClusterStateBundle();
+ lib::ClusterState::CSP newState(clusterStateBundle->getBaselineClusterState());
setCurrentOwnershipWithStateNoLock(*newState);
}
diff --git a/storage/src/vespa/storage/storageserver/mergethrottler.cpp b/storage/src/vespa/storage/storageserver/mergethrottler.cpp
index 60dedab5ce8..73fa61e9fb7 100644
--- a/storage/src/vespa/storage/storageserver/mergethrottler.cpp
+++ b/storage/src/vespa/storage/storageserver/mergethrottler.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 "mergethrottler.h"
+#include <vespa/storage/common/cluster_state_bundle.h>
#include <vespa/storage/common/nodestateupdater.h>
#include <vespa/storage/persistence/messages.h>
#include <vespa/messagebus/message.h>
@@ -712,7 +713,7 @@ MergeThrottler::handleMessageDown(
if (msg->getType() == api::MessageType::MERGEBUCKET) {
auto& mergeCmd = static_cast<const api::MergeBucketCommand&>(*msg);
- uint32_t ourVersion = _component.getStateUpdater().getSystemState()->getVersion();
+ uint32_t ourVersion = _component.getStateUpdater().getClusterStateBundle()->getVersion();
if (mergeCmd.getClusterStateVersion() > ourVersion) {
LOG(debug, "Merge %s with newer cluster state than us arrived",
diff --git a/storage/src/vespa/storage/storageserver/statemanager.cpp b/storage/src/vespa/storage/storageserver/statemanager.cpp
index 3ab6d311d09..1908eab96ec 100644
--- a/storage/src/vespa/storage/storageserver/statemanager.cpp
+++ b/storage/src/vespa/storage/storageserver/statemanager.cpp
@@ -9,6 +9,7 @@
#include <vespa/storageapi/messageapi/storagemessage.h>
#include <vespa/storage/storageserver/storagemetricsset.h>
#include <vespa/storage/common/bucketoperationlogger.h>
+#include <vespa/storage/common/cluster_state_bundle.h>
#include <sys/types.h>
#include <unistd.h>
#include <vespa/vespalib/util/stringfmt.h>
@@ -36,7 +37,7 @@ StateManager::StateManager(StorageComponentRegister& compReg,
_notifyingListeners(false),
_nodeState(new lib::NodeState(_component.getNodeType(), lib::State::INITIALIZING)),
_nextNodeState(),
- _systemState(new lib::ClusterState),
+ _systemState(std::make_shared<const ClusterStateBundle>(lib::ClusterState())),
_nextSystemState(),
_stateListeners(),
_queuedStateRequests(),
@@ -144,10 +145,11 @@ StateManager::reportHtmlStatus(std::ostream& out,
{
vespalib::LockGuard lock(_stateLock);
+ const auto &baseLineClusterState = _systemState->getBaselineClusterState();
out << "<h1>Current system state</h1>\n"
- << "<code>" << _systemState->toString(true) << "</code>\n"
+ << "<code>" << baseLineClusterState->toString(true) << "</code>\n"
<< "<h1>Current node state</h1>\n"
- << "<code>" << _systemState->getNodeState(lib::Node(
+ << "<code>" << baseLineClusterState->getNodeState(lib::Node(
_component.getNodeType(), _component.getIndex())
).toString(true)
<< "</code>\n"
@@ -163,7 +165,7 @@ StateManager::reportHtmlStatus(std::ostream& out,
it != _systemStateHistory.rend(); ++it)
{
out << "<tr><td>" << it->first << "</td><td>"
- << *it->second << "</td></tr>\n";
+ << *it->second->getBaselineClusterState() << "</td></tr>\n";
}
out << "</table>\n";
}
@@ -186,12 +188,12 @@ lib::NodeState::CSP
StateManager::getCurrentNodeState() const
{
vespalib::LockGuard lock(_stateLock);
- return lib::NodeState::SP(new lib::NodeState(
- _systemState->getNodeState(thisNode())));
+ return std::make_shared<const lib::NodeState>
+ (_systemState->getBaselineClusterState()->getNodeState(thisNode()));
}
-lib::ClusterState::CSP
-StateManager::getSystemState() const
+std::shared_ptr<const ClusterStateBundle>
+StateManager::getClusterStateBundle() const
{
vespalib::LockGuard lock(_stateLock);
return _systemState;
@@ -359,12 +361,12 @@ StateManager::enableNextClusterState()
void
StateManager::logNodeClusterStateTransition(
- const lib::ClusterState& currentState,
- const lib::ClusterState& newState) const
+ const ClusterStateBundle& currentState,
+ const ClusterStateBundle& newState) const
{
lib::Node self(thisNode());
- const lib::State& before(currentState.getNodeState(self).getState());
- const lib::State& after(newState.getNodeState(self).getState());
+ const lib::State& before(currentState.getBaselineClusterState()->getNodeState(self).getState());
+ const lib::State& after(newState.getBaselineClusterState()->getNodeState(self).getState());
if (before != after) {
LOG(info, "Transitioning from state '%s' to '%s' "
"(cluster state version %u)",
@@ -423,7 +425,7 @@ StateManager::setClusterState(const lib::ClusterState& c)
{
{
vespalib::LockGuard lock(_stateLock);
- _nextSystemState.reset(new lib::ClusterState(c));
+ _nextSystemState = std::make_shared<const ClusterStateBundle>(c);
}
notifyStateListeners();
}
diff --git a/storage/src/vespa/storage/storageserver/statemanager.h b/storage/src/vespa/storage/storageserver/statemanager.h
index 82ef93f87d5..8d3e4d75a88 100644
--- a/storage/src/vespa/storage/storageserver/statemanager.h
+++ b/storage/src/vespa/storage/storageserver/statemanager.h
@@ -33,6 +33,8 @@ namespace metrics {
namespace storage {
+class ClusterStateBundle;
+
class StateManager : public NodeStateUpdater,
public StorageLink,
public framework::HtmlStatusReporter,
@@ -48,8 +50,8 @@ class StateManager : public NodeStateUpdater,
std::atomic<bool> _notifyingListeners;
std::shared_ptr<lib::NodeState> _nodeState;
std::shared_ptr<lib::NodeState> _nextNodeState;
- std::shared_ptr<lib::ClusterState> _systemState;
- std::shared_ptr<lib::ClusterState> _nextSystemState;
+ std::shared_ptr<const ClusterStateBundle> _systemState;
+ std::shared_ptr<const ClusterStateBundle> _nextSystemState;
std::list<StateListener*> _stateListeners;
typedef std::pair<framework::MilliSecTime,
api::GetNodeStateCommand::SP> TimeStatePair;
@@ -57,8 +59,7 @@ class StateManager : public NodeStateUpdater,
mutable vespalib::Monitor _threadMonitor;
framework::MilliSecTime _lastProgressUpdateCausingSend;
vespalib::Double _progressLastInitStateSend;
- typedef std::pair<framework::MilliSecTime,
- lib::ClusterState::SP> TimeSysStatePair;
+ using TimeSysStatePair = std::pair<framework::MilliSecTime, std::shared_ptr<const ClusterStateBundle>>;
std::deque<TimeSysStatePair> _systemStateHistory;
uint32_t _systemStateHistorySize;
std::unique_ptr<HostInfo> _hostInfo;
@@ -79,7 +80,7 @@ public:
lib::NodeState::CSP getReportedNodeState() const override;
lib::NodeState::CSP getCurrentNodeState() const override;
- lib::ClusterState::CSP getSystemState() const override;
+ std::shared_ptr<const ClusterStateBundle> getClusterStateBundle() const override;
void addStateListener(StateListener&) override;
void removeStateListener(StateListener&) override;
@@ -123,8 +124,8 @@ private:
* state differs between currentState and newState.
*/
void logNodeClusterStateTransition(
- const lib::ClusterState& currentState,
- const lib::ClusterState& newState) const;
+ const ClusterStateBundle& currentState,
+ const ClusterStateBundle& newState) const;
bool onGetNodeState(const std::shared_ptr<api::GetNodeStateCommand>&) override;
bool onSetSystemState(const std::shared_ptr<api::SetSystemStateCommand>&) override;