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.

71 lines
1.5 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. package topic
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/filer"
  5. "github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
  6. "time"
  7. )
  8. type Topic struct {
  9. Namespace string
  10. Name string
  11. }
  12. func NewTopic(namespace string, name string) Topic {
  13. return Topic{
  14. Namespace: namespace,
  15. Name: name,
  16. }
  17. }
  18. func FromPbTopic(topic *mq_pb.Topic) Topic {
  19. return Topic{
  20. Namespace: topic.Namespace,
  21. Name: topic.Name,
  22. }
  23. }
  24. func (tp Topic) String() string {
  25. return fmt.Sprintf("%s.%s", tp.Namespace, tp.Name)
  26. }
  27. type Segment struct {
  28. Topic Topic
  29. Id int32
  30. Partition Partition
  31. LastModified time.Time
  32. }
  33. func FromPbSegment(segment *mq_pb.Segment) *Segment {
  34. return &Segment{
  35. Topic: Topic{
  36. Namespace: segment.Namespace,
  37. Name: segment.Topic,
  38. },
  39. Id: segment.Id,
  40. Partition: Partition{
  41. RangeStart: segment.Partition.RangeStart,
  42. RangeStop: segment.Partition.RangeStop,
  43. RingSize: segment.Partition.RingSize,
  44. },
  45. }
  46. }
  47. func (segment *Segment) ToPbSegment() *mq_pb.Segment {
  48. return &mq_pb.Segment{
  49. Namespace: string(segment.Topic.Namespace),
  50. Topic: segment.Topic.Name,
  51. Id: segment.Id,
  52. Partition: &mq_pb.Partition{
  53. RingSize: segment.Partition.RingSize,
  54. RangeStart: segment.Partition.RangeStart,
  55. RangeStop: segment.Partition.RangeStop,
  56. },
  57. }
  58. }
  59. func (segment *Segment) DirAndName() (dir string, name string) {
  60. dir = fmt.Sprintf("%s/%s/%s", filer.TopicsDir, segment.Topic.Namespace, segment.Topic.Name)
  61. name = fmt.Sprintf("%4d.segment", segment.Id)
  62. return
  63. }