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

watchKeyspace initial load not complete #6527

Closed
AmoebaProtozoa opened this issue May 28, 2023 · 0 comments · Fixed by #6528
Closed

watchKeyspace initial load not complete #6527

AmoebaProtozoa opened this issue May 28, 2023 · 0 comments · Fixed by #6528
Labels
severity/minor type/bug The issue is confirmed as a bug.

Comments

@AmoebaProtozoa
Copy link
Contributor

Bug Report

What did you do?

  1. Write a script that continuously create keyspaces
#!/bin/bash

# Set the number of keyspaces you want to create
n=800

for ((i=1; i<=n; i++))
do
    curl -X POST http://localhost:2379/pd/api/v2/keyspaces \
         -H 'Content-Type: application/json' \
         -d '{"name":"test-'$i'", "config": {}}'
done
  1. Use pdClient.WatchKeyspace
func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	pdCli, err := pd.NewClient([]string{PDAddress}, pd.SecurityOption{})
	if err != nil {
		log.Fatal("failed to create pd client", zap.Error(err))
	}

	keyspacesChan, err := pdCli.WatchKeyspaces(ctx)
	if err != nil {
		log.Fatal("failed to watch keyspace", zap.Error(err))
	}

	packIndex := 0
	totalKeyspaceCount := 0
	for {
		select {
		case <-ctx.Done():
			return
		case keyspaces := <-keyspacesChan:
			log.Info("keyspaces received",
				zap.Int("pack-index", packIndex),
				zap.Int("keyspace-count", len(keyspaces)),
				zap.Int("total-keyspace-count", totalKeyspaceCount),
			)
			for _, keyspace := range keyspaces {
				log.Info("keyspace meta",
					zap.Uint32("keyspace-id", keyspace.GetId()),
					zap.String("keyspace-name", keyspace.GetName()),
					zap.String("keyspace-state", keyspace.GetState().String()),
				)
			}
			packIndex++
			totalKeyspaceCount += len(keyspaces)
		}
	}
}

What did you expect to see?

  1. The first load from channel should contain all current keyspaces.
  2. each subsequent load from channel should contain subsequent update to keyspaces.

What did you see instead?

  1. The first load from channel only contains the first 400 keyspaces.
  2. subsequent load start from the current keyspace (600+), causing keyspace meta in the middle to be lost

What version of PD are you using (pd-server -V)?

nightly (7.2.0)

@AmoebaProtozoa AmoebaProtozoa added the type/bug The issue is confirmed as a bug. label May 28, 2023
ti-chi-bot bot pushed a commit that referenced this issue May 29, 2023
close #6527

Signed-off-by: AmoebaProtozoa <8039876+AmoebaProtozoa@users.noreply.github.com>
rleungx pushed a commit to rleungx/pd that referenced this issue Aug 2, 2023
close tikv#6527

Signed-off-by: AmoebaProtozoa <8039876+AmoebaProtozoa@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/minor type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants