github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/topic/topicoptions/topicoptions_alter.go (about)

     1  package topicoptions
     2  
     3  import (
     4  	"sort"
     5  	"time"
     6  
     7  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic"
     8  	"github.com/ydb-platform/ydb-go-sdk/v3/topic/topictypes"
     9  )
    10  
    11  // AlterOption type of options for change topic settings
    12  type AlterOption interface {
    13  	ApplyAlterOption(req *rawtopic.AlterTopicRequest)
    14  }
    15  
    16  // AlterWithMeteringMode change metering mode for topic (need for serverless installations)
    17  func AlterWithMeteringMode(m topictypes.MeteringMode) AlterOption {
    18  	return withMeteringMode(m)
    19  }
    20  
    21  // AlterWithMinActivePartitions change min active partitions of the topic
    22  func AlterWithMinActivePartitions(minActivePartitions int64) AlterOption {
    23  	return withMinActivePartitions(minActivePartitions)
    24  }
    25  
    26  // AlterWithPartitionCountLimit change partition count limit of the topic
    27  func AlterWithPartitionCountLimit(partitionCountLimit int64) AlterOption {
    28  	return withPartitionCountLimit(partitionCountLimit)
    29  }
    30  
    31  // AlterWithRetentionPeriod change retention period of topic
    32  func AlterWithRetentionPeriod(retentionPeriod time.Duration) AlterOption {
    33  	return withRetentionPeriod(retentionPeriod)
    34  }
    35  
    36  // AlterWithRetentionStorageMB change retention storage size in MB.
    37  func AlterWithRetentionStorageMB(retentionStorageMB int64) AlterOption {
    38  	return withRetentionStorageMB(retentionStorageMB)
    39  }
    40  
    41  // AlterWithSupportedCodecs change set of codec, allowed for the topic
    42  func AlterWithSupportedCodecs(codecs ...topictypes.Codec) AlterOption {
    43  	sort.Slice(codecs, func(i, j int) bool {
    44  		return codecs[i] < codecs[j]
    45  	})
    46  
    47  	return withSupportedCodecs(codecs)
    48  }
    49  
    50  // AlterWithPartitionWriteSpeedBytesPerSecond change limit of write speed for partitions of the topic
    51  func AlterWithPartitionWriteSpeedBytesPerSecond(bytesPerSecond int64) AlterOption {
    52  	return withPartitionWriteSpeedBytesPerSecond(bytesPerSecond)
    53  }
    54  
    55  // AlterWithPartitionWriteBurstBytes change burst size for write to partition of topic
    56  func AlterWithPartitionWriteBurstBytes(burstBytes int64) AlterOption {
    57  	return withPartitionWriteBurstBytes(burstBytes)
    58  }
    59  
    60  // AlterWithAttributes change attributes map of topic
    61  func AlterWithAttributes(attributes map[string]string) AlterOption {
    62  	return withAttributes(attributes)
    63  }
    64  
    65  // AlterWithAddConsumers add consumer to the topic
    66  func AlterWithAddConsumers(consumers ...topictypes.Consumer) AlterOption {
    67  	sort.Slice(consumers, func(i, j int) bool {
    68  		return consumers[i].Name < consumers[j].Name
    69  	})
    70  
    71  	return withAddConsumers(consumers)
    72  }
    73  
    74  // AlterWithDropConsumers drop consumer from the topic
    75  func AlterWithDropConsumers(consumersName ...string) AlterOption {
    76  	sort.Strings(consumersName)
    77  
    78  	return withDropConsumers(consumersName)
    79  }
    80  
    81  // AlterConsumerWithImportant set/remove important flag for the consumer of topic
    82  func AlterConsumerWithImportant(name string, important bool) AlterOption {
    83  	return withConsumerWithImportant{
    84  		name:      name,
    85  		important: important,
    86  	}
    87  }
    88  
    89  // AlterConsumerWithReadFrom change min time of messages, received for the topic
    90  func AlterConsumerWithReadFrom(name string, readFrom time.Time) AlterOption {
    91  	return withConsumerWithReadFrom{
    92  		name:     name,
    93  		readFrom: readFrom,
    94  	}
    95  }
    96  
    97  // AlterConsumerWithSupportedCodecs change codecs, supported by the consumer
    98  func AlterConsumerWithSupportedCodecs(name string, codecs []topictypes.Codec) AlterOption {
    99  	sort.Slice(codecs, func(i, j int) bool {
   100  		return codecs[i] < codecs[j]
   101  	})
   102  
   103  	return withConsumerWithSupportedCodecs{
   104  		name:   name,
   105  		codecs: codecs,
   106  	}
   107  }
   108  
   109  // AlterConsumerWithAttributes change attributes of the consumer
   110  func AlterConsumerWithAttributes(name string, attributes map[string]string) AlterOption {
   111  	return withConsumerWithAttributes{
   112  		name:       name,
   113  		attributes: attributes,
   114  	}
   115  }
   116  
   117  func ensureAlterConsumer(
   118  	consumers []rawtopic.AlterConsumer,
   119  	name string,
   120  ) (
   121  	newConsumers []rawtopic.AlterConsumer,
   122  	index int,
   123  ) {
   124  	for i := range consumers {
   125  		if consumers[i].Name == name {
   126  			return consumers, i
   127  		}
   128  	}
   129  	consumers = append(consumers, rawtopic.AlterConsumer{Name: name})
   130  
   131  	return consumers, len(consumers) - 1
   132  }