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.

62 lines
1.3 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
2 years ago
  1. package mq
  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 Namespace string
  9. type Topic struct {
  10. Namespace Namespace
  11. Name string
  12. }
  13. type Partition struct {
  14. RangeStart int32
  15. RangeStop int32 // exclusive
  16. RingSize int32
  17. }
  18. type Segment struct {
  19. Topic Topic
  20. Id int32
  21. Partition Partition
  22. LastModified time.Time
  23. }
  24. func FromPbSegment(segment *mq_pb.Segment) *Segment {
  25. return &Segment{
  26. Topic: Topic{
  27. Namespace: Namespace(segment.Namespace),
  28. Name: segment.Topic,
  29. },
  30. Id: segment.Id,
  31. Partition: Partition{
  32. RangeStart: segment.Partition.RangeStart,
  33. RangeStop: segment.Partition.RangeStop,
  34. RingSize: segment.Partition.RingSize,
  35. },
  36. }
  37. }
  38. func (segment *Segment) ToPbSegment() *mq_pb.Segment {
  39. return &mq_pb.Segment{
  40. Namespace: string(segment.Topic.Namespace),
  41. Topic: segment.Topic.Name,
  42. Id: segment.Id,
  43. Partition: &mq_pb.Partition{
  44. RingSize: segment.Partition.RingSize,
  45. RangeStart: segment.Partition.RangeStart,
  46. RangeStop: segment.Partition.RangeStop,
  47. },
  48. }
  49. }
  50. func (segment *Segment) DirAndName() (dir string, name string) {
  51. dir = fmt.Sprintf("%s/%s/%s", filer.TopicsDir, segment.Topic.Namespace, segment.Topic.Name)
  52. name = fmt.Sprintf("%4d.segment", segment.Id)
  53. return
  54. }