// CopyTable copies all data in source to the existing destination table using
CopyTable copies all data in source to the existing destination table using
// CopyTable copies all data in source to the existing destination table using
func (c *Client) CopyTable(parentCtx context.Context, dst string, src string, workers int, onError func(err error, cancelFunc context.CancelFunc)) error {
	ctx, cancel := context.WithCancel(parentCtx)
	defer cancel()
	errChan := make(chan error, workers)
	readComplete := make(chan struct{})
	dataChan := make(chan map[string]*dynamodb.AttributeValue, workers)
	var wg sync.WaitGroup
	wg.Add(1 + workers)
	var working int64
	for i := 0; i < workers; i++ {
		go c.copyTableWorker(ctx, dst, readComplete, dataChan, &working, &wg, errChan)
	}
	go func() {
		defer wg.Done()
		err := c.ParallelScanIterator(ctx, &dynamodb.ScanInput{
			TableName: aws.String(src),
		}, workers, func(output *dynamodb.ScanOutput) error {
			for _, item := range output.Items {
				select {
				case dataChan <- item:
				case <-ctx.Done():
					return ctx.Err()
				}
			}
			return nil
		}, true)
		close(dataChan)
		close(readComplete)
		if err != nil {
			select {
			case <-ctx.Done():
			case errChan <- err:
			}
		}
	}()
	complete := make(chan struct{})
	go func() {
		wg.Wait()
		close(complete)
	}()
	for {
		select {
		case <-ctx.Done():
			return ctx.Err()
		case err := <-errChan:
			if onError == nil {
				cancel()
				<-complete
				return err
			}
			onError(err, cancel)
		case <-complete:
			return nil
		}
	}
}
func ( c * Client ) CopyTable ( parentCtx context . Context , dst string , src string , workers int , onError func ( err error , cancelFunc context . CancelFunc ) ) error { ctx , cancel := context . WithCancel ( parentCtx ) defer cancel ( ) errChan := make ( chan error , workers ) readComplete := make ( chan struct { } ) dataChan := make ( chan map [ string ] * dynamodb . AttributeValue , workers ) var wg sync . WaitGroup wg . Add ( 1 + workers ) var working int64 for i := 0 ; i < workers ; i ++ { go c . copyTableWorker ( ctx , dst , readComplete , dataChan , & working , & wg , errChan ) } go func ( ) { defer wg . Done ( ) err := c . ParallelScanIterator ( ctx , & dynamodb . ScanInput { TableName : aws . String ( src ) , } , workers , func ( output * dynamodb . ScanOutput ) error { for _ , item := range output . Items { select { case dataChan <- item : case <- ctx . Done ( ) : return ctx . Err ( ) } } return nil } , true ) close ( dataChan ) close ( readComplete ) if err != nil { select { case <- ctx . Done ( ) : case errChan <- err : } } } ( ) complete := make ( chan struct { } ) go func ( ) { wg . Wait ( ) close ( complete ) } ( ) for { select { case <- ctx . Done ( ) : return ctx . Err ( ) case err := <- errChan : if onError == nil { cancel ( ) <- complete return err } onError ( err , cancel ) case <- complete : return nil } } }
CopyTable copies all data in source to the existing destination table using
CopyTable copies all data in source to the existing destination table using