Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/res_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func runResCluster(args []string, stdout, stderr io.Writer) int {
if err != nil {
return fail(err)
}
st, err := rescluster.RunFiles(in, files, *spill, *bucket, *root)
st, err := rescluster.RunFiles(in, files, *spill, *bucket, *root, stderr)
if err != nil {
return fail(err)
}
Expand Down
2 changes: 1 addition & 1 deletion resource/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func stream(t *testing.T, in Input, res *Result) {
if err := resource.WriteResources(a, res.Resources); err != nil {
t.Fatal(err)
}
st, err := RunFiles(in, files, t.TempDir(), 1, b)
st, err := RunFiles(in, files, t.TempDir(), 1, b, nil)
if err != nil {
t.Fatal(err)
}
Expand Down
14 changes: 12 additions & 2 deletions resource/cluster/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"cmp"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"slices"
Expand All @@ -23,8 +24,11 @@ type Stream struct {
Partition *Partition // the partition, with no Bucket
}

// RunFiles is a partitioned run (RS10.8) that reads the source records from the files and writes the resources to the shards of records/resources/ in the tree at root. The records of in are not used. It writes the records of each bucket and the resources to files in a new directory in tmp, and removes the directory at the end. It keeps in memory the keys of the records, the records of one bucket and the resources of one group of shards. The resources and the pairs are those of Run on the records of the files.
func RunFiles(in Input, files []string, tmp string, size int, root string) (*Stream, error) {
// RunFiles is a partitioned run (RS10.8) that reads the source records from the files and writes the resources to the shards of records/resources/ in the tree at root. The records of in are not used. When log is not nil, RunFiles writes the progress of each step to it. It writes the records of each bucket and the resources to files in a new directory in tmp, and removes the directory at the end. It keeps in memory the keys of the records, the records of one bucket and the resources of one group of shards. The resources and the pairs are those of Run on the records of the files.
func RunFiles(in Input, files []string, tmp string, size int, root string, log io.Writer) (*Stream, error) {
if log == nil {
log = io.Discard
}
dir, err := os.MkdirTemp(tmp, "cluster-")
if err != nil {
return nil, err
Expand Down Expand Up @@ -57,6 +61,7 @@ func RunFiles(in Input, files []string, tmp string, size int, root string) (*Str
}
of, p := pt.buckets(recs, size)
st := &Stream{Records: len(recs), Joins: map[string]int{}, Skipped: len(p.Large), Partition: p}
_, _ = fmt.Fprintf(log, "cluster: %d records in %d buckets, %d components, the largest with %d records\n", len(recs), p.Buckets, p.Components, p.Largest)

// The records of each bucket.
ws := make([]*spill.Writer, p.Buckets)
Expand Down Expand Up @@ -120,6 +125,9 @@ func RunFiles(in Input, files []string, tmp string, size int, root string) (*Str
}); err != nil {
return nil, err
}
if len(rs) > 10*size || b%100 == 0 {
_, _ = fmt.Fprintf(log, "cluster: the bucket %d of %d has %d records\n", b+1, p.Buckets, len(rs))
}
bin := in
bin.Records, bin.Existing, bin.Crosswalks, bin.Large = rs, existBy[b], linkBy[b], p.Large
g, _ := passes(bin)
Expand Down Expand Up @@ -186,6 +194,7 @@ func RunFiles(in Input, files []string, tmp string, size int, root string) (*Str
}

// The steps that read all the resources, as finish runs them.
_, _ = fmt.Fprintf(log, "cluster: the passes are done, %d new resources\n", len(news))
exprs := map[string]string{}
if err := each(func(r *resource.Resource) error {
offeringIndex(exprs, r)
Expand Down Expand Up @@ -255,6 +264,7 @@ func RunFiles(in Input, files []string, tmp string, size int, root string) (*Str
}); err != nil {
return nil, err
}
_, _ = fmt.Fprintf(log, "cluster: writing %d live resources\n", st.Resources)
if _, err := sp.Write(root); err != nil {
return nil, err
}
Expand Down
Loading