Search in sources :

Example 1 with HelixDefinedState

use of org.apache.helix.HelixDefinedState in project ambry by linkedin.

the class AmbryStateModelDefinition method getDefinition.

static StateModelDefinition getDefinition() {
    StateModelDefinition.Builder builder = new StateModelDefinition.Builder(AMBRY_LEADER_STANDBY_MODEL);
    // Init state
    builder.initialState(ReplicaState.OFFLINE.name());
    /*
     * States and their priority which are managed by Helix controller.
     *
     * The implication is that transition to a state which has a higher number is
     * considered a "downward" transition by Helix. Downward transitions are not
     * throttled.
     */
    builder.addState(ReplicaState.LEADER.name(), 0);
    builder.addState(ReplicaState.STANDBY.name(), 1);
    builder.addState(ReplicaState.BOOTSTRAP.name(), 2);
    builder.addState(ReplicaState.INACTIVE.name(), 2);
    builder.addState(ReplicaState.OFFLINE.name(), 3);
    // HelixDefinedState adds two additional states: ERROR and DROPPED. The priority is Integer.MAX_VALUE
    for (HelixDefinedState state : HelixDefinedState.values()) {
        builder.addState(state.name());
    }
    // Add valid transitions between the states.
    builder.addTransition(ReplicaState.OFFLINE.name(), ReplicaState.BOOTSTRAP.name(), 3);
    builder.addTransition(ReplicaState.BOOTSTRAP.name(), ReplicaState.STANDBY.name(), 2);
    builder.addTransition(ReplicaState.STANDBY.name(), ReplicaState.LEADER.name(), 1);
    builder.addTransition(ReplicaState.LEADER.name(), ReplicaState.STANDBY.name(), 0);
    builder.addTransition(ReplicaState.STANDBY.name(), ReplicaState.INACTIVE.name(), 2);
    builder.addTransition(ReplicaState.INACTIVE.name(), ReplicaState.OFFLINE.name(), 3);
    builder.addTransition(ReplicaState.OFFLINE.name(), HelixDefinedState.DROPPED.name());
    // States constraints
    /*
     * Static constraint: number of leader replica for certain partition shouldn't exceed 1 at any time.
     */
    builder.upperBound(ReplicaState.LEADER.name(), 1);
    /*
     * Dynamic constraint: R means it should be derived based on the replication factor for the cluster
     * this allows a different replication factor for each resource without having to define a new state model.
     */
    builder.dynamicUpperBound(ReplicaState.STANDBY.name(), UPPER_BOUND_REPLICATION_FACTOR);
    return builder.build();
}
Also used : StateModelDefinition(org.apache.helix.model.StateModelDefinition) HelixDefinedState(org.apache.helix.HelixDefinedState)

Example 2 with HelixDefinedState

use of org.apache.helix.HelixDefinedState in project bookkeeper by apache.

the class WriteReadSMD method build.

/**
 * Build Write-Read state model definition.
 *
 * @return State model definition.
 */
public static StateModelDefinition build() {
    StateModelDefinition.Builder builder = new StateModelDefinition.Builder(NAME);
    // init state
    builder.initialState(States.OFFLINE.name());
    // add states
    builder.addState(States.WRITE.name(), 0);
    builder.addState(States.READ.name(), 1);
    builder.addState(States.OFFLINE.name(), 2);
    for (HelixDefinedState state : HelixDefinedState.values()) {
        builder.addState(state.name());
    }
    // add transitions
    builder.addTransition(States.WRITE.name(), States.READ.name(), 0);
    builder.addTransition(States.READ.name(), States.WRITE.name(), 1);
    builder.addTransition(States.OFFLINE.name(), States.READ.name(), 2);
    builder.addTransition(States.READ.name(), States.OFFLINE.name(), 3);
    builder.addTransition(States.OFFLINE.name(), HelixDefinedState.DROPPED.name());
    // bounds
    builder.upperBound(States.WRITE.name(), 1);
    builder.dynamicUpperBound(States.READ.name(), "R");
    return builder.build();
}
Also used : StateModelDefinition(org.apache.helix.model.StateModelDefinition) HelixDefinedState(org.apache.helix.HelixDefinedState)

Example 3 with HelixDefinedState

use of org.apache.helix.HelixDefinedState in project helix by apache.

the class LeaderStandbySMD method build.

/**
 * Build Leader-standby state model definition
 * @return
 */
public static StateModelDefinition build() {
    StateModelDefinition.Builder builder = new StateModelDefinition.Builder(name);
    // init state
    builder.initialState(States.OFFLINE.name());
    // add states
    builder.addState(States.LEADER.name(), 0);
    builder.addState(States.STANDBY.name(), 1);
    builder.addState(States.OFFLINE.name(), 2);
    for (HelixDefinedState state : HelixDefinedState.values()) {
        builder.addState(state.name());
    }
    // add transitions
    builder.addTransition(States.LEADER.name(), States.STANDBY.name(), 0);
    builder.addTransition(States.STANDBY.name(), States.LEADER.name(), 1);
    builder.addTransition(States.OFFLINE.name(), States.STANDBY.name(), 2);
    builder.addTransition(States.STANDBY.name(), States.OFFLINE.name(), 3);
    builder.addTransition(States.OFFLINE.name(), HelixDefinedState.DROPPED.name());
    // bounds
    builder.upperBound(States.LEADER.name(), 1);
    builder.dynamicUpperBound(States.STANDBY.name(), "R");
    return builder.build();
}
Also used : HelixDefinedState(org.apache.helix.HelixDefinedState)

Example 4 with HelixDefinedState

use of org.apache.helix.HelixDefinedState in project helix by apache.

the class MasterSlaveSMD method build.

/**
 * Build Master-slave state model definition
 * @return
 */
public static StateModelDefinition build() {
    StateModelDefinition.Builder builder = new StateModelDefinition.Builder(name);
    // init state
    builder.initialState(States.OFFLINE.name());
    // add states
    builder.addState(States.MASTER.name(), 0);
    builder.addState(States.SLAVE.name(), 1);
    builder.addState(States.OFFLINE.name(), 2);
    for (HelixDefinedState state : HelixDefinedState.values()) {
        builder.addState(state.name());
    }
    // add transitions
    builder.addTransition(States.MASTER.name(), States.SLAVE.name(), 0);
    builder.addTransition(States.SLAVE.name(), States.MASTER.name(), 1);
    builder.addTransition(States.OFFLINE.name(), States.SLAVE.name(), 2);
    builder.addTransition(States.SLAVE.name(), States.OFFLINE.name(), 3);
    builder.addTransition(States.OFFLINE.name(), HelixDefinedState.DROPPED.name());
    // bounds
    builder.upperBound(States.MASTER.name(), 1);
    builder.dynamicUpperBound(States.SLAVE.name(), "R");
    return builder.build();
}
Also used : HelixDefinedState(org.apache.helix.HelixDefinedState)

Example 5 with HelixDefinedState

use of org.apache.helix.HelixDefinedState in project helix by apache.

the class StorageSchemataSMD method build.

/**
 * Build StorageSchemata state model definition
 * @return
 */
public static StateModelDefinition build() {
    StateModelDefinition.Builder builder = new StateModelDefinition.Builder(name);
    // init state
    builder.initialState(States.OFFLINE.name());
    // add states
    builder.addState(States.MASTER.name(), 0);
    builder.addState(States.OFFLINE.name(), 1);
    for (HelixDefinedState state : HelixDefinedState.values()) {
        builder.addState(state.name());
    }
    // add transitions
    builder.addTransition(States.MASTER.name(), States.OFFLINE.name(), 0);
    builder.addTransition(States.OFFLINE.name(), States.MASTER.name(), 1);
    builder.addTransition(States.OFFLINE.name(), HelixDefinedState.DROPPED.name());
    // bounds
    builder.dynamicUpperBound(States.MASTER.name(), "N");
    return builder.build();
}
Also used : HelixDefinedState(org.apache.helix.HelixDefinedState)

Aggregations

HelixDefinedState (org.apache.helix.HelixDefinedState)8 StateModelDefinition (org.apache.helix.model.StateModelDefinition)2 StateTransitionTableBuilder (org.apache.helix.model.builder.StateTransitionTableBuilder)1