use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.
the class DatabaseHandler method saveWantedStates.
public void saveWantedStates(Context context) throws InterruptedException {
log.log(LogLevel.DEBUG, "Fleetcontroller " + nodeIndex + ": Checking whether wanted states have changed compared to zookeeper version.");
Map<Node, NodeState> wantedStates = new TreeMap<>();
for (NodeInfo info : context.getCluster().getNodeInfo()) {
if (!info.getUserWantedState().equals(new NodeState(info.getNode().getType(), State.UP))) {
wantedStates.put(info.getNode(), info.getUserWantedState());
}
}
// - The value is different from the value we know is stored.
if (pendingStore.wantedStates != null || currentlyStored.wantedStates == null || !currentlyStored.wantedStates.equals(wantedStates)) {
log.log(LogLevel.DEBUG, "Fleetcontroller " + nodeIndex + ": Scheduling new wanted states to be stored into zookeeper.");
pendingStore.wantedStates = wantedStates;
doNextZooKeeperTask(context);
}
}
use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.
the class ZooKeeperDatabase method retrieveWantedStates.
public Map<Node, NodeState> retrieveWantedStates() throws InterruptedException {
try {
log.log(LogLevel.DEBUG, "Fleetcontroller " + nodeIndex + ": Fetching wanted states at '" + zooKeeperRoot + "wantedstates'");
Stat stat = new Stat();
byte[] data = session.getData(zooKeeperRoot + "wantedstates", false, stat);
Map<Node, NodeState> wanted = new TreeMap<>();
if (data != null && data.length > 0) {
StringTokenizer st = new StringTokenizer(new String(data, utf8), "\n", false);
while (st.hasMoreTokens()) {
String token = st.nextToken();
int colon = token.indexOf(':');
try {
if (colon < 0)
throw new Exception();
Node node = new Node(token.substring(0, colon));
NodeState nodeState = NodeState.deserialize(node.getType(), token.substring(colon + 1));
wanted.put(node, nodeState);
} catch (Exception e) {
log.log(LogLevel.WARNING, "Fleetcontroller " + nodeIndex + ": Ignoring invalid wantedstate line in zookeeper '" + token + "'.");
}
}
}
return wanted;
} catch (InterruptedException e) {
throw (InterruptedException) new InterruptedException("Interrupted").initCause(e);
} catch (Exception e) {
if (sessionOpen && reportErrors) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
log.log(LogLevel.WARNING, "Fleetcontroller " + nodeIndex + ": Failed to retrieve wanted states from zookeeper: " + e.getMessage() + "\n" + sw);
}
return null;
}
}
use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.
the class ZooKeeperDatabase method storeWantedStates.
public boolean storeWantedStates(Map<Node, NodeState> states) throws InterruptedException {
if (states == null)
states = new TreeMap<>();
StringBuilder sb = new StringBuilder();
for (Node node : states.keySet()) {
NodeState nodeState = states.get(node);
if (!nodeState.equals(new NodeState(node.getType(), State.UP))) {
NodeState toStore = new NodeState(node.getType(), nodeState.getState());
toStore.setDescription(nodeState.getDescription());
if (!toStore.equals(nodeState)) {
log.warning("Attempted to store wanted state with more than just a main state. Extra data stripped. Original data '" + nodeState.serialize(true));
}
sb.append(node.toString()).append(':').append(toStore.serialize(true)).append('\n');
}
}
byte[] val = sb.toString().getBytes(utf8);
try {
log.log(LogLevel.DEBUG, "Fleetcontroller " + nodeIndex + ": Storing wanted states at '" + zooKeeperRoot + "wantedstates'");
session.setData(zooKeeperRoot + "wantedstates", val, -1);
return true;
} catch (InterruptedException e) {
throw (InterruptedException) new InterruptedException("Interrupted").initCause(e);
} catch (Exception e) {
if (sessionOpen && reportErrors) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
log.log(LogLevel.WARNING, "Fleetcontroller " + nodeIndex + ": Failed to store wanted states in zookeeper: " + e.getMessage() + "\n" + sw);
}
return false;
}
}
use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.
the class NodeStateChangeCheckerTest method evaluateDownTransition.
private NodeStateChangeChecker.Result evaluateDownTransition(ClusterState clusterState, State reportedState, int hostInfoClusterStateVersion, int lastAlldisksBuckets) {
ContentCluster cluster = createCluster(createNodes(4));
NodeStateChangeChecker nodeStateChangeChecker = createChangeChecker(cluster);
StorageNodeInfo nodeInfo = cluster.clusterInfo().getStorageNodeInfo(nodeStorage.getIndex());
nodeInfo.setReportedState(new NodeState(NodeType.STORAGE, reportedState), 0);
nodeInfo.setHostInfo(createHostInfoWithMetrics(hostInfoClusterStateVersion, lastAlldisksBuckets));
return nodeStateChangeChecker.evaluateTransition(nodeStorage, clusterState, SetUnitStateRequest.Condition.SAFE, UP_NODE_STATE, DOWN_NODE_STATE);
}
use of com.yahoo.vdslib.state.NodeState in project vespa by vespa-engine.
the class NodeStateChangeCheckerTest method testCanSetUpEvenIfOldWantedStateIsDown.
@Test
public void testCanSetUpEvenIfOldWantedStateIsDown() {
ContentCluster cluster = createCluster(createNodes(4));
NodeStateChangeChecker nodeStateChangeChecker = createChangeChecker(cluster);
setAllNodesUp(cluster, HostInfo.createHostInfo(createDistributorHostInfo(4, 3, 6)));
NodeStateChangeChecker.Result result = nodeStateChangeChecker.evaluateTransition(nodeStorage, defaultAllUpClusterState(), SetUnitStateRequest.Condition.SAFE, new NodeState(NodeType.STORAGE, State.DOWN), UP_NODE_STATE);
assertTrue(result.settingWantedStateIsAllowed());
assertFalse(result.wantedStateAlreadySet());
}
Aggregations