[ARVADOS] created: 752c9fe791d1aff193a4dc4807183b19c1b67d1d

git at public.curoverse.com git at public.curoverse.com
Sat Dec 5 03:47:34 EST 2015


        at  752c9fe791d1aff193a4dc4807183b19c1b67d1d (commit)


commit 752c9fe791d1aff193a4dc4807183b19c1b67d1d
Author: Tom Clegg <tom at curoverse.com>
Date:   Sat Dec 5 03:47:04 2015 -0500

    7937: Fix ignored error from GetKeepServersAndSummarize.

diff --git a/services/datamanager/collection/collection.go b/services/datamanager/collection/collection.go
index eecfff7..1229f29 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 c1a5cbe..604a6db 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 9f1eab6..6e463d7 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
 }

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list