[ 
https://issues.apache.org/jira/browse/HELIX-144?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13719050#comment-13719050
 ] 

kishore gopalakrishna commented on HELIX-144:
---------------------------------------------

Here is the clojure version from Kyle on validating the statemodel.

https://gist.github.com/aphyr/ab2d1cd9da8879b408b2

We should also take in the statemodel class and verify that it confirms to this 
FSM

(defn fsm-definition
  "An FSM definition is a named collection of states, describing their
  priorities, transitions, constraints, etc. It looks like: 
    
  {:name   :my-fsm
   :states {:master {:priority 1
                     :transitions :slave
                     :upper-bound 1}
            :slave  {:priority 2
                     :transitions [:master :offline]
                     :upper-bound :R}
            :offline {:transitions :slave
                      :initial? true}}})
 
  This function validates the structure of an FSM definition, blessing it for
  use later."
  [d]
  ; Has a name
  (assert (or (string? (:name d))
              (keyword? (:name d))))
 
  (let [states (:states d)]
    ; Has states
    (assert (map? states))
 
    ; Normalize transitions
    (let [states (->> states
                      (map (fn [[k v]]
                             [k (assoc v :transitions
                                       (let [t (:transitions v)]
                                         (cond
                                           (nil? t) []
                                           (sequential? t) t
                                           :else [t])))]))
                      (into {}))
 
          ; Compute all state names
          state-names (->> (keys states)
                           (concat (mapcat :transitions (vals states)))
                           (remove nil?)
                           set)]
 
      ; Exactly one initial state.
      (let [initials (->> d :states vals (filter :initial?) count)]
        (assert (= 1 initials) 
                (str "needs exactly one initial state; has " initials)))
              
      ; Validate state names
      (dorun (map validate-state-name state-names))
 
      ; Has a DROPPED state
      (assert (:DROPPED states) "must have a :DROPPED state")
 
      ; All states can reach DROPPED
      (doseq [state state-names]
        (assert (contains? (reachable-states {:states states} state)
                         :DROPPED)
                (str "state " state " has no path to :DROPPED")))
 
      ; No transitions to states that aren't defined.
      (assert (= state-names (set (keys states))))
 
      ; Done
      (assoc d :states states))))



                
> Need to validate StateModelDefinition when adding new StateModelDefinition to 
> Cluster
> -------------------------------------------------------------------------------------
>
>                 Key: HELIX-144
>                 URL: https://issues.apache.org/jira/browse/HELIX-144
>             Project: Apache Helix
>          Issue Type: Bug
>            Reporter: dafu
>
> we see that when DROPPED state is not in the StateModelDefinition, partition 
> will fail to be dropped. this causes problem when we are using auto_rebalance 
> mode, because we are dropping mappings and assign new mappings to nodes. 
> things need to verify:
> 1) state transitions are all valid, no self loop/loop, no unreachable state
> 2) state meta is valid
> 3) drop state included

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to