-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
*: sort by ASCEND on missing sort order #6672
Conversation
@@ -105,6 +106,13 @@ func getGetOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) { | |||
opts = append(opts, clientv3.WithRev(getRev)) | |||
} | |||
|
|||
if getSortOrder == "" && getSortTarget != "" { | |||
ExitWithError(ExitBadFeature, errors.New("missing sort order (--order)")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exitbadflag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have bad flag exit. Instead used ExitBadArgs
. Is that ok?
PTAL.
ea4ed1f
to
4981faf
Compare
If there is no order given, shouldnt etcd assumes an ordering? |
I do not know why i tell etcdctl to sort by create revision but it does not. |
@xiang90 func WithSort(target SortTarget, order SortOrder) OpOption {
return func(op *Op) {
if target == SortByKey && order == SortAscend {
// If order != SortNone, server fetches the entire key-space,
// and then applies the sort and limit, if provided.
// Since current mvcc.Range implementation returns results
// sorted by keys in lexiographically ascending order,
// client should ignore SortOrder if the target is SortByKey.
order = SortNone
}
op.sort = &SortOption{target, order}
}
} But this doesn't cover the case of It works when |
We should fill in a default order for users when they specify sort-by x when x is not key. |
@xiang90 Right that's better. Will rework on this with more tests. Thanks. |
4981faf
to
1531a5d
Compare
1531a5d
to
5aa6e43
Compare
@@ -137,6 +137,13 @@ func getGetOp(cmd *cobra.Command, args []string) (string, []clientv3.OpOption) { | |||
ExitWithError(ExitBadFeature, fmt.Errorf("bad sort target %v", getSortTarget)) | |||
} | |||
|
|||
if sortByTarget != clientv3.SortByKey && sortByOrder == clientv3.SortNone { | |||
// Since current mvcc.Range implementation returns results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively, can we fix this at server side? in apply.go line 321?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if any target is specified and sort_order == none, we should set sort order to ascend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure will try that.
17fb4b7
to
41aad54
Compare
@@ -227,6 +227,8 @@ func WithSort(target SortTarget, order SortOrder) OpOption { | |||
// client should ignore SortOrder if the target is SortByKey. | |||
order = SortNone | |||
} | |||
// server-side sets order == SortAscend by default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok removed.
41aad54
to
48bfe45
Compare
@@ -323,6 +323,11 @@ func (a *applierV3backend) Range(txnID int64, r *pb.RangeRequest) (*pb.RangeResp | |||
sort.Sort(sorter) | |||
case r.SortOrder == pb.RangeRequest_DESCEND: | |||
sort.Sort(sort.Reverse(sorter)) | |||
case r.SortTarget != pb.RangeRequest_KEY: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i do not understand this. we will only reach this code if sort order is not none (see 307). What we want is to sort the keys if target == create and order == none.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, will fix.
de21c8c
to
c123f7e
Compare
c123f7e
to
4de2128
Compare
@@ -226,6 +226,21 @@ func TestKVRange(t *testing.T) { | |||
{Key: []byte("fop"), Value: nil, CreateRevision: 9, ModRevision: 9, Version: 1}, | |||
}, | |||
}, | |||
// range all with SortByKey, missing sorting order (ASCEND by default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably should also add a server side test.
LGTM |
@xiang90 Also added a test case in server side. Will merge if there's no objection? Thanks. |
LGTM |
Address #6671.
/cc @xiang90