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.

69 lines
1.7 KiB

2 years ago
2 years ago
2 years ago
2 years ago
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
2 years ago
2 years ago
2 years ago
  1. package topic
  2. import (
  3. "bytes"
  4. "errors"
  5. "fmt"
  6. "github.com/seaweedfs/seaweedfs/weed/filer"
  7. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  8. "github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
  9. jsonpb "google.golang.org/protobuf/encoding/protojson"
  10. )
  11. type Topic struct {
  12. Namespace string
  13. Name string
  14. }
  15. func NewTopic(namespace string, name string) Topic {
  16. return Topic{
  17. Namespace: namespace,
  18. Name: name,
  19. }
  20. }
  21. func FromPbTopic(topic *mq_pb.Topic) Topic {
  22. return Topic{
  23. Namespace: topic.Namespace,
  24. Name: topic.Name,
  25. }
  26. }
  27. func (t Topic) ToPbTopic() *mq_pb.Topic {
  28. return &mq_pb.Topic{
  29. Namespace: t.Namespace,
  30. Name: t.Name,
  31. }
  32. }
  33. func (t Topic) String() string {
  34. return fmt.Sprintf("%s.%s", t.Namespace, t.Name)
  35. }
  36. func (t Topic) Dir() string {
  37. return fmt.Sprintf("%s/%s/%s", filer.TopicsDir, t.Namespace, t.Name)
  38. }
  39. func (t Topic) ReadConfFile(client filer_pb.SeaweedFilerClient) (*mq_pb.ConfigureTopicResponse, error) {
  40. data, err := filer.ReadInsideFiler(client, t.Dir(), filer.TopicConfFile)
  41. if errors.Is(err, filer_pb.ErrNotFound) {
  42. return nil, err
  43. }
  44. if err != nil {
  45. return nil, fmt.Errorf("read topic.conf of %v: %v", t, err)
  46. }
  47. // parse into filer conf object
  48. conf := &mq_pb.ConfigureTopicResponse{}
  49. if err = jsonpb.Unmarshal(data, conf); err != nil {
  50. return nil, fmt.Errorf("unmarshal topic %v conf: %v", t, err)
  51. }
  52. return conf, nil
  53. }
  54. func (t Topic) WriteConfFile(client filer_pb.SeaweedFilerClient, conf *mq_pb.ConfigureTopicResponse) error {
  55. var buf bytes.Buffer
  56. filer.ProtoToText(&buf, conf)
  57. if err := filer.SaveInsideFiler(client, t.Dir(), filer.TopicConfFile, buf.Bytes()); err != nil {
  58. return fmt.Errorf("save topic %v conf: %v", t, err)
  59. }
  60. return nil
  61. }