Search in sources :

Example 11 with ClusterState

use of com.yahoo.vdslib.state.ClusterState in project vespa by vespa-engine.

the class StateWaiter method waitForState.

/**
 * WARNING: If timeIntervalToProvokeRetry is set != 0 that means time will can be set far into future
 * and thus hit various unintended timeout periods. Only auto-step time if this is a non-issue.
 */
public void waitForState(String stateRegex, long timeout, long timeIntervalToProvokeRetry) {
    Pattern p = Pattern.compile(stateRegex);
    long startTime = System.currentTimeMillis();
    final long endTime = startTime + timeout;
    int iteration = 0;
    while (true) {
        ClusterState currentClusterState;
        synchronized (timer) {
            currentClusterState = current;
            if (currentClusterState != null) {
                Matcher m = p.matcher(currentClusterState.toString());
                if (m.matches()) {
                    return;
                }
            }
            try {
                if (timeIntervalToProvokeRetry == 0) {
                    timer.wait(endTime - startTime);
                } else {
                    if (++iteration % 10 == 0) {
                        timer.advanceTime(timeIntervalToProvokeRetry);
                    }
                    timer.wait(10);
                }
            } catch (InterruptedException e) {
            }
        }
        startTime = System.currentTimeMillis();
        if (startTime >= endTime) {
            throw new IllegalStateException("Timeout. Did not find a state matching " + stateRegex + " within timeout of " + timeout + " milliseconds. Current state is " + currentClusterState);
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) ClusterState(com.yahoo.vdslib.state.ClusterState) Matcher(java.util.regex.Matcher)

Example 12 with ClusterState

use of com.yahoo.vdslib.state.ClusterState in project vespa by vespa-engine.

the class StateWaiter method waitForInitProgressPassed.

public void waitForInitProgressPassed(Node node, double minProgress, int timeoutMS) {
    long startTime = System.currentTimeMillis();
    long endTime = startTime + timeoutMS;
    while (true) {
        ClusterState currentClusterState;
        synchronized (timer) {
            currentClusterState = current;
            if (currentClusterState != null) {
                if (currentClusterState.getNodeState(node).getInitProgress() >= minProgress) {
                    return;
                }
            }
            try {
                timer.wait(endTime - startTime);
            } catch (InterruptedException e) {
            }
        }
        startTime = System.currentTimeMillis();
        if (startTime >= endTime) {
            throw new IllegalStateException("Timeout. Did not get to " + minProgress + " init progress on node " + node + " within timeout of " + timeoutMS + " ms. Current init progress is " + currentClusterState.getNodeState(node).getInitProgress());
        }
    }
}
Also used : ClusterState(com.yahoo.vdslib.state.ClusterState)

Example 13 with ClusterState

use of com.yahoo.vdslib.state.ClusterState in project vespa by vespa-engine.

the class DistributionTestCase method testDistributorNoGroupTakeover.

@Test
public void testDistributorNoGroupTakeover() throws Exception {
    test = new DistributionTestFactory("hierarchical-grouping-distributor-notakeover").setDistribution(buildHierarchicalConfig(6, 3, 1, "1|2|*", 3).distributor_auto_ownership_transfer_on_whole_group_down(false)).setNodeType(NodeType.DISTRIBUTOR).setClusterState(new ClusterState("distributor:2 storage:9"));
    int[] counts = new int[10];
    int noneExisting = 0;
    for (BucketId bucket : getTestBuckets()) {
        DistributionTestFactory.Test t = test.recordResult(bucket);
        List<Integer> nodes = t.getNodes();
        if (nodes.isEmpty()) {
            ++noneExisting;
            t.assertFailure(DistributionTestFactory.Failure.NO_DISTRIBUTORS_AVAILABLE);
        } else {
            t.assertNodeCount(1);
            for (int i : nodes) {
                ++counts[i];
            }
        }
    }
    for (int i = 2; i < 10; ++i) {
        assertEquals(0, counts[i]);
    }
    for (int i = 0; i < 2; ++i) {
        assertTrue(counts[i] > 0);
    }
    assertEquals(15, noneExisting);
}
Also used : ClusterState(com.yahoo.vdslib.state.ClusterState) BucketId(com.yahoo.document.BucketId) Test(org.junit.Test)

Example 14 with ClusterState

use of com.yahoo.vdslib.state.ClusterState in project vespa by vespa-engine.

the class DistributionTestCase method testMinimalMovement.

@Test
public void testMinimalMovement() throws Exception {
    test = new DistributionTestFactory("minimal-movement").setClusterState(new ClusterState("distributor:4 .2.s:d"));
    DistributionTestFactory control = new DistributionTestFactory("minimal-movement-reference").setClusterState(new ClusterState("distributor:4"));
    int moved = 0;
    int staying = 0;
    for (BucketId bucket : getTestBuckets()) {
        DistributionTestFactory.Test org = control.recordResult(bucket).assertNodeCount(1);
        DistributionTestFactory.Test res = test.recordResult(bucket).assertNodeCount(1);
        if (org.getNodes().get(0) == 2) {
            assertTrue(res.getNodes().get(0) != 2);
            ++moved;
        } else {
            assertEquals(org, res);
            ++staying;
        }
    }
    assertEquals(63, moved);
    assertEquals(81, staying);
}
Also used : ClusterState(com.yahoo.vdslib.state.ClusterState) BucketId(com.yahoo.document.BucketId) Test(org.junit.Test)

Example 15 with ClusterState

use of com.yahoo.vdslib.state.ClusterState in project vespa by vespa-engine.

the class LegacyIndexPageRequestHandler method calculateDerivedClusterStateTransitions.

private List<ClusterStateTransition> calculateDerivedClusterStateTransitions(ClusterStateHistoryEntry currentEntry, ClusterStateHistoryEntry lastEntry) {
    List<ClusterStateTransition> result = new ArrayList<>();
    currentEntry.getDerivedBucketSpaceStates().forEach((bucketSpace, currentState) -> {
        ClusterState lastState = (lastEntry != null ? lastEntry.getDerivedBucketSpaceStates().get(bucketSpace) : null);
        if ((!currentState.equals(currentEntry.getBaselineState())) || ((lastState != null) && (!lastState.equals(lastEntry.getBaselineState())))) {
            result.add(ClusterStateTransition.forBucketSpace(currentState, lastState, bucketSpace));
        }
    });
    return result;
}
Also used : ClusterState(com.yahoo.vdslib.state.ClusterState)

Aggregations

ClusterState (com.yahoo.vdslib.state.ClusterState)38 Test (org.junit.Test)11 NodeState (com.yahoo.vdslib.state.NodeState)10 Node (com.yahoo.vdslib.state.Node)8 BucketId (com.yahoo.document.BucketId)6 ConfiguredNode (com.yahoo.vdslib.distribution.ConfiguredNode)6 State (com.yahoo.vdslib.state.State)4 Request (com.yahoo.jrt.Request)2 Spec (com.yahoo.jrt.Spec)2 Supervisor (com.yahoo.jrt.Supervisor)2 Target (com.yahoo.jrt.Target)2 Transport (com.yahoo.jrt.Transport)2 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 ParseException (com.yahoo.document.select.parser.ParseException)1 StringValue (com.yahoo.jrt.StringValue)1 Distribution (com.yahoo.vdslib.distribution.Distribution)1 NodeType (com.yahoo.vdslib.state.NodeType)1 AnnotatedClusterState (com.yahoo.vespa.clustercontroller.core.AnnotatedClusterState)1 HostInfo (com.yahoo.vespa.clustercontroller.core.hostinfo.HostInfo)1