|
@ -5,6 +5,7 @@ import "sync" |
|
|
type LocalTopic struct { |
|
|
type LocalTopic struct { |
|
|
Topic |
|
|
Topic |
|
|
Partitions []*LocalPartition |
|
|
Partitions []*LocalPartition |
|
|
|
|
|
partitionLock sync.RWMutex |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NewLocalTopic(topic Topic) *LocalTopic { |
|
|
func NewLocalTopic(topic Topic) *LocalTopic { |
|
@ -15,6 +16,9 @@ func NewLocalTopic(topic Topic) *LocalTopic { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (localTopic *LocalTopic) findPartition(partition Partition) *LocalPartition { |
|
|
func (localTopic *LocalTopic) findPartition(partition Partition) *LocalPartition { |
|
|
|
|
|
localTopic.partitionLock.RLock() |
|
|
|
|
|
defer localTopic.partitionLock.RUnlock() |
|
|
|
|
|
|
|
|
for _, localPartition := range localTopic.Partitions { |
|
|
for _, localPartition := range localTopic.Partitions { |
|
|
if localPartition.Partition.Equals(partition) { |
|
|
if localPartition.Partition.Equals(partition) { |
|
|
return localPartition |
|
|
return localPartition |
|
@ -23,6 +27,9 @@ func (localTopic *LocalTopic) findPartition(partition Partition) *LocalPartition |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
func (localTopic *LocalTopic) removePartition(partition Partition) bool { |
|
|
func (localTopic *LocalTopic) removePartition(partition Partition) bool { |
|
|
|
|
|
localTopic.partitionLock.Lock() |
|
|
|
|
|
defer localTopic.partitionLock.Unlock() |
|
|
|
|
|
|
|
|
foundPartitionIndex := -1 |
|
|
foundPartitionIndex := -1 |
|
|
for i, localPartition := range localTopic.Partitions { |
|
|
for i, localPartition := range localTopic.Partitions { |
|
|
if localPartition.Partition.Equals(partition) { |
|
|
if localPartition.Partition.Equals(partition) { |
|
@ -37,10 +44,14 @@ func (localTopic *LocalTopic) removePartition(partition Partition) bool { |
|
|
localTopic.Partitions = append(localTopic.Partitions[:foundPartitionIndex], localTopic.Partitions[foundPartitionIndex+1:]...) |
|
|
localTopic.Partitions = append(localTopic.Partitions[:foundPartitionIndex], localTopic.Partitions[foundPartitionIndex+1:]...) |
|
|
return true |
|
|
return true |
|
|
} |
|
|
} |
|
|
func (localTopic *LocalTopic) AddPartition(localPartition *LocalPartition) { |
|
|
|
|
|
if localTopic.findPartition(localPartition.Partition) != nil { |
|
|
|
|
|
|
|
|
func (localTopic *LocalTopic) addPartition(localPartition *LocalPartition) { |
|
|
|
|
|
localTopic.partitionLock.Lock() |
|
|
|
|
|
defer localTopic.partitionLock.Unlock() |
|
|
|
|
|
for _, partition := range localTopic.Partitions { |
|
|
|
|
|
if localPartition.Partition.Equals(partition.Partition) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
localTopic.Partitions = append(localTopic.Partitions, localPartition) |
|
|
localTopic.Partitions = append(localTopic.Partitions, localPartition) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|