Return-Path: X-Original-To: apmail-helix-commits-archive@minotaur.apache.org Delivered-To: apmail-helix-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 88FE51026D for ; Thu, 17 Oct 2013 21:48:08 +0000 (UTC) Received: (qmail 36287 invoked by uid 500); 17 Oct 2013 21:45:54 -0000 Delivered-To: apmail-helix-commits-archive@helix.apache.org Received: (qmail 36006 invoked by uid 500); 17 Oct 2013 21:45:38 -0000 Mailing-List: contact commits-help@helix.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@helix.incubator.apache.org Delivered-To: mailing list commits@helix.incubator.apache.org Received: (qmail 35848 invoked by uid 99); 17 Oct 2013 21:45:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Oct 2013 21:45:30 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Oct 2013 21:45:15 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5BA942388CA6; Thu, 17 Oct 2013 21:43:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1533269 [23/27] - in /incubator/helix/site-content: ./ apidocs/assets/ apidocs/reference/ apidocs/reference/org/apache/helix/ apidocs/reference/org/apache/helix/agent/ apidocs/reference/org/apache/helix/alerts/ apidocs/reference/org/apache... Date: Thu, 17 Oct 2013 21:43:20 -0000 To: commits@helix.incubator.apache.org From: kanak@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131017214358.5BA942388CA6@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: incubator/helix/site-content/recipes/user-defined-rebalancer/project-reports.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/recipes/user-defined-rebalancer/project-reports.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/recipes/user-defined-rebalancer/project-reports.html (original) +++ incubator/helix/site-content/recipes/user-defined-rebalancer/project-reports.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix :: Recipes :: user-defined-rebalancer - Generated Reports @@ -106,7 +106,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/recipes/user-defined-rebalancer/project-summary.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/recipes/user-defined-rebalancer/project-summary.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/recipes/user-defined-rebalancer/project-summary.html (original) +++ incubator/helix/site-content/recipes/user-defined-rebalancer/project-summary.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix :: Recipes :: user-defined-rebalancer - Project Summary @@ -106,7 +106,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/recipes/user-defined-rebalancer/sonar.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/recipes/user-defined-rebalancer/sonar.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/recipes/user-defined-rebalancer/sonar.html (original) +++ incubator/helix/site-content/recipes/user-defined-rebalancer/sonar.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix :: Recipes :: user-defined-rebalancer - Sonar @@ -106,7 +106,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/recipes/user-defined-rebalancer/source-repository.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/recipes/user-defined-rebalancer/source-repository.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/recipes/user-defined-rebalancer/source-repository.html (original) +++ incubator/helix/site-content/recipes/user-defined-rebalancer/source-repository.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix :: Recipes :: user-defined-rebalancer - Source Repository @@ -106,7 +106,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/recipes/user-defined-rebalancer/team-list.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/recipes/user-defined-rebalancer/team-list.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/recipes/user-defined-rebalancer/team-list.html (original) +++ incubator/helix/site-content/recipes/user-defined-rebalancer/team-list.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix :: Recipes :: user-defined-rebalancer - Team list @@ -106,7 +106,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/recipes/user_def_rebalancer.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/recipes/user_def_rebalancer.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/recipes/user_def_rebalancer.html (original) +++ incubator/helix/site-content/recipes/user_def_rebalancer.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/releasenotes/release-0.6.0-incubating.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/releasenotes/release-0.6.0-incubating.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/releasenotes/release-0.6.0-incubating.html (original) +++ incubator/helix/site-content/releasenotes/release-0.6.0-incubating.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - Release Notes for 0.6.0-incubating Apache Helix @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/releasenotes/release-0.6.1-incubating.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/releasenotes/release-0.6.1-incubating.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/releasenotes/release-0.6.1-incubating.html (original) +++ incubator/helix/site-content/releasenotes/release-0.6.1-incubating.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - Release Notes for 0.6.1-incubating Apache Helix @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/releasing.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/releasing.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/releasing.html (original) +++ incubator/helix/site-content/releasing.html Thu Oct 17 21:43:06 2013 @@ -1,6 +1,6 @@ @@ -8,7 +8,7 @@ - + Apache Helix - Helix release process @@ -175,7 +175,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/sonar.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/sonar.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/sonar.html (original) +++ incubator/helix/site-content/sonar.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - Sonar @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/source-repository.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/source-repository.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/source-repository.html (original) +++ incubator/helix/site-content/source-repository.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - Source Repository @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/team-list.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/team-list.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/team-list.html (original) +++ incubator/helix/site-content/team-list.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - Team list @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/tutorial_admin.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/tutorial_admin.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/tutorial_admin.html (original) +++ incubator/helix/site-content/tutorial_admin.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/tutorial_controller.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/tutorial_controller.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/tutorial_controller.html (original) +++ incubator/helix/site-content/tutorial_controller.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/tutorial_health.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/tutorial_health.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/tutorial_health.html (original) +++ incubator/helix/site-content/tutorial_health.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/tutorial_messaging.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/tutorial_messaging.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/tutorial_messaging.html (original) +++ incubator/helix/site-content/tutorial_messaging.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/tutorial_participant.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/tutorial_participant.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/tutorial_participant.html (original) +++ incubator/helix/site-content/tutorial_participant.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/tutorial_propstore.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/tutorial_propstore.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/tutorial_propstore.html (original) +++ incubator/helix/site-content/tutorial_propstore.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/tutorial_rebalance.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/tutorial_rebalance.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/tutorial_rebalance.html (original) +++ incubator/helix/site-content/tutorial_rebalance.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/tutorial_spectator.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/tutorial_spectator.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/tutorial_spectator.html (original) +++ incubator/helix/site-content/tutorial_spectator.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/tutorial_state.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/tutorial_state.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/tutorial_state.html (original) +++ incubator/helix/site-content/tutorial_state.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • @@ -201,19 +201,65 @@ KIND, either express or implied. See th specific language governing permissions and limitations under the License. -->

    Helix Tutorial: State Machine Configuration

    In this chapter, we'll learn about the state models provided by Helix, and how to create your own custom state model.

    State Models

    Helix comes with 3 default state models that are commonly used. It is possible to have multiple state models in a cluster. Every resource that is added should be configured to use a state model that govern its ideal state.

    MASTER-SLAVE

      -
    • Has 3 states: OFFLINE, SLAVE, MASTER
    • -
    • Maximum # of masters: 1
    • -
    • Slaves are based on the replication factor. Replication factor can be specified while adding the resource
    • +
    • 3 states: OFFLINE, SLAVE, MASTER
    • +
    • Maximum number of masters: 1
    • +
    • Slaves are based on the replication factor. The replication factor can be specified while adding the resource.

    ONLINE-OFFLINE

    • Has 2 states: OFFLINE and ONLINE. This simple state model is a good starting point for most applications.

    LEADER-STANDBY

    • 1 Leader and multiple stand-bys. The idea is that exactly one leader accomplishes a designated task, the stand-bys are ready to take over if the leader fails.
    • -

    Constraints

    In addition to the state machine configuration, one can specify the constraints of states and transitions.

    For example, one can say: * MASTER:1 Maximum number of replicas in MASTER state at any time is 1

    +

    Constraints

    In addition to the state machine configuration, one can specify the constraints of states and transitions.

    For example, one can say:

      -
    • OFFLINE-SLAVE:5 Maximum number of OFFLINE-SLAVE transitions that can happen concurrently in the system is 5 in this example.
    • -

    State Priority

    Helix uses a greedy approach to satisfy the state constraints. For example, if the state machine configuration says it needs 1 MASTER and 2 SLAVES, but only 1 node is active, Helix must promote it to MASTER. This behavior is achieved by providing the state priority list as MASTER,SLAVE.

    State Transition Priority

    Helix tries to fire as many transitions as possible in parallel to reach the stable state without violating constraints. By default, Helix simply sorts the transitions alphabetically and fires as many as it can without violating the constraints. You can control this by overriding the priority order.

    +
  • MASTER:1
    Maximum number of replicas in MASTER state at any time is 1

  • +
  • OFFLINE-SLAVE:5
    Maximum number of OFFLINE-SLAVE transitions that can happen concurrently in the system is 5 in this example.

  • +

    Dynamic State Constraints

    We also support two dynamic upper bounds for the number of replicas in each state:

    +
      +
    • N: The number of replicas in the state is at most the number of live participants in the cluster
    • +
    • R: The number of replicas in the state is at most the specified replica count for the partition
    • +

    State Priority

    Helix uses a greedy approach to satisfy the state constraints. For example, if the state machine configuration says it needs 1 MASTER and 2 SLAVES, but only 1 node is active, Helix must promote it to MASTER. This behavior is achieved by providing the state priority list as [MASTER, SLAVE].

    State Transition Priority

    Helix tries to fire as many transitions as possible in parallel to reach the stable state without violating constraints. By default, Helix simply sorts the transitions alphabetically and fires as many as it can without violating the constraints. You can control this by overriding the priority order.

    Special States

    DROPPED

    The DROPPED state is used to signify a replica that was serve d by a given participant, but is no longer served. This allows Helix and its participants to effectively clean up. There are two requirements that every new state model should follow with respect to the DROPPED state:

    +
      +
    • The DROPPED state must be defined
    • +
    • There must be a path to DROPPED for every state in the model
    • +

    ERROR

    The ERROR state is used whenever the participant serving a partition encountered an error and cannot continue to serve the partition. HelixAdmin has "reset" functionality to allow for participants to recover from the ERROR state.

    Annotated Example

    Below is a complete definition of a Master-Slave state model. Notice the fields marked REQUIRED; these are essential for any state model definition.

    +
    StateModelDefinition stateModel = new StateModelDefinition.Builder("MasterSlave")
    +  // OFFLINE is the state that the system starts in (initial state is REQUIRED)
    +  .initialState("OFFLINE")
    +
    +  // Lowest number here indicates highest priority, no value indicates lowest priority
    +  .addState("MASTER", 1)
    +  .addState("SLAVE", 2)
    +  .addState("OFFLINE")
    +
    +  // Note the special inclusion of the DROPPED state (REQUIRED)
    +  .addState(HelixDefinedState.DROPPED.toString())
    +
    +  // No more than one master allowed
    +  .upperBound("MASTER", 1)
    +
    +  // R indicates an upper bound of number of replicas for each partition
    +  .dynamicUpperBound("SLAVE", "R")
    +
    +  // Add some high-priority transitions
    +  .addTransition("SLAVE", "MASTER", 1)
    +  .addTransition("OFFLINE", "SLAVE", 2)
    +
    +  // Using the same priority value indicates that these transitions can fire in any order
    +  .addTransition("MASTER", "SLAVE", 3)
    +  .addTransition("SLAVE", "OFFLINE", 3)
    +
    +  // Not specifying a value defaults to lowest priority
    +  // Notice the inclusion of the OFFLINE to DROPPED transition
    +  // Since every state has a path to OFFLINE, they each now have a path to DROPPED (REQUIRED)
    +  .addTransition("OFFLINE", HelixDefinedState.DROPPED.toString())
    +
    +  // Create the StateModelDefinition instance
    +  .build();
    +
    +  // Use the isValid() function to make sure the StateModelDefinition will work without issues
    +  Assert.assertTrue(stateModel.isValid());
    +
    Modified: incubator/helix/site-content/tutorial_throttling.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/tutorial_throttling.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/tutorial_throttling.html (original) +++ incubator/helix/site-content/tutorial_throttling.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/tutorial_user_def_rebalancer.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/tutorial_user_def_rebalancer.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/tutorial_user_def_rebalancer.html (original) +++ incubator/helix/site-content/tutorial_user_def_rebalancer.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/tutorial_yaml.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/tutorial_yaml.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/tutorial_yaml.html (original) +++ incubator/helix/site-content/tutorial_yaml.html Thu Oct 17 21:43:06 2013 @@ -1,13 +1,13 @@ - + Apache Helix - @@ -174,7 +174,7 @@ -
  • Last Published: 2013-10-06
  • +
  • Last Published: 2013-10-17
  • Modified: incubator/helix/site-content/xref-test/allclasses-frame.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref-test/allclasses-frame.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/xref-test/allclasses-frame.html (original) +++ incubator/helix/site-content/xref-test/allclasses-frame.html Thu Oct 17 21:43:06 2013 @@ -723,6 +723,9 @@ TestStateModelParser
  • + TestStateModelValidity +
  • +
  • TestStateTransitionTimeout
  • Added: incubator/helix/site-content/xref-test/org/apache/helix/model/TestStateModelValidity.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref-test/org/apache/helix/model/TestStateModelValidity.html?rev=1533269&view=auto ============================================================================== --- incubator/helix/site-content/xref-test/org/apache/helix/model/TestStateModelValidity.html (added) +++ incubator/helix/site-content/xref-test/org/apache/helix/model/TestStateModelValidity.html Thu Oct 17 21:43:06 2013 @@ -0,0 +1,265 @@ + + + + +TestStateModelValidity xref + + + +
    +
    +1   package org.apache.helix.model;
    +2   
    +3   /*
    +4    * Licensed to the Apache Software Foundation (ASF) under one
    +5    * or more contributor license agreements.  See the NOTICE file
    +6    * distributed with this work for additional information
    +7    * regarding copyright ownership.  The ASF licenses this file
    +8    * to you under the Apache License, Version 2.0 (the
    +9    * "License"); you may not use this file except in compliance
    +10   * with the License.  You may obtain a copy of the License at
    +11   *
    +12   *   http://www.apache.org/licenses/LICENSE-2.0
    +13   *
    +14   * Unless required by applicable law or agreed to in writing,
    +15   * software distributed under the License is distributed on an
    +16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +17   * KIND, either express or implied.  See the License for the
    +18   * specific language governing permissions and limitations
    +19   * under the License.
    +20   */
    +21  
    +22  import java.util.ArrayList;
    +23  import java.util.HashMap;
    +24  import java.util.List;
    +25  import java.util.Map;
    +26  
    +27  import org.apache.helix.HelixDefinedState;
    +28  import org.apache.helix.ZNRecord;
    +29  import org.apache.helix.model.StateModelDefinition.StateModelDefinitionProperty;
    +30  import org.apache.helix.tools.StateModelConfigGenerator;
    +31  import org.testng.Assert;
    +32  import org.testng.annotations.Test;
    +33  
    +34  import com.google.common.collect.Lists;
    +35  
    +36  public class TestStateModelValidity {
    +37    /**
    +38     * Ensure that state models that we know to be good pass validation
    +39     */
    +40    @Test
    +41    public void testValidModels() {
    +42      StateModelDefinition masterSlave =
    +43          new StateModelDefinition(StateModelConfigGenerator.generateConfigForMasterSlave());
    +44      Assert.assertTrue(masterSlave.isValid());
    +45  
    +46      StateModelDefinition leaderStandby =
    +47          new StateModelDefinition(StateModelConfigGenerator.generateConfigForLeaderStandby());
    +48      Assert.assertTrue(leaderStandby.isValid());
    +49  
    +50      StateModelDefinition onlineOffline =
    +51          new StateModelDefinition(StateModelConfigGenerator.generateConfigForOnlineOffline());
    +52      Assert.assertTrue(onlineOffline.isValid());
    +53    }
    +54  
    +55    /**
    +56     * Ensure that Helix responds negatively if DROPPED is not specified
    +57     */
    +58    @Test
    +59    public void testNoDroppedState() {
    +60      StateModelDefinition stateModel =
    +61          new StateModelDefinition.Builder("stateModel").initialState("OFFLINE").addState("OFFLINE")
    +62              .addState("MASTER").addState("SLAVE").addTransition("OFFLINE", "SLAVE")
    +63              .addTransition("SLAVE", "MASTER").addTransition("MASTER", "SLAVE")
    +64              .addTransition("SLAVE", "OFFLINE").build();
    +65      Assert.assertFalse(stateModel.isValid());
    +66    }
    +67  
    +68    /**
    +69     * Ensure that Helix can catch when a state doesn't have a path to DROPPED
    +70     */
    +71    @Test
    +72    public void testNoPathToDropped() {
    +73      StateModelDefinition stateModel =
    +74          new StateModelDefinition.Builder("stateModel").initialState("OFFLINE").addState("OFFLINE")
    +75              .addState("MASTER").addState("SLAVE").addState("DROPPED")
    +76              .addTransition("OFFLINE", "SLAVE").addTransition("SLAVE", "MASTER")
    +77              .addTransition("SLAVE", "OFFLINE").addTransition("OFFLINE", "DROPPED").build();
    +78      Assert.assertFalse(stateModel.isValid());
    +79  
    +80      // now see that adding MASTER-DROPPED fixes the problem
    +81      stateModel =
    +82          new StateModelDefinition.Builder("stateModel").initialState("OFFLINE").addState("OFFLINE")
    +83              .addState("MASTER").addState("SLAVE").addState("DROPPED")
    +84              .addTransition("OFFLINE", "SLAVE").addTransition("SLAVE", "MASTER")
    +85              .addTransition("SLAVE", "OFFLINE").addTransition("OFFLINE", "DROPPED")
    +86              .addTransition("MASTER", "DROPPED").build();
    +87      Assert.assertTrue(stateModel.isValid());
    +88    }
    +89  
    +90    /**
    +91     * The initial state should be added as a state, otherwise validation check should fail
    +92     */
    +93    @Test
    +94    public void testInitialStateIsNotState() {
    +95      StateModelDefinition stateModel =
    +96          new StateModelDefinition.Builder("stateModel").initialState("OFFLINE").addState("MASTER")
    +97              .addState("SLAVE").addState("DROPPED").addTransition("OFFLINE", "SLAVE")
    +98              .addTransition("SLAVE", "MASTER").addTransition("SLAVE", "OFFLINE")
    +99              .addTransition("OFFLINE", "DROPPED").addTransition("MASTER", "SLAVE").build();
    +100     Assert.assertFalse(stateModel.isValid());
    +101   }
    +102 
    +103   /**
    +104    * There should be an initial state, otherwise instantiation should fail
    +105    */
    +106   @Test
    +107   public void testNoInitialState() {
    +108     try {
    +109       new StateModelDefinition.Builder("stateModel").addState("OFFLINE").addState("MASTER")
    +110           .addState("SLAVE").addState("DROPPED").addTransition("OFFLINE", "SLAVE")
    +111           .addTransition("SLAVE", "MASTER").addTransition("SLAVE", "OFFLINE")
    +112           .addTransition("OFFLINE", "DROPPED").addTransition("MASTER", "SLAVE").build();
    +113       Assert.fail("StateModelDefinition creation should fail if no initial state");
    +114     } catch (IllegalArgumentException e) {
    +115     }
    +116   }
    +117 
    +118   /**
    +119    * SRC and DEST in a transition SRC-TEST must be valid states
    +120    */
    +121   @Test
    +122   public void testTransitionsWithInvalidStates() {
    +123     // invalid to state
    +124     StateModelDefinition stateModel =
    +125         new StateModelDefinition.Builder("stateModel").initialState("OFFLINE").addState("OFFLINE")
    +126             .addState("MASTER").addState("SLAVE").addState("DROPPED")
    +127             .addTransition("OFFLINE", "SLAVE").addTransition("SLAVE", "MASTER")
    +128             .addTransition("SLAVE", "OFFLINE").addTransition("OFFLINE", "DROPPED")
    +129             .addTransition("MASTER", "SLAVE").addTransition("OFFLINE", "INVALID").build();
    +130     Assert.assertFalse(stateModel.isValid());
    +131 
    +132     // invalid from state
    +133     stateModel =
    +134         new StateModelDefinition.Builder("stateModel").initialState("OFFLINE").addState("OFFLINE")
    +135             .addState("MASTER").addState("SLAVE").addState("DROPPED")
    +136             .addTransition("OFFLINE", "SLAVE").addTransition("SLAVE", "MASTER")
    +137             .addTransition("SLAVE", "OFFLINE").addTransition("OFFLINE", "DROPPED")
    +138             .addTransition("MASTER", "SLAVE").addTransition("INVALID", "MASTER").build();
    +139     Assert.assertFalse(stateModel.isValid());
    +140   }
    +141 
    +142   /**
    +143    * The initial state should be able to reach all states, should fail validation otherwise
    +144    */
    +145   @Test
    +146   public void testUnreachableState() {
    +147     StateModelDefinition stateModel =
    +148         new StateModelDefinition.Builder("stateModel").initialState("OFFLINE").addState("OFFLINE")
    +149             .addState("MASTER").addState("SLAVE").addState("DROPPED")
    +150             .addTransition("OFFLINE", "SLAVE").addTransition("SLAVE", "OFFLINE")
    +151             .addTransition("OFFLINE", "DROPPED").addTransition("MASTER", "SLAVE")
    +152             .addTransition("MASTER", "DROPPED").build();
    +153     Assert.assertFalse(stateModel.isValid());
    +154   }
    +155 
    +156   /**
    +157    * The validator should fail on any detected infinite loops
    +158    */
    +159   @Test
    +160   public void testLoopInStateModel() {
    +161     // create an infinite loop ONE --> TWO --> ONE
    +162     ZNRecord record = new ZNRecord("MasterSlave");
    +163     record.setSimpleField(StateModelDefinitionProperty.INITIAL_STATE.toString(), "OFFLINE");
    +164     List<String> statePriorityList =
    +165         Lists.newArrayList("ONE", "TWO", "THREE", "OFFLINE", "DROPPED", "ERROR");
    +166     record.setListField(StateModelDefinitionProperty.STATE_PRIORITY_LIST.toString(),
    +167         statePriorityList);
    +168     for (String state : statePriorityList) {
    +169       String key = state + ".meta";
    +170       Map<String, String> metadata = new HashMap<String, String>();
    +171       metadata.put("count", "-1");
    +172       record.setMapField(key, metadata);
    +173     }
    +174     for (String state : statePriorityList) {
    +175       String key = state + ".next";
    +176       if (state.equals("ONE")) {
    +177         Map<String, String> metadata = new HashMap<String, String>();
    +178         metadata.put("THREE", "TWO");
    +179         metadata.put("TWO", "TWO");
    +180         metadata.put("OFFLINE", "OFFLINE");
    +181         metadata.put("DROPPED", "DROPPED");
    +182         record.setMapField(key, metadata);
    +183       } else if (state.equals("TWO")) {
    +184         Map<String, String> metadata = new HashMap<String, String>();
    +185         metadata.put("THREE", "ONE");
    +186         metadata.put("OFFLINE", "OFFLINE");
    +187         metadata.put("DROPPED", "OFFLINE");
    +188         record.setMapField(key, metadata);
    +189       } else if (state.equals("THREE")) {
    +190         Map<String, String> metadata = new HashMap<String, String>();
    +191         metadata.put("OFFLINE", "OFFLINE");
    +192         metadata.put("DROPPED", "OFFLINE");
    +193         record.setMapField(key, metadata);
    +194       } else if (state.equals("OFFLINE")) {
    +195         Map<String, String> metadata = new HashMap<String, String>();
    +196         metadata.put("ONE", "ONE");
    +197         metadata.put("TWO", "TWO");
    +198         metadata.put("THREE", "THREE");
    +199         metadata.put("DROPPED", "DROPPED");
    +200         record.setMapField(key, metadata);
    +201       } else if (state.equals("ERROR")) {
    +202         Map<String, String> metadata = new HashMap<String, String>();
    +203         metadata.put("OFFLINE", "OFFLINE");
    +204         record.setMapField(key, metadata);
    +205       }
    +206     }
    +207     List<String> stateTransitionPriorityList = new ArrayList<String>();
    +208     record.setListField(StateModelDefinitionProperty.STATE_TRANSITION_PRIORITYLIST.toString(),
    +209         stateTransitionPriorityList);
    +210 
    +211     StateModelDefinition stateModel = new StateModelDefinition(record);
    +212     Assert.assertFalse(stateModel.isValid());
    +213   }
    +214 
    +215   /**
    +216    * This is the example used on the website, so this must work
    +217    */
    +218   @Test
    +219   public void testBasic() {
    +220     StateModelDefinition stateModel = new StateModelDefinition.Builder("MasterSlave")
    +221     // OFFLINE is the state that the system starts in (initial state is REQUIRED)
    +222         .initialState("OFFLINE")
    +223 
    +224         // Lowest number here indicates highest priority, no value indicates lowest priority
    +225         .addState("MASTER", 1).addState("SLAVE", 2).addState("OFFLINE")
    +226 
    +227         // Note the special inclusion of the DROPPED state (REQUIRED)
    +228         .addState(HelixDefinedState.DROPPED.toString())
    +229 
    +230         // No more than one master allowed
    +231         .upperBound("MASTER", 1)
    +232 
    +233         // R indicates an upper bound of number of replicas for each partition
    +234         .dynamicUpperBound("SLAVE", "R")
    +235 
    +236         // Add some high-priority transitions
    +237         .addTransition("SLAVE", "MASTER", 1).addTransition("OFFLINE", "SLAVE", 2)
    +238 
    +239         // Using the same priority value indicates that these transitions can fire in any order
    +240         .addTransition("MASTER", "SLAVE", 3).addTransition("SLAVE", "OFFLINE", 3)
    +241 
    +242         // Not specifying a value defaults to lowest priority
    +243         // Notice the inclusion of the OFFLINE to DROPPED transition
    +244         // Since every state has a path to OFFLINE, they each now have a path to DROPPED (REQUIRED)
    +245         .addTransition("OFFLINE", HelixDefinedState.DROPPED.toString())
    +246 
    +247         // Create the StateModelDefinition instance
    +248         .build();
    +249 
    +250     Assert.assertTrue(stateModel.isValid());
    +251   }
    +252 }
    +
    +
    + Modified: incubator/helix/site-content/xref-test/org/apache/helix/model/package-frame.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref-test/org/apache/helix/model/package-frame.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/xref-test/org/apache/helix/model/package-frame.html (original) +++ incubator/helix/site-content/xref-test/org/apache/helix/model/package-frame.html Thu Oct 17 21:43:06 2013 @@ -24,6 +24,9 @@
  • TestInstanceConfig
  • +
  • + TestStateModelValidity +
  • Modified: incubator/helix/site-content/xref-test/org/apache/helix/model/package-summary.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref-test/org/apache/helix/model/package-summary.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/xref-test/org/apache/helix/model/package-summary.html (original) +++ incubator/helix/site-content/xref-test/org/apache/helix/model/package-summary.html Thu Oct 17 21:43:06 2013 @@ -50,6 +50,11 @@ TestInstanceConfig + + + TestStateModelValidity + + Modified: incubator/helix/site-content/xref/allclasses-frame.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref/allclasses-frame.html?rev=1533269&r1=1533268&r2=1533269&view=diff ============================================================================== --- incubator/helix/site-content/xref/allclasses-frame.html (original) +++ incubator/helix/site-content/xref/allclasses-frame.html Thu Oct 17 21:43:06 2013 @@ -1206,6 +1206,9 @@ StateModelDefinitionProperty
  • + StateModelDefinitionValidator +
  • +
  • StateModelFactory