github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/topic/topictypes/topictypes.go (about) 1 package topictypes 2 3 import ( 4 "time" 5 6 "github.com/ydb-platform/ydb-go-sdk/v3/internal/clone" 7 "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic" 8 "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopiccommon" 9 ) 10 11 // Codec code for use in topics 12 // Allow to use custom values in interval [10000,20000) 13 type Codec int32 14 15 const ( 16 CodecRaw = Codec(rawtopiccommon.CodecRaw) 17 CodecGzip = Codec(rawtopiccommon.CodecGzip) 18 19 // CodecLzop not supported by default, customer need provide own codec library 20 CodecLzop = Codec(rawtopiccommon.CodecLzop) 21 22 // CodecZstd not supported by default, customer need provide own codec library 23 CodecZstd = Codec(rawtopiccommon.CodecZstd) 24 25 CodecCustomerFirst = Codec(rawtopiccommon.CodecCustomerFirst) 26 CodecCustomerEnd = Codec(rawtopiccommon.CodecCustomerEnd) // last allowed custom codec id is CodecCustomerEnd-1 27 ) 28 29 func (c Codec) ToRaw(r *rawtopiccommon.Codec) { 30 *r = rawtopiccommon.Codec(c) 31 } 32 33 // Consumer contains info about topic consumer 34 type Consumer struct { 35 Name string 36 Important bool 37 SupportedCodecs []Codec 38 ReadFrom time.Time 39 Attributes map[string]string 40 } 41 42 // ToRaw public format to internal. Used internally only. 43 func (c *Consumer) ToRaw(raw *rawtopic.Consumer) { 44 raw.Name = c.Name 45 raw.Important = c.Important 46 raw.Attributes = c.Attributes 47 48 raw.SupportedCodecs = make(rawtopiccommon.SupportedCodecs, len(c.SupportedCodecs)) 49 for index, codec := range c.SupportedCodecs { 50 raw.SupportedCodecs[index] = rawtopiccommon.Codec(codec) 51 } 52 53 if !c.ReadFrom.IsZero() { 54 raw.ReadFrom.HasValue = true 55 raw.ReadFrom.Value = c.ReadFrom 56 } 57 raw.Attributes = c.Attributes 58 } 59 60 // FromRaw convert internal format to public. Used internally only. 61 func (c *Consumer) FromRaw(raw *rawtopic.Consumer) { 62 c.Attributes = raw.Attributes 63 c.Important = raw.Important 64 c.Name = raw.Name 65 66 c.SupportedCodecs = make([]Codec, len(raw.SupportedCodecs)) 67 for index, codec := range raw.SupportedCodecs { 68 c.SupportedCodecs[index] = Codec(codec) 69 } 70 71 if raw.ReadFrom.HasValue { 72 c.ReadFrom = raw.ReadFrom.Value 73 } 74 } 75 76 // MeteringMode mode of topic's metering. Used for serverless installations. 77 type MeteringMode int 78 79 const ( 80 MeteringModeUnspecified = MeteringMode(rawtopic.MeteringModeUnspecified) 81 MeteringModeReservedCapacity = MeteringMode(rawtopic.MeteringModeReservedCapacity) 82 MeteringModeRequestUnits = MeteringMode(rawtopic.MeteringModeRequestUnits) 83 ) 84 85 // FromRaw convert from internal format to public. Used internally only. 86 func (m *MeteringMode) FromRaw(raw rawtopic.MeteringMode) { 87 *m = MeteringMode(raw) 88 } 89 90 // ToRaw convert from public format to internal. Used internally only. 91 func (m *MeteringMode) ToRaw(raw *rawtopic.MeteringMode) { 92 *raw = rawtopic.MeteringMode(*m) 93 } 94 95 // PartitionSettings settings of partitions 96 type PartitionSettings struct { 97 MinActivePartitions int64 98 PartitionCountLimit int64 99 } 100 101 // ToRaw convert public format to internal. Used internally only. 102 func (s *PartitionSettings) ToRaw(raw *rawtopic.PartitioningSettings) { 103 raw.MinActivePartitions = s.MinActivePartitions 104 raw.PartitionCountLimit = s.PartitionCountLimit 105 } 106 107 // FromRaw convert internal format to public. Used internally only. 108 func (s *PartitionSettings) FromRaw(raw *rawtopic.PartitioningSettings) { 109 s.MinActivePartitions = raw.MinActivePartitions 110 s.PartitionCountLimit = raw.PartitionCountLimit 111 } 112 113 // TopicDescription contains info about topic. 114 type TopicDescription struct { 115 Path string 116 PartitionSettings PartitionSettings 117 Partitions []PartitionInfo 118 RetentionPeriod time.Duration 119 RetentionStorageMB int64 120 SupportedCodecs []Codec 121 PartitionWriteBurstBytes int64 122 PartitionWriteSpeedBytesPerSecond int64 123 Attributes map[string]string 124 Consumers []Consumer 125 MeteringMode MeteringMode 126 } 127 128 // FromRaw convert from public format to internal. Used internally only. 129 func (d *TopicDescription) FromRaw(raw *rawtopic.DescribeTopicResult) { 130 d.Path = raw.Self.Name 131 d.PartitionSettings.FromRaw(&raw.PartitioningSettings) 132 133 d.Partitions = make([]PartitionInfo, len(raw.Partitions)) 134 for i := range raw.Partitions { 135 d.Partitions[i].FromRaw(&raw.Partitions[i]) 136 } 137 138 d.RetentionPeriod = raw.RetentionPeriod 139 d.RetentionStorageMB = raw.RetentionStorageMB 140 141 d.SupportedCodecs = make([]Codec, len(raw.SupportedCodecs)) 142 for i := 0; i < len(raw.SupportedCodecs); i++ { 143 d.SupportedCodecs[i] = Codec(raw.SupportedCodecs[i]) 144 } 145 146 d.PartitionWriteSpeedBytesPerSecond = raw.PartitionWriteSpeedBytesPerSecond 147 d.PartitionWriteBurstBytes = raw.PartitionWriteBurstBytes 148 149 d.RetentionPeriod = raw.RetentionPeriod 150 d.RetentionStorageMB = raw.RetentionStorageMB 151 152 d.Attributes = make(map[string]string) 153 for k, v := range raw.Attributes { 154 d.Attributes[k] = v 155 } 156 157 d.Consumers = make([]Consumer, len(raw.Consumers)) 158 for i := 0; i < len(raw.Consumers); i++ { 159 d.Consumers[i].FromRaw(&raw.Consumers[i]) 160 } 161 162 d.MeteringMode.FromRaw(raw.MeteringMode) 163 } 164 165 // PartitionInfo contains info about partition. 166 type PartitionInfo struct { 167 PartitionID int64 168 Active bool 169 ChildPartitionIDs []int64 170 ParentPartitionIDs []int64 171 } 172 173 // FromRaw convert from internal format to public. Used internally only. 174 func (p *PartitionInfo) FromRaw(raw *rawtopic.PartitionInfo) { 175 p.PartitionID = raw.PartitionID 176 p.Active = raw.Active 177 178 p.ChildPartitionIDs = clone.Int64Slice(raw.ChildPartitionIDs) 179 p.ParentPartitionIDs = clone.Int64Slice(raw.ParentPartitionIDs) 180 }