xline-kv / Xline

A geo-distributed KV store for metadata management
https://xline.cloud
Apache License 2.0
562 stars 70 forks source link

[etcdapi] [Bug]: Repeated revision #848

Open liangyuanpeng opened 2 weeks ago

liangyuanpeng commented 2 weeks ago

Description about the bug

I'm testing xline with kubernetes conformance. There's a high probability i will get an error: the object has been modified; please apply your changes to the latest version and try again, In general this is a specific design of the k8s, not a fault, but it is a real problem when it becomes a blocker to conformance testing.

the reason is xline retrun the repeate revision.

try to reproduce:

package main

import (
    "context"
    "fmt"
    "log"
    "sync"
    "time"

    clientv3 "go.etcd.io/etcd/client/v3"
)

func main() {
    config := clientv3.Config{
        Endpoints: []string{"192.168.66.2:12379"},
        DialTimeout: 5 * time.Second,
    }
    client, err := clientv3.New(config)
    if err != nil {
        log.Fatal("init client error:", err)
    }

    fmt.Println(client.Cluster.MemberList(context.TODO()))
    c := make(chan *kvresp, 100)
    revmap := make(map[int64]string)
    var mu sync.RWMutex
    putdata(client, 6, c)
    for {
        x := <-c
        mu.RLock()
        if _, ok := revmap[x.reversion]; ok {
            log.Fatalf("exist reversion:%d when working for key:%s !! \n", x.reversion, x.key)
        }
        revmap[x.reversion] = x.key
        log.Printf("finished for key:%s and reversion:%d \n", x.key, x.reversion)
        mu.RUnlock()
    }

}

type kvresp struct {
    key       string
    reversion int64
}

func putdata(client *clientv3.Client, channelcount int, cc chan *kvresp) {

    sts := []string{"/kindtest/configmaps/namespace/cm2", "/kindtest/configmaps/namespace/cm1", "/kindtest/configmaps/namespace/cm3", "/kindtest/configmaps/namespace/cm4", "/kindtest/configmaps/namespace/cm5", "/kindtest/configmaps/namespace/cm6"}

    for i := 0; i < channelcount; i++ {
        go func() {
            for {
                k := sts[i]
                resp, err := client.KV.Put(context.TODO(), k, "world1111111111111111kkkkkkkkkkkkkkkkkkkkkkkkkkkkxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxpppppppppppppppppppppppppwwwwwwwwwwwwwwwwwwwwwwwwwwqqqqqqqqqqqqqqqqqqqqqqqq")
                if err != nil {
                    log.Fatal("put data failed!", err)
                }
                cc <- &kvresp{
                    reversion: resp.Header.Revision,
                    key:       k,
                }
                // time.Sleep(200)
            }

        }()
    }
}

cc @Phoenix500526 @bsbds

Version

xline version: master (ghcr.io/xline-kv/xline:latest) go version: 1.22

Relevant log output

$ go run main.go 
&{cluster_id:18175749204089910324 member_id:16162903154130446168 revision:10233  [ID:16162903154130446168 name:"xline" peerURLs:"0.0.0.0:12379" clientURLs:"http://0.0.0.0:12379" ] {} [] 0} <nil>
2024/06/11 07:44:18 finished for key:/kindtest/configmaps/namespace/cm6 and reversion:10237 
2024/06/11 07:44:18 finished for key:/kindtest/configmaps/namespace/cm2 and reversion:10234 
2024/06/11 07:44:18 exist reversion:10237 when working for key:/kindtest/configmaps/namespace/cm3 !! 
exit status 1

Code of Conduct

github-actions[bot] commented 2 weeks ago

👋 Thanks for opening this issue!

Reply with the following command on its own line to get help or engage:

bsbds commented 2 weeks ago

This is a known issue in Xline, it will be fixed in 0.7.0