kvtools / redis

Valkeyrie: redis
Apache License 2.0
3 stars 5 forks source link

Not notified by the WatchTree when delete the root key #4

Open sunyakun opened 1 year ago

sunyakun commented 1 year ago

Welcome

Description of the problem

The traefik kv provider utilizes the WatchTree interface to monitor events of key changes in the kv store. However, when we delete the root key in Redis, the WatchTree fails to notify the kv provider about the modification of certain keys.

Version of Valkeyrie

commitID: 7cf91fd7ec3f113bf4ef40af497ccb1e803f69c8

Version of store

commitID: d785cd6b72f2e2ca764d18bddf4a98121e2d4033

Go environment

```console $ go version && go env go version go1.20.5 linux/amd64 GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/sunyakun.king/.cache/go-build" GOENV="/home/sunyakun.king/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/data00/home/sunyakun.king/go/pkg/mod" GOOS="linux" GOPATH="/data00/home/sunyakun.king/go" GOPROXY="https://goproxy.cn,https://proxy.golang.org,direct" GOROOT="/home/sunyakun.king/sdk/go1.20.5" GOSUMDB="sum.golang.google.cn" GOTMPDIR="" GOTOOLDIR="/home/sunyakun.king/sdk/go1.20.5/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.20.5" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/sunyakun.king/kvtools/redis/go.mod" GOWORK="/home/sunyakun.king/kvtools/go.work" CGO_CFLAGS="-O2 -g" CGO_CPPFLAGS="" CGO_CXXFLAGS="-O2 -g" CGO_FFLAGS="-O2 -g" CGO_LDFLAGS="-O2 -g" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1759202274=/tmp/go-build -gno-record-gcc-switches" ```

Code example or link to a public repository

First you should start a local redis running in the docker container. ```console $ docker run -d --rm --name redis -p 6379:6379 redis ``` Then execute the script. ```go package main import ( "context" "time" "github.com/kvtools/redis" "github.com/kvtools/valkeyrie" "github.com/sirupsen/logrus" ) var ( RedisAddr = "localhost:6379" ) func main() { ctx := context.Background() r, err := valkeyrie.NewStore( context.Background(), redis.StoreName, []string{RedisAddr}, &redis.Config{ DB: 0, }, ) if err != nil { logrus.Fatal(err) } kvpairsCh, err := r.WatchTree(ctx, "traefik", nil) if err != nil { logrus.Fatal(err) } go func() { for kvpairs := range kvpairsCh { logrus.Info("====== Receive ======") for _, pair := range kvpairs { logrus.Info(pair.Key) } logrus.Info("====== End ======") } }() time.Sleep(1 * time.Second) // put key to kv store err = r.Put(ctx, "traefik/node1", []byte("val1"), nil) if err != nil { logrus.Fatal(err) } time.Sleep(1 * time.Second) // delete key from kv store err = r.Delete(ctx, "traefik/node1") if err != nil { logrus.Fatal(err) } time.Sleep(1 * time.Second) logrus.Info("exit!") } ``` Expected output: ```console // watchLoop will fetch all kv pairs before receive message from redis INFO[0000] ====== Receive ====== INFO[0000] ====== End ====== // receive key set message from redis INFO[0001] ====== Receive ====== INFO[0001] traefik/node1 INFO[0001] ====== End ====== // receive key del message from redis INFO[0002] ====== Receive ====== INFO[0002] ====== End ====== INFO[0003] exit! ``` Actual output ```console INFO[0001] ====== Receive ====== INFO[0001] traefik/node1 INFO[0001] ====== End ====== INFO[0003] exit! ```