}
var (
+ dataFetcher summary.DataFetcher
readCollections collection.ReadCollections
keepServerInfo keep.ReadServers
)
- if !summary.MaybeReadData(arvLogger, &readCollections, &keepServerInfo) {
- collectionChannel := make(chan collection.ReadCollections)
-
- go func() {
- collectionChannel <- collection.GetCollectionsAndSummarize(
- collection.GetCollectionsParams{
- Client: arv,
- Logger: arvLogger,
- BatchSize: 50})
- }()
-
- keepServerInfo = keep.GetKeepServersAndSummarize(
- keep.GetKeepServersParams{
- Client: arv,
- Logger: arvLogger,
- Limit: 1000})
-
- readCollections = <-collectionChannel
+ if summary.ShouldReadData() {
+ dataFetcher = summary.ReadData
+ } else {
+ dataFetcher = BuildDataFetcher(arv)
}
+ dataFetcher(arvLogger, &readCollections, &keepServerInfo)
+
summary.MaybeWriteData(arvLogger, readCollections, keepServerInfo)
buckets := summary.BucketReplication(readCollections, keepServerInfo)
log.Printf("Blocks In Collections: %d, "+
"\nBlocks In Keep: %d.",
- len(readCollections.BlockToReplication),
+ len(readCollections.BlockToDesiredReplication),
len(keepServerInfo.BlockToServers))
log.Println(replicationCounts.PrettyPrint())
pullServers := summary.ComputePullServers(kc,
&keepServerInfo,
- readCollections.BlockToReplication,
+ readCollections.BlockToDesiredReplication,
replicationSummary.UnderReplicatedBlocks)
pullLists := summary.BuildPullLists(pullServers)
})
}
}
+
+// Returns a data fetcher that fetches data from remote servers.
+func BuildDataFetcher(arv arvadosclient.ArvadosClient) summary.DataFetcher {
+ return func(arvLogger *logger.Logger,
+ readCollections *collection.ReadCollections,
+ keepServerInfo *keep.ReadServers) {
+ collectionChannel := make(chan collection.ReadCollections)
+
+ go func() {
+ collectionChannel <- collection.GetCollectionsAndSummarize(
+ collection.GetCollectionsParams{
+ Client: arv,
+ Logger: arvLogger,
+ BatchSize: 50})
+ }()
+
+ *keepServerInfo = keep.GetKeepServersAndSummarize(
+ keep.GetKeepServersParams{
+ Client: arv,
+ Logger: arvLogger,
+ Limit: 1000})
+
+ *readCollections = <-collectionChannel
+ }
+}