зеркало из https://github.com/github/vitess-gh.git
Merge pull request #658 from yaoshengzhe/fix_add_reload_schema_flag
add enableReloadSchema flag to ExecuteFetchAsDba in tabletmanager
This commit is contained in:
Коммит
34d0e6afdf
|
@ -611,7 +611,7 @@ func (fra *fakeRPCAgent) ExecuteFetch(ctx context.Context, query string, maxrows
|
|||
|
||||
func agentRPCTestExecuteFetch(ctx context.Context, t *testing.T, client tmclient.TabletManagerClient, ti *topo.TabletInfo) {
|
||||
testExecuteFetchDbConfigName = dbconfigs.DbaConfigName
|
||||
qr, err := client.ExecuteFetchAsDba(ctx, ti, testExecuteFetchQuery, testExecuteFetchMaxRows, true, true)
|
||||
qr, err := client.ExecuteFetchAsDba(ctx, ti, testExecuteFetchQuery, testExecuteFetchMaxRows, true, true, false)
|
||||
compareError(t, "ExecuteFetch", err, qr, testExecuteFetchResult)
|
||||
testExecuteFetchDbConfigName = dbconfigs.AppConfigName
|
||||
qr, err = client.ExecuteFetchAsApp(ctx, ti, testExecuteFetchQuery, testExecuteFetchMaxRows, true)
|
||||
|
@ -619,7 +619,7 @@ func agentRPCTestExecuteFetch(ctx context.Context, t *testing.T, client tmclient
|
|||
}
|
||||
|
||||
func agentRPCTestExecuteFetchPanic(ctx context.Context, t *testing.T, client tmclient.TabletManagerClient, ti *topo.TabletInfo) {
|
||||
_, err := client.ExecuteFetchAsDba(ctx, ti, testExecuteFetchQuery, testExecuteFetchMaxRows, true, true)
|
||||
_, err := client.ExecuteFetchAsDba(ctx, ti, testExecuteFetchQuery, testExecuteFetchMaxRows, true, true, false)
|
||||
expectRPCWrapPanic(t, err)
|
||||
|
||||
_, err = client.ExecuteFetchAsApp(ctx, ti, testExecuteFetchQuery, testExecuteFetchMaxRows, true)
|
||||
|
|
|
@ -142,7 +142,7 @@ func (client *FakeTabletManagerClient) ApplySchema(ctx context.Context, tablet *
|
|||
}
|
||||
|
||||
// ExecuteFetchAsDba is part of the tmclient.TabletManagerClient interface
|
||||
func (client *FakeTabletManagerClient) ExecuteFetchAsDba(ctx context.Context, tablet *topo.TabletInfo, query string, maxRows int, wantFields, disableBinlogs bool) (*mproto.QueryResult, error) {
|
||||
func (client *FakeTabletManagerClient) ExecuteFetchAsDba(ctx context.Context, tablet *topo.TabletInfo, query string, maxRows int, wantFields, disableBinlogs, reloadSchema bool) (*mproto.QueryResult, error) {
|
||||
var qr mproto.QueryResult
|
||||
return &qr, nil
|
||||
}
|
||||
|
|
|
@ -90,6 +90,7 @@ type ExecuteFetchArgs struct {
|
|||
MaxRows int
|
||||
WantFields bool
|
||||
DisableBinlogs bool
|
||||
ReloadSchema bool
|
||||
DBConfigName dbconfigs.DbConfigName
|
||||
}
|
||||
|
||||
|
|
|
@ -223,13 +223,14 @@ func (client *GoRPCTabletManagerClient) ApplySchema(ctx context.Context, tablet
|
|||
}
|
||||
|
||||
// ExecuteFetchAsDba is part of the tmclient.TabletManagerClient interface
|
||||
func (client *GoRPCTabletManagerClient) ExecuteFetchAsDba(ctx context.Context, tablet *topo.TabletInfo, query string, maxRows int, wantFields, disableBinlogs bool) (*mproto.QueryResult, error) {
|
||||
func (client *GoRPCTabletManagerClient) ExecuteFetchAsDba(ctx context.Context, tablet *topo.TabletInfo, query string, maxRows int, wantFields, disableBinlogs, reloadSchema bool) (*mproto.QueryResult, error) {
|
||||
var qr mproto.QueryResult
|
||||
if err := client.rpcCallTablet(ctx, tablet, actionnode.TabletActionExecuteFetch, &gorpcproto.ExecuteFetchArgs{
|
||||
Query: query,
|
||||
MaxRows: maxRows,
|
||||
WantFields: wantFields,
|
||||
DisableBinlogs: disableBinlogs,
|
||||
ReloadSchema: reloadSchema,
|
||||
DBConfigName: dbconfigs.DbaConfigName,
|
||||
}, &qr); err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -207,6 +207,9 @@ func (tm *TabletManager) ExecuteFetch(ctx context.Context, args *gorpcproto.Exec
|
|||
qr, err := tm.agent.ExecuteFetch(ctx, args.Query, args.MaxRows, args.WantFields, args.DisableBinlogs, args.DBConfigName)
|
||||
if err == nil {
|
||||
*reply = *qr
|
||||
if args.ReloadSchema {
|
||||
tm.agent.ReloadSchema(ctx)
|
||||
}
|
||||
}
|
||||
return err
|
||||
})
|
||||
|
|
|
@ -84,7 +84,7 @@ type TabletManagerClient interface {
|
|||
ApplySchema(ctx context.Context, tablet *topo.TabletInfo, change *myproto.SchemaChange) (*myproto.SchemaChangeResult, error)
|
||||
|
||||
// ExecuteFetchAsDba executes a query remotely using the DBA pool
|
||||
ExecuteFetchAsDba(ctx context.Context, tablet *topo.TabletInfo, query string, maxRows int, wantFields, disableBinlogs bool) (*mproto.QueryResult, error)
|
||||
ExecuteFetchAsDba(ctx context.Context, tablet *topo.TabletInfo, query string, maxRows int, wantFields, disableBinlogs, reloadSchema bool) (*mproto.QueryResult, error)
|
||||
|
||||
// ExecuteFetchAsApp executes a query remotely using the App pool
|
||||
ExecuteFetchAsApp(ctx context.Context, tablet *topo.TabletInfo, query string, maxRows int, wantFields bool) (*mproto.QueryResult, error)
|
||||
|
|
|
@ -973,6 +973,8 @@ func commandExecuteFetchAsDba(ctx context.Context, wr *wrangler.Wrangler, subFla
|
|||
maxRows := subFlags.Int("max_rows", 10000, "maximum number of rows to allow in reset")
|
||||
wantFields := subFlags.Bool("want_fields", false, "also get the field names")
|
||||
disableBinlogs := subFlags.Bool("disable_binlogs", false, "disable writing to binlogs during the query")
|
||||
reloadSchema := subFlags.Bool("reload_schema", false, "if this flag is true, tablet schema will be reloaded after executing given query")
|
||||
|
||||
if err := subFlags.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -985,7 +987,7 @@ func commandExecuteFetchAsDba(ctx context.Context, wr *wrangler.Wrangler, subFla
|
|||
return err
|
||||
}
|
||||
query := subFlags.Arg(1)
|
||||
qr, err := wr.ExecuteFetchAsDba(ctx, alias, query, *maxRows, *wantFields, *disableBinlogs)
|
||||
qr, err := wr.ExecuteFetchAsDba(ctx, alias, query, *maxRows, *wantFields, *disableBinlogs, *reloadSchema)
|
||||
if err == nil {
|
||||
wr.Logger().Printf("%v\n", jscfg.ToJSON(qr))
|
||||
}
|
||||
|
|
|
@ -540,8 +540,8 @@ func (wr *Wrangler) CopySchemaShard(ctx context.Context, srcTabletAlias topo.Tab
|
|||
}
|
||||
createSql := sd.ToSQLStrings()
|
||||
|
||||
for _, sqlLine := range createSql {
|
||||
err = wr.applySqlShard(ctx, tabletInfo, sqlLine)
|
||||
for i, sqlLine := range createSql {
|
||||
err = wr.applySqlShard(ctx, tabletInfo, sqlLine, i == len(createSql)-1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -556,7 +556,7 @@ func (wr *Wrangler) CopySchemaShard(ctx context.Context, srcTabletAlias topo.Tab
|
|||
// Thus it should be used only for changes that can be applies on a live instance without causing issues;
|
||||
// it shouldn't be used for anything that will require a pivot.
|
||||
// The SQL statement string is expected to have {{.DatabaseName}} in place of the actual db name.
|
||||
func (wr *Wrangler) applySqlShard(ctx context.Context, tabletInfo *topo.TabletInfo, change string) error {
|
||||
func (wr *Wrangler) applySqlShard(ctx context.Context, tabletInfo *topo.TabletInfo, change string, reloadSchema bool) error {
|
||||
filledChange, err := fillStringTemplate(change, map[string]string{"DatabaseName": tabletInfo.DbName()})
|
||||
if err != nil {
|
||||
return fmt.Errorf("fillStringTemplate failed: %v", err)
|
||||
|
@ -564,7 +564,7 @@ func (wr *Wrangler) applySqlShard(ctx context.Context, tabletInfo *topo.TabletIn
|
|||
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
defer cancel()
|
||||
// Need to make sure that we enable binlog, since we're only applying the statement on masters.
|
||||
_, err = wr.tmc.ExecuteFetchAsDba(ctx, tabletInfo, filledChange, 0, false, false)
|
||||
_, err = wr.tmc.ExecuteFetchAsDba(ctx, tabletInfo, filledChange, 0, false, false, reloadSchema)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -269,10 +269,10 @@ func (wr *Wrangler) DeleteTablet(tabletAlias topo.TabletAlias) error {
|
|||
}
|
||||
|
||||
// ExecuteFetchAsDba executes a query remotely using the DBA pool
|
||||
func (wr *Wrangler) ExecuteFetchAsDba(ctx context.Context, tabletAlias topo.TabletAlias, query string, maxRows int, wantFields, disableBinlogs bool) (*mproto.QueryResult, error) {
|
||||
func (wr *Wrangler) ExecuteFetchAsDba(ctx context.Context, tabletAlias topo.TabletAlias, query string, maxRows int, wantFields, disableBinlogs bool, reloadSchema bool) (*mproto.QueryResult, error) {
|
||||
ti, err := wr.ts.GetTablet(tabletAlias)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return wr.tmc.ExecuteFetchAsDba(ctx, ti, query, maxRows, wantFields, disableBinlogs)
|
||||
return wr.tmc.ExecuteFetchAsDba(ctx, ti, query, maxRows, wantFields, disableBinlogs, reloadSchema)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче