MCPcopy Create free account
hub / github.com/couchbase/cbft / buildCopyPartitionRequestUtil

Function buildCopyPartitionRequestUtil

pindex_copy_request.go:153–207  ·  view source on GitHub ↗

buildCopyPartitionRequestUtil creates the partition copy request with a sorted list of source nodeDefs for the given pindex.

(planPIndexes *cbgt.PlanPIndexes,
	pindexName string, stats *CopyPartitionStats, nodeDefs *cbgt.NodeDefs,
	sourceUUIDs []string, formerPrimary string, mgr *cbgt.Manager,
	stopCh chan struct{})

Source from the content-addressed store, hash-verified

151// buildCopyPartitionRequestUtil creates the partition copy request
152// with a sorted list of source nodeDefs for the given pindex.
153func buildCopyPartitionRequestUtil(planPIndexes *cbgt.PlanPIndexes,
154 pindexName string, stats *CopyPartitionStats, nodeDefs *cbgt.NodeDefs,
155 sourceUUIDs []string, formerPrimary string, mgr *cbgt.Manager,
156 stopCh chan struct{}) (*CopyPartitionRequest, error) {
157 // compute the given partition load on the cluster nodes.
158 nodeParitionCount := make(map[string]int)
159 for _, pp := range planPIndexes.PlanPIndexes {
160 for node := range pp.Nodes {
161 if _, ok := nodeParitionCount[node]; !ok {
162 nodeParitionCount[node] = 1
163 } else {
164 nodeParitionCount[node]++
165 }
166 }
167 }
168
169 // form the source partition candidates.
170 planPIndex := planPIndexes.PlanPIndexes[pindexName]
171 var sps []*srcPartition
172 for _, uuid := range sourceUUIDs {
173 if nodeDef, ok := nodeDefs.NodeDefs[uuid]; ok {
174 node := planPIndex.Nodes[uuid]
175 sp := &srcPartition{nodeDef: nodeDef,
176 partitionCountOnNode: nodeParitionCount[uuid]}
177 if node.Priority == 0 {
178 sp.state = "primary"
179 } else if node.Priority > 0 {
180 sp.state = "replica"
181 }
182 sps = append(sps, sp)
183 }
184 }
185
186 // sort them in the order of preference.
187 sort.Sort(&srcPartitionSorter{
188 sps: sps,
189 state: "primary",
190 rack: mgr.Container()})
191
192 if len(sps) > 0 {
193 var sourceNodes []*cbgt.NodeDef
194 for _, sp := range sps {
195 sourceNodes = append(sourceNodes, sp.nodeDef)
196 }
197 return &CopyPartitionRequest{
198 SourceNodes: sourceNodes,
199 SourcePIndexName: planPIndex.Name,
200 SourceUUID: planPIndex.UUID,
201 Stats: stats,
202 CancelCh: stopCh,
203 }, nil
204 }
205
206 return nil, nil
207}
208
209// getNodesHostingPIndex confirms the list of node UUIDs
210// hosting the given pindex.

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected