Search in sources :

Example 16 with NestedTransaction

use of com.yahoo.transaction.NestedTransaction in project vespa by vespa-engine.

the class CuratorDatabaseClient method addNodesInState.

/**
 * Adds a set of nodes. Rollbacks/fails transaction if any node is not in the expected state.
 */
public List<Node> addNodesInState(List<Node> nodes, Node.State expectedState) {
    NestedTransaction transaction = new NestedTransaction();
    CuratorTransaction curatorTransaction = curatorDatabase.newCuratorTransactionIn(transaction);
    for (Node node : nodes) {
        if (node.state() != expectedState)
            throw new IllegalArgumentException(node + " is not in the " + node.state() + " state");
        node = node.with(node.history().recordStateTransition(null, expectedState, Agent.system, clock.instant()));
        curatorTransaction.add(CuratorOperations.create(toPath(node).getAbsolute(), nodeSerializer.toJson(node)));
    }
    transaction.commit();
    for (Node node : nodes) log.log(LogLevel.INFO, "Added " + node);
    return nodes;
}
Also used : CuratorTransaction(com.yahoo.vespa.curator.transaction.CuratorTransaction) Node(com.yahoo.vespa.hosted.provision.Node) NestedTransaction(com.yahoo.transaction.NestedTransaction)

Example 17 with NestedTransaction

use of com.yahoo.transaction.NestedTransaction in project vespa by vespa-engine.

the class CuratorDatabaseClient method removeNodes.

/**
 * Removes multiple nodes in a single transaction.
 *
 * @param nodes list of the nodes to remove
 */
public void removeNodes(List<Node> nodes) {
    NestedTransaction transaction = new NestedTransaction();
    for (Node node : nodes) {
        Path path = toPath(node.state(), node.hostname());
        CuratorTransaction curatorTransaction = curatorDatabase.newCuratorTransactionIn(transaction);
        curatorTransaction.add(CuratorOperations.delete(path.getAbsolute()));
    }
    transaction.commit();
    nodes.forEach(node -> log.log(LogLevel.INFO, "Removed node " + node.hostname() + " in state " + node.state()));
}
Also used : Path(com.yahoo.path.Path) CuratorTransaction(com.yahoo.vespa.curator.transaction.CuratorTransaction) Node(com.yahoo.vespa.hosted.provision.Node) NestedTransaction(com.yahoo.transaction.NestedTransaction)

Example 18 with NestedTransaction

use of com.yahoo.transaction.NestedTransaction in project vespa by vespa-engine.

the class CuratorDatabaseClient method writeTo.

/**
 * Writes the given nodes and returns a copy of the incoming nodes in their persisted state.
 *
 * @param  nodes the list of nodes to write
 * @param  agent the agent causing this change
 * @return the nodes in their persisted state
 */
public List<Node> writeTo(List<Node> nodes, Agent agent, Optional<String> reason) {
    if (nodes.isEmpty())
        return Collections.emptyList();
    List<Node> writtenNodes = new ArrayList<>(nodes.size());
    try (NestedTransaction nestedTransaction = new NestedTransaction()) {
        Map<Node.State, List<Node>> nodesByState = nodes.stream().collect(Collectors.groupingBy(Node::state));
        for (Map.Entry<Node.State, List<Node>> entry : nodesByState.entrySet()) {
            writtenNodes.addAll(writeTo(entry.getKey(), entry.getValue(), agent, reason, nestedTransaction));
        }
        nestedTransaction.commit();
    }
    return writtenNodes;
}
Also used : Node(com.yahoo.vespa.hosted.provision.Node) ArrayList(java.util.ArrayList) NestedTransaction(com.yahoo.transaction.NestedTransaction) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

NestedTransaction (com.yahoo.transaction.NestedTransaction)18 CuratorTransaction (com.yahoo.vespa.curator.transaction.CuratorTransaction)9 Node (com.yahoo.vespa.hosted.provision.Node)5 HostSpec (com.yahoo.config.provision.HostSpec)4 Test (org.junit.Test)4 ApplicationId (com.yahoo.config.provision.ApplicationId)3 Zone (com.yahoo.config.provision.Zone)3 ClusterMembership (com.yahoo.config.provision.ClusterMembership)1 ClusterSpec (com.yahoo.config.provision.ClusterSpec)1 HostFilter (com.yahoo.config.provision.HostFilter)1 Path (com.yahoo.path.Path)1 ActivationConflictException (com.yahoo.vespa.config.server.ActivationConflictException)1 TimeoutBudget (com.yahoo.vespa.config.server.TimeoutBudget)1 TenantApplications (com.yahoo.vespa.config.server.application.TenantApplications)1 InternalServerException (com.yahoo.vespa.config.server.http.InternalServerException)1 LocalSession (com.yahoo.vespa.config.server.session.LocalSession)1 LocalSessionRepo (com.yahoo.vespa.config.server.session.LocalSessionRepo)1 ActivateLock (com.yahoo.vespa.config.server.tenant.ActivateLock)1 Rotations (com.yahoo.vespa.config.server.tenant.Rotations)1 Tenant (com.yahoo.vespa.config.server.tenant.Tenant)1