[
https://issues.apache.org/jira/browse/KAFKA-5258?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Onur Karaman updated KAFKA-5258:
--------------------------------
Description:
Today the PartitionStateMachine and ReplicaStateMachine defines and asserts the
valid state transitions inline for each state, looking something like:
{code}
private def handleStateChange(...) {
targetState match {
case stateA => {
assertValidPreviousStates(topicAndPartition, List(stateX, stateY,
stateZ), stateA)
// actual work
}
case stateB => {
assertValidPreviousStates(topicAndPartition, List(stateD, stateE), stateB)
// actual work
}
}
}
{code}
It would be cleaner to move all partition and replica state transition rules
into their and simply do the assertion at the top of the handleStateChange
method like so:
{code}
private def handleStateChange(...) {
assertValidTransition(targetState)
targetState match {
case stateA => {
// actual work
}
case stateB => {
// actual work
}
}
}
sealed trait State {
def state: Byte
def validPreviousStates: Set[State]
}
case object StateA extends State {
val state: Byte = 1
val validPreviousStates: Set[State] = Set(StateX)
}
case object StateB extends State {
val state: Byte = 2
val validPreviousStates: Set[State] = Set(StateX, StateY, StateZ)
}
{code}
was:
Today the PartitionStateMachine and ReplicaStateMachine defines and asserts the
valid state transitions inline for each state, looking something like:
{code}
private def handleStateChange(...) {
targetState match {
case stateA => {
assertValidPreviousStates(topicAndPartition, List(stateX, stateY,
stateZ), stateA)
// actual work
}
case stateB => {
assertValidPreviousStates(topicAndPartition, List(stateD, stateE), stateB)
// actual work
}
}
}
{code}
It would be cleaner to move all partition and replica state transition rules
into a map and simply do the assertion at the top of the handleStateChange
method like so:
{code}
private val validPreviousStates: Map[State, Set[State]] = ...
private def handleStateChange(...) {
assertValidTransition(targetState)
targetState match {
case stateA => {
// actual work
}
case stateB => {
// actual work
}
}
}
{code}
> move all partition and replica state transition rules into their states
> -----------------------------------------------------------------------
>
> Key: KAFKA-5258
> URL: https://issues.apache.org/jira/browse/KAFKA-5258
> Project: Kafka
> Issue Type: Sub-task
> Reporter: Onur Karaman
> Assignee: Onur Karaman
> Priority: Minor
>
> Today the PartitionStateMachine and ReplicaStateMachine defines and asserts
> the valid state transitions inline for each state, looking something like:
> {code}
> private def handleStateChange(...) {
> targetState match {
> case stateA => {
> assertValidPreviousStates(topicAndPartition, List(stateX, stateY,
> stateZ), stateA)
> // actual work
> }
> case stateB => {
> assertValidPreviousStates(topicAndPartition, List(stateD, stateE),
> stateB)
> // actual work
> }
> }
> }
> {code}
> It would be cleaner to move all partition and replica state transition rules
> into their and simply do the assertion at the top of the handleStateChange
> method like so:
> {code}
> private def handleStateChange(...) {
> assertValidTransition(targetState)
> targetState match {
> case stateA => {
> // actual work
> }
> case stateB => {
> // actual work
> }
> }
> }
> sealed trait State {
> def state: Byte
> def validPreviousStates: Set[State]
> }
> case object StateA extends State {
> val state: Byte = 1
> val validPreviousStates: Set[State] = Set(StateX)
> }
> case object StateB extends State {
> val state: Byte = 2
> val validPreviousStates: Set[State] = Set(StateX, StateY, StateZ)
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)