Skip to content

Commit e63f912

Browse files
committed
go: store/datas/pull: pull_chunk_tracker.go: PR feedback.
1 parent 43da391 commit e63f912

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

go/store/datas/pull/pull_chunk_fetcher_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,25 @@ func TestPop(t *testing.T) {
190190
backing[i] = new(int)
191191
*backing[i] = i
192192
}
193+
// s is pointers of [0, 1, 2, ..., 16]
193194
s := backing[:]
195+
assert.Len(t, s, 16)
196+
// pop continuously and assert that we see
197+
// the sequence 0, 1, 2, ..., 16 and each
198+
// prior element at the end of the list is
199+
// |nil|.
194200
for i := range 16 {
195-
assert.Len(t, s, 16-i)
196201
var p *int
197202
p, s = pop(s)
198203
assert.Len(t, s, 16-i-1)
199204
assert.Equal(t, i, *p)
205+
// One off the end of the new |s| is now nil.
200206
assert.Nil(t, backing[16-i-1], "i is %d", i)
201207
}
208+
// pop has a precondition of len > 0. This should panic.
209+
assert.Panics(t, func() {
210+
pop(backing[:0])
211+
})
202212
}
203213

204214
func TestAppendAbsent(t *testing.T) {

go/store/datas/pull/pull_chunk_tracker.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,12 @@ func (t *PullChunkTracker) reqRespThread(ctx context.Context, initial hash.HashS
186186
outstanding -= 1
187187
if resp.err != nil {
188188
err = errors.Join(err, resp.err)
189+
} else if len(resp.hs) > 0 {
190+
// Add all the resp.hs hashes, those which are not already present
191+
// in dest, to our batches of absent hashes we will return through
192+
// GetChunksToFetch.
193+
absent = appendAbsent(absent, resp.hs, t.cfg.BatchSize)
189194
}
190-
// Add all the resp.hs hashes, those which are not already present
191-
// in dest, to our batches of absent hashes we will return through
192-
// GetChunksToFetch.
193-
absent = appendAbsent(absent, resp.hs, t.cfg.BatchSize)
194195
case thisHasManyReqCh <- hasManyReq:
195196
// We delivered a hasMany request to a hasManyThread.
196197
// Remove it here. We do not need to update |outstanding|, since
@@ -232,7 +233,7 @@ func (t *PullChunkTracker) reqRespThread(ctx context.Context, initial hash.HashS
232233
return eg.Wait()
233234
}
234235

235-
// Pop returns the first element of s and the remaining elements of
236+
// pop returns the first element of s and the remaining elements of
236237
// s. It copies any suffix to the front of |s| and nils the last
237238
// element of |s| so that memory doesn't leak through |s[1:]| retaining
238239
// s[0].

0 commit comments

Comments
 (0)