-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
br/operator: added some commands for managing migrations (#56857)
close #56760
- Loading branch information
Showing
7 changed files
with
426 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package operator | ||
|
||
import ( | ||
"context" | ||
"encoding/base64" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/fatih/color" | ||
"github.com/pingcap/tidb/br/pkg/storage" | ||
) | ||
|
||
func Base64ify(ctx context.Context, cfg Base64ifyConfig) error { | ||
return runEncode(ctx, cfg) // Assuming runEncode will be similarly modified to accept Base64ifyConfig | ||
} | ||
|
||
func runEncode(ctx context.Context, cfg Base64ifyConfig) error { | ||
s, err := storage.ParseBackend(cfg.StorageURI, &cfg.BackendOptions) | ||
if err != nil { | ||
return err | ||
} | ||
if cfg.LoadCerd { | ||
_, err := storage.New(ctx, s, &storage.ExternalStorageOptions{ | ||
SendCredentials: true, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Fprintln(os.Stderr, color.HiRedString("Credientials are encoded to the base64 string. DON'T share this with untrusted people!")) | ||
} | ||
|
||
sBytes, err := s.Marshal() | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(base64.StdEncoding.EncodeToString(sBytes)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package operator | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/fatih/color" | ||
"github.com/pingcap/tidb/br/pkg/glue" | ||
"github.com/pingcap/tidb/br/pkg/storage" | ||
"github.com/pingcap/tidb/br/pkg/stream" | ||
) | ||
|
||
// statusOK make a string like <green>●</green> <bold>{message}</bold> | ||
func statusOK(message string) string { | ||
return color.GreenString("●") + color.New(color.Bold).Sprintf(" %s", message) | ||
} | ||
|
||
func RunListMigrations(ctx context.Context, cfg ListMigrationConfig) error { | ||
backend, err := storage.ParseBackend(cfg.StorageURI, &cfg.BackendOptions) | ||
if err != nil { | ||
return err | ||
} | ||
st, err := storage.Create(ctx, backend, false) | ||
if err != nil { | ||
return err | ||
} | ||
ext := stream.MigerationExtension(st) | ||
migs, err := ext.Load(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
if cfg.JSONOutput { | ||
if err := json.NewEncoder(os.Stdout).Encode(migs); err != nil { | ||
return err | ||
} | ||
} else { | ||
console := glue.ConsoleOperations{ConsoleGlue: glue.StdIOGlue{}} | ||
console.Println(statusOK(fmt.Sprintf("Total %d Migrations.", len(migs.Layers)+1))) | ||
console.Printf("> BASE <\n") | ||
tbl := console.CreateTable() | ||
stream.AddMigrationToTable(migs.Base, tbl) | ||
tbl.Print() | ||
for _, t := range migs.Layers { | ||
console.Printf("> %08d <\n", t.SeqNum) | ||
tbl := console.CreateTable() | ||
stream.AddMigrationToTable(&t.Content, tbl) | ||
tbl.Print() | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.