// newKeyspaceIDResolverFactory creates a new
// keyspaceIDResolverFactory for the provided keyspace and cell.
172294
func newKeyspaceIDResolverFactory(ctx context.Context, ts *topo.Server, keyspace string, cell string) (keyspaceIDResolverFactory, error) {
	if *useV3ReshardingMode {
		return newKeyspaceIDResolverFactoryV3(ctx, ts, keyspace, cell)
	}

	return newKeyspaceIDResolverFactoryV2(ctx, ts, keyspace)
}
209088
func NewNamespaceMetadata(Name string, NamespaceId string, NamespaceType *NamespaceType) *NamespaceMetadata {
	s := new(NamespaceMetadata)
	s.Name = Name
	s.NamespaceId = NamespaceId
	s.NamespaceType = NamespaceType
	return s
}
789359
func newV3ResolverFromColumnList(keyspaceSchema *vindexes.KeyspaceSchema, name string, columns []string) (keyspaceIDResolver, error) {
	tableSchema, ok := keyspaceSchema.Tables[name]
	if !ok {
		return nil, vterrors.Errorf(vtrpc.Code_FAILED_PRECONDITION, "no vschema definition for table %v", name)
	}
	// use the lowest cost unique vindex as the sharding key
	colVindex, err := vindexes.FindVindexForSharding(name, tableSchema.ColumnVindexes)
	if err != nil {
		return nil, err
	}

	// Find the sharding key column index.
	columnIndex := -1
	for i, n := range columns {
		if colVindex.Columns[0].EqualString(n) {
			columnIndex = i
			break
		}
	}
	if columnIndex == -1 {
		return nil, vterrors.Errorf(vtrpc.Code_FAILED_PRECONDITION, "table %v has a Vindex on unknown column %v", name, colVindex.Columns[0])
	}

	return &v3Resolver{
		shardingColumnIndex: columnIndex,
		vindex:              colVindex.Vindex,
	}, nil
}
801984
func NewMiekgDNSResolver(addr string) (Resolver, error) {
	if _, _, e := net.SplitHostPort(addr); e != nil {
		return nil, e
	}
	return &MiekgDNSResolver{
		client:     new(dns.Client),
		serverAddr: addr,
	}, nil
}
783465
func (actor Actor) BindServiceBySpace(appName string, serviceInstanceName string, spaceGUID string, bindingName string, parameters map[string]interface{}) (ServiceBinding, Warnings, error) {
	var allWarnings Warnings
	app, warnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
	allWarnings = append(allWarnings, warnings...)
	if err != nil {
		return ServiceBinding{}, allWarnings, err
	}

	serviceInstance, warnings, err := actor.GetServiceInstanceByNameAndSpace(serviceInstanceName, spaceGUID)
	allWarnings = append(allWarnings, warnings...)
	if err != nil {
		return ServiceBinding{}, allWarnings, err
	}

	serviceBinding, ccv2Warnings, err := actor.CloudControllerClient.CreateServiceBinding(app.GUID, serviceInstance.GUID, bindingName, true, parameters)
	allWarnings = append(allWarnings, ccv2Warnings...)

	return ServiceBinding(serviceBinding), allWarnings, err
}
1112015
func CreateKeyspaceWithNetworkTopologyStrategy(c *gocql.ClusterConfig, ks string, rfmap map[string]uint) error {
	kis, err := GetKeyspaces(c)
	if err != nil {
		return err
	}
	kss := set.NewStringSet(kis)
	if !kss.Contains(ks) {
		log.Printf("Creating keyspace: %v\n", ks)
		c.Keyspace = ""
		s, err := c.CreateSession()
		if err != nil {
			return err
		}
		defer s.Close()
		q := fmt.Sprintf("CREATE KEYSPACE IF NOT EXISTS %v WITH REPLICATION = {'class': '%v', ", ks, "NetworkTopologyStrategy")
		rfsl := []string{}
		for dc, rf := range rfmap {
			rfsl = append(rfsl, fmt.Sprintf("'%v' : %v", dc, rf))
		}
		q = fmt.Sprintf("%v%v};", q, strings.Join(rfsl, ", "))
		err = s.Query(q).Exec()
		if err != nil {
			return err
		}
	}
	c.Keyspace = ks
	return nil
}
722716
func NewNamespace(modelUUID string) (Namespace, error) {
	if !names.IsValidModel(modelUUID) {
		return nil, errors.Errorf("model ID %q is not a valid model", modelUUID)
	}
	// The suffix is the last six hex digits of the model uuid.
	suffix := modelUUID[len(modelUUID)-uuidSuffixDigits:]

	return &namespace{name: suffix}, nil
}
1225612
func NewRowRouter(shardInfos []*topo.ShardInfo, keyResolver keyspaceIDResolver) RowRouter {
	keyRanges := make([]*topodatapb.KeyRange, len(shardInfos))
	for i, si := range shardInfos {
		keyRanges[i] = si.KeyRange
	}
	return RowRouter{keyResolver, keyRanges}
}
599380
func (agent *ActionAgent) maybeRebuildKeyspace(cell, keyspace string) {
	_, err := agent.TopoServer.GetSrvKeyspace(agent.batchCtx, cell, keyspace)
	switch {
	case err == nil:
		// SrvKeyspace exists, we're done
		log.Infof("SrvKeyspace(%v,%v) exists, not building it", cell, keyspace)
		return
	case topo.IsErrType(err, topo.NoNode):
		log.Infof("SrvKeyspace(%v,%v) doesn't exist, rebuilding it", cell, keyspace)
		// SrvKeyspace doesn't exist, we'll try to rebuild it
	default:
		log.Warningf("Cannot read SrvKeyspace(%v,%v) (may need to run 'vtctl RebuildKeyspaceGraph %v'), skipping rebuild: %v", cell, keyspace, keyspace, err)
		return
	}

	if err := topotools.RebuildKeyspace(agent.batchCtx, logutil.NewConsoleLogger(), agent.TopoServer, keyspace, []string{cell}); err != nil {
		log.Warningf("RebuildKeyspace(%v,%v) failed: %v, may need to run 'vtctl RebuildKeyspaceGraph %v')", cell, keyspace, err, keyspace)
		return
	}

	if err := topotools.RebuildVSchema(agent.batchCtx, logutil.NewConsoleLogger(), agent.TopoServer, []string{cell}); err != nil {
		log.Warningf("RebuildVSchema(%v) failed: %v, may need to run 'vtctl RebuildVSchemaGraph --cells %v", cell, err, cell)
	}
}
564803
func (scw *SplitCloneWorker) createKeyResolver(td *tabletmanagerdatapb.TableDefinition) (keyspaceIDResolver, error) {
	if scw.cloneType == verticalSplit {
		// VerticalSplitClone currently always has exactly one destination shard
		// and therefore does not require routing between multiple shards.
		return nil, nil
	}

	if *useV3ReshardingMode {
		return newV3ResolverFromTableDefinition(scw.keyspaceSchema, td)
	}
	return newV2Resolver(scw.destinationKeyspaceInfo, td)
}
1114192
func NewNamespacedID(id, ns string) NamespacedID {
	return NamespacedID{
		ID:        id,
		Namespace: ns,
	}
}
263546
func NewIDService(ctx context.Context, h host.Host) *IDService {
	s := &IDService{
		Host:          h,
		ctx:           ctx,
		currid:        make(map[inet.Conn]chan struct{}),
		observedAddrs: NewObservedAddrSet(ctx),
	}
	h.SetStreamHandler(ID, s.requestHandler)
	h.SetStreamHandler(IDPush, s.pushHandler)
	h.Network().Notify((*netNotifiee)(s))
	return s
}
863957
func InitializeKeyspace(ctx context.Context, pub Publisher, pins pin.Pinner, key ci.PrivKey) error {
	emptyDir := ft.EmptyDirNode()

	// pin recursively because this might already be pinned
	// and doing a direct pin would throw an error in that case
	err := pins.Pin(ctx, emptyDir, true)
	if err != nil {
		return err
	}

	err = pins.Flush()
	if err != nil {
		return err
	}

	return pub.Publish(ctx, key, path.FromCid(emptyDir.Cid()))
}
648107
func (client *Client) CreateSpace(spaceName string, orgGUID string) (Space, Warnings, error) {
	requestBody := createSpaceRequestBody{
		Name:             spaceName,
		OrganizationGUID: orgGUID,
	}

	bodyBytes, _ := json.Marshal(requestBody)

	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.PostSpaceRequest,
		Body:        bytes.NewReader(bodyBytes),
	})

	if err != nil {
		return Space{}, nil, err
	}

	var space Space
	response := cloudcontroller.Response{
		DecodeJSONResponseInto: &space,
	}

	err = client.connection.Make(request, &response)

	return space, response.Warnings, err
}
582953
func NewDomainVerificationAddDomainSuccessType(Description string) *DomainVerificationAddDomainSuccessType {
	s := new(DomainVerificationAddDomainSuccessType)
	s.Description = Description
	return s
}
747083
func ParseKeyspaceIDType(param string) (topodatapb.KeyspaceIdType, error) {
	if param == "" {
		return topodatapb.KeyspaceIdType_UNSET, nil
	}
	value, ok := topodatapb.KeyspaceIdType_value[strings.ToUpper(param)]
	if !ok {
		return topodatapb.KeyspaceIdType_UNSET, fmt.Errorf("unknown KeyspaceIdType %v", param)
	}
	return topodatapb.KeyspaceIdType(value), nil
}
1266864
func NewNamedFactory(name string, errtext string) ErrorFactory {
	if _, ok := namedFactories[name]; ok {
		panic(fmt.Errorf("error factory name duplicated: %q", name))
	}
	factory := &errorFactory{
		errtext: errtext,
		name:    name,
	}
	namedFactories[name] = factory
	return factory
}