-
Notifications
You must be signed in to change notification settings - Fork 97
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
PEERDB_CLICKHOUSE_BINARY_FORMAT #2407
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"log/slog" | ||
"os" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/aws/smithy-go/ptr" | ||
|
@@ -107,6 +108,14 @@ var DynamicSettings = [...]*protos.DynamicSetting{ | |
ApplyMode: protos.DynconfApplyMode_APPLY_MODE_NEW_MIRROR, | ||
TargetForSetting: protos.DynconfTarget_ALL, | ||
}, | ||
{ | ||
Name: "PEERDB_CLICKHOUSE_BINARY_FORMAT", | ||
Description: "Binary field encoding on clickhouse destination; either raw, hex, or base64", | ||
DefaultValue: "base64", | ||
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. change to raw as a TODO 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. by time we change default to raw we can probably remove this option |
||
ValueType: protos.DynconfValueType_STRING, | ||
ApplyMode: protos.DynconfApplyMode_APPLY_MODE_AFTER_RESUME, | ||
TargetForSetting: protos.DynconfTarget_CLICKHOUSE, | ||
}, | ||
{ | ||
Name: "PEERDB_SNOWFLAKE_MERGE_PARALLELISM", | ||
Description: "Parallel MERGE statements to run for CDC mirrors with Snowflake targets. -1 for no limit", | ||
|
@@ -238,6 +247,15 @@ var DynamicIndex = func() map[string]int { | |
return defaults | ||
}() | ||
|
||
type BinaryFormat int | ||
|
||
const ( | ||
BinaryFormatInvalid = iota | ||
BinaryFormatRaw | ||
BinaryFormatBase64 | ||
BinaryFormatHex | ||
) | ||
|
||
func dynLookup(ctx context.Context, env map[string]string, key string) (string, error) { | ||
if val, ok := env[key]; ok { | ||
return val, nil | ||
|
@@ -249,6 +267,11 @@ func dynLookup(ctx context.Context, env map[string]string, key string) (string, | |
return "", fmt.Errorf("failed to get catalog connection pool: %w", err) | ||
} | ||
|
||
var setting *protos.DynamicSetting | ||
if idx, ok := DynamicIndex[key]; ok { | ||
setting = DynamicSettings[idx] | ||
} | ||
|
||
var value pgtype.Text | ||
query := "SELECT config_value FROM dynamic_settings WHERE config_name=$1" | ||
if err := conn.QueryRow(ctx, query, key).Scan(&value); err != nil && err != pgx.ErrNoRows { | ||
|
@@ -257,12 +280,21 @@ func dynLookup(ctx context.Context, env map[string]string, key string) (string, | |
} | ||
if !value.Valid { | ||
if val, ok := os.LookupEnv(key); ok { | ||
if env != nil && setting != nil && setting.ApplyMode != protos.DynconfApplyMode_APPLY_MODE_IMMEDIATE { | ||
env[key] = val | ||
} | ||
return val, nil | ||
} | ||
if idx, ok := DynamicIndex[key]; ok { | ||
return DynamicSettings[idx].DefaultValue, nil | ||
if setting != nil { | ||
if env != nil && setting.ApplyMode != protos.DynconfApplyMode_APPLY_MODE_IMMEDIATE { | ||
env[key] = setting.DefaultValue | ||
} | ||
return setting.DefaultValue, nil | ||
} | ||
} | ||
if env != nil && setting != nil && setting.ApplyMode != protos.DynconfApplyMode_APPLY_MODE_IMMEDIATE { | ||
env[key] = value.String | ||
} | ||
return value.String, nil | ||
} | ||
|
||
|
@@ -398,6 +430,23 @@ func PeerDBNullable(ctx context.Context, env map[string]string) (bool, error) { | |
return dynamicConfBool(ctx, env, "PEERDB_NULLABLE") | ||
} | ||
|
||
func PeerDBBinaryFormat(ctx context.Context, env map[string]string) (BinaryFormat, error) { | ||
format, err := dynLookup(ctx, env, "PEERDB_CLICKHOUSE_BINARY_FORMAT") | ||
if err != nil { | ||
return 0, err | ||
} | ||
switch strings.ToLower(strings.TrimSpace(format)) { | ||
case "raw": | ||
serprex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return BinaryFormatRaw, nil | ||
case "hex": | ||
return BinaryFormatHex, nil | ||
case "base64": | ||
return BinaryFormatBase64, nil | ||
default: | ||
return 0, fmt.Errorf("unknown binary format %s", format) | ||
} | ||
} | ||
|
||
func PeerDBEnableClickHousePrimaryUpdate(ctx context.Context, env map[string]string) (bool, error) { | ||
return dynamicConfBool(ctx, env, "PEERDB_CLICKHOUSE_ENABLE_PRIMARY_UPDATE") | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a panic can cause issues with maintenance mode (relies on flow-worker being active to pause mirrors)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
panic can never happen unless a logic error is introduced in code, & bad code can always panic anyways