You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.1 KiB

Merge accumulated changes related to message queue (#5098) * balance partitions on brokers * prepare topic partition first and then publish, move partition * purge unused APIs * clean up * adjust logs * add BalanceTopics() grpc API * configure topic * configure topic command * refactor * repair missing partitions * sequence of operations to ensure ordering * proto to close publishers and consumers * rename file * topic partition versioned by unixTimeNs * create local topic partition * close publishers * randomize the client name * wait until no publishers * logs * close stop publisher channel * send last ack * comments * comment * comments * support list of brokers * add cli options * Update .gitignore * logs * return io.eof directly * refactor * optionally create topic * refactoring * detect consumer disconnection * sub client wait for more messages * subscribe by time stamp * rename * rename to sub_balancer * rename * adjust comments * rename * fix compilation * rename * rename * SubscriberToSubCoordinator * sticky rebalance * go fmt * add tests * balance partitions on brokers * prepare topic partition first and then publish, move partition * purge unused APIs * clean up * adjust logs * add BalanceTopics() grpc API * configure topic * configure topic command * refactor * repair missing partitions * sequence of operations to ensure ordering * proto to close publishers and consumers * rename file * topic partition versioned by unixTimeNs * create local topic partition * close publishers * randomize the client name * wait until no publishers * logs * close stop publisher channel * send last ack * comments * comment * comments * support list of brokers * add cli options * Update .gitignore * logs * return io.eof directly * refactor * optionally create topic * refactoring * detect consumer disconnection * sub client wait for more messages * subscribe by time stamp * rename * rename to sub_balancer * rename * adjust comments * rename * fix compilation * rename * rename * SubscriberToSubCoordinator * sticky rebalance * go fmt * add tests * tracking topic=>broker * merge * comment
1 year ago
  1. package topic
  2. import "sync"
  3. type LocalPartitionPublishers struct {
  4. publishers map[string]*LocalPublisher
  5. publishersLock sync.RWMutex
  6. }
  7. type LocalPublisher struct {
  8. }
  9. func NewLocalPublisher() *LocalPublisher {
  10. return &LocalPublisher{}
  11. }
  12. func (p *LocalPublisher) SignalShutdown() {
  13. }
  14. func NewLocalPartitionPublishers() *LocalPartitionPublishers {
  15. return &LocalPartitionPublishers{
  16. publishers: make(map[string]*LocalPublisher),
  17. }
  18. }
  19. func (p *LocalPartitionPublishers) AddPublisher(clientName string, publisher *LocalPublisher) {
  20. p.publishersLock.Lock()
  21. defer p.publishersLock.Unlock()
  22. p.publishers[clientName] = publisher
  23. }
  24. func (p *LocalPartitionPublishers) RemovePublisher(clientName string) {
  25. p.publishersLock.Lock()
  26. defer p.publishersLock.Unlock()
  27. delete(p.publishers, clientName)
  28. }
  29. func (p *LocalPartitionPublishers) SignalShutdown() {
  30. p.publishersLock.RLock()
  31. defer p.publishersLock.RUnlock()
  32. for _, publisher := range p.publishers {
  33. publisher.SignalShutdown()
  34. }
  35. }
  36. func (p *LocalPartitionPublishers) IsEmpty() bool {
  37. p.publishersLock.RLock()
  38. defer p.publishersLock.RUnlock()
  39. return len(p.publishers) == 0
  40. }