-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
VReplication: Enable VPlayerBatching in unit tests #17339
Changes from all commits
e1d2649
b9a4ca9
f49cb05
ce3998e
26f93d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ import ( | |
"vitess.io/vitess/go/vt/vterrors" | ||
) | ||
|
||
const beginStmtLen = int64(len("begin;")) | ||
|
||
// vdbClient is a wrapper on binlogplayer.DBClient. | ||
// It allows us to retry a failed transactions on lock errors. | ||
type vdbClient struct { | ||
|
@@ -56,16 +58,19 @@ func (vc *vdbClient) Begin() error { | |
if vc.InTransaction { | ||
return nil | ||
} | ||
if err := vc.DBClient.Begin(); err != nil { | ||
return err | ||
if vc.maxBatchSize > 0 { | ||
// We are batching the contents of the transaction, which | ||
// starts with the BEGIN and ends with the COMMIT, so we | ||
// do not send a BEGIN down the wire ahead of time. | ||
vc.queriesPos = int64(len(vc.queries)) | ||
vc.batchSize = beginStmtLen | ||
} else { | ||
// We're not batching so we start the transaction here | ||
// by sending the BEGIN down the wire. | ||
if err := vc.DBClient.Begin(); err != nil { | ||
return err | ||
} | ||
Comment on lines
+61
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the fix for the noted extraneous BEGIN that surfaced in the unit tests. This was harmless, but also unnecessary and corrected here. |
||
} | ||
|
||
// If we're batching, we only batch the contents of the | ||
// transaction, which starts with the begin and ends with | ||
// the commit. | ||
vc.queriesPos = int64(len(vc.queries)) | ||
vc.batchSize = 6 // begin and semicolon | ||
|
||
vc.queries = append(vc.queries, "begin") | ||
vc.InTransaction = true | ||
vc.startTime = time.Now() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -508,8 +508,14 @@ func (vr *vreplicator) setState(state binlogdatapb.VReplicationWorkflowState, me | |
} | ||
vr.stats.State.Store(state.String()) | ||
query := fmt.Sprintf("update _vt.vreplication set state='%v', message=%v where id=%v", state, encodeString(binlogplayer.MessageTruncate(message)), vr.id) | ||
if _, err := vr.dbClient.ExecuteFetch(query, 1); err != nil { | ||
return fmt.Errorf("could not set state: %v: %v", query, err) | ||
// If we're batching a transaction, then include the state update | ||
// in the current transaction batch. | ||
if vr.dbClient.InTransaction && vr.dbClient.maxBatchSize > 0 { | ||
vr.dbClient.AddQueryToTrxBatch(query) | ||
} else { // Otherwise, send it down the wire | ||
if _, err := vr.dbClient.ExecuteFetch(query, 1); err != nil { | ||
return fmt.Errorf("could not set state: %v: %v", query, err) | ||
} | ||
Comment on lines
+511
to
+518
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the fix for the noted extraneous state update that surfaced in the unit tests. This caused no known issues, but was unnecessary and corrected here. |
||
} | ||
if state == vr.state { | ||
return nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where the flags were disabled for all of the unit tests and I did not notice it previously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want this PR to be able to stand on its own, I could change this line to
vttablet.DefaultVReplicationConfig.ExperimentalFlags = 7
rather than removing it.