func multiRestoreCmd(mysqld *mysqlctl.Mysqld, subFlags *flag.FlagSet, args []string) { starts := subFlags.String("starts", "", "starts of the key range") ends := subFlags.String("ends", "", "ends of the key range") fetchRetryCount := subFlags.Int("fetch_retry_count", 3, "how many times to retry a failed transfer") concurrency := subFlags.Int("concurrency", 8, "how many concurrent db inserts to run simultaneously") fetchConcurrency := subFlags.Int("fetch_concurrency", 4, "how many files to fetch simultaneously") insertTableConcurrency := subFlags.Int("insert_table_concurrency", 4, "how many myisam tables to load into a single destination table simultaneously") strategy := subFlags.String("strategy", "", "which strategy to use for restore, can contain:\n"+ " skipAutoIncrement(TTT): we won't add the AUTO_INCREMENT back to that table\n"+ " delayPrimaryKey: we won't add the primary key until after the table is populated\n"+ " delaySecondaryIndexes: we won't add the secondary indexes until after the table is populated\n"+ " useMyIsam: create the table as MyISAM, then convert it to InnoDB after population\n"+ " writeBinLogs: write all operations to the binlogs") subFlags.Parse(args) if subFlags.NArg() < 2 { log.Fatalf("multirestore requires <destination_dbname> <source_host>[/<source_dbname>]... %v", args) } startArray := strings.Split(*starts, ",") endArray := strings.Split(*ends, ",") if len(startArray) != len(endArray) || len(startArray) != subFlags.NArg()-1 { log.Fatalf("Need as many starts and ends as source URLs") } keyRanges := make([]key.KeyRange, len(startArray)) for i, s := range startArray { var err error keyRanges[i], err = key.ParseKeyRangeParts(s, endArray[i]) if err != nil { log.Fatalf("Invalid start or end: %v", err) } } dbName, dbis := subFlags.Arg(0), subFlags.Args()[1:] sources := make([]*url.URL, len(dbis)) for i, dbi := range dbis { if !strings.HasPrefix(dbi, "vttp://") && !strings.HasPrefix(dbi, "http://") { dbi = "vttp://" + dbi } dbUrl, err := url.Parse(dbi) if err != nil { log.Fatalf("incorrect source url: %v", err) } sources[i] = dbUrl } if err := mysqld.MultiRestore(dbName, keyRanges, sources, nil, *concurrency, *fetchConcurrency, *insertTableConcurrency, *fetchRetryCount, *strategy); err != nil { log.Fatalf("multirestore failed: %v", err) } }
func multiRestoreCmd(mysqld *mysqlctl.Mysqld, subFlags *flag.FlagSet, args []string) { start := subFlags.String("start", "", "start of the key range") end := subFlags.String("end", "", "end of the key range") fetchRetryCount := subFlags.Int("fetch-retry-count", 3, "how many times to retry a failed transfer") concurrency := subFlags.Int("concurrency", 8, "how many concurrent db inserts to run simultaneously") fetchConcurrency := subFlags.Int("fetch-concurrency", 4, "how many files to fetch simultaneously") insertTableConcurrency := subFlags.Int("insert-table-concurrency", 4, "how many myisam tables to load into a single destination table simultaneously") strategy := subFlags.String("strategy", "", "which strategy to use for restore, can contain:\n"+ " skipAutoIncrement(TTT): we won't add the AUTO_INCREMENT back to that table\n"+ " delayPrimaryKey: we won't add the primary key until after the table is populated\n"+ " delaySecondaryIndexes: we won't add the secondary indexes until after the table is populated\n"+ " useMyIsam: create the table as MyISAM, then convert it to InnoDB after population\n"+ " writeBinLogs: write all operations to the binlogs") subFlags.Parse(args) s, err := key.HexKeyspaceId(*start).Unhex() if err != nil { log.Fatalf("Invalid start key %v: %v", *start, err) } e, err := key.HexKeyspaceId(*end).Unhex() if err != nil { log.Fatalf("Invalid end key %v: %v", *end, err) } keyRange := key.KeyRange{Start: s, End: e} if subFlags.NArg() < 2 { log.Fatalf("multirestore requires <destination_dbname> <source_host>[/<source_dbname>]... %v", args) } dbName, dbis := subFlags.Arg(0), subFlags.Args()[1:] sources := make([]*url.URL, len(dbis)) for i, dbi := range dbis { if !strings.HasPrefix(dbi, "vttp://") && !strings.HasPrefix(dbi, "http://") { dbi = "vttp://" + dbi } dbUrl, err := url.Parse(dbi) if err != nil { log.Fatalf("incorrect source url: %v", err) } sources[i] = dbUrl } if err := mysqld.MultiRestore(dbName, keyRange, sources, *concurrency, *fetchConcurrency, *insertTableConcurrency, *fetchRetryCount, *strategy); err != nil { log.Fatalf("multirestore failed: %v", err) } }