X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/073396900805175acfc32f974abfea91c456e986..abf6347cc1d56bc448e993249c9d6359ba60c606:/services/datamanager/summary/pull_list.go diff --git a/services/datamanager/summary/pull_list.go b/services/datamanager/summary/pull_list.go index cc01249a62..d7fb3eb8f7 100644 --- a/services/datamanager/summary/pull_list.go +++ b/services/datamanager/summary/pull_list.go @@ -9,7 +9,6 @@ import ( "git.curoverse.com/arvados.git/sdk/go/keepclient" "git.curoverse.com/arvados.git/sdk/go/logger" "git.curoverse.com/arvados.git/services/datamanager/keep" - "git.curoverse.com/arvados.git/services/datamanager/loggerutil" "log" "os" "strings" @@ -72,7 +71,7 @@ func ComputePullServers(kc *keepclient.KeepClient, blockToDesiredReplication map[blockdigest.DigestWithSize]int, underReplicated BlockSet) (m map[Locator]PullServers) { m = map[Locator]PullServers{} - // We use CanonicalString to avoid filling memory with dupicate + // We use CanonicalString to avoid filling memory with duplicate // copies of the same string. var cs CanonicalString @@ -176,23 +175,41 @@ func BuildPullLists(lps map[Locator]PullServers) (spl map[string]PullList) { // This is just a hack for prototyping, it is not expected to be used // in production. func WritePullLists(arvLogger *logger.Logger, - pullLists map[string]PullList) { + pullLists map[string]PullList, + dryRun bool) error { r := strings.NewReplacer(":", ".") + for host, list := range pullLists { + if arvLogger != nil { + // We need a local variable because Update doesn't call our mutator func until later, + // when our list variable might have been reused by the next loop iteration. + host := host + listLen := len(list) + arvLogger.Update(func(p map[string]interface{}, e map[string]interface{}) { + pullListInfo := logger.GetOrCreateMap(p, "pull_list_len") + pullListInfo[host] = listLen + }) + } + + if dryRun { + log.Print("dry run, not sending pull list to service %s with %d blocks", host, len(list)) + continue + } + filename := fmt.Sprintf("pull_list.%s", r.Replace(RemoveProtocolPrefix(host))) pullListFile, err := os.Create(filename) if err != nil { - loggerutil.FatalWithMessage(arvLogger, - fmt.Sprintf("Failed to open %s: %v", filename, err)) + return err } defer pullListFile.Close() enc := json.NewEncoder(pullListFile) err = enc.Encode(list) if err != nil { - loggerutil.FatalWithMessage(arvLogger, - fmt.Sprintf("Failed to write pull list to %s: %v", filename, err)) + return err } log.Printf("Wrote pull list to %s.", filename) } + + return nil }