Skip to content

Commit

Permalink
new codec by keyspace meta (#1538)
Browse files Browse the repository at this point in the history
 

Signed-off-by: ystaticy <[email protected]>
  • Loading branch information
ystaticy authored Dec 26, 2024
1 parent 44e6239 commit 105df23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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) {
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

// 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

0 comments on commit 105df23

Please sign in to comment.