diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-06-07 09:48:24 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-06-07 09:50:24 +0200 |
commit | 7b29da0d2943f2aa9e1c6601a538cd4ba0d100be (patch) | |
tree | 23682623d9b33b769a86ef4717cb20ac4977502f /documentapi | |
parent | ef7c93a1ffcc993b54d656c6e25a3f40366429f3 (diff) |
Hide the system state lock
Diffstat (limited to 'documentapi')
12 files changed, 36 insertions, 28 deletions
diff --git a/documentapi/src/tests/messages/messages50test.cpp b/documentapi/src/tests/messages/messages50test.cpp index 3c9f068468f..834bea0e757 100644 --- a/documentapi/src/tests/messages/messages50test.cpp +++ b/documentapi/src/tests/messages/messages50test.cpp @@ -1,12 +1,12 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "messages50test.h" -#include <vespa/document/datatype/datatype.h> -#include <vespa/document/fieldvalue/document.h> -#include <vespa/document/update/fieldpathupdates.h> -#include <vespa/document/datatype/documenttype.h> #include <vespa/documentapi/documentapi.h> #include <vespa/vdslib/container/writabledocumentlist.h> +#include <vespa/document/update/fieldpathupdates.h> +#include <vespa/document/datatype/documenttype.h> +#include <vespa/document/bucket/bucketidfactory.h> +#include <vespa/document/select/parser.h> using document::DataType; using document::DocumentTypeRepo; diff --git a/documentapi/src/tests/systemstate/systemstate.cpp b/documentapi/src/tests/systemstate/systemstate.cpp index e3163937a3f..d1ca470f670 100644 --- a/documentapi/src/tests/systemstate/systemstate.cpp +++ b/documentapi/src/tests/systemstate/systemstate.cpp @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/documentapi/messagebus/systemstate/systemstate.h> +#include <vespa/documentapi/messagebus/systemstate/nodestate.h> #include <vespa/documentapi/messagebus/systemstate/systemstatehandle.h> #include <vespa/vespalib/testkit/testapp.h> diff --git a/documentapi/src/vespa/documentapi/messagebus/messages/batchdocumentupdatemessage.cpp b/documentapi/src/vespa/documentapi/messagebus/messages/batchdocumentupdatemessage.cpp index 01e95e9f035..aa95cba1785 100644 --- a/documentapi/src/vespa/documentapi/messagebus/messages/batchdocumentupdatemessage.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/messages/batchdocumentupdatemessage.cpp @@ -3,8 +3,7 @@ #include "batchdocumentupdatemessage.h" #include "batchdocumentupdatereply.h" #include <vespa/documentapi/messagebus/documentprotocol.h> -#include <vespa/document/select/parser.h> -#include <vespa/document/bucket/bucketselector.h> +#include <vespa/document/bucket/bucketidfactory.h> #include <vespa/vespalib/util/exceptions.h> namespace documentapi { diff --git a/documentapi/src/vespa/documentapi/messagebus/messages/documentmessage.cpp b/documentapi/src/vespa/documentapi/messagebus/messages/documentmessage.cpp index e2903097934..af1203926b5 100644 --- a/documentapi/src/vespa/documentapi/messagebus/messages/documentmessage.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/messages/documentmessage.cpp @@ -2,6 +2,7 @@ #include "documentmessage.h" #include <vespa/documentapi/messagebus/documentprotocol.h> +#include <cassert> namespace documentapi { @@ -16,7 +17,7 @@ mbus::Reply::UP DocumentMessage::createReply() const { mbus::Reply::UP ret(doCreateReply().release()); - assert(ret.get() != NULL); + assert(ret.get() != nullptr); return ret; } diff --git a/documentapi/src/vespa/documentapi/messagebus/messages/emptybucketsmessage.cpp b/documentapi/src/vespa/documentapi/messagebus/messages/emptybucketsmessage.cpp index 641feb85f9d..24ac666eae9 100644 --- a/documentapi/src/vespa/documentapi/messagebus/messages/emptybucketsmessage.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/messages/emptybucketsmessage.cpp @@ -1,7 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "emptybucketsmessage.h" -#include <vespa/documentapi/messagebus/documentprotocol.h> namespace documentapi { diff --git a/documentapi/src/vespa/documentapi/messagebus/messages/removelocationmessage.cpp b/documentapi/src/vespa/documentapi/messagebus/messages/removelocationmessage.cpp index e07566cf22f..f23ecdf3556 100644 --- a/documentapi/src/vespa/documentapi/messagebus/messages/removelocationmessage.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/messages/removelocationmessage.cpp @@ -1,4 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + #include "removelocationmessage.h" #include <vespa/documentapi/messagebus/documentprotocol.h> #include <vespa/document/select/parser.h> diff --git a/documentapi/src/vespa/documentapi/messagebus/messages/removelocationmessage.h b/documentapi/src/vespa/documentapi/messagebus/messages/removelocationmessage.h index c56ef8b0ede..799fbe5bde8 100644 --- a/documentapi/src/vespa/documentapi/messagebus/messages/removelocationmessage.h +++ b/documentapi/src/vespa/documentapi/messagebus/messages/removelocationmessage.h @@ -3,8 +3,9 @@ #include "documentmessage.h" #include <vespa/document/bucket/bucketid.h> -#include <vespa/document/bucket/bucketselector.h> -#include <vespa/document/select/parser.h> + +namespace document::select { class Parser; } +namespace document { class BucketIdFactory; } namespace documentapi { diff --git a/documentapi/src/vespa/documentapi/messagebus/replymerger.cpp b/documentapi/src/vespa/documentapi/messagebus/replymerger.cpp index 50cf7129016..ef791cc55f1 100644 --- a/documentapi/src/vespa/documentapi/messagebus/replymerger.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/replymerger.cpp @@ -6,6 +6,7 @@ #include <vespa/documentapi/messagebus/messages/updatedocumentreply.h> #include <vespa/documentapi/messagebus/messages/getdocumentreply.h> #include <vespa/messagebus/emptyreply.h> +#include <cassert> namespace documentapi { diff --git a/documentapi/src/vespa/documentapi/messagebus/routablefactories50.cpp b/documentapi/src/vespa/documentapi/messagebus/routablefactories50.cpp index b620611695e..d9c8cd765a1 100644 --- a/documentapi/src/vespa/documentapi/messagebus/routablefactories50.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/routablefactories50.cpp @@ -4,6 +4,8 @@ #include <vespa/documentapi/documentapi.h> #include <vespa/documentapi/loadtypes/loadtypeset.h> #include <vespa/vespalib/objects/nbostream.h> +#include <vespa/document/bucket/bucketidfactory.h> +#include <vespa/document/select/parser.h> using vespalib::nbostream; using std::make_unique; diff --git a/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstate.cpp b/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstate.cpp index 627a760b324..64e05fec793 100644 --- a/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstate.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstate.cpp @@ -1,6 +1,8 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "systemstate.h" +#include "nodestate.h" +#include <vespa/vespalib/util/sync.h> #include <vespa/vespalib/util/stringfmt.h> #include <boost/spirit/include/classic_core.hpp> #include <boost/spirit/include/classic_parse_tree.hpp> @@ -256,7 +258,9 @@ parseSystemState(SystemStateGrammar &grammar, boost::spirit::classic::tree_node< return ret; } -vespalib::Lock SystemState::_parseLock; +namespace { + vespalib::Lock _G_parseLock; +} SystemState::UP SystemState::newInstance(const string &state) @@ -265,7 +269,7 @@ SystemState::newInstance(const string &state) return SystemState::UP(new SystemState(NodeState::UP(new NodeState()))); } try { - vespalib::LockGuard guard(_parseLock); + vespalib::LockGuard guard(_G_parseLock); SystemStateGrammar grammar; boost::spirit::classic::tree_parse_info<> info = boost::spirit::classic::pt_parse(static_cast<const char *>(&*state.begin()), @@ -289,15 +293,14 @@ SystemState::newInstance(const string &state) } } catch(std::exception& e) { - std::cerr << "SystemState::parse() internal error: " - << e.what() << std::endl; + LOG(fatal, "SystemState::parse() internal error: %s", e.what()); } return SystemState::UP(); } SystemState::SystemState(NodeState::UP root) : _root(std::move(root)), - _lock() { - // empty -} + _lock(std::make_unique<vespalib::Lock>()) +{} +SystemState::~SystemState() {}
\ No newline at end of file diff --git a/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstate.h b/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstate.h index 1d958c42b2d..169e1fbb9b6 100644 --- a/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstate.h +++ b/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstate.h @@ -1,11 +1,13 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include "nodestate.h" -#include <vespa/vespalib/util/sync.h> +#include <vespa/documentapi/common.h> +namespace vespalib { class Lock; } namespace documentapi { +class NodeState; + /** * This class is a factory to create a tree of {@link NodeState} objects from a parseable node state * string. The naming of this class is intended to capture the fact that this annotated service tree actually @@ -13,10 +15,8 @@ namespace documentapi { */ class SystemState { private: - static vespalib::Lock _parseLock; - - NodeState::UP _root; - vespalib::Lock _lock; + std::unique_ptr<NodeState> _root; + std::unique_ptr<vespalib::Lock> _lock; friend class SystemStateHandle; @@ -26,9 +26,10 @@ private: * * @param root The root node state. */ - SystemState(NodeState::UP root); + SystemState(std::unique_ptr<NodeState> root); public: + ~SystemState(); SystemState(const SystemState &) = delete; SystemState & operator = (const SystemState &) = delete; /** @@ -47,4 +48,3 @@ public: }; } - diff --git a/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstatehandle.cpp b/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstatehandle.cpp index 6d3d9a19568..ea43665facb 100644 --- a/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstatehandle.cpp +++ b/documentapi/src/vespa/documentapi/messagebus/systemstate/systemstatehandle.cpp @@ -11,14 +11,14 @@ SystemStateHandover::SystemStateHandover(SystemState *state, vespalib::LockGuard SystemStateHandle::SystemStateHandle(SystemState &state) : _state(&state), - _guard(state._lock) + _guard(*state._lock) {} SystemStateHandle::SystemStateHandle(SystemStateHandle &rhs) : _state(rhs._state), _guard(rhs._guard) { - rhs._state = NULL; + rhs._state = nullptr; } SystemStateHandle::SystemStateHandle(const SystemStateHandover &rhs) : @@ -31,7 +31,7 @@ SystemStateHandle::~SystemStateHandle() {} SystemStateHandle::operator SystemStateHandover() { SystemStateHandover ret(_state, _guard); - _state = NULL; + _state = nullptr; return ret; } |