Skip to content
Open
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
7 changes: 6 additions & 1 deletion internal/mockstore/mocktikv/pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"github.com/tikv/client-go/v2/util"
pd "github.com/tikv/pd/client"
pdgc "github.com/tikv/pd/client/clients/gc"
"github.com/tikv/pd/client/clients/metastorage"
"github.com/tikv/pd/client/clients/router"
"github.com/tikv/pd/client/clients/tso"
"github.com/tikv/pd/client/constants"
Expand Down Expand Up @@ -430,6 +431,10 @@
return nil, nil
}

func (c *pdClient) LoadKeyspaceByID(ctx context.Context, id uint32) (*keyspacepb.KeyspaceMeta, error) {
return nil, nil
}

func (c *pdClient) WatchKeyspaces(ctx context.Context) (chan []*keyspacepb.KeyspaceMeta, error) {
return nil, nil
}
Expand Down Expand Up @@ -486,7 +491,7 @@
return nil
}

func (c *pdClient) Watch(ctx context.Context, key []byte, opts ...opt.MetaStorageOption) (chan []*meta_storagepb.Event, error) {
func (c *pdClient) Watch(ctx context.Context, key []byte, opts ...opt.MetaStorageOption) (chan *metastorage.WatchResponse, error) {

Check failure on line 494 in internal/mockstore/mocktikv/pd.go

View workflow job for this annotation

GitHub Actions / golangci

undefined: metastorage.WatchResponse (typecheck)

Check failure on line 494 in internal/mockstore/mocktikv/pd.go

View workflow job for this annotation

GitHub Actions / race-test

undefined: metastorage.WatchResponse

Check failure on line 494 in internal/mockstore/mocktikv/pd.go

View workflow job for this annotation

GitHub Actions / test

undefined: metastorage.WatchResponse

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect the vendored/pinned pd client's metastorage package for the actual exported types.
fd -t d 'metastorage' | xargs -I{} find {} -name '*.go' | xargs -I{} sh -c 'echo "== {} =="; grep -n "^type\|^func" {}'

Repository: tikv/client-go

Length of output: 152


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '== go.mod ==\n'
sed -n '1,220p' go.mod

printf '\n== references to WatchResponse and metastorage ==\n'
rg -n "WatchResponse|metastorage\.Watch|metastorage" internal/mockstore/mocktikv/pd.go txnkv/transaction/test_util.go . -g '!**/vendor/**'

printf '\n== pd.go around Watch ==\n'
sed -n '450,560p' internal/mockstore/mocktikv/pd.go

printf '\n== test_util.go relevant section ==\n'
sed -n '1,220p' txnkv/transaction/test_util.go

Repository: tikv/client-go

Length of output: 15244


🌐 Web query:

github.com/tikv/pd/client metastorage WatchResponse exported type watch response

💡 Result:

In the TiKV and PD (Placement Driver) ecosystem, WatchResponse is an exported type originating from the kvproto repository [1][2], specifically defined within the meta_storagepb package. While the PD Go client (github.com/tikv/pd/client) interacts with PD, WatchResponse is primarily associated with the gRPC-based Meta Storage API used for watching changes to meta data [1][2]. In the TiKV Rust client implementation, WatchResponse is used as part of the streaming response when a watch request is initiated against the Meta Storage service [1][2]. Key points regarding the usage of WatchResponse: - Definition: It is a protobuf-generated message type defined in kvproto under meta_storagepb [1][2]. - Usage: It is utilized in streaming RPC calls (e.g., in Rust, it is returned via grpcio::ClientSStreamReceiver<WatchResponse>) to handle updates or events related to watched keys or paths [1][2]. - Go Client Context: While the Go client library provides methods like WatchGlobalConfig [3], it manages its own internal channels and response types (e.g., GlobalConfigItem) rather than directly exposing the meta_storagepb.WatchResponse type to the high-level application developer interface [3]. If you are working directly with the generated gRPC client in Go, you would import it from the generated meta_storagepb package [1][2]. If you are encountering issues with WatchResponse (such as memory management or channel handling), developers often look at the underlying gRPC stream processing, as errors in the stream are typically accessible via the Err() method on the response object or during the stream consumption process [4].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== go.mod snippets =='
rg -n 'github.com/tikv/pd/client|replace .*pd/client|metastorage' go.mod go.sum

echo
echo '== local module cache candidates =='
go env GOPATH GOMODCACHE

echo
echo '== search module cache for metastorage package files =='
modcache="$(go env GOMODCACHE)"
find "$modcache" -path '*github.com/tikv/pd/client*' -path '*metastorage*' -type f -name '*.go' 2>/dev/null | head -n 50

echo
echo '== search for WatchResponse symbols in cached pd client =='
grep -RIn --include='*.go' 'type .*WatchResponse\|WatchResponse' "$modcache"/github.com/tikv/pd/client* 2>/dev/null | head -n 80

Repository: tikv/client-go

Length of output: 808


🏁 Script executed:

#!/bin/bash
set -euo pipefail

modcache="$(go env GOMODCACHE)"
file="$modcache/github.com/tikv/pd/client@v0.0.0-20260601035915-3ef6a3b10c84/clients/metastorage/client.go"

printf '== %s ==\n' "$file"
cat -n "$file" | sed -n '1,260p'

printf '\n== watch-related declarations ==\n'
rg -n 'Watch|WatchResponse|type .*Response|meta_storagepb' "$file"

Repository: tikv/client-go

Length of output: 4496


Replace metastorage.WatchResponse with []*meta_storagepb.Event

github.com/tikv/pd/client@v0.0.0-20260601035915-3ef6a3b10c84 exposes Watch(ctx, ...) (chan []*meta_storagepb.Event, error) in clients/metastorage, so both this mock and txnkv/transaction/test_util.go should use that element type.

🧰 Tools
🪛 GitHub Check: golangci

[failure] 494-494:
undefined: metastorage.WatchResponse (typecheck)

🪛 GitHub Check: test

[failure] 494-494:
undefined: metastorage.WatchResponse

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/mockstore/mocktikv/pd.go` at line 494, Update the Watch API return
type to match the PD client’s metastorage contract: the pdClient.Watch method
should return a channel of []*meta_storagepb.Event instead of chan
*metastorage.WatchResponse, and the corresponding test helper in
txnkv/transaction/test_util.go should use the same element type. Make sure any
WatchResponse-specific handling is removed or adapted so the mock aligns with
the clients/metastorage Watch signature.

Sources: Linters/SAST tools, Pipeline failures

return nil, nil
}

Expand Down
8 changes: 7 additions & 1 deletion txnkv/transaction/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"github.com/tikv/client-go/v2/util/async"
pd "github.com/tikv/pd/client"
"github.com/tikv/pd/client/clients/gc"
"github.com/tikv/pd/client/clients/metastorage"
"github.com/tikv/pd/client/clients/router"
"github.com/tikv/pd/client/clients/tso"
"github.com/tikv/pd/client/opt"
Expand Down Expand Up @@ -254,6 +255,11 @@
panic("unimplemented")
}

// LoadKeyspaceByID implements pd.Client.
func (u *unimplementedPDClient) LoadKeyspaceByID(ctx context.Context, id uint32) (*keyspacepb.KeyspaceMeta, error) {
panic("unimplemented")
}

// LoadResourceGroups implements pd.Client.
func (u *unimplementedPDClient) LoadResourceGroups(ctx context.Context) ([]*resource_manager.ResourceGroup, int64, error) {
panic("unimplemented")
Expand Down Expand Up @@ -335,7 +341,7 @@
}

// Watch implements pd.Client.
func (u *unimplementedPDClient) Watch(ctx context.Context, key []byte, opts ...opt.MetaStorageOption) (chan []*meta_storagepb.Event, error) {
func (u *unimplementedPDClient) Watch(ctx context.Context, key []byte, opts ...opt.MetaStorageOption) (chan *metastorage.WatchResponse, error) {

Check failure on line 344 in txnkv/transaction/test_util.go

View workflow job for this annotation

GitHub Actions / race-test

undefined: metastorage.WatchResponse

Check failure on line 344 in txnkv/transaction/test_util.go

View workflow job for this annotation

GitHub Actions / test

undefined: metastorage.WatchResponse

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate the file and nearby references
git ls-files | rg '^txnkv/transaction/test_util\.go$|^internal/mockstore/mocktikv/pd\.go$|metastorage\.WatchResponse|WatchResponse|MetaStorageOption'

# Show the relevant section of txnkv/transaction/test_util.go
if [ -f txnkv/transaction/test_util.go ]; then
  sed -n '300,380p' txnkv/transaction/test_util.go
fi

# Show the relevant section of internal/mockstore/mocktikv/pd.go if present
if [ -f internal/mockstore/mocktikv/pd.go ]; then
  sed -n '1,220p' internal/mockstore/mocktikv/pd.go
fi

# Search for the Watch method and WatchResponse type usages across the repo
rg -n "func \(u \*unimplementedPDClient\) Watch|metastorage\.WatchResponse|type WatchResponse|WatchResponse" .

Repository: tikv/client-go

Length of output: 11025


🏁 Script executed:

set -euo pipefail

# Show the pd/client version pinned by this repo
rg -n 'github.com/tikv/pd/client|github.com/tikv/pd' go.mod go.sum

# Search for any local references to metastorage.WatchResponse or WatchResponse
rg -n 'metastorage\.WatchResponse|type WatchResponse|WatchResponse' .

# Inspect the pd.Client-facing watch methods around the mock implementation
sed -n '470,520p' internal/mockstore/mocktikv/pd.go
sed -n '330,360p' txnkv/transaction/test_util.go

Repository: tikv/client-go

Length of output: 3925


🏁 Script executed:

set -euo pipefail

echo "GOMODCACHE=$(go env GOMODCACHE)"
echo "GOPATH=$(go env GOPATH)"

modcache="$(go env GOMODCACHE)"
pdroot="$modcache/github.com/tikv/pd/client@v0.0.0-20260601035915-3ef6a3b10c84"

if [ -d "$pdroot" ]; then
  echo "FOUND_MODULE_CACHE=$pdroot"
  rg -n "type WatchResponse|WatchResponse" "$pdroot"/clients/metastorage "$pdroot"/clients -g'*.go'
  sed -n '1,220p' "$pdroot"/clients/metastorage/*.go 2>/dev/null || true
else
  echo "Module cache directory not found: $pdroot"
fi

Repository: tikv/client-go

Length of output: 320


🏁 Script executed:

set -euo pipefail

modcache="$(go env GOMODCACHE)"
pdroot="$modcache/github.com/tikv/pd/client@v0.0.0-20260601035915-3ef6a3b10c84"

echo "Files under clients/metastorage:"
find "$pdroot/clients/metastorage" -maxdepth 2 -type f | sort

echo
echo "Search for WatchResponse and package declarations:"
rg -n "type WatchResponse|WatchResponse|package " "$pdroot/clients/metastorage" -g'*.go'

echo
echo "Show the metastorage files:"
for f in "$pdroot"/clients/metastorage/*.go; do
  echo "---- $f ----"
  sed -n '1,220p' "$f"
done

Repository: tikv/client-go

Length of output: 3805


Use chan []*meta_storagepb.Event here

metastorage.WatchResponse doesn’t exist in the pinned github.com/tikv/pd/client version; pd.Client.Watch now returns chan []*meta_storagepb.Event, so this signature breaks the build.

🧰 Tools
🪛 GitHub Check: test

[failure] 344-344:
undefined: metastorage.WatchResponse

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@txnkv/transaction/test_util.go` at line 344, The unimplemented PD client
Watch signature is using an outdated return type, which breaks compilation
against the pinned pd client version. Update the Watch method on
unimplementedPDClient to match pd.Client.Watch by returning chan
[]*meta_storagepb.Event instead of chan *metastorage.WatchResponse, and ensure
the surrounding transaction test utilities use the same event type consistently.

Sources: Linters/SAST tools, Pipeline failures

panic("unimplemented")
}

Expand Down
Loading