diff options
author | Geir Storli <geirstorli@yahoo.no> | 2018-03-13 15:11:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-13 15:11:44 +0100 |
commit | 90b181a18db82e887c5eefaae814cfb6cc054df2 (patch) | |
tree | ca8662782764dfef4af7ee1799285b9b2f0d9b7c | |
parent | 677af9869b4cee6baf2a2de3a4a7edf35693caf8 (diff) | |
parent | 9bb1014f5d84342bd6390e7fd33cec778e451baa (diff) |
Merge pull request #5308 from vespa-engine/toregge/add-clusterstate-to-content-bucket-space
Add cluster state to content bucket space.
8 files changed, 42 insertions, 9 deletions
diff --git a/storage/src/tests/common/testnodestateupdater.cpp b/storage/src/tests/common/testnodestateupdater.cpp index c7fd47e37c7..ae3f69e2605 100644 --- a/storage/src/tests/common/testnodestateupdater.cpp +++ b/storage/src/tests/common/testnodestateupdater.cpp @@ -8,7 +8,7 @@ namespace storage { TestNodeStateUpdater::TestNodeStateUpdater(const lib::NodeType& type) : _reported(new lib::NodeState(type, lib::State::UP)), _current(new lib::NodeState(type, lib::State::UP)), - _clusterStateBundle(), + _clusterStateBundle(std::make_shared<const lib::ClusterStateBundle>(lib::ClusterState())), _listeners() { } diff --git a/storage/src/tests/storageserver/statemanagertest.cpp b/storage/src/tests/storageserver/statemanagertest.cpp index 7c5303f74fe..8821d271e52 100644 --- a/storage/src/tests/storageserver/statemanagertest.cpp +++ b/storage/src/tests/storageserver/statemanagertest.cpp @@ -228,7 +228,7 @@ StateManagerTest::testClusterStateVersion() { ClusterState state(*_manager->getClusterStateBundle()->getBaselineClusterState()); state.setVersion(123); - _manager->setClusterState(state); + _manager->setClusterStateBundle(lib::ClusterStateBundle(state)); std::string nodeInfoString(_manager->getNodeInfo()); vespalib::Memory goldenMemory(nodeInfoString); diff --git a/storage/src/vespa/storage/common/content_bucket_space.cpp b/storage/src/vespa/storage/common/content_bucket_space.cpp index 4344bccc785..2bae118e364 100644 --- a/storage/src/vespa/storage/common/content_bucket_space.cpp +++ b/storage/src/vespa/storage/common/content_bucket_space.cpp @@ -8,21 +8,36 @@ ContentBucketSpace::ContentBucketSpace(document::BucketSpace bucketSpace) : _bucketSpace(bucketSpace), _bucketDatabase(), _lock(), + _clusterState(), _distribution() { } void +ContentBucketSpace::setClusterState(std::shared_ptr<const lib::ClusterState> clusterState) +{ + std::lock_guard guard(_lock); + _clusterState = std::move(clusterState); +} + +std::shared_ptr<const lib::ClusterState> +ContentBucketSpace::getClusterState() const +{ + std::lock_guard guard(_lock); + return _clusterState; +} + +void ContentBucketSpace::setDistribution(std::shared_ptr<const lib::Distribution> distribution) { - std::lock_guard<std::mutex> guard(_lock); + std::lock_guard guard(_lock); _distribution = std::move(distribution); } std::shared_ptr<const lib::Distribution> ContentBucketSpace::getDistribution() const { - std::lock_guard<std::mutex> guard(_lock); + std::lock_guard guard(_lock); return _distribution; } diff --git a/storage/src/vespa/storage/common/content_bucket_space.h b/storage/src/vespa/storage/common/content_bucket_space.h index 3b3dddade4f..6ccc82bc4fb 100644 --- a/storage/src/vespa/storage/common/content_bucket_space.h +++ b/storage/src/vespa/storage/common/content_bucket_space.h @@ -7,7 +7,10 @@ namespace storage { -namespace lib { class Distribution; } +namespace lib { +class ClusterState; +class Distribution; +} /** * Class representing a bucket space (with associated bucket database) on a content node. @@ -17,6 +20,7 @@ private: document::BucketSpace _bucketSpace; StorBucketDatabase _bucketDatabase; mutable std::mutex _lock; + std::shared_ptr<const lib::ClusterState> _clusterState; std::shared_ptr<const lib::Distribution> _distribution; public: @@ -25,6 +29,8 @@ public: document::BucketSpace bucketSpace() const noexcept { return _bucketSpace; } StorBucketDatabase &bucketDatabase() { return _bucketDatabase; } + void setClusterState(std::shared_ptr<const lib::ClusterState> clusterState); + std::shared_ptr<const lib::ClusterState> getClusterState() const; void setDistribution(std::shared_ptr<const lib::Distribution> distribution); std::shared_ptr<const lib::Distribution> getDistribution() const; }; diff --git a/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp b/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp index 311dc52767d..d5e08da7fe0 100644 --- a/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp +++ b/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp @@ -61,6 +61,7 @@ FileStorManager(const config::ConfigUri & configUri, _component.registerMetric(*_metrics); _component.registerStatusPage(*this); _component.getStateUpdater().addStateListener(*this); + propagateClusterStates(); } FileStorManager::~FileStorManager() @@ -980,7 +981,7 @@ FileStorManager::updateState() } for (const auto &elem : _component.getBucketSpaceRepo()) { BucketSpace bucketSpace(elem.first); - spi::ClusterState spiState(*state, _component.getIndex(), *elem.second->getDistribution()); + spi::ClusterState spiState(*elem.second->getClusterState(), _component.getIndex(), *elem.second->getDistribution()); _provider->setClusterState(bucketSpace, spiState); } _nodeUpInLastNodeStateSeenByProvider = nodeUp; @@ -993,8 +994,18 @@ FileStorManager::storageDistributionChanged() } void +FileStorManager::propagateClusterStates() +{ + auto clusterStateBundle = _component.getStateUpdater().getClusterStateBundle(); + for (const auto &elem : _component.getBucketSpaceRepo()) { + elem.second->setClusterState(clusterStateBundle->getDerivedClusterState(elem.first)); + } +} + +void FileStorManager::handleNewState() { + propagateClusterStates(); //TODO: Don't update if it isn't necessary (distributor-only change) updateState(); } diff --git a/storage/src/vespa/storage/persistence/filestorage/filestormanager.h b/storage/src/vespa/storage/persistence/filestorage/filestormanager.h index fe103fdcdd0..4043bb9de8b 100644 --- a/storage/src/vespa/storage/persistence/filestorage/filestormanager.h +++ b/storage/src/vespa/storage/persistence/filestorage/filestormanager.h @@ -183,6 +183,7 @@ private: void reportHtmlStatus(std::ostream&, const framework::HttpUrlPath&) const override; void storageDistributionChanged() override; void updateState(); + void propagateClusterStates(); }; } // storage diff --git a/storage/src/vespa/storage/storageserver/statemanager.cpp b/storage/src/vespa/storage/storageserver/statemanager.cpp index 11ca0bcc9ae..24e0c9209a9 100644 --- a/storage/src/vespa/storage/storageserver/statemanager.cpp +++ b/storage/src/vespa/storage/storageserver/statemanager.cpp @@ -421,7 +421,7 @@ StateManager::onGetNodeState(const api::GetNodeStateCommand::SP& cmd) } void -StateManager::setClusterState(const lib::ClusterState& c) +StateManager::setClusterStateBundle(const ClusterStateBundle& c) { { vespalib::LockGuard lock(_stateLock); @@ -434,7 +434,7 @@ bool StateManager::onSetSystemState( const std::shared_ptr<api::SetSystemStateCommand>& cmd) { - setClusterState(cmd->getSystemState()); + setClusterStateBundle(cmd->getClusterStateBundle()); std::shared_ptr<api::SetSystemStateReply> reply( new api::SetSystemStateReply(*cmd)); sendUp(reply); diff --git a/storage/src/vespa/storage/storageserver/statemanager.h b/storage/src/vespa/storage/storageserver/statemanager.h index 9f5c60b42aa..9e997098c04 100644 --- a/storage/src/vespa/storage/storageserver/statemanager.h +++ b/storage/src/vespa/storage/storageserver/statemanager.h @@ -88,7 +88,7 @@ public: Lock::SP grabStateChangeLock() override; void setReportedNodeState(const lib::NodeState& state) override; - void setClusterState(const lib::ClusterState& c); + void setClusterStateBundle(const ClusterStateBundle& c); HostInfo& getHostInfo() { return *_hostInfo; } private: |