Skip to content

Commit

Permalink
Use new truncation for vreplication.message too
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Feb 28, 2024
1 parent 64502bf commit 4296f8a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 2 additions & 3 deletions go/vt/vttablet/tabletmanager/vreplication/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions go/vt/vttablet/tabletmanager/vreplication/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions go/vt/vttablet/tabletmanager/vreplication/vreplicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4296f8a

Please sign in to comment.