github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/server/serverpb/admin.go (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package serverpb
    12  
    13  // Add adds values from ots to ts.
    14  func (ts *TableStatsResponse) Add(ots *TableStatsResponse) {
    15  	ts.RangeCount += ots.RangeCount
    16  	ts.ReplicaCount += ots.ReplicaCount
    17  	ts.ApproximateDiskBytes += ots.ApproximateDiskBytes
    18  	ts.Stats.Add(ots.Stats)
    19  
    20  	// The stats in TableStatsResponse were generated by getting separate stats
    21  	// for each node, then aggregating them into TableStatsResponse.
    22  	// So resulting NodeCount should be the same, unless ots contains nodeData
    23  	// in MissingNodes that isn't already tracked in ts.MissingNodes.
    24  	// Note: when comparing missingNode objects, there's a chance that the nodeId
    25  	// could be the same, but that the error messages differ. Keeping the first
    26  	// and dropping subsequent ones seems reasonable to do, and is what is done
    27  	// here.
    28  	missingNodeIds := make(map[string]struct{})
    29  	for _, nodeData := range ts.MissingNodes {
    30  		missingNodeIds[nodeData.NodeID] = struct{}{}
    31  	}
    32  	for _, nodeData := range ots.MissingNodes {
    33  		if _, found := missingNodeIds[nodeData.NodeID]; !found {
    34  			ts.MissingNodes = append(ts.MissingNodes, nodeData)
    35  			ts.NodeCount--
    36  		}
    37  	}
    38  }