Show bootstrap progress in verbose mode · Entire

Show bootstrap progress in verbose mode

Sessions

6afc8032e5a1View transcript

Changes

2

45 unmodified lines

46
47
48
49
50
51
52

45 unmodified lines

ProtocolMode:  protocolModeAuto,
        ShowStats:     true,
        MeasureMemory: true,
        Verbose:       true,
    })
    if err != nil {
        t.Fatalf("live linux bootstrap failed: %v\nbackend-stderr:\n%s", err, server.Stderr())

Minternal/syncer/live_bootstrap_test.go+1

865 unmodified lines

866
867
868
869
870
871
872
873
4 unmodified lines

878
879
880
881
882
883
884
58 unmodified lines

943
944
945
946
947
948
949
8 unmodified lines

958
959
960
961
962
963
964
965
966
967
968
969
970
971
1 unmodified line

973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
27 unmodified lines

1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
28 unmodified lines

1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
89 unmodified lines

1156
1157
1158
1159
1160
1161
1162
24 unmodified lines

1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
13 unmodified lines

1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1043 unmodified lines

2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292

865 unmodified lines

return bootstrapBatchedWithInputs(ctx, cfg, stats, sourceConn, targetConn, sourceService, targetAdv, plans, desiredRefs, targetRefs, result)
    }

progressf(cfg.Verbose, "bootstrap: fetching %d ref(s) from source", len(plans))

packReader, err := sourceService.FetchPack(ctx, sourceConn, desiredRefs, nil)
    if err != nil {
        if errors.Is(err, git.NoErrAlreadyUpToDate)
    4 unmodified lines

defer packReader.Close()
        packReader = limitPackReadCloser(packReader, cfg.MaxPackBytes)

progressf(cfg.Verbose, "bootstrap: pushing %d ref(s) to target", len(plans))
        if err := pushPackToTarget(ctx, targetConn, targetAdv, plans, packReader, cfg.Verbose); err != nil {
            return result, fmt.Errorf("push target refs: %w", err)
        }
    58 unmodified lines

err error
    )
    if len(planRefs) > 0 {
        progressf(cfg.Verbose, "bootstrap-batch: planning checkpoints for %d branch ref(s)", len(planRefs))
        batches, err = planBootstrapBatches(ctx, cfg, sourceConn, sourceService, planRefs, targetRefs)
        if err != nil {
            return result, err
    8 unmodified lines

for _, batch := range batches {
            result.PlannedBatchCount += len(batch.Checkpoints)
            result.TempRefs = append(result.TempRefs, batch.TempRef.String())
            progressf(
                cfg.Verbose,
                "bootstrap-batch: branch=%s temp-ref=%s planned-batches=%d resume=%s",
                batch.Plan.TargetRef,
                batch.TempRef,
                len(batch.Checkpoints),
                shortHash(batch.ResumeHash),
            )
            current := batch.ResumeHash
            startIdx, err := bootstrapResumeIndex(batch.Checkpoints, batch.ResumeHash)
            if err != nil {
    1 unmodified line
    }
            for idx := startIdx; idx < len(batch.Checkpoints); idx++ {
                checkpoint := batch.Checkpoints[idx]
                progressf(
                    cfg.Verbose,
                    "bootstrap-batch: branch=%s batch=%d/%d from=%s to=%s",
                    batch.Plan.TargetRef,
                    idx+1,
                    len(batch.Checkpoints),
                    shortHash(current),
                    shortHash(checkpoint),
                )
                stagePlans := []BranchPlan{
                    {
                        Branch:     batch.Plan.Branch,
    27 unmodified lines
            }
                if err := pushPackToTarget(ctx, targetConn, targetAdv, stagePlans, packReader, cfg.Verbose); err != nil {
                    return result, fmt.Errorf("push bootstrap batch for %s: %w", batch.Plan.TargetRef, err)
                }
                progressf(
                    cfg.Verbose,
                    "bootstrap-batch: branch=%s batch=%d/%d complete",
                    batch.Plan.TargetRef,
                    idx+1,
                    len(batch.Checkpoints),
                )
                current = checkpoint
                result.BatchCount++
            }
        28 unmodified lines

if err := pushCommandsToTarget(ctx, targetConn, targetAdv, []BranchPlan{deleteTempPlan}, cfg.Verbose); err != nil {
            return result, fmt.Errorf("delete bootstrap temp ref for %s: %w", batch.Plan.TargetRef, err)
        }
        progressf(cfg.Verbose, "bootstrap-batch: branch=%s finalized", batch.Plan.TargetRef)
    }

if len(tagPlans) > 0 {
        progressf(cfg.Verbose, "bootstrap-batch: pushing %d tag(s) after branch batches", len(tagPlans))
        tagTargetRefs := copyRefHashMap(targetRefs)
        for _, batch := range batches {
            tagTargetRefs[batch.Plan.TargetRef] = batch.Plan.SourceHash
    89 unmodified lines

sourceService *sourceRefService,
    ref desiredRef,
) ([]plumbing.Hash, error) {
        progressf(cfg.Verbose, "bootstrap-batch: fetching commit graph for %s", ref.TargetRef)
        graphRepo, err := git.Init(memory.NewStorage(), nil)
        if err != nil {
            return nil, fmt.Errorf("init bootstrap planning repository: %w", err)
        }

prevIdx = bestIdx
        prevHash = chain[bestIdx]
        checkpoints = append(checkpoints, prevHash)
        progressf(
            cfg.Verbose,
            "bootstrap-batch: branch=%s planned-checkpoint=%s (%d/%d)",
            ref.TargetRef,
            shortHash(prevHash),
            len(checkpoints),
            len(chain),
        )
    }
    return checkpoints, nil
}

13 unmodified lines

best := -1
    for lo <= hi {
        mid := lo + (hi-lo)/2
        progressf(
            cfg.Verbose,
            "bootstrap-batch: branch=%s probe checkpoint=%s base=%s",
            ref.TargetRef,
            shortHash(chain[mid]),
            shortHash(prevHash),
        )
        tooLarge, err := sourcePackExceedsLimit(ctx, sourceConn, sourceService, ref, chain[mid], prevHash, cfg.BatchMaxPackBytes)
        if err != nil {
            return -1, fmt.Errorf("measure bootstrap batch for %s at %s: %w", ref.TargetRef, shortHash(chain[mid]), err)
        }
        if tooLarge {
            progressf(cfg.Verbose, "bootstrap-batch: checkpoint=%s exceeds limit=%d", shortHash(chain[mid]), cfg.BatchMaxPackBytes)
            hi = mid - 1
            continue
        }
        progressf(cfg.Verbose, "bootstrap-batch: checkpoint=%s fits limit=%d", shortHash(chain[mid]), cfg.BatchMaxPackBytes)
        best = mid
        lo = mid + 1
    }
1043 unmodified lines

return os.Stderr
}

func progressf(verbose bool, format string, args ...interface{}) {
    if !verbose {
        return
    }
    fmt.Fprintf(os.Stderr, "[git-sync] %s\n", fmt.Sprintf(format, args...))
}

func (e Endpoint) authMethod() transport.AuthMethod {
    if e.BearerToken != "" {
        return &transporthttp.TokenAuth{Token: e.BearerToken}
    }