Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Make kafka-cluster chunk save messages partition aware. #472

Merged
merged 1 commit into from Jan 18, 2017

Conversation

woodsaj
Copy link
Member

@woodsaj woodsaj commented Jan 13, 2017

  • Move partition fetching/validation to shared kafka lib
  • Refactor sending MetricPersist messages to set the correct
    PartitionKey.
  • Update consumer to only consume from configured partitions

Issue #452

@woodsaj woodsaj force-pushed the partitionedNotifyKafka branch 2 times, most recently from c0a9918 to b0226dc Compare January 16, 2017 03:18
log.Info("kafka-mdm: available partitions %v", availParts)
if partitionStr == "*" {
partitions = availParts
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like the whole block in the if on lines 111 - 118 could be moved in here and that if could be dropped, that would safe an if. On the other hand it would instantiate sarama even if the defined partitionStr has an invalid format, but I'd just assume the format should be right in the "normal" case.

Copy link
Member Author

Choose a reason for hiding this comment

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

good call. i have made that change.

return nil, fmt.Errorf("No partitions returned for topic %s", topic)
}
if i > 0 {
if len(partitions) != partitionCount {
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't there also be a check to verify that all topics are using the same set of partitions? otherwise GetPartitions() will always just return the partitions of the last topic in topics.

Copy link
Member Author

Choose a reason for hiding this comment

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

Kafka uses sequential partition numbers. So if the partitionCount is the same, then the partitions will also be the same.

log.Debug("kafka-notifier sending %d batch metricPersist messages", len(msg.SavedChunks))

data, err := json.Marshal(&msg)
// In order to correctly routes the saveMessages to the correct partition,
Copy link
Contributor

Choose a reason for hiding this comment

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

route without s

binary.Write(buf, binary.LittleEndian, uint8(mdata.PersistMessageBatchV1))
buf.Write(data)
encoder := json.NewEncoder(buf)
pMsg = mdata.PersistMessageBatch{Instance: c.instance, SavedChunks: c.buf[i:i]}
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm confused about [i:i], wouldn't that always return an empty list? should that be [i:i+1]?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, that should definitely be [i:i+1]

@woodsaj woodsaj force-pushed the partitionedNotifyKafka branch 2 times, most recently from 2ea6951 to c428c3d Compare January 17, 2017 19:10
- Move partition fetching/validation to shared kafka lib
- Refactor sending MetricPersist messages to set the correct
  PartitionKey.
- Update consumer to only consume from configured partitions
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants