-
Notifications
You must be signed in to change notification settings - Fork 48
sink(cloudstorage): add use-table-id-as-path option (#4356) #4594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
880bc47
3604c30
faaf93c
98d5fa1
5988587
61d51aa
b157aea
683f885
e7fd829
3bd9d51
0545713
61bda94
0d78442
75827fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,8 @@ const ( | |
|
|
||
| // TxnAtomicityKey specifies the key of the transaction-atomicity in the SinkURI. | ||
| TxnAtomicityKey = "transaction-atomicity" | ||
| // UseTableIDAsPathKey specifies the key of the use-table-id-as-path in the SinkURI. | ||
| UseTableIDAsPathKey = "use-table-id-as-path" | ||
| // defaultTxnAtomicity is the default atomicity level. | ||
| defaultTxnAtomicity = noneTxnAtomicity | ||
| // unknownTxnAtomicity is an invalid atomicity level and will be treated as | ||
|
|
@@ -698,6 +700,8 @@ type CloudStorageConfig struct { | |
| FileExpirationDays *int `toml:"file-expiration-days" json:"file-expiration-days,omitempty"` | ||
| FileCleanupCronSpec *string `toml:"file-cleanup-cron-spec" json:"file-cleanup-cron-spec,omitempty"` | ||
| FlushConcurrency *int `toml:"flush-concurrency" json:"flush-concurrency,omitempty"` | ||
| // UseTableIDAsPath is only available when the downstream is Storage (TiCI only). | ||
| UseTableIDAsPath *bool `toml:"use-table-id-as-path" json:"use-table-id-as-path,omitempty"` | ||
|
|
||
| // OutputRawChangeEvent controls whether to split the update pk/uk events. | ||
| OutputRawChangeEvent *bool `toml:"output-raw-change-event" json:"output-raw-change-event,omitempty"` | ||
|
|
@@ -711,6 +715,27 @@ func (c *CloudStorageConfig) GetOutputRawChangeEvent() bool { | |
| return *c.OutputRawChangeEvent | ||
| } | ||
|
|
||
| // CheckUseTableIDAsPathCompatibility checks the compatibility between sink config and sink URI. | ||
| func CheckUseTableIDAsPathCompatibility( | ||
| sinkConfig *SinkConfig, | ||
| useTableIDAsPathFromURI *bool, | ||
| ) error { | ||
| if sinkConfig == nil || | ||
| sinkConfig.CloudStorageConfig == nil || | ||
| sinkConfig.CloudStorageConfig.UseTableIDAsPath == nil || | ||
| useTableIDAsPathFromURI == nil { | ||
| return nil | ||
| } | ||
| useTableIDAsPathFromConfig := sinkConfig.CloudStorageConfig.UseTableIDAsPath | ||
| if util.GetOrZero(useTableIDAsPathFromConfig) == util.GetOrZero(useTableIDAsPathFromURI) { | ||
| return nil | ||
| } | ||
| return cerror.ErrIncompatibleSinkConfig.GenWithStackByArgs( | ||
| fmt.Sprintf("%s=%t", UseTableIDAsPathKey, util.GetOrZero(useTableIDAsPathFromURI)), | ||
| fmt.Sprintf("%s=%t", UseTableIDAsPathKey, util.GetOrZero(useTableIDAsPathFromConfig)), | ||
| ) | ||
| } | ||
|
Comment on lines
+718
to
+737
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Persist This compatibility path only sees the new URI. A changefeed created with 💡 Suggested fix func (s *SinkConfig) applyParameterBySinkURI(sinkURI *url.URL) error {
if sinkURI == nil {
return nil
}
cfgInSinkURI := map[string]string{}
cfgInFile := map[string]string{}
params := sinkURI.Query()
@@
protocolFromURI := params.Get(ProtocolKey)
if protocolFromURI != "" {
if s.Protocol != nil && util.GetOrZero(s.Protocol) != protocolFromURI {
cfgInSinkURI[ProtocolKey] = protocolFromURI
cfgInFile[ProtocolKey] = util.GetOrZero(s.Protocol)
}
s.Protocol = util.AddressOf(protocolFromURI)
}
+
+ if IsStorageScheme(sinkURI.Scheme) {
+ useTableIDAsPathFromURI := params.Get(UseTableIDAsPathKey)
+ if useTableIDAsPathFromURI != "" {
+ enabled, err := strconv.ParseBool(useTableIDAsPathFromURI)
+ if err != nil {
+ return cerror.WrapError(cerror.ErrSinkURIInvalid, err)
+ }
+ if s.CloudStorageConfig == nil {
+ s.CloudStorageConfig = &CloudStorageConfig{}
+ }
+ if s.CloudStorageConfig.UseTableIDAsPath != nil &&
+ util.GetOrZero(s.CloudStorageConfig.UseTableIDAsPath) != enabled {
+ cfgInSinkURI[UseTableIDAsPathKey] = strconv.FormatBool(enabled)
+ cfgInFile[UseTableIDAsPathKey] = strconv.FormatBool(util.GetOrZero(s.CloudStorageConfig.UseTableIDAsPath))
+ }
+ s.CloudStorageConfig.UseTableIDAsPath = util.AddressOf(enabled)
+ }
+ }Also applies to: 1005-1056 🤖 Prompt for AI Agents |
||
|
|
||
| func (s *SinkConfig) validateAndAdjust(sinkURI *url.URL) error { | ||
| if err := s.validateAndAdjustSinkURI(sinkURI); err != nil { | ||
| return err | ||
|
|
@@ -977,15 +1002,59 @@ func (s *SinkConfig) CheckCompatibilityWithSinkURI( | |
| return cerror.WrapError(cerror.ErrSinkURIInvalid, err) | ||
| } | ||
|
|
||
| var useTableIDAsPathFromURI *bool | ||
| if IsStorageScheme(sinkURI.Scheme) { | ||
| useTableIDAsPathValue := sinkURI.Query().Get(UseTableIDAsPathKey) | ||
| if useTableIDAsPathValue != "" { | ||
| enabled, parseErr := strconv.ParseBool(useTableIDAsPathValue) | ||
| if parseErr != nil { | ||
| return cerror.WrapError(cerror.ErrSinkURIInvalid, parseErr) | ||
| } | ||
| useTableIDAsPathFromURI = util.AddressOf(enabled) | ||
| } | ||
| } | ||
|
|
||
| getUseTableIDAsPath := func(cfg *SinkConfig) *bool { | ||
| if cfg == nil || cfg.CloudStorageConfig == nil { | ||
| return nil | ||
| } | ||
| return cfg.CloudStorageConfig.UseTableIDAsPath | ||
| } | ||
|
|
||
| useTableIDAsPathChanged := func() bool { | ||
| newVal := getUseTableIDAsPath(s) | ||
| oldVal := getUseTableIDAsPath(oldSinkConfig) | ||
| if newVal == nil && oldVal == nil { | ||
| return false | ||
| } | ||
| if newVal == nil || oldVal == nil { | ||
| return true | ||
| } | ||
| return *newVal != *oldVal | ||
| } | ||
|
|
||
| cfgParamsChanged := s.Protocol != oldSinkConfig.Protocol || | ||
| s.TxnAtomicity != oldSinkConfig.TxnAtomicity | ||
| s.TxnAtomicity != oldSinkConfig.TxnAtomicity || | ||
| useTableIDAsPathChanged() | ||
|
|
||
| isURIParamsChanged := func(oldCfg SinkConfig) bool { | ||
| err := oldCfg.applyParameterBySinkURI(sinkURI) | ||
| return cerror.ErrIncompatibleSinkConfig.Equal(err) | ||
| if cerror.ErrIncompatibleSinkConfig.Equal(err) { | ||
| return true | ||
| } | ||
| if useTableIDAsPathFromURI == nil { | ||
| return false | ||
| } | ||
| return CheckUseTableIDAsPathCompatibility(&oldCfg, useTableIDAsPathFromURI) != nil | ||
| } | ||
| uriParamsChanged := isURIParamsChanged(*oldSinkConfig) | ||
|
|
||
| if !uriParamsChanged && IsStorageScheme(sinkURI.Scheme) { | ||
| if err := CheckUseTableIDAsPathCompatibility(s, useTableIDAsPathFromURI); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| if !uriParamsChanged && !cfgParamsChanged { | ||
| return nil | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.