Skip to content

Commit

Permalink
Handle --vreplication_experimental_flags options properly
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Dec 24, 2024
1 parent 059d01a commit fd3b43d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
6 changes: 4 additions & 2 deletions go/vt/vttablet/tabletmanager/vreplication/replicator_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,9 @@ func (tp *TablePlan) applyChange(rowChange *binlogdatapb.RowChange, executor fun
// It still has the data bit set, however, even though it's not really
// present. So we have to account for this by unsetting the data bit so
// that the column's current JSON value is not lost.
setBit(rowChange.DataColumns.Cols, i, false)
if rowChange.DataColumns != nil {
setBit(rowChange.DataColumns.Cols, i, false)
}
newVal = ptr.Of(sqltypes.MakeTrusted(querypb.Type_EXPRESSION, nil))
} else {
escapedName := sqlescape.EscapeID(field.Name)
Expand Down Expand Up @@ -482,7 +484,7 @@ func (tp *TablePlan) applyChange(rowChange *binlogdatapb.RowChange, executor fun
for i, field := range tp.Fields {
if field.Type == querypb.Type_JSON && rowChange.JsonPartialValues != nil {
switch {
case !isBitSet(rowChange.JsonPartialValues.Cols, jsonIndex):
case rowChange.JsonPartialValues != nil && !isBitSet(rowChange.JsonPartialValues.Cols, jsonIndex):
// We use the full AFTER value which we already have.
case len(afterVals[i].Raw()) == 0:
// If the JSON column was NOT updated then the JSON column is marked as partial
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vterrors"
vttablet "vitess.io/vitess/go/vt/vttablet/common"
)

// isBitSet returns true if the bit at index is set
Expand All @@ -47,13 +46,11 @@ func setBit(data []byte, index int, value bool) {
}

func (tp *TablePlan) isPartial(rowChange *binlogdatapb.RowChange) bool {
if (tp.WorkflowConfig.ExperimentalFlags /**/ & /**/ vttablet.VReplicationExperimentalFlagAllowNoBlobBinlogRowImage) == 0 ||
rowChange.DataColumns == nil ||
rowChange.DataColumns.Count == 0 {

if rowChange == nil {
return false
}
return true
return (rowChange.DataColumns != nil && rowChange.DataColumns.Count > 0) ||
(rowChange.JsonPartialValues != nil && rowChange.JsonPartialValues.Count > 0)
}

func (tpb *tablePlanBuilder) generatePartialValuesPart(buf *sqlparser.TrackedBuffer, bvf *bindvarFormatter, dataColumns *binlogdatapb.RowChange_Bitmap) *sqlparser.ParsedQuery {
Expand Down
20 changes: 15 additions & 5 deletions go/vt/vttablet/tabletmanager/vreplication/vplayer_flaky_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1762,11 +1762,21 @@ func TestPlayerPartialImages(t *testing.T) {
execStatements(t, []string{tc.input})
var want qh.ExpectationSequencer
if tc.error != "" {
want = qh.Expect(
"rollback",
).Then(qh.Immediately(
fmt.Sprintf("/update _vt.vreplication set message=.*%s.*", tc.error),
))
if vttablet.DefaultVReplicationConfig.ExperimentalFlags&vttablet.VReplicationExperimentalFlagVPlayerBatching == 0 {
want = qh.Expect(
"begin",
"delete from dst where id=3",
"rollback",
).Then(qh.Immediately(
fmt.Sprintf("/update _vt.vreplication set message=.*%s.*", tc.error),
))
} else {
want = qh.Expect(
"rollback",
).Then(qh.Immediately(
fmt.Sprintf("/update _vt.vreplication set message=.*%s.*", tc.error),
))
}
expectDBClientQueries(t, want)
} else {
want = qh.Expect(
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vttablet/tabletserver/vstreamer/vstreamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1031,8 +1031,8 @@ func (vs *vstreamer) processRowEvent(vevents []*binlogdatapb.VEvent, plan *strea
}
if afterOK {
rowChange.After = sqltypes.RowToProto3(afterValues)
if (vs.config.ExperimentalFlags /**/ & /**/ vttablet.VReplicationExperimentalFlagAllowNoBlobBinlogRowImage != 0) &&
(partial || row.JSONPartialValues.Count() > 0) {
if ((vs.config.ExperimentalFlags /**/ & /**/ vttablet.VReplicationExperimentalFlagAllowNoBlobBinlogRowImage != 0) &&
partial) || (row.JSONPartialValues.Count() > 0) {

rowChange.DataColumns = &binlogdatapb.RowChange_Bitmap{
Count: int64(rows.DataColumns.Count()),
Expand Down

0 comments on commit fd3b43d

Please sign in to comment.