Search in sources :

Example 1 with CuratorTransaction

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

the class CuratorDatabase method newCuratorTransactionIn.

// --------- Write operations ------------------------------------------------------------------------------
// These must either create a nested transaction ending in a counter increment or not depend on prior state
/**
 * Creates a new curator transaction against this database and adds it to the given nested transaction.
 * Important: It is the nested transaction which must be committed - never the curator transaction directly.
 */
public CuratorTransaction newCuratorTransactionIn(NestedTransaction transaction) {
    // Add a counting transaction first, to make sure we always invalidate the current state on any transaction commit
    transaction.add(new EagerCountingCuratorTransaction(changeGenerationCounter), CuratorTransaction.class);
    CuratorTransaction curatorTransaction = new CuratorTransaction(curator);
    transaction.add(curatorTransaction);
    return curatorTransaction;
}
Also used : CuratorTransaction(com.yahoo.vespa.curator.transaction.CuratorTransaction)

Example 2 with CuratorTransaction

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

the class CuratorDatabaseTest method commitCreate.

private void commitCreate(String path, CuratorDatabase database) {
    NestedTransaction t = new NestedTransaction();
    CuratorTransaction c = database.newCuratorTransactionIn(t);
    c.add(CuratorOperations.create(path));
    t.commit();
}
Also used : CuratorTransaction(com.yahoo.vespa.curator.transaction.CuratorTransaction) NestedTransaction(com.yahoo.transaction.NestedTransaction)

Example 3 with CuratorTransaction

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

the class CuratorDatabaseTest method testThatCounterIncreasesAlsoOnCommitFailureFromExistingTransaction.

@Test
public void testThatCounterIncreasesAlsoOnCommitFailureFromExistingTransaction() throws Exception {
    MockCurator curator = new MockCurator();
    CuratorDatabase database = new CuratorDatabase(curator, Path.fromString("/"), true);
    assertEquals(0L, (long) curator.counter("/changeCounter").get().get().postValue());
    try {
        NestedTransaction t = new NestedTransaction();
        CuratorTransaction separateC = new CuratorTransaction(curator);
        // fail as parent does not exist
        separateC.add(CuratorOperations.create("/1/2"));
        t.add(separateC);
        CuratorTransaction c = database.newCuratorTransactionIn(t);
        // does not fail
        c.add(CuratorOperations.create("/1"));
        t.commit();
        fail("Expected exception");
    } catch (Exception expected) {
    // expected because the parent does not exist
    }
    assertEquals(1L, (long) curator.counter("/changeCounter").get().get().postValue());
}
Also used : CuratorTransaction(com.yahoo.vespa.curator.transaction.CuratorTransaction) NestedTransaction(com.yahoo.transaction.NestedTransaction) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Test(org.junit.Test)

Example 4 with CuratorTransaction

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

the class NodeFailTester method activate.

private void activate(ApplicationId applicationId, ClusterSpec cluster, Capacity capacity) {
    List<HostSpec> hosts = provisioner.prepare(applicationId, cluster, capacity, 1, null);
    NestedTransaction transaction = new NestedTransaction().add(new CuratorTransaction(curator));
    provisioner.activate(transaction, applicationId, hosts);
    transaction.commit();
}
Also used : CuratorTransaction(com.yahoo.vespa.curator.transaction.CuratorTransaction) NestedTransaction(com.yahoo.transaction.NestedTransaction) HostSpec(com.yahoo.config.provision.HostSpec)

Example 5 with CuratorTransaction

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

the class RetiredExpirerTest method activate.

private void activate(ApplicationId applicationId, ClusterSpec cluster, int nodes, int groups, NodeRepositoryProvisioner provisioner) {
    List<HostSpec> hosts = provisioner.prepare(applicationId, cluster, Capacity.fromNodeCount(nodes), groups, null);
    NestedTransaction transaction = new NestedTransaction().add(new CuratorTransaction(curator));
    provisioner.activate(transaction, applicationId, hosts);
    transaction.commit();
}
Also used : CuratorTransaction(com.yahoo.vespa.curator.transaction.CuratorTransaction) NestedTransaction(com.yahoo.transaction.NestedTransaction) HostSpec(com.yahoo.config.provision.HostSpec)

Aggregations

CuratorTransaction (com.yahoo.vespa.curator.transaction.CuratorTransaction)13 NestedTransaction (com.yahoo.transaction.NestedTransaction)9 Node (com.yahoo.vespa.hosted.provision.Node)4 HostSpec (com.yahoo.config.provision.HostSpec)2 ClusterMembership (com.yahoo.config.provision.ClusterMembership)1 ClusterSpec (com.yahoo.config.provision.ClusterSpec)1 Path (com.yahoo.path.Path)1 MockCurator (com.yahoo.vespa.curator.mock.MockCurator)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1