Skip to content
/ etcd Public
forked from etcd-io/etcd

Commit

Permalink
ctlv3: default sort order on missing sort target
Browse files Browse the repository at this point in the history
Address etcd-io#6671.
  • Loading branch information
gyuho committed Oct 18, 2016
1 parent 20bdb31 commit 1531a5d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions e2e/ctl_v3_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func getTest(cx ctlCtx) {
{[]string{"key", "--prefix", "--limit=2"}, kvs[:2]},
{[]string{"key", "--prefix", "--order=ASCEND", "--sort-by=MODIFY"}, kvs},
{[]string{"key", "--prefix", "--order=ASCEND", "--sort-by=VERSION"}, kvs},
{[]string{"key", "--prefix", "--sort-by=CREATE"}, kvs}, // ASCEND by default
{[]string{"key", "--prefix", "--order=DESCEND", "--sort-by=CREATE"}, revkvs},
{[]string{"key", "--prefix", "--order=DESCEND", "--sort-by=KEY"}, revkvs},
}
Expand Down
7 changes: 7 additions & 0 deletions etcdctl/ctlv3/command/get_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// sorted by keys in lexiographically ascending order,
// set the default sort order when target is not 'KEY'
sortByOrder = clientv3.SortAscend
}

opts = append(opts, clientv3.WithSort(sortByTarget, sortByOrder))

if getPrefix {
Expand Down

0 comments on commit 1531a5d

Please sign in to comment.