diff --git a/go/vt/vttablet/tabletmanager/vreplication/utils.go b/go/vt/vttablet/tabletmanager/vreplication/utils.go index e53bad4b6d6..cd12e4cc9e5 100644 --- a/go/vt/vttablet/tabletmanager/vreplication/utils.go +++ b/go/vt/vttablet/tabletmanager/vreplication/utils.go @@ -35,10 +35,9 @@ import ( const ( vreplicationLogTableName = "vreplication_log" // This comes from the fact that the message column in the vreplication_log table is of type TEXT. - // See: go/vt/sidecardb/schema/vreplication/vreplication_log.sql - // https://dev.mysql.com/doc/refman/en/string-type-syntax.html and - // https://dev.mysql.com/doc/refman/en/storage-requirements.html#data-types-storage-reqs-strings maxVReplicationLogMessageLen = 65535 + // This comes from the fact that the message column in the vreplication table is varbinary(1000). + maxVReplicationMessageLen = 1000 ) // vrepliationLogTruncationStr is the string that is used to indicate that a message has been diff --git a/go/vt/vttablet/tabletmanager/vreplication/utils_test.go b/go/vt/vttablet/tabletmanager/vreplication/utils_test.go index ed312146fd5..5eb9d7ddd34 100644 --- a/go/vt/vttablet/tabletmanager/vreplication/utils_test.go +++ b/go/vt/vttablet/tabletmanager/vreplication/utils_test.go @@ -76,9 +76,12 @@ func TestInsertLogTruncation(t *testing.T) { } for _, tc := range tests { t.Run("insertLog", func(t *testing.T) { - var messageOut string + var ( + messageOut string + err error + ) if tc.expectTruncation { - messageOut, err := textutil.TruncateText(tc.message, maxVReplicationLogMessageLen, textutil.TruncationLocationMiddle, vreplicationLogTruncationStr) + messageOut, err = textutil.TruncateText(tc.message, maxVReplicationLogMessageLen, textutil.TruncationLocationMiddle, vreplicationLogTruncationStr) require.NoError(t, err) require.True(t, strings.HasPrefix(messageOut, tc.message[:1024])) // Confirm we still have the same beginning require.True(t, strings.HasSuffix(messageOut, tc.message[len(tc.message)-1024:])) // Confirm we still have the same end diff --git a/go/vt/vttablet/tabletmanager/vreplication/vreplicator.go b/go/vt/vttablet/tabletmanager/vreplication/vreplicator.go index 67496ca37f9..224a1141d77 100644 --- a/go/vt/vttablet/tabletmanager/vreplication/vreplicator.go +++ b/go/vt/vttablet/tabletmanager/vreplication/vreplicator.go @@ -29,6 +29,7 @@ import ( "vitess.io/vitess/go/mysql/replication" "vitess.io/vitess/go/mysql/sqlerror" "vitess.io/vitess/go/sqltypes" + "vitess.io/vitess/go/textutil" "vitess.io/vitess/go/timer" "vitess.io/vitess/go/vt/binlog/binlogplayer" "vitess.io/vitess/go/vt/log" @@ -450,8 +451,11 @@ func (vr *vreplicator) readSettings(ctx context.Context, dbClient *vdbClient) (s return settings, numTablesToCopy, nil } -func (vr *vreplicator) setMessage(message string) error { - message = binlogplayer.MessageTruncate(message) +func (vr *vreplicator) setMessage(message string) (err error) { + message, err = textutil.TruncateText(message, maxVReplicationMessageLen, textutil.TruncationLocationMiddle, vreplicationLogTruncationStr) + if err != nil { + return err + } vr.stats.History.Add(&binlogplayer.StatsHistoryRecord{ Time: time.Now(), Message: message,