9437: gofmt
[arvados.git] / services / datamanager / keep / keep.go
index d52191c61c6782c4ff040415a9ab7e3f607a4651..e7843ea02f8090133a4270465ba2330f579f3be5 100644 (file)
@@ -77,13 +77,13 @@ type ServiceList struct {
        KeepServers    []ServerAddress `json:"items"`
 }
 
-var supportedServiceType string
+var serviceType string
 
 func init() {
-       flag.StringVar(&supportedServiceType,
+       flag.StringVar(&serviceType,
                "service-type",
                "disk",
-               "Supported keepservice type. Default is disk.")
+               "Operate only on keep_services with the specified service_type, ignoring all others.")
 }
 
 // String
@@ -118,7 +118,7 @@ func GetKeepServersAndSummarize(params GetKeepServersParams) (results ReadServer
 // GetKeepServers from api server
 func GetKeepServers(params GetKeepServersParams) (results ReadServers, err error) {
        sdkParams := arvadosclient.Dict{
-               "filters": [][]string{[]string{"service_type", "!=", "proxy"}},
+               "filters": [][]string{{"service_type", "!=", "proxy"}},
        }
        if params.Limit > 0 {
                sdkParams["limit"] = params.Limit
@@ -131,19 +131,17 @@ func GetKeepServers(params GetKeepServersParams) (results ReadServers, err error
                return
        }
 
-       // Ignore any services that are of type other than the "supportedServiceType".
-       // If no services of the "supportedServiceType" are found, raise an error.
-       var indexableKeepServers []ServerAddress
+       var keepServers []ServerAddress
        for _, server := range sdkResponse.KeepServers {
-               if server.ServiceType == supportedServiceType {
-                       indexableKeepServers = append(indexableKeepServers, server)
+               if server.ServiceType == serviceType {
+                       keepServers = append(keepServers, server)
                } else {
-                       log.Printf("Ignore unsupported service type: %v", server.ServiceType)
+                       log.Printf("Skipping keep_service %q because its service_type %q does not match -service-type=%q", server, server.ServiceType, serviceType)
                }
        }
 
-       if len(indexableKeepServers) == 0 {
-               return results, fmt.Errorf("Found no keepservices with the supported type %v", supportedServiceType)
+       if len(keepServers) == 0 {
+               return results, fmt.Errorf("Found no keepservices with the service type %v", serviceType)
        }
 
        if params.Logger != nil {
@@ -152,7 +150,7 @@ func GetKeepServers(params GetKeepServersParams) (results ReadServers, err error
                        keepInfo["num_keep_servers_available"] = sdkResponse.ItemsAvailable
                        keepInfo["num_keep_servers_received"] = len(sdkResponse.KeepServers)
                        keepInfo["keep_servers"] = sdkResponse.KeepServers
-                       keepInfo["indexable_keep_servers"] = indexableKeepServers
+                       keepInfo["indexable_keep_servers"] = keepServers
                })
        }
 
@@ -162,7 +160,7 @@ func GetKeepServers(params GetKeepServersParams) (results ReadServers, err error
                return results, fmt.Errorf("Did not receive all available keep servers: %+v", sdkResponse)
        }
 
-       results.KeepServerIndexToAddress = indexableKeepServers
+       results.KeepServerIndexToAddress = keepServers
        results.KeepServerAddressToIndex = make(map[ServerAddress]int)
        for i, address := range results.KeepServerIndexToAddress {
                results.KeepServerAddressToIndex[address] = i
@@ -468,13 +466,29 @@ type TrashRequest struct {
 type TrashList []TrashRequest
 
 // SendTrashLists to trash queue
-func SendTrashLists(kc *keepclient.KeepClient, spl map[string]TrashList) (errs []error) {
+func SendTrashLists(arvLogger *logger.Logger, kc *keepclient.KeepClient, spl map[string]TrashList, dryRun bool) (errs []error) {
        count := 0
        barrier := make(chan error)
 
        client := kc.Client
 
        for url, v := range spl {
+               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.
+                       url := url
+                       trashLen := len(v)
+                       arvLogger.Update(func(p map[string]interface{}, e map[string]interface{}) {
+                               trashListInfo := logger.GetOrCreateMap(p, "trash_list_len")
+                               trashListInfo[url] = trashLen
+                       })
+               }
+
+               if dryRun {
+                       log.Printf("dry run, not sending trash list to service %s with %d blocks", url, len(v))
+                       continue
+               }
+
                count++
                log.Printf("Sending trash list to %v", url)
 
@@ -514,7 +528,6 @@ func SendTrashLists(kc *keepclient.KeepClient, spl map[string]TrashList) (errs [
                                barrier <- nil
                        }
                })(url, v)
-
        }
 
        for i := 0; i < count; i++ {