Skip to content

Commit 4e320b8

Browse files
authored
server/internal/chunks: remove chunks package (ollama#9755)
1 parent eb2b22b commit 4e320b8

File tree

7 files changed

+32
-321
lines changed

7 files changed

+32
-321
lines changed

server/internal/cache/blob/chunked.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ import (
55
"errors"
66
"io"
77
"os"
8-
9-
"github.com/ollama/ollama/server/internal/chunks"
108
)
119

12-
type Chunk = chunks.Chunk // TODO: move chunks here?
10+
// Chunk represents a range of bytes in a blob.
11+
type Chunk struct {
12+
Start int64
13+
End int64
14+
}
15+
16+
// Size returns end minus start plus one.
17+
func (c Chunk) Size() int64 {
18+
return c.End - c.Start + 1
19+
}
1320

1421
// Chunker writes to a blob in chunks.
1522
// Its zero value is invalid. Use [DiskCache.Chunked] to create a new Chunker.

server/internal/chunks/chunks.go

Lines changed: 0 additions & 81 deletions
This file was deleted.

server/internal/chunks/chunks_test.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

server/internal/client/ollama/registry.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"golang.org/x/sync/errgroup"
3737

3838
"github.com/ollama/ollama/server/internal/cache/blob"
39-
"github.com/ollama/ollama/server/internal/chunks"
4039
"github.com/ollama/ollama/server/internal/internal/backoff"
4140
"github.com/ollama/ollama/server/internal/internal/names"
4241

@@ -500,7 +499,7 @@ func (r *Registry) Pull(ctx context.Context, name string) error {
500499
if err != nil {
501500
return err
502501
}
503-
req.Header.Set("Range", fmt.Sprintf("bytes=%s", cs.Chunk))
502+
req.Header.Set("Range", fmt.Sprintf("bytes=%d-%d", cs.Chunk.Start, cs.Chunk.End))
504503
res, err := sendRequest(r.client(), req)
505504
if err != nil {
506505
return err
@@ -794,7 +793,7 @@ func (r *Registry) chunksums(ctx context.Context, name string, l *Layer) iter.Se
794793
yield(chunksum{}, err)
795794
return
796795
}
797-
chunk, err := chunks.Parse(s.Bytes())
796+
chunk, err := parseChunk(s.Bytes())
798797
if err != nil {
799798
yield(chunksum{}, fmt.Errorf("invalid chunk range for digest %s: %q", d, s.Bytes()))
800799
return
@@ -1059,3 +1058,23 @@ func splitExtended(s string) (scheme, name, digest string) {
10591058
}
10601059
return scheme, s, digest
10611060
}
1061+
1062+
// parseChunk parses a string in the form "start-end" and returns the Chunk.
1063+
func parseChunk[S ~string | ~[]byte](s S) (blob.Chunk, error) {
1064+
startPart, endPart, found := strings.Cut(string(s), "-")
1065+
if !found {
1066+
return blob.Chunk{}, fmt.Errorf("chunks: invalid range %q: missing '-'", s)
1067+
}
1068+
start, err := strconv.ParseInt(startPart, 10, 64)
1069+
if err != nil {
1070+
return blob.Chunk{}, fmt.Errorf("chunks: invalid start to %q: %v", s, err)
1071+
}
1072+
end, err := strconv.ParseInt(endPart, 10, 64)
1073+
if err != nil {
1074+
return blob.Chunk{}, fmt.Errorf("chunks: invalid end to %q: %v", s, err)
1075+
}
1076+
if start > end {
1077+
return blob.Chunk{}, fmt.Errorf("chunks: invalid range %q: start > end", s)
1078+
}
1079+
return blob.Chunk{Start: start, End: end}, nil
1080+
}

server/internal/client/ollama/registry_test.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"time"
2222

2323
"github.com/ollama/ollama/server/internal/cache/blob"
24-
"github.com/ollama/ollama/server/internal/chunks"
2524
"github.com/ollama/ollama/server/internal/testutil"
2625
)
2726

@@ -531,56 +530,6 @@ func TestRegistryPullMixedCachedNotCached(t *testing.T) {
531530
}
532531
}
533532

534-
func TestRegistryPullChunking(t *testing.T) {
535-
t.Skip("TODO: BRING BACK BEFORE LANDING")
536-
537-
rc, _ := newClient(t, func(w http.ResponseWriter, r *http.Request) {
538-
t.Log("request:", r.URL.Host, r.Method, r.URL.Path, r.Header.Get("Range"))
539-
if r.URL.Host != "blob.store" {
540-
// The production registry redirects to the blob store.
541-
http.Redirect(w, r, "http://blob.store"+r.URL.Path, http.StatusFound)
542-
return
543-
}
544-
if strings.Contains(r.URL.Path, "/blobs/") {
545-
rng := r.Header.Get("Range")
546-
if rng == "" {
547-
http.Error(w, "missing range", http.StatusBadRequest)
548-
return
549-
}
550-
_, c, err := chunks.ParseRange(r.Header.Get("Range"))
551-
if err != nil {
552-
panic(err)
553-
}
554-
io.WriteString(w, "remote"[c.Start:c.End+1])
555-
return
556-
}
557-
fmt.Fprintf(w, `{"layers":[{"digest":%q,"size":6}]}`, blob.DigestFromBytes("remote"))
558-
})
559-
560-
// Force chunking by setting the threshold to less than the size of the
561-
// layer.
562-
rc.ChunkingThreshold = 3
563-
rc.MaxChunkSize = 3
564-
565-
var reads []int64
566-
ctx := WithTrace(t.Context(), &Trace{
567-
Update: func(d *Layer, n int64, err error) {
568-
if err != nil {
569-
t.Errorf("update %v %d %v", d, n, err)
570-
}
571-
reads = append(reads, n)
572-
},
573-
})
574-
575-
err := rc.Pull(ctx, "remote")
576-
testutil.Check(t, err)
577-
578-
want := []int64{0, 3, 6}
579-
if !slices.Equal(reads, want) {
580-
t.Errorf("reads = %v; want %v", reads, want)
581-
}
582-
}
583-
584533
func TestRegistryResolveByDigest(t *testing.T) {
585534
check := testutil.Checker(t)
586535

server/internal/cmd/oppbench/oppbench.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)