Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAFKA-5258: move all partition and replica state transition rules into their states #3071

Closed
wants to merge 2 commits into from

Conversation

onurkaraman
Copy link
Contributor

Today the PartitionStateMachine and ReplicaStateMachine defines and asserts the valid state transitions inline for each state. 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.

@asfbot
Copy link

asfbot commented May 16, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/4007/
Test PASSed (JDK 8 and Scala 2.12).

@asfbot
Copy link

asfbot commented May 16, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.11/4021/
Test PASSed (JDK 7 and Scala 2.11).

@onurkaraman
Copy link
Contributor Author

@ijuma @junrao can you take a look?

Map(NewPartition -> Set(NonExistentPartition),
OnlinePartition -> Set(NewPartition, OnlinePartition, OfflinePartition),
OfflinePartition -> Set(NewPartition, OnlinePartition, OfflinePartition),
NonExistentPartition -> Set(OfflinePartition))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider defining this in the PartitionState types? For example:

case object NewPartition extends PartitionState {
  val state: Byte = 0
  val validPreviousStates = Set(NonExistentPartition)
}

If a new state is added, it will be clear (i.e. there will be a compiler error) that this method needs to be implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! I'll make the change.

…o their states

Today the PartitionStateMachine and ReplicaStateMachine defines and asserts the valid state transitions inline for each state. It would be cleaner to move all partition and replica state transition rules into their states and simply do the assertion at the top of the handleStateChange.
@onurkaraman onurkaraman changed the title KAFKA-5258: move all partition and replica state transition rules into a map KAFKA-5258: move all partition and replica state transition rules into their states May 17, 2017
@asfbot
Copy link

asfbot commented May 17, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.11/4082/
Test PASSed (JDK 7 and Scala 2.11).

@asfbot
Copy link

asfbot commented May 17, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/4068/
Test FAILed (JDK 8 and Scala 2.12).

@@ -146,18 +146,17 @@ class PartitionStateMachine(controller: KafkaController) extends Logging {
val topicAndPartition = TopicAndPartition(topic, partition)
val currState = partitionState.getOrElseUpdate(topicAndPartition, NonExistentPartition)
try {
assertValidTransition(topicAndPartition, targetState)
targetState match {
case NewPartition =>
// pre: partition did not exist before this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, should we remove all the pre comments? It seems like they duplicate what's encoded as the validPreviousStates. Also, if we want to add comments, we should add them in validPreviousStates as they are less likely to get out of date there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with either option. Which do you prefer? By the way, sometimes there are post comments as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the pre comments just repeat what's in the code (which was the case for the ones I checked), I'd personally remove them. I saw the post comments as well. Since this PR is only about the valid transition states, I'd be OK with keeping things as they are for the post comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@asfbot
Copy link

asfbot commented May 18, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/4118/
Test PASSed (JDK 8 and Scala 2.12).

@asfbot
Copy link

asfbot commented May 18, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.11/4131/
Test PASSed (JDK 7 and Scala 2.11).

Copy link
Contributor

@ijuma ijuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, LGTM.

@asfgit asfgit closed this in 5aaaba7 May 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants