// populateEndpoints processes p.streams and adds the corresponding // StreamEndpointSpects to the processors' input and output specs. func (dsp *distSQLPlanner) populateEndpoints(planCtx *planningCtx, p *physicalPlan) { // Note: we could fill in the input/output specs directly instead of adding // streams to p.streams, but this makes the rest of the code a bit simpler. for sIdx, s := range p.streams { p1 := &p.processors[s.sourceProcessor] p2 := &p.processors[s.destProcessor] endpoint := distsql.StreamEndpointSpec{StreamID: distsql.StreamID(sIdx)} if p1.node == p2.node { endpoint.Type = distsql.StreamEndpointSpec_LOCAL } else { endpoint.Type = distsql.StreamEndpointSpec_REMOTE } p2.spec.Input[s.destInput].Streams = append(p2.spec.Input[s.destInput].Streams, endpoint) if endpoint.Type == distsql.StreamEndpointSpec_REMOTE { endpoint.TargetAddr = planCtx.nodeAddresses[p2.node] } router := &p1.spec.Output[0] // We are about to put this stream on the len(router.Streams) position in // the router; verify this matches the sourceRouterSlot. We expect it to // because the streams should be in order; if that assumption changes we can // reorder them here according to sourceRouterSlot. if len(router.Streams) != s.sourceRouterSlot { panic(fmt.Sprintf( "sourceRouterSlot mismatch: %d, expected %d", len(router.Streams), s.sourceRouterSlot, )) } router.Streams = append(router.Streams, endpoint) } }
// populateEndpoints processes p.streams and adds the corresponding // StreamEndpointSpects to the processors' input and output specs. func (dsp *distSQLPlanner) populateEndpoints(planCtx *planningCtx, p *physicalPlan) { // Note: we could fill in the input/output specs directly instead of adding // streams to p.streams, but this makes the rest of the code a bit simpler. for sIdx, s := range p.streams { p1 := &p.processors[s.sourceProcessor] p2 := &p.processors[s.destProcessor] endpoint := distsql.StreamEndpointSpec{StreamID: distsql.StreamID(sIdx)} if p1.node == p2.node { endpoint.Type = distsql.StreamEndpointSpec_LOCAL } else { endpoint.Type = distsql.StreamEndpointSpec_REMOTE } p2.spec.Input[s.destInput].Streams = append(p2.spec.Input[s.destInput].Streams, endpoint) if endpoint.Type == distsql.StreamEndpointSpec_REMOTE { endpoint.TargetAddr = planCtx.nodeAddresses[p2.node] } p1.spec.Output[0].Streams = append(p1.spec.Output[0].Streams, endpoint) } }