Skip to content

Commit 0f9445a

Browse files
committed
address review comments
1 parent 7f9355f commit 0f9445a

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

lib/backend/backend.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,15 @@ type Backend interface {
117117
// IterateParams are parameters that are provided to
118118
// [BackendWithItems.Items] to alter the iteration behavior.
119119
type IterateParams struct {
120-
// StartKey is the key at which to begin iteration. This key
120+
// StartKey is the minimum key in the range yielded by the iteration. This key
121121
// will be included in the results if it exists.
122122
StartKey Key
123-
// EndKey is the key at which to end iteration. This key
123+
// EndKey is the maximum key in the range yielded by the iteration. This key
124124
// will be included in the results if it exists.
125125
EndKey Key
126-
// Descending indicates which direction the items should be produced,
127-
// by default from [StartKey] to [EndKey].
126+
// Descending makes the iteration yield items from the biggest to the smallest
127+
// key (i.e. from EndKey to StartKey). If unset, the iteration will proceed in the
128+
// usual ascending order (i.e. from StartKey to EndKey).
128129
Descending bool
129130
// Limit is an optional maximum number of items to retrieve during iteration.
130131
Limit int

lib/backend/etcdbk/etcd.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,9 @@ func (b *EtcdBackend) Items(ctx context.Context, params backend.IterateParams) i
689689
batchReadLatencies.Observe(time.Since(start).Seconds())
690690
batchReadRequests.Inc()
691691
if err := convertErr(err); err != nil {
692-
if yield(backend.Item{}, trace.Wrap(err)) {
693-
b.logger.ErrorContext(ctx, "items iteration allowed to continue after encountering error (this is a bug)", "error", err)
692+
if !yield(backend.Item{}, trace.Wrap(err)) {
693+
return
694694
}
695-
return
696695
}
697696

698697
if len(re.Kvs) == 0 {
@@ -702,10 +701,9 @@ func (b *EtcdBackend) Items(ctx context.Context, params backend.IterateParams) i
702701
for _, kv := range re.Kvs {
703702
value, err := unmarshal(kv.Value)
704703
if err != nil {
705-
if yield(backend.Item{}, trace.Wrap(err)) {
706-
b.logger.ErrorContext(ctx, "items iteration allowed to continue after encountering error (this is a bug)", "error", err)
704+
if !yield(backend.Item{}, trace.Wrap(err)) {
705+
return
707706
}
708-
return
709707
}
710708

711709
if !yield(backend.Item{
@@ -725,7 +723,7 @@ func (b *EtcdBackend) Items(ctx context.Context, params backend.IterateParams) i
725723
if params.Descending {
726724
endKey = string(re.Kvs[len(re.Kvs)-1].Key)
727725
} else {
728-
inclusiveStartKey = backend.RangeEnd(backend.KeyFromString(string(re.Kvs[len(re.Kvs)-1].Key))).String()
726+
inclusiveStartKey = string(re.Kvs[len(re.Kvs)-1].Key) + "\x00"
729727
}
730728
}
731729
}

lib/backend/test/suite.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ func testItems(t *testing.T, newBackend Constructor) {
567567
t.Run("descending", func(t *testing.T) {
568568
i := count - 1
569569
for item := range it.Items(ctx, backend.IterateParams{StartKey: prefix("page"), EndKey: backend.RangeEnd(prefix("page")), Descending: true}) {
570-
t.Logf("expected=%s|actual=%s", expected[i], string(item.Value))
571570
assert.Equal(t, expected[i], string(item.Value))
572571
i--
573572
}

0 commit comments

Comments
 (0)