Skip to content

KAFKA-8333; Cache checkpointed high watermarks for reuse on LeaderAndIsr request#6696

Closed
hachikuji wants to merge 1 commit into
apache:trunkfrom
hachikuji:KAFKA-8333
Closed

KAFKA-8333; Cache checkpointed high watermarks for reuse on LeaderAndIsr request#6696
hachikuji wants to merge 1 commit into
apache:trunkfrom
hachikuji:KAFKA-8333

Conversation

@hachikuji

@hachikuji hachikuji commented May 8, 2019

Copy link
Copy Markdown
Contributor

Currently we load the high watermark checkpoint file separately for every partition that is loaded on a broker. This patch adds logic to load the checkpoint file only once when a LeaderAndIsr request is received. The results are reused for all partitions included in the request.

Additionally, this patch removes the dependence on ReplicaManager inside Partition, which should make testing easier. I have also simplified the future replica loading logic since it was unnecessarily loading the checkpoint file.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@hachikuji
hachikuji force-pushed the KAFKA-8333 branch 2 times, most recently from 2004b6c to 885d7ae Compare May 9, 2019 01:20

@mumrah mumrah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good all around. Abstracting ZK, removing ReplicaManager and isOffline from Partition, this will definitely help reduce mocking in tests. I'm always a fan of polymorphism over endless conditional checks scattered everywhere (e.g., if (!isOffline)). Only a few comments in-line.

private val tags = Map("topic" -> topic, "partition" -> partitionId.toString)

// Do not create metrics if this partition is ReplicaManager.OfflinePartition
if (!isOffline) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So we're able to remove the isOffline flag here due to the new OfflinePartition in ReplicaManager (which does not include a Partition instance)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is something I've been meaning to do for quite a while. The sentinel we had before is just a bad practice.

}
}

// Visible for testing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have an annotation like Guava's @VisibleForTesting? I always preferred that to comments

def makeLeader(controllerId: Int,
partitionStateInfo: LeaderAndIsrRequest.PartitionState,
correlationId: Int,
highWatermarkCheckpoint: LazyOffsetCheckpoints): Boolean = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we add a simple trait for LazyOffsetCheckpoints? I see that it gets used in lots of method calls, but would probably simplify testing it we had an interface to provide fetch(String, TopicPartition): Option[Long]

}
private def shrinkIsr(newIsr: Set[Replica]): Unit = {
val newLeaderAndIsr = new LeaderAndIsr(localBrokerId, leaderEpoch, newIsr.map(_.brokerId).toList, zkVersion)
val zkVersionOpt = stateStore.shrinkIsr(controllerEpoch, newLeaderAndIsr)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Drop the "zk" name here? (since stateStore is now abstracted from ZK)

@hachikuji

Copy link
Copy Markdown
Contributor Author

@mumrah Thanks for the review. I think I am going to try and separate the refactor into another patch to make review a bit easier.

@hachikuji

Copy link
Copy Markdown
Contributor Author

Going to close this and open a new PR since #6705 was merged.

@hachikuji hachikuji closed this May 23, 2019
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.

2 participants