github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/topic/topicoptions/topicoptions.go (about) 1 package topicoptions 2 3 import ( 4 "time" 5 6 "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic" 7 "github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopiccommon" 8 "github.com/ydb-platform/ydb-go-sdk/v3/internal/topic" 9 "github.com/ydb-platform/ydb-go-sdk/v3/topic/topictypes" 10 ) 11 12 type ( 13 CheckErrorRetryFunction = topic.PublicCheckErrorRetryFunction 14 CheckErrorRetryArgs = topic.PublicCheckErrorRetryArgs 15 CheckErrorRetryResult = topic.PublicCheckRetryResult 16 ) 17 18 var ( 19 CheckErrorRetryDecisionDefault = topic.PublicRetryDecisionDefault // Apply default behavior for the error 20 CheckErrorRetryDecisionRetry = topic.PublicRetryDecisionRetry // Do once more retry 21 CheckErrorRetryDecisionStop = topic.PublicRetryDecisionStop // Do not retry 22 ) 23 24 type withMeteringMode topictypes.MeteringMode 25 26 func (mode withMeteringMode) ApplyCreateOption(request *rawtopic.CreateTopicRequest) { 27 (*topictypes.MeteringMode)(&mode).ToRaw(&request.MeteringMode) 28 } 29 30 func (mode withMeteringMode) ApplyAlterOption(req *rawtopic.AlterTopicRequest) { 31 (*topictypes.MeteringMode)(&mode).ToRaw(&req.SetMeteringMode) 32 } 33 34 type withMinActivePartitions int64 35 36 func (minActivePartitions withMinActivePartitions) ApplyCreateOption(request *rawtopic.CreateTopicRequest) { 37 request.PartitionSettings.MinActivePartitions = int64(minActivePartitions) 38 } 39 40 func (minActivePartitions withMinActivePartitions) ApplyAlterOption(req *rawtopic.AlterTopicRequest) { 41 req.AlterPartitionSettings.SetMinActivePartitions.HasValue = true 42 req.AlterPartitionSettings.SetMinActivePartitions.Value = int64(minActivePartitions) 43 } 44 45 type withPartitionCountLimit int64 46 47 func (partitionCountLimit withPartitionCountLimit) ApplyCreateOption(request *rawtopic.CreateTopicRequest) { 48 request.PartitionSettings.PartitionCountLimit = int64(partitionCountLimit) 49 } 50 51 func (partitionCountLimit withPartitionCountLimit) ApplyAlterOption(req *rawtopic.AlterTopicRequest) { 52 req.AlterPartitionSettings.SetPartitionCountLimit.HasValue = true 53 req.AlterPartitionSettings.SetPartitionCountLimit.Value = int64(partitionCountLimit) 54 } 55 56 type withRetentionPeriod time.Duration 57 58 func (retentionPeriod withRetentionPeriod) ApplyCreateOption(request *rawtopic.CreateTopicRequest) { 59 request.RetentionPeriod = time.Duration(retentionPeriod) 60 } 61 62 func (retentionPeriod withRetentionPeriod) ApplyAlterOption(req *rawtopic.AlterTopicRequest) { 63 req.SetRetentionPeriod.HasValue = true 64 req.SetRetentionPeriod.Value = time.Duration(retentionPeriod) 65 } 66 67 type withRetentionStorageMB int64 68 69 func (retentionStorageMB withRetentionStorageMB) ApplyCreateOption(request *rawtopic.CreateTopicRequest) { 70 request.RetentionStorageMB = int64(retentionStorageMB) 71 } 72 73 func (retentionStorageMB withRetentionStorageMB) ApplyAlterOption(req *rawtopic.AlterTopicRequest) { 74 req.SetRetentionStorageMB.HasValue = true 75 req.SetRetentionStorageMB.Value = int64(retentionStorageMB) 76 } 77 78 type withSupportedCodecs []topictypes.Codec 79 80 func (codecs withSupportedCodecs) ApplyCreateOption(request *rawtopic.CreateTopicRequest) { 81 request.SupportedCodecs = make(rawtopiccommon.SupportedCodecs, len(codecs)) 82 for i, c := range codecs { 83 c.ToRaw(&request.SupportedCodecs[i]) 84 } 85 } 86 87 func (codecs withSupportedCodecs) ApplyAlterOption(req *rawtopic.AlterTopicRequest) { 88 req.SetSupportedCodecs = true 89 req.SetSupportedCodecsValue = make(rawtopiccommon.SupportedCodecs, len(codecs)) 90 for i, codec := range codecs { 91 req.SetSupportedCodecsValue[i] = rawtopiccommon.Codec(codec) 92 } 93 } 94 95 type withPartitionWriteSpeedBytesPerSecond int64 96 97 func (bytesPerSecond withPartitionWriteSpeedBytesPerSecond) ApplyCreateOption(request *rawtopic.CreateTopicRequest) { 98 request.PartitionWriteSpeedBytesPerSecond = int64(bytesPerSecond) 99 } 100 101 func (bytesPerSecond withPartitionWriteSpeedBytesPerSecond) ApplyAlterOption(req *rawtopic.AlterTopicRequest) { 102 req.SetPartitionWriteSpeedBytesPerSecond.HasValue = true 103 req.SetPartitionWriteSpeedBytesPerSecond.Value = int64(bytesPerSecond) 104 } 105 106 type withPartitionWriteBurstBytes int64 107 108 func (burstBytes withPartitionWriteBurstBytes) ApplyCreateOption(request *rawtopic.CreateTopicRequest) { 109 request.PartitionWriteBurstBytes = int64(burstBytes) 110 } 111 112 func (burstBytes withPartitionWriteBurstBytes) ApplyAlterOption(req *rawtopic.AlterTopicRequest) { 113 req.SetPartitionWriteBurstBytes.HasValue = true 114 req.SetPartitionWriteBurstBytes.Value = int64(burstBytes) 115 } 116 117 type withAttributes map[string]string 118 119 func (attributes withAttributes) ApplyCreateOption(request *rawtopic.CreateTopicRequest) { 120 request.Attributes = attributes 121 } 122 123 func (attributes withAttributes) ApplyAlterOption(req *rawtopic.AlterTopicRequest) { 124 req.AlterAttributes = attributes 125 } 126 127 type withAddConsumers []topictypes.Consumer 128 129 func (consumers withAddConsumers) ApplyCreateOption(request *rawtopic.CreateTopicRequest) { 130 request.Consumers = make([]rawtopic.Consumer, len(consumers)) 131 for i := range consumers { 132 consumers[i].ToRaw(&request.Consumers[i]) 133 } 134 } 135 136 func (consumers withAddConsumers) ApplyAlterOption(req *rawtopic.AlterTopicRequest) { 137 req.AddConsumers = make([]rawtopic.Consumer, len(consumers)) 138 for i := range consumers { 139 consumers[i].ToRaw(&req.AddConsumers[i]) 140 } 141 } 142 143 type withDropConsumers []string 144 145 func (consumers withDropConsumers) ApplyAlterOption(req *rawtopic.AlterTopicRequest) { 146 req.DropConsumers = consumers 147 } 148 149 type withConsumerWithImportant struct { 150 name string 151 important bool 152 } 153 154 func (consumerImportant withConsumerWithImportant) ApplyAlterOption(req *rawtopic.AlterTopicRequest) { 155 var index int 156 req.AlterConsumers, index = ensureAlterConsumer(req.AlterConsumers, consumerImportant.name) 157 req.AlterConsumers[index].SetImportant.HasValue = true 158 req.AlterConsumers[index].SetImportant.Value = consumerImportant.important 159 } 160 161 type withConsumerWithReadFrom struct { 162 name string 163 readFrom time.Time 164 } 165 166 func (consumerReadFrom withConsumerWithReadFrom) ApplyAlterOption(req *rawtopic.AlterTopicRequest) { 167 var index int 168 req.AlterConsumers, index = ensureAlterConsumer(req.AlterConsumers, consumerReadFrom.name) 169 req.AlterConsumers[index].SetReadFrom.HasValue = true 170 req.AlterConsumers[index].SetReadFrom.Value = consumerReadFrom.readFrom 171 } 172 173 type withConsumerWithSupportedCodecs struct { 174 name string 175 codecs []topictypes.Codec 176 } 177 178 func (consumerCodecs withConsumerWithSupportedCodecs) ApplyAlterOption(req *rawtopic.AlterTopicRequest) { 179 var index int 180 req.AlterConsumers, index = ensureAlterConsumer(req.AlterConsumers, consumerCodecs.name) 181 182 consumer := &req.AlterConsumers[index] 183 consumer.SetSupportedCodecs = make(rawtopiccommon.SupportedCodecs, len(consumerCodecs.codecs)) 184 for i, codec := range consumerCodecs.codecs { 185 consumer.SetSupportedCodecs[i] = rawtopiccommon.Codec(codec) 186 } 187 } 188 189 type withConsumerWithAttributes struct { 190 name string 191 attributes map[string]string 192 } 193 194 func (consumerAttributes withConsumerWithAttributes) ApplyAlterOption(req *rawtopic.AlterTopicRequest) { 195 var index int 196 req.AlterConsumers, index = ensureAlterConsumer(req.AlterConsumers, consumerAttributes.name) 197 req.AlterConsumers[index].AlterAttributes = consumerAttributes.attributes 198 }