Skip to content
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

new codec by keyspace meta #1538

Merged
merged 6 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions internal/locate/pd_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ func NewCodecPDClientWithKeyspace(mode apicodec.Mode, client pd.Client, keyspace
return &CodecPDClient{client, codec}, nil
}

// NewCodecPDClientWithKeyspaceMeta creates a CodecPDClient in API v2 with keyspace meta.
func NewCodecPDClientWithKeyspaceMeta(mode apicodec.Mode, client pd.Client, keyspaceMeta *keyspacepb.KeyspaceMeta) (*CodecPDClient, error) {
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
if keyspaceMeta == nil {
return NewCodecPDClient(mode, client), nil
}

codec, err := apicodec.NewCodecV2(mode, keyspaceMeta)
if err != nil {
return nil, err
}
return &CodecPDClient{client, codec}, nil
}

// GetKeyspaceID attempts to retrieve keyspace ID corresponding to the given keyspace name from PD.
func GetKeyspaceID(client pd.Client, name string) (uint32, error) {
meta, err := client.LoadKeyspace(context.Background(), apicodec.BuildKeyspaceName(name))
Expand Down
3 changes: 3 additions & 0 deletions tikv/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ var NewCodecPDClient = locate.NewCodecPDClient
// NewCodecPDClientWithKeyspace creates a CodecPDClient in API v2 with keyspace name.
var NewCodecPDClientWithKeyspace = locate.NewCodecPDClientWithKeyspace
ystaticy marked this conversation as resolved.
Show resolved Hide resolved

// NewCodecPDClientWithKeyspaceMeta creates a CodecPDClient in API v2 with keyspace meta.
var NewCodecPDClientWithKeyspaceMeta = locate.NewCodecPDClientWithKeyspaceMeta

// NewCodecV1 is a constructor for v1 Codec.
var NewCodecV1 = apicodec.NewCodecV1

Expand Down
Loading