mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #109623 from stevekuznetsov/skuznets/clarify-list-flow
storage/etcd3: clarify the pagingation flow in LIST
This commit is contained in:
commit
1ad0940732
@ -593,9 +593,11 @@ func (s *store) GetList(ctx context.Context, key string, opts storage.ListOption
|
|||||||
|
|
||||||
// set the appropriate clientv3 options to filter the returned data set
|
// set the appropriate clientv3 options to filter the returned data set
|
||||||
var limitOption *clientv3.OpOption
|
var limitOption *clientv3.OpOption
|
||||||
var limit int64 = pred.Limit
|
limit := pred.Limit
|
||||||
|
var paging bool
|
||||||
options := make([]clientv3.OpOption, 0, 4)
|
options := make([]clientv3.OpOption, 0, 4)
|
||||||
if s.pagingEnabled && pred.Limit > 0 {
|
if s.pagingEnabled && pred.Limit > 0 {
|
||||||
|
paging = true
|
||||||
options = append(options, clientv3.WithLimit(limit))
|
options = append(options, clientv3.WithLimit(limit))
|
||||||
limitOption = &options[len(options)-1]
|
limitOption = &options[len(options)-1]
|
||||||
}
|
}
|
||||||
@ -722,7 +724,7 @@ func (s *store) GetList(ctx context.Context, key string, opts storage.ListOption
|
|||||||
|
|
||||||
// take items from the response until the bucket is full, filtering as we go
|
// take items from the response until the bucket is full, filtering as we go
|
||||||
for i, kv := range getResp.Kvs {
|
for i, kv := range getResp.Kvs {
|
||||||
if limitOption != nil && int64(v.Len()) >= pred.Limit {
|
if paging && int64(v.Len()) >= pred.Limit {
|
||||||
hasMore = true
|
hasMore = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -748,7 +750,7 @@ func (s *store) GetList(ctx context.Context, key string, opts storage.ListOption
|
|||||||
}
|
}
|
||||||
|
|
||||||
// no more results remain or we didn't request paging
|
// no more results remain or we didn't request paging
|
||||||
if !hasMore || limitOption == nil {
|
if !hasMore || !paging {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// we're paging but we have filled our bucket
|
// we're paging but we have filled our bucket
|
||||||
|
Loading…
Reference in New Issue
Block a user