refactor TopicPartition struct

This commit is contained in:
chrislu
2023-10-02 01:01:45 -07:00
parent 2a578b9033
commit 734178093e
6 changed files with 18 additions and 24 deletions

View File

@@ -75,10 +75,12 @@ func (manager *LocalTopicManager) CollectStats(duration time.Duration) *mq_pb.Br
manager.topics.IterCb(func(topic string, localTopic *LocalTopic) {
for _, localPartition := range localTopic.Partitions {
topicPartition := &TopicPartition{
Namespace: string(localTopic.Namespace),
Topic: localTopic.Name,
RangeStart: localPartition.RangeStart,
RangeStop: localPartition.RangeStop,
Topic: Topic{Namespace: localTopic.Namespace, Name: localTopic.Name},
Partition: Partition{
RingSize: localPartition.RingSize,
RangeStart: localPartition.RangeStart,
RangeStop: localPartition.RangeStop,
},
}
stats.Stats[topicPartition.String()] = &mq_pb.TopicPartitionStats{
Topic: &mq_pb.Topic{

View File

@@ -7,14 +7,12 @@ import (
"time"
)
type Namespace string
type Topic struct {
Namespace Namespace
Namespace string
Name string
}
func NewTopic(namespace Namespace, name string) Topic {
func NewTopic(namespace string, name string) Topic {
return Topic{
Namespace: namespace,
Name: name,
@@ -22,7 +20,7 @@ func NewTopic(namespace Namespace, name string) Topic {
}
func FromPbTopic(topic *mq_pb.Topic) Topic {
return Topic{
Namespace: Namespace(topic.Namespace),
Namespace: topic.Namespace,
Name: topic.Name,
}
}
@@ -41,7 +39,7 @@ type Segment struct {
func FromPbSegment(segment *mq_pb.Segment) *Segment {
return &Segment{
Topic: Topic{
Namespace: Namespace(segment.Namespace),
Namespace: segment.Namespace,
Name: segment.Topic,
},
Id: segment.Id,

View File

@@ -3,10 +3,8 @@ package topic
import "fmt"
type TopicPartition struct {
Namespace string
Topic string
RangeStart int32
RangeStop int32
Topic
Partition
}
func (tp *TopicPartition) String() string {