Skip to content

Commit

Permalink
cmd/gomote: use ListDirectoryStreaming
Browse files Browse the repository at this point in the history
Use the streaming directory listing RPC to avoid
overflowing the maximum RPC response size.

For golang/go#69732

Change-Id: I2529d3788843844e3ccdde79c12c5c453b09bb25
Reviewed-on: https://go-review.googlesource.com/c/build/+/617161
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
neild committed Oct 2, 2024
1 parent 25d5d8f commit 0b78e17
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
16 changes: 13 additions & 3 deletions cmd/gomote/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"flag"
"fmt"
"io"
"log"
"os"
"strings"
Expand Down Expand Up @@ -71,7 +72,7 @@ func ls(args []string) error {
}
for _, inst := range lsSet {
client := gomoteServerClient(ctx)
resp, err := client.ListDirectory(ctx, &protos.ListDirectoryRequest{
stream, err := client.ListDirectoryStreaming(ctx, &protos.ListDirectoryRequest{
GomoteId: inst,
Directory: dir,
Recursive: recursive,
Expand All @@ -84,8 +85,17 @@ func ls(args []string) error {
if len(lsSet) > 1 {
fmt.Fprintf(os.Stdout, "# %s\n", inst)
}
for _, entry := range resp.GetEntries() {
fmt.Fprintf(os.Stdout, "%s\n", entry)
for {
resp, err := stream.Recv()
if err == io.EOF {
break
}
if err != nil {
return fmt.Errorf("unable to ls: %w", err)
}
for _, entry := range resp.GetEntries() {
fmt.Fprintf(os.Stdout, "%s\n", entry)
}
}
if len(lsSet) > 1 {
fmt.Fprintln(os.Stdout)
Expand Down
21 changes: 15 additions & 6 deletions cmd/gomote/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func doPush(ctx context.Context, name, goroot string, dryRun, detailedProgress b
remote := map[string]buildlet.DirEntry{} // keys like "src/make.bash"

client := gomoteServerClient(ctx)
resp, err := client.ListDirectory(ctx, &protos.ListDirectoryRequest{
stream, err := client.ListDirectoryStreaming(ctx, &protos.ListDirectoryRequest{
GomoteId: name,
Directory: ".",
Recursive: true,
Expand All @@ -99,11 +99,20 @@ func doPush(ctx context.Context, name, goroot string, dryRun, detailedProgress b
if err != nil {
return fmt.Errorf("error listing buildlet's existing files: %w", err)
}
for _, entry := range resp.GetEntries() {
de := buildlet.DirEntry{Line: entry}
en := de.Name()
if strings.HasPrefix(en, "go/") && en != "go/" {
remote[en[len("go/"):]] = de
for {
resp, err := stream.Recv()
if err == io.EOF {
break
}
if err != nil {
return fmt.Errorf("error listing buildlet's existing files: %w", err)
}
for _, entry := range resp.GetEntries() {
de := buildlet.DirEntry{Line: entry}
en := de.Name()
if strings.HasPrefix(en, "go/") && en != "go/" {
remote[en[len("go/"):]] = de
}
}
}
// TODO(66635) remove once gomotes can no longer be created via the coordinator.
Expand Down

0 comments on commit 0b78e17

Please sign in to comment.