Skip to content

watchKeyspace initial load not complete #6527

@AmoebaProtozoa

Description

@AmoebaProtozoa

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions