k3s-io / kine

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

question: why order by id asc for list query #191

Closed wangyanphp closed 1 year ago

wangyanphp commented 1 year ago

when i send a list request to kine, i get results which are order by id. image

but when i send a list request to etcd, i will get results which are order by name.

so my question is: The behavior of kine and etcd isn't the same, is this an expected behavior?

brandond commented 1 year ago

Ordering by key isn't guaranteed anywhere as far as I know. We consider it an implementation detail that we have not chosen to replicate. Kubernetes doesn't require it.

wangyanphp commented 1 year ago

Ordering by key isn't guaranteed anywhere as far as I know. We consider it an implementation detail that we have not chosen to replicate. Kubernetes doesn't require it.

ok, I didn't realize that k8s relies on the order of keys until I saw it using keys for paging list: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go#L800

in k8s paging list implement, the next list request using last key+'\x00' as key

wangyanphp commented 1 year ago

Ordering by key isn't guaranteed anywhere as far as I know. We consider it an implementation detail that we have not chosen to replicate. Kubernetes doesn't require it.

ok, I didn't realize that k8s relies on the order of keys until I saw it using keys for paging list: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go#L800

in k8s paging list implement, the next list request using last key+'\x00' as key

I had a misunderstanding about the code implementation, but I've corrected my understanding by debugging the code step by step, thank you very much