From 95e7cb1e1e813786b9399ef88031520717dd2dd5 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Sat, 5 Dec 2015 03:47:04 -0500 Subject: [PATCH] 7937: Fix ignored error from GetKeepServersAndSummarize. --- services/datamanager/collection/collection.go | 6 +-- services/datamanager/datamanager.go | 34 +++++++------ services/datamanager/summary/file.go | 49 +++++++++---------- 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/services/datamanager/collection/collection.go b/services/datamanager/collection/collection.go index eecfff7559..1229f2917e 100644 --- a/services/datamanager/collection/collection.go +++ b/services/datamanager/collection/collection.go @@ -38,7 +38,6 @@ type ReadCollections struct { CollectionUUIDToIndex map[string]int CollectionIndexToUUID []string BlockToCollectionIndices map[blockdigest.DigestWithSize][]int - Err error } // GetCollectionsParams params @@ -93,10 +92,9 @@ func WriteHeapProfile() error { } // GetCollectionsAndSummarize gets collections from api and summarizes -func GetCollectionsAndSummarize(params GetCollectionsParams) (results ReadCollections) { - results, err := GetCollections(params) +func GetCollectionsAndSummarize(params GetCollectionsParams) (results ReadCollections, err error) { + results, err = GetCollections(params) if err != nil { - results.Err = err return } diff --git a/services/datamanager/datamanager.go b/services/datamanager/datamanager.go index c1a5cbed75..604a6db2f4 100644 --- a/services/datamanager/datamanager.go +++ b/services/datamanager/datamanager.go @@ -108,10 +108,9 @@ func singlerun(arv arvadosclient.ArvadosClient) error { dataFetcher = BuildDataFetcher(arv) } - dataFetcher(arvLogger, &readCollections, &keepServerInfo) - - if readCollections.Err != nil { - return readCollections.Err + err = dataFetcher(arvLogger, &readCollections, &keepServerInfo) + if err != nil { + return err } err = summary.MaybeWriteData(arvLogger, readCollections, keepServerInfo) @@ -182,30 +181,35 @@ func singlerun(arv arvadosclient.ArvadosClient) error { // BuildDataFetcher returns a data fetcher that fetches data from remote servers. func BuildDataFetcher(arv arvadosclient.ArvadosClient) summary.DataFetcher { - return func(arvLogger *logger.Logger, + return func( + arvLogger *logger.Logger, readCollections *collection.ReadCollections, - keepServerInfo *keep.ReadServers) { - collectionChannel := make(chan collection.ReadCollections) - + keepServerInfo *keep.ReadServers, + ) error { + collDone := make(chan struct{}) + var collErr error go func() { - collectionChannel <- collection.GetCollectionsAndSummarize( + *readCollections, collErr = collection.GetCollectionsAndSummarize( collection.GetCollectionsParams{ Client: arv, Logger: arvLogger, BatchSize: 50}) + collDone <- struct{}{} }() - var err error - *keepServerInfo, err = keep.GetKeepServersAndSummarize( + var keepErr error + *keepServerInfo, keepErr = keep.GetKeepServersAndSummarize( keep.GetKeepServersParams{ Client: arv, Logger: arvLogger, Limit: 1000}) - if err != nil { - return - } + <- collDone - *readCollections = <-collectionChannel + // Return a nil error only if both parts succeeded. + if collErr != nil { + return collErr + } + return keepErr } } diff --git a/services/datamanager/summary/file.go b/services/datamanager/summary/file.go index 9f1eab6641..6e463d7670 100644 --- a/services/datamanager/summary/file.go +++ b/services/datamanager/summary/file.go @@ -28,7 +28,7 @@ var ( // DataFetcher to fetch data from keep servers type DataFetcher func(arvLogger *logger.Logger, readCollections *collection.ReadCollections, - keepServerInfo *keep.ReadServers) + keepServerInfo *keep.ReadServers) error func init() { flag.StringVar(&WriteDataTo, @@ -86,33 +86,30 @@ func ShouldReadData() bool { // working with stale data. func ReadData(arvLogger *logger.Logger, readCollections *collection.ReadCollections, - keepServerInfo *keep.ReadServers) { + keepServerInfo *keep.ReadServers) error { if readDataFrom == "" { - readCollections.Err = fmt.Errorf("ReadData() called with empty filename.") - return - } else { - summaryFile, err := os.Open(readDataFrom) - if err != nil { - readCollections.Err = err - return - } - defer summaryFile.Close() + return fmt.Errorf("ReadData() called with empty filename.") + } + summaryFile, err := os.Open(readDataFrom) + if err != nil { + return err + } + defer summaryFile.Close() - dec := gob.NewDecoder(summaryFile) - data := serializedData{} - err = dec.Decode(&data) - if err != nil { - readCollections.Err = err - return - } + dec := gob.NewDecoder(summaryFile) + data := serializedData{} + err = dec.Decode(&data) + if err != nil { + return err + } - // re-summarize data, so that we can update our summarizing - // functions without needing to do all our network i/o - data.ReadCollections.Summarize(arvLogger) - data.KeepServerInfo.Summarize(arvLogger) + // re-summarize data, so that we can update our summarizing + // functions without needing to do all our network i/o + data.ReadCollections.Summarize(arvLogger) + data.KeepServerInfo.Summarize(arvLogger) - *readCollections = data.ReadCollections - *keepServerInfo = data.KeepServerInfo - log.Printf("Read summary data from: %s", readDataFrom) - } + *readCollections = data.ReadCollections + *keepServerInfo = data.KeepServerInfo + log.Printf("Read summary data from: %s", readDataFrom) + return nil } -- 2.30.2