Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report: ApplySchema --batch-size fails to apply zero-date and causes premature ReloadSchema #14952

Closed
shlomi-noach opened this issue Jan 15, 2024 · 1 comment

Comments

@shlomi-noach
Copy link
Contributor

shlomi-noach commented Jan 15, 2024

Overview of the Issue

ApplySchema --batch-size sees two different problems, both caused by the fact we run batched commands via ExecuteFetchAsDBA RPC.

  1. When running with --ddl-strategy="direct --allow-zero-in-date, and when --batch-size > 1, and when multiple queries supplied in --sql, then parsing of the injected /*vt+ allowZeroInDate=true */ fails. This is because ExecuteFetchAsDBA implementation in server/engine assumes the received SQL contains a single statement:

if stmt, err := tm.SQLParser.Parse(string(req.Query)); err == nil {
if cmnt, ok := stmt.(sqlparser.Commented); ok {
directives = cmnt.GetParsedComments().Directives()
}
}

  1. Related to ExecuteFetch misbehavior when running multiple queies #14948, when we apply multiple CREATE TABLE... statements, we do only consume the result set of the first statement. This blocks 2nd and 3rd, ... statements from running, and as result this ReloadSchema code only sees the 1st table:

if err == nil && req.ReloadSchema {
reloadErr := tm.QueryServiceControl.ReloadSchema(ctx)
if reloadErr != nil {
log.Errorf("failed to reload the schema %v", reloadErr)
}
}

The rest of the statements/tables do get applied when the connection is terminated, which makes this issue evasive.


Related: #13693


This issue affects release-18.0. Because both vtctld and vttablet are involved, there is no single bugfix that will make everything right. We should:

  • Offer a solution that is "good enough" for both current + v18
  • Offer a moving-forward solution that will apply in v19&v20, based on enhanced RPC.

Reproduction Steps

In examples/101, run the following:

vtctldclient ApplySchema --ddl-strategy="direct --allow-zero-in-date" --batch-size=5 --sql "create table if not exists t1 (id int primary key); create table if not exists t2 (id int primary key); create table if not exists t3 (id int primary key);" commerce

Tail the PRIMARY tablet logs. You will see:

Jan 15 06:15:45 I0115 06:15:45.561796  316725 rpc_schema.go:57] ReloadSchema requested via RPC
Jan 15 06:15:45 I0115 06:15:45.575769  316725 engine.go:551] schema engine created [t1], altered [], dropped []

In the above only t1 gets reloaded.

Binary Version

v18
current (v19)

Operating System and Environment details

-

Log Fragments

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant