k3s-io / kine

Run Kubernetes on MySQL, Postgres, sqlite, dqlite, not etcd.
Apache License 2.0
1.54k stars 231 forks source link

question: in mysql, GetRevisionAfterSQL sql will return empty when subquery return null value #186

Closed wangyanphp closed 1 year ago

wangyanphp commented 1 year ago

image when this subquery return null( there is no selected rows), the where clause will become "mkv.id > NULL", it's the expected behavior?

brandond commented 1 year ago

Yes? Is there a problem?

wangyanphp commented 1 year ago

Yes, when i called range method with revision options, i alway get empty result. so i tried modify code for mysql, it works. but i'm not sure if there will be any side effects image

brandond commented 1 year ago

Are you sure you're calling it with valid options? Where did you get the revision from?

I'm not sure how the subquery would ever return null unless you're using a key or revision that don't exist.

wangyanphp commented 1 year ago

yes, i used a non-existent key, my request is:

        key := "/registry"
        opts = []clientv3.OpOption{clientv3.WithLimit(1000), clientv3.WithRev(357286)}
        rangeEnd := clientv3.GetPrefixRangeEnd(key)
        opts = append(opts, clientv3.WithRange(rangeEnd))

the key "/registry" doesn't exist

brandond commented 1 year ago

Kine intentionally implements only the bits of etcd that Kubernetes uses. If Kubernetes doesn't make calls in that same way, it's likely that kine does not implement that functionality. Can you get the desired behavior out of a real etcd server, given the same keys and client calls?

wangyanphp commented 1 year ago

Kine intentionally implements only the bits of etcd that Kubernetes uses. If Kubernetes doesn't make calls in that same way, it's likely that kine does not implement that functionality. Can you get the desired behavior out of a real etcd server, given the same keys and client calls?

yes, Kubernetes doesn't make calls in that way. i'm migrating data from etcd to kine using etcdctl make-mirror tool. I can get the desired behavior out of a real etcd server with the same key and options. And i also can get the desired behavior from kine when i added COALESCE function in "idOfKey" sql:

    idOfKey = `
        AND
        mkv.id <= ? AND
        mkv.id > COALESCE((
            SELECT MAX(ikv.id) AS id
            FROM kine AS ikv
            WHERE
                ikv.name = ? AND
                ikv.id <= ?), 0)`
brandond commented 1 year ago

K3s itself has a kine -> etcd data migration function built in, you can find it at: https://github.com/k3s-io/k3s/blob/213d7ad499e166290872f51c63d8eaa2f1fe78b3/pkg/etcd/etcd.go#LL740C2

I imagine you could use that same function, but swap the clients, to go the other direction.