|
| 1 | +#include "topic_description.h" |
| 2 | +#include "ydb_convert.h" |
| 3 | + |
| 4 | +#include <ydb/core/base/appdata_fwd.h> |
| 5 | +#include <ydb/core/base/feature_flags.h> |
| 6 | +#include <ydb/core/persqueue/utils.h> |
| 7 | +#include <ydb/core/protos/feature_flags.pb.h> |
| 8 | +#include <ydb/core/protos/pqconfig.pb.h> |
| 9 | +#include <ydb/library/persqueue/topic_parser/topic_parser.h> |
| 10 | + |
| 11 | +namespace NKikimr { |
| 12 | + |
| 13 | +bool FillConsumer(Ydb::Topic::Consumer& out, const NKikimrPQ::TPQTabletConfig_TConsumer& in, |
| 14 | + Ydb::StatusIds_StatusCode& status, TString& error) |
| 15 | +{ |
| 16 | + const NKikimrPQ::TPQConfig pqConfig = AppData()->PQConfig; |
| 17 | + auto consumerName = NPersQueue::ConvertOldConsumerName(in.GetName(), pqConfig); |
| 18 | + out.set_name(consumerName); |
| 19 | + out.mutable_read_from()->set_seconds(in.GetReadFromTimestampsMs() / 1000); |
| 20 | + auto version = in.GetVersion(); |
| 21 | + if (version != 0) |
| 22 | + (*out.mutable_attributes())["_version"] = TStringBuilder() << version; |
| 23 | + for (const auto &codec : in.GetCodec().GetIds()) { |
| 24 | + out.mutable_supported_codecs()->add_codecs((Ydb::Topic::Codec) (codec + 1)); |
| 25 | + } |
| 26 | + |
| 27 | + out.set_important(in.GetImportant()); |
| 28 | + TString serviceType = ""; |
| 29 | + if (in.HasServiceType()) { |
| 30 | + serviceType = in.GetServiceType(); |
| 31 | + } else { |
| 32 | + if (pqConfig.GetDisallowDefaultClientServiceType()) { |
| 33 | + error = "service type must be set for all read rules"; |
| 34 | + status = Ydb::StatusIds::INTERNAL_ERROR; |
| 35 | + return false; |
| 36 | + } |
| 37 | + serviceType = pqConfig.GetDefaultClientServiceType().GetName(); |
| 38 | + } |
| 39 | + (*out.mutable_attributes())["_service_type"] = serviceType; |
| 40 | + return true; |
| 41 | +} |
| 42 | + |
| 43 | +bool FillTopicDescription(Ydb::Topic::DescribeTopicResult& out, const NKikimrSchemeOp::TPersQueueGroupDescription& inDesc, |
| 44 | + const NKikimrSchemeOp::TDirEntry& inDirEntry, const TMaybe<TString>& cdcName, |
| 45 | + Ydb::StatusIds_StatusCode& status, TString& error) { |
| 46 | + |
| 47 | + const NKikimrPQ::TPQConfig pqConfig = AppData()->PQConfig; |
| 48 | + |
| 49 | + Ydb::Scheme::Entry *selfEntry = out.mutable_self(); |
| 50 | + ConvertDirectoryEntry(inDirEntry, selfEntry, true); |
| 51 | + if (cdcName) { |
| 52 | + selfEntry->set_name(*cdcName); |
| 53 | + } |
| 54 | + |
| 55 | + for (auto& sourcePart: inDesc.GetPartitions()) { |
| 56 | + auto destPart = out.add_partitions(); |
| 57 | + destPart->set_partition_id(sourcePart.GetPartitionId()); |
| 58 | + destPart->set_active(sourcePart.GetStatus() == ::NKikimrPQ::ETopicPartitionStatus::Active); |
| 59 | + if (sourcePart.HasKeyRange()) { |
| 60 | + if (sourcePart.GetKeyRange().HasFromBound()) { |
| 61 | + destPart->mutable_key_range()->set_from_bound(sourcePart.GetKeyRange().GetFromBound()); |
| 62 | + } |
| 63 | + if (sourcePart.GetKeyRange().HasToBound()) { |
| 64 | + destPart->mutable_key_range()->set_to_bound(sourcePart.GetKeyRange().GetToBound()); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + for (size_t i = 0; i < sourcePart.ChildPartitionIdsSize(); ++i) { |
| 69 | + destPart->add_child_partition_ids(static_cast<int64_t>(sourcePart.GetChildPartitionIds(i))); |
| 70 | + } |
| 71 | + |
| 72 | + for (size_t i = 0; i < sourcePart.ParentPartitionIdsSize(); ++i) { |
| 73 | + destPart->add_parent_partition_ids(static_cast<int64_t>(sourcePart.GetParentPartitionIds(i))); |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + const auto &config = inDesc.GetPQTabletConfig(); |
| 78 | + if (AppData()->FeatureFlags.GetEnableTopicSplitMerge() && NPQ::SplitMergeEnabled(config)) { |
| 79 | + out.mutable_partitioning_settings()->set_min_active_partitions(config.GetPartitionStrategy().GetMinPartitionCount()); |
| 80 | + } else { |
| 81 | + out.mutable_partitioning_settings()->set_min_active_partitions(inDesc.GetTotalGroupCount()); |
| 82 | + } |
| 83 | + |
| 84 | + out.mutable_partitioning_settings()->set_max_active_partitions(config.GetPartitionStrategy().GetMaxPartitionCount()); |
| 85 | + switch(config.GetPartitionStrategy().GetPartitionStrategyType()) { |
| 86 | + case ::NKikimrPQ::TPQTabletConfig_TPartitionStrategyType::TPQTabletConfig_TPartitionStrategyType_CAN_SPLIT: |
| 87 | + out.mutable_partitioning_settings()->mutable_auto_partitioning_settings()->set_strategy(Ydb::Topic::AutoPartitioningStrategy::AUTO_PARTITIONING_STRATEGY_SCALE_UP); |
| 88 | + break; |
| 89 | + case ::NKikimrPQ::TPQTabletConfig_TPartitionStrategyType::TPQTabletConfig_TPartitionStrategyType_CAN_SPLIT_AND_MERGE: |
| 90 | + out.mutable_partitioning_settings()->mutable_auto_partitioning_settings()->set_strategy(Ydb::Topic::AutoPartitioningStrategy::AUTO_PARTITIONING_STRATEGY_SCALE_UP_AND_DOWN); |
| 91 | + break; |
| 92 | + case ::NKikimrPQ::TPQTabletConfig_TPartitionStrategyType::TPQTabletConfig_TPartitionStrategyType_PAUSED: |
| 93 | + out.mutable_partitioning_settings()->mutable_auto_partitioning_settings()->set_strategy(Ydb::Topic::AutoPartitioningStrategy::AUTO_PARTITIONING_STRATEGY_PAUSED); |
| 94 | + break; |
| 95 | + default: |
| 96 | + out.mutable_partitioning_settings()->mutable_auto_partitioning_settings()->set_strategy(Ydb::Topic::AutoPartitioningStrategy::AUTO_PARTITIONING_STRATEGY_DISABLED); |
| 97 | + break; |
| 98 | + } |
| 99 | + out.mutable_partitioning_settings()->mutable_auto_partitioning_settings()->mutable_partition_write_speed()->mutable_stabilization_window()->set_seconds(config.GetPartitionStrategy().GetScaleThresholdSeconds()); |
| 100 | + out.mutable_partitioning_settings()->mutable_auto_partitioning_settings()->mutable_partition_write_speed()->set_down_utilization_percent(config.GetPartitionStrategy().GetScaleDownPartitionWriteSpeedThresholdPercent()); |
| 101 | + out.mutable_partitioning_settings()->mutable_auto_partitioning_settings()->mutable_partition_write_speed()->set_up_utilization_percent(config.GetPartitionStrategy().GetScaleUpPartitionWriteSpeedThresholdPercent()); |
| 102 | + |
| 103 | + if (!config.GetRequireAuthWrite()) { |
| 104 | + (*out.mutable_attributes())["_allow_unauthenticated_write"] = "true"; |
| 105 | + } |
| 106 | + |
| 107 | + if (!config.GetRequireAuthRead()) { |
| 108 | + (*out.mutable_attributes())["_allow_unauthenticated_read"] = "true"; |
| 109 | + } |
| 110 | + |
| 111 | + if (inDesc.GetPartitionPerTablet() != 2) { |
| 112 | + (*out.mutable_attributes())["_partitions_per_tablet"] = |
| 113 | + TStringBuilder() << inDesc.GetPartitionPerTablet(); |
| 114 | + } |
| 115 | + if (config.HasAbcId()) { |
| 116 | + (*out.mutable_attributes())["_abc_id"] = TStringBuilder() << config.GetAbcId(); |
| 117 | + } |
| 118 | + if (config.HasAbcSlug()) { |
| 119 | + (*out.mutable_attributes())["_abc_slug"] = config.GetAbcSlug(); |
| 120 | + } |
| 121 | + if (config.HasFederationAccount()) { |
| 122 | + (*out.mutable_attributes())["_federation_account"] = config.GetFederationAccount(); |
| 123 | + } |
| 124 | + bool local = config.GetLocalDC(); |
| 125 | + const auto &partConfig = config.GetPartitionConfig(); |
| 126 | + i64 msip = partConfig.GetMaxSizeInPartition(); |
| 127 | + if (partConfig.HasMaxSizeInPartition() && msip != Max<i64>()) { |
| 128 | + (*out.mutable_attributes())["_max_partition_storage_size"] = TStringBuilder() << msip; |
| 129 | + } |
| 130 | + out.mutable_retention_period()->set_seconds(partConfig.GetLifetimeSeconds()); |
| 131 | + out.set_retention_storage_mb(partConfig.GetStorageLimitBytes() / 1024 / 1024); |
| 132 | + (*out.mutable_attributes())["_message_group_seqno_retention_period_ms"] = TStringBuilder() << (partConfig.GetSourceIdLifetimeSeconds() * 1000); |
| 133 | + (*out.mutable_attributes())["__max_partition_message_groups_seqno_stored"] = TStringBuilder() << partConfig.GetSourceIdMaxCounts(); |
| 134 | + |
| 135 | + if (local || pqConfig.GetTopicsAreFirstClassCitizen()) { |
| 136 | + out.set_partition_write_speed_bytes_per_second(partConfig.GetWriteSpeedInBytesPerSecond()); |
| 137 | + out.set_partition_write_burst_bytes(partConfig.GetBurstSize()); |
| 138 | + } |
| 139 | + |
| 140 | + if (pqConfig.GetQuotingConfig().GetPartitionReadQuotaIsTwiceWriteQuota()) { |
| 141 | + auto readSpeedPerConsumer = partConfig.GetWriteSpeedInBytesPerSecond() * 2; |
| 142 | + out.set_partition_total_read_speed_bytes_per_second(readSpeedPerConsumer * pqConfig.GetQuotingConfig().GetMaxParallelConsumersPerPartition()); |
| 143 | + out.set_partition_consumer_read_speed_bytes_per_second(readSpeedPerConsumer); |
| 144 | + } |
| 145 | + |
| 146 | + for (const auto &codec : config.GetCodecs().GetIds()) { |
| 147 | + out.mutable_supported_codecs()->add_codecs((Ydb::Topic::Codec)(codec + 1)); |
| 148 | + } |
| 149 | + |
| 150 | + if (pqConfig.GetBillingMeteringConfig().GetEnabled()) { |
| 151 | + switch (config.GetMeteringMode()) { |
| 152 | + case NKikimrPQ::TPQTabletConfig::METERING_MODE_RESERVED_CAPACITY: |
| 153 | + out.set_metering_mode(Ydb::Topic::METERING_MODE_RESERVED_CAPACITY); |
| 154 | + break; |
| 155 | + case NKikimrPQ::TPQTabletConfig::METERING_MODE_REQUEST_UNITS: |
| 156 | + out.set_metering_mode(Ydb::Topic::METERING_MODE_REQUEST_UNITS); |
| 157 | + break; |
| 158 | + default: |
| 159 | + break; |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + for (const auto& consumer : config.GetConsumers()) { |
| 164 | + if (!FillConsumer(*out.add_consumers(), consumer, status, error)) { |
| 165 | + return false; |
| 166 | + } |
| 167 | + } |
| 168 | + return true; |
| 169 | +} |
| 170 | + |
| 171 | +} // namespace NKikimr |
0 commit comments