Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes the incorrect total items count in a paginated list items q… #271

Merged
merged 2 commits into from
Feb 2, 2024

Conversation

HemantNegi
Copy link
Contributor

@HemantNegi HemantNegi commented Jan 25, 2024

When making a list query the returned total matched items count is wrong.

Steps to replicate:
create some keys in the database with specific prefix say /registry then query with limit clause.

kine ❯ etcdctl get --prefix /registry --limit 1 --write-out=json | jq
{
  "header": {
    "revision": 494943
  },
  "kvs": [
    {
      "key": "L3JlZ2lzdHJ5L2hlYWx0aA==",
      "create_revision": 2,
      "mod_revision": 2,
      "value": "eyJoZWFsdGgiOiJ0cnVlIn0="
    }
  ],
  "more": true,
  "count": 2
}

the count shows wrong value.

After this Fix

kine ❯ etcdctl get --prefix /registry --limit 1 --write-out=json | jq
{
  "header": {
    "revision": 495036
  },
  "kvs": [
    {
      "key": "L3JlZ2lzdHJ5L2hlYWx0aA==",
      "create_revision": 2,
      "mod_revision": 2,
      "value": "eyJoZWFsdGgiOiJ0cnVlIn0="
    }
  ],
  "more": true,
  "count": 1842
}

@HemantNegi HemantNegi requested a review from a team as a code owner January 25, 2024 12:02
@HemantNegi
Copy link
Contributor Author

This problem was originally noticed while we were using Kine with a k8s api server. We make a paginated list objects api call and it returned incorrect remainingItemCount.

Please consider merging this or else fix this issue.

@HemantNegi HemantNegi changed the title fixes the incorrect remaining items count in a paginated list items q… fixes the incorrect total items count in a paginated list items q… Jan 25, 2024
Copy link
Member

@brandond brandond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I do have one note about read consistency on the count call.

pkg/server/list.go Outdated Show resolved Hide resolved
@brandond brandond dismissed their stale review January 26, 2024 01:44

have contributed

@brandond brandond requested a review from a team January 26, 2024 01:44
@brandond brandond force-pushed the fix_remaining_item_count branch 2 times, most recently from 1111c8b to 3e49adc Compare January 26, 2024 01:50
@brandond
Copy link
Member

brandond commented Jan 26, 2024

Can also test this with:

kubectl proxy &
curl -s 'http://localhost:8001/api/v1/namespaces/kube-system/pods?limit=1&resourceVersion=700&resourceVersionMatch=Exact'

On a default k3s cluster shortly after startup, there should be 6 items remaining.

HemantNegi and others added 2 commits January 30, 2024 22:18
…uery

Signed-off-by: Hemant Singh <shemant@vmware.com>
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
@brandond brandond requested review from dereknola and a team January 30, 2024 22:18
@HemantNegi
Copy link
Contributor Author

Thankyou for taking quick action on this and fixing other case as well. Looking forward to get it merged.

@brandond brandond merged commit 3773672 into k3s-io:master Feb 2, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants