summaryrefslogtreecommitdiffstats
path: root/persistence
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahoo-inc.com>2017-04-26 13:14:35 +0000
committerTor Brede Vekterli <vekterli@yahoo-inc.com>2017-04-26 14:31:54 +0000
commit1ec697c0e62e4957f680c8c32d96dc5b2ee5fea1 (patch)
treef21c98a7c98cf3e3b4a6844f3d1bd92c1c409f64 /persistence
parente645c567e32a94abde0c7493172ff1c274d1bbc2 (diff)
Add node retirement accessor to SPI cluster state
Diffstat (limited to 'persistence')
-rw-r--r--persistence/src/tests/spi/clusterstatetest.cpp28
-rw-r--r--persistence/src/vespa/persistence/spi/clusterstate.cpp51
-rw-r--r--persistence/src/vespa/persistence/spi/clusterstate.h8
3 files changed, 55 insertions, 32 deletions
diff --git a/persistence/src/tests/spi/clusterstatetest.cpp b/persistence/src/tests/spi/clusterstatetest.cpp
index 7770b9045e0..ba9b0e28d50 100644
--- a/persistence/src/tests/spi/clusterstatetest.cpp
+++ b/persistence/src/tests/spi/clusterstatetest.cpp
@@ -18,12 +18,14 @@ struct ClusterStateTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testNodeUp);
CPPUNIT_TEST(testNodeInitializing);
CPPUNIT_TEST(testReady);
+ CPPUNIT_TEST(can_infer_own_node_retired_state);
CPPUNIT_TEST_SUITE_END();
void testClusterUp();
void testNodeUp();
void testNodeInitializing();
void testReady();
+ void can_infer_own_node_retired_state();
};
CPPUNIT_TEST_SUITE_REGISTRATION(ClusterStateTest);
@@ -222,5 +224,31 @@ ClusterStateTest::testReady()
}
}
+namespace {
+
+bool
+node_marked_as_retired_in_state(const std::string& stateStr,
+ const lib::Distribution& d,
+ uint16_t node)
+{
+ lib::ClusterState s(stateStr);
+ ClusterState state(s, node, d);
+ return state.nodeRetired();
+}
+
+}
+
+void ClusterStateTest::can_infer_own_node_retired_state() {
+ lib::Distribution d(lib::Distribution::getDefaultDistributionConfig(3, 3));
+
+ CPPUNIT_ASSERT(!node_marked_as_retired_in_state("distributor:3 storage:3", d, 0));
+ CPPUNIT_ASSERT(!node_marked_as_retired_in_state("distributor:3 storage:3 .0.s:i", d, 0));
+ CPPUNIT_ASSERT(!node_marked_as_retired_in_state("distributor:3 storage:3 .0.s:d", d, 0));
+ CPPUNIT_ASSERT(!node_marked_as_retired_in_state("distributor:3 storage:3 .0.s:m", d, 0));
+ CPPUNIT_ASSERT(node_marked_as_retired_in_state("distributor:3 storage:3 .0.s:r", d, 0));
+ CPPUNIT_ASSERT(!node_marked_as_retired_in_state("distributor:3 storage:3 .0.s:r", d, 1));
+ CPPUNIT_ASSERT(!node_marked_as_retired_in_state("distributor:3 storage:3 .1.s:r", d, 0));
+}
+
} // spi
} // storage
diff --git a/persistence/src/vespa/persistence/spi/clusterstate.cpp b/persistence/src/vespa/persistence/spi/clusterstate.cpp
index c505c8c8d3b..70bc8724c96 100644
--- a/persistence/src/vespa/persistence/spi/clusterstate.cpp
+++ b/persistence/src/vespa/persistence/spi/clusterstate.cpp
@@ -16,12 +16,9 @@ ClusterState::ClusterState(const lib::ClusterState& state,
_nodeIndex(nodeIndex),
_distribution(new lib::Distribution(distribution.serialize()))
{
-
}
-void
-ClusterState::deserialize(vespalib::nbostream& i)
-{
+void ClusterState::deserialize(vespalib::nbostream& i) {
vespalib::string clusterState;
vespalib::string distribution;
@@ -33,13 +30,11 @@ ClusterState::deserialize(vespalib::nbostream& i)
_distribution.reset(new lib::Distribution(distribution));
}
-ClusterState::ClusterState(vespalib::nbostream& i)
-{
+ClusterState::ClusterState(vespalib::nbostream& i) {
deserialize(i);
}
-ClusterState::ClusterState(const ClusterState& other)
-{
+ClusterState::ClusterState(const ClusterState& other) {
vespalib::nbostream o;
other.serialize(o);
deserialize(o);
@@ -47,9 +42,7 @@ ClusterState::ClusterState(const ClusterState& other)
ClusterState::~ClusterState() { }
-ClusterState&
-ClusterState::operator=(const ClusterState& other)
-{
+ClusterState& ClusterState::operator=(const ClusterState& other) {
ClusterState copy(other);
_state = std::move(copy._state);
_nodeIndex = copy._nodeIndex;
@@ -57,9 +50,7 @@ ClusterState::operator=(const ClusterState& other)
return *this;
}
-bool
-ClusterState::shouldBeReady(const Bucket& b) const
-{
+bool ClusterState::shouldBeReady(const Bucket& b) const {
assert(_distribution.get());
assert(_state.get());
@@ -77,31 +68,29 @@ ClusterState::shouldBeReady(const Bucket& b) const
return false;
}
-bool
-ClusterState::clusterUp() const
-{
+bool ClusterState::clusterUp() const {
return _state.get() && _state->getClusterState() == lib::State::UP;
}
-bool
-ClusterState::nodeUp() const
-{
+bool ClusterState::nodeHasStateOneOf(const char* states) const {
return _state.get() &&
- _state->getNodeState(lib::Node(lib::NodeType::STORAGE, _nodeIndex)).
- getState().oneOf("uir");
+ _state->getNodeState(lib::Node(lib::NodeType::STORAGE, _nodeIndex)).
+ getState().oneOf(states);
}
-bool
-ClusterState::nodeInitializing() const
-{
- return _state.get() &&
- _state->getNodeState(lib::Node(lib::NodeType::STORAGE, _nodeIndex)).
- getState().oneOf("i");
+bool ClusterState::nodeUp() const {
+ return nodeHasStateOneOf("uir");
}
-void
-ClusterState::serialize(vespalib::nbostream& o) const
-{
+bool ClusterState::nodeInitializing() const {
+ return nodeHasStateOneOf("i");
+}
+
+bool ClusterState::nodeRetired() const {
+ return nodeHasStateOneOf("r");
+}
+
+void ClusterState::serialize(vespalib::nbostream& o) const {
assert(_distribution.get());
assert(_state.get());
vespalib::asciistream tmp;
diff --git a/persistence/src/vespa/persistence/spi/clusterstate.h b/persistence/src/vespa/persistence/spi/clusterstate.h
index 52a71c561dd..f0fe3cfafa8 100644
--- a/persistence/src/vespa/persistence/spi/clusterstate.h
+++ b/persistence/src/vespa/persistence/spi/clusterstate.h
@@ -53,11 +53,16 @@ public:
bool nodeUp() const;
/**
- * Returns true if this node is marked as Initializing in the cluster state.
+ * Returns true iff this node is marked as Initializing in the cluster state.
*/
bool nodeInitializing() const;
/**
+ * Returns true iff this node is marked as Retired in the cluster state.
+ */
+ bool nodeRetired() const;
+
+ /**
* Returns a serialized form of this object.
*/
void serialize(vespalib::nbostream& o) const;
@@ -68,6 +73,7 @@ private:
std::unique_ptr<lib::Distribution> _distribution;
void deserialize(vespalib::nbostream&);
+ bool nodeHasStateOneOf(const char* states) const;
};
}