// Clone creates a new Backoffer which keeps current Backoffer's sleep time and errors, and shares
// current Backoffer's context.
423739
func (b *Backoffer) Clone() *Backoffer {
	return &Backoffer{
		ctx:        b.ctx,
		maxSleep:   b.maxSleep,
		totalSleep: b.totalSleep,
		errors:     b.errors,
		vars:       b.vars,
	}
}
1200304
func (n *NkeyUser) clone() *NkeyUser {
	if n == nil {
		return nil
	}
	clone := &NkeyUser{}
	*clone = *n
	clone.Permissions = n.Permissions.clone()
	return clone
}
109224
func (fos *FanOutSink) Clone() Sink {
	sinkClones := make([]Sink, len(fos.sinks))
	for i, sink := range fos.sinks {
		sinkClones[i] = sink.Clone()
	}

	return &FanOutSink{
		sinks:  sinkClones,
		stores: make(chan storeOp),
	}
}
531028
func (sc *serverCreds) Clone() credentials.TransportCredentials {
	creds := NewServerTransportCredentials(sc.serverConfig, sc.logger)
	return creds
}
550672
func (h *Host) Clone() *Host {
	var c Host
	c.Copy(h)
	return &c
}
631044
func (m *MockBackoff) Clone() backoff.Backoff {
	r0 := m.CloneFunc.nextHook()()
	m.CloneFunc.history = append(m.CloneFunc.history, BackoffCloneFuncCall{r0})
	return r0
}
338866
func (ds *DiskSink) Clone() Sink {
	dsc := &DiskSink{
		BasePath: ds.BasePath,

		Container:   ds.Container,
		BlockHashes: ds.BlockHashes,
	}

	if ds.Compressor != nil {
		dsc.Compressor = ds.Compressor.Clone()
	}

	return dsc
}
168008
func (ds *DelayedSource) Clone() Source {
	return &DelayedSource{
		Source:  ds.Source.Clone(),
		Latency: ds.Latency,
	}
}
13994
func (c Collector) Clone() Collector {
	col := make(Collector)
	col.Copy(c)
	return col
}
507282
func (scw *SplitCloneWorker) clone(ctx context.Context, state StatusWorkerState) error {
	if state != WorkerStateCloneOnline && state != WorkerStateCloneOffline {
		panic(fmt.Sprintf("invalid state passed to clone(): %v", state))
	}
	scw.setState(state)
	start := time.Now()
	defer func() {
		statsStateDurationsNs.Set(string(state), time.Since(start).Nanoseconds())
	}()

	var firstSourceTablet, err = scw.findFirstSourceTablet(ctx, state)
	if err != nil {
		return err
	}

	statsCounters, tableStatusList := scw.getCounters(state)

	// The throttlers exist only for the duration of this clone() call.
	// That means a SplitClone invocation with both online and offline phases
	// will create throttlers for each phase.
	if err := scw.createThrottlers(); err != nil {
		return err
	}
	defer scw.closeThrottlers()

	sourceSchemaDefinition, err := scw.getSourceSchema(ctx, firstSourceTablet)
	if err != nil {
		return err
	}
	scw.wr.Logger().Infof("Source tablet 0 has %v tables to copy", len(sourceSchemaDefinition.TableDefinitions))
	tableStatusList.initialize(sourceSchemaDefinition)

	var firstError error

	ctx, cancelCopy := context.WithCancel(ctx)
	defer cancelCopy()
	processError := func(format string, args ...interface{}) {
		// in theory we could have two threads see firstError as null and both write to the variable
		// that should not cause any problems though - canceling and logging is concurrently safe,
		// and overwriting the variable will not cause any problems
		scw.wr.Logger().Errorf(format, args...)
		if firstError == nil {
			firstError = vterrors.Errorf(vtrpc.Code_INTERNAL, format, args...)
			cancelCopy()
		}
	}

	// NOTE: Code below this point must *not* use "return" to exit this Go routine
	// early. Instead, "processError" must be called to cancel the context. This
	// way all launched Go routines will terminate as well.
	// (However, "return" in a new Go routine, i.e. not this one, is fine.)
	// If Go routines have already been started, make sure that Wait() on the
	// respective WaitGroup is called as well e.g. "destinationWaitGroup.Wait()"
	// must always be reached. Waiting for the Go routines is important to avoid
	// races between "defer throttler.ThreadFinished()" (must be executed first)
	// and "defer scw.closeThrottlers()". Otherwise, vtworker will panic.

	// In parallel, setup the channels to send SQL data chunks to for each destination tablet:
	insertChannels := make([]chan string, len(scw.destinationShards))
	destinationWaitGroup := sync.WaitGroup{}
	for shardIndex, si := range scw.destinationShards {
		// We create one channel per destination tablet. It is sized to have a
		// buffer of a maximum of destinationWriterCount * 2 items, to hopefully
		// always have data. We then have destinationWriterCount go routines reading
		// from it.
		insertChannels[shardIndex] = make(chan string, scw.destinationWriterCount*2)

		for j := 0; j < scw.destinationWriterCount; j++ {
			destinationWaitGroup.Add(1)
			go scw.startExecutor(ctx, &destinationWaitGroup, si.Keyspace(), si.ShardName(), insertChannels[shardIndex], j, processError)
		}
	}

	// Now for each table, read data chunks and send them to all
	// insertChannels
	readers := sync.WaitGroup{}

	err = scw.startCloningData(ctx, state, sourceSchemaDefinition, processError, firstSourceTablet, tableStatusList, start, statsCounters, insertChannels, &readers)
	if err != nil {
		return vterrors.Wrap(err, "failed to startCloningData")
	}
	readers.Wait()

	for shardIndex := range scw.destinationShards {
		close(insertChannels[shardIndex])
	}
	destinationWaitGroup.Wait()

	return firstError
}
740473
func (c *SyncCollector) Clone() SyncCollectors {
	var co Collector

	c.rw.RLock()
	co = c.c.Clone()
	c.rw.RUnlock()

	so := SyncCollector{c: co}
	return &so
}
827598
func (p *Properties) Clone() *Properties {
	clone := *p
	clone.LogStreamDescriptor = proto.Clone(p.LogStreamDescriptor).(*logpb.LogStreamDescriptor)
	return &clone
}
322930
func (tp *TranslationProvider) Clone(d *deps.Deps) error {
	d.Translate = tp.t.Func(d.Language.Lang)

	return nil
}
691595
func (r *RemoteGatewayOpts) clone() *RemoteGatewayOpts {
	if r == nil {
		return nil
	}
	clone := &RemoteGatewayOpts{
		Name: r.Name,
		URLs: deepCopyURLs(r.URLs),
	}
	if r.TLSConfig != nil {
		clone.TLSConfig = r.TLSConfig.Clone()
		clone.TLSTimeout = r.TLSTimeout
	}
	return clone
}
1185536
func (t *Record) Clone() interface{} {
	retVal := new(Record)
	ts := BorrowTypes(len(t.ts))
	for i, tt := range t.ts {
		if c, ok := tt.(Cloner); ok {
			ts[i] = c.Clone().(Type)
		} else {
			ts[i] = tt
		}
	}
	retVal.ts = ts
	retVal.name = t.name

	return retVal
}
35473
func (c *CertAuthorityV2) Clone() CertAuthority {
	out := *c
	out.Spec.CheckingKeys = utils.CopyByteSlices(c.Spec.CheckingKeys)
	out.Spec.SigningKeys = utils.CopyByteSlices(c.Spec.SigningKeys)
	for i, kp := range c.Spec.TLSKeyPairs {
		out.Spec.TLSKeyPairs[i] = TLSKeyPair{
			Key:  utils.CopyByteSlice(kp.Key),
			Cert: utils.CopyByteSlice(kp.Cert),
		}
	}
	out.Spec.Roles = utils.CopyStrings(c.Spec.Roles)
	return &out
}
651833
func (h Headers) Clone() Headers {
	r := make(Headers, len(h))
	copy(r, h)
	return r
}