forked from cockroachdb/pebble
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathingest_with_blobs.go
More file actions
66 lines (57 loc) · 1.98 KB
/
ingest_with_blobs.go
File metadata and controls
66 lines (57 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2025 The LevelDB-Go and Pebble Authors. All rights reserved. Use
// of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
package pebble
import (
"context"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/pebble/objstorage"
)
// LocalSSTables represents a set of sstables on local disk to be ingested into
// the DB, along with their associated blob files.
type LocalSSTables []LocalSST
// TotalFiles returns the total number of files (sstables + blob files)
// represented by this LocalSSTables.
func (l LocalSSTables) TotalFiles() int {
total := len(l)
for _, sst := range l {
total += len(sst.BlobPaths)
}
return total
}
// LocalSST represents a single sstable on local disk to be ingested into
// the DB, along with its associated blob files.
// Any blob files provided must have been written at the time of writing
// the sst, meaning they contain values solely for the sstable at Path.
type LocalSST struct {
Path string
BlobPaths []string
}
// closeReadables closes all readables in the slice, combining any errors.
func closeReadables(readables []objstorage.Readable) error {
var errs error
for _, r := range readables {
errs = errors.CombineErrors(errs, r.Close())
}
return errs
}
func createBlobReadables(
ctx context.Context, opts *Options, blobPaths []string,
) ([]objstorage.Readable, error) {
readables := make([]objstorage.Readable, 0, len(blobPaths))
for _, path := range blobPaths {
f, err := opts.FS.Open(path)
if err != nil {
// Close any readables we've already created before returning the error.
return nil, errors.CombineErrors(err, closeReadables(readables))
}
readable, err := objstorage.NewSimpleReadable(f)
if err != nil {
// Close the file and any readables we've already created.
closeErr := errors.CombineErrors(f.Close(), closeReadables(readables))
return nil, errors.CombineErrors(err, closeErr)
}
readables = append(readables, readable)
}
return readables, nil
}