Moved some logic from datamanager.go to keep.go.
authormishaz <misha@curoverse.com>
Tue, 13 Jan 2015 00:23:17 +0000 (00:23 +0000)
committerTom Clegg <tom@curoverse.com>
Fri, 13 Feb 2015 21:25:30 +0000 (16:25 -0500)
services/datamanager/datamanager.go
services/datamanager/keep/keep.go

index 6bd9ee8afa8fc0de7df8bc17e93be3c3caacb2dd..9b1f6d6830d0600c3b41a92c9816ccce6ef8ef88 100644 (file)
@@ -77,10 +77,14 @@ func main() {
                collection.GetCollectionsParams{
                        Client: arv, Logger: arvLogger, BatchSize: 50}) }()
 
-       RunKeep(keep.GetKeepServersParams{Client: arv, Limit: 1000})
+       keepServerInfo := keep.GetKeepServersAndSummarize(
+               keep.GetKeepServersParams{Client: arv, Limit: 1000})
 
        readCollections := <-collectionChannel
-       _ = readCollections  // Make compiler happy.
+
+  // Make compiler happy.
+       _ = readCollections
+       _ = keepServerInfo
 
        // Log that we're finished
        if arvLogger != nil {
@@ -91,20 +95,6 @@ func main() {
        }
 }
 
-func RunKeep(params keep.GetKeepServersParams) {
-       readServers := keep.GetKeepServers(params)
-
-       log.Printf("Returned %d keep disks", len(readServers.ServerToContents))
-
-       blockReplicationCounts := make(map[int]int)
-       for _, infos := range readServers.BlockToServers {
-               replication := len(infos)
-               blockReplicationCounts[replication] += 1
-       }
-
-       log.Printf("Replication level distribution: %v", blockReplicationCounts)
-}
-
 func LogMemoryAlloc(properties map[string]interface{}, entry map[string]interface{}) {
        _ = entry  // keep the compiler from complaining
        runInfo := properties["run_info"].(map[string]interface{})
index 91af2014aee83272608b8653e0f861a3880262ce..413e1be7f18ff3fe567647b0151d8f97e380d397 100644 (file)
@@ -48,11 +48,12 @@ type ServerResponse struct {
 }
 
 type ReadServers struct {
-       ReadAllServers bool
-       KeepServerIndexToAddress []ServerAddress
-       KeepServerAddressToIndex map[ServerAddress]int
-       ServerToContents map[ServerAddress]ServerContents
-       BlockToServers map[blockdigest.BlockDigest][]BlockServerInfo
+       ReadAllServers            bool
+       KeepServerIndexToAddress  []ServerAddress
+       KeepServerAddressToIndex  map[ServerAddress]int
+       ServerToContents          map[ServerAddress]ServerContents
+       BlockToServers            map[blockdigest.BlockDigest][]BlockServerInfo
+       BlockReplicationCounts    map[int]int
 }
 
 type GetKeepServersParams struct {
@@ -109,6 +110,17 @@ func getDataManagerToken() (string) {
        return dataManagerToken
 }
 
+func GetKeepServersAndSummarize(params GetKeepServersParams) (results ReadServers) {
+       results = GetKeepServers(params)
+       log.Printf("Returned %d keep disks", len(results.ServerToContents))
+
+       ComputeBlockReplicationCounts(&results)
+       log.Printf("Replication level distribution: %v",
+               results.BlockReplicationCounts)
+
+       return
+}
+
 func GetKeepServers(params GetKeepServersParams) (results ReadServers) {
        if &params.Client == nil {
                log.Fatalf("params.Client passed to GetKeepServers() should " +
@@ -288,3 +300,11 @@ func parseBlockInfoFromIndexLine(indexLine string) (blockInfo BlockInfo, err err
        blockInfo.Size = locator.Size
        return
 }
+
+func ComputeBlockReplicationCounts(readServers *ReadServers) {
+       readServers.BlockReplicationCounts = make(map[int]int)
+       for _, infos := range readServers.BlockToServers {
+               replication := len(infos)
+               readServers.BlockReplicationCounts[replication] += 1
+       }
+}