Skip to content
2 changes: 1 addition & 1 deletion downstreamadapter/dispatcher/basic_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func (d *BasicDispatcher) handleEvents(dispatcherEvents []DispatcherEvent, wakeC
log.Info("dispatcher receive ddl event",
zap.Stringer("dispatcher", d.id),
zap.String("query", ddl.Query),
zap.Any("tableSpan", d.GetTableSpan()),
zap.String("tableSpan", common.FormatTableSpan(d.GetTableSpan())),
zap.Int64("table", ddl.GetTableID()),
zap.Uint64("commitTs", event.GetCommitTs()),
zap.Uint64("seq", event.GetSeq()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ func createMergedSpan[T dispatcher.Dispatcher](changefeedID common.ChangeFeedID,
zap.Stringer("changefeedID", changefeedID),
zap.Any("dispatcherIDs", dispatcherIDs),
zap.Int64("mode", dispatcherItem.GetMode()),
zap.Any("prevTableSpan", prevTableSpan),
zap.Any("currentTableSpan", currentTableSpan),
zap.String("prevTableSpan", common.FormatTableSpan(prevTableSpan)),
zap.String("currentTableSpan", common.FormatTableSpan(currentTableSpan)),
)
return nil, 0, 0
}
Expand Down
36 changes: 18 additions & 18 deletions logservice/logpuller/regionlock/region_range_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package regionlock
import (
"bytes"
"context"
"encoding/hex"
"fmt"
"math"
"sync"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/pingcap/log"
"github.com/pingcap/ticdc/heartbeatpb"
"github.com/pingcap/ticdc/pkg/common"
"github.com/pingcap/ticdc/pkg/util"
"github.com/pingcap/ticdc/utils/heap"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -105,8 +105,8 @@ func rangeLockEntryLess(a, b *rangeLockEntry) bool {
func (e *rangeLockEntry) String() string {
return fmt.Sprintf("region %v [%v, %v), version %v, %d waiters",
e.regionID,
hex.EncodeToString(e.startKey),
hex.EncodeToString(e.endKey),
util.RedactKey(e.startKey),
util.RedactKey(e.endKey),
e.regionVersion,
len(e.waiterSignalChs))
}
Expand Down Expand Up @@ -194,16 +194,16 @@ func (l *RangeLock) UnlockRange(
if !ok {
log.Panic("unlocking a not locked range",
zap.Uint64("regionID", regionID),
zap.String("startKey", hex.EncodeToString(startKey)),
zap.String("endKey", hex.EncodeToString(endKey)),
zap.String("startKey", util.RedactKey(startKey)),
zap.String("endKey", util.RedactKey(endKey)),
zap.Uint64("version", version))
}
if entry.regionID != regionID {
log.Panic("unlocked a range but regionID mismatch",
zap.Uint64("expectedRegionID", regionID),
zap.Uint64("foundRegionID", entry.regionID),
zap.String("startKey", hex.EncodeToString(startKey)),
zap.String("endKey", hex.EncodeToString(endKey)))
zap.String("startKey", util.RedactKey(startKey)),
zap.String("endKey", util.RedactKey(endKey)))
}
if entry != l.regionIDToLockedRanges[regionID] {
log.Panic("range lock and region id lock mismatch when trying to unlock",
Expand All @@ -217,8 +217,8 @@ func (l *RangeLock) UnlockRange(
if entry.regionVersion != version || !bytes.Equal(entry.endKey, endKey) {
log.Panic("unlocking region doesn't match the locked region",
zap.Uint64("regionID", regionID),
zap.String("startKey", hex.EncodeToString(startKey)),
zap.String("endKey", hex.EncodeToString(endKey)),
zap.String("startKey", util.RedactKey(startKey)),
zap.String("endKey", util.RedactKey(endKey)),
zap.Uint64("version", version),
zap.String("foundLockEntry", entry.String()))
}
Expand Down Expand Up @@ -247,8 +247,8 @@ func (l *RangeLock) UnlockRange(
log.Debug("unlocked range",
zap.Uint64("lockID", l.id), zap.Uint64("regionID", entry.regionID),
zap.Uint64("resolvedTs", newResolvedTs),
zap.String("startKey", hex.EncodeToString(startKey)),
zap.String("endKey", hex.EncodeToString(endKey)))
zap.String("startKey", util.RedactKey(startKey)),
zap.String("endKey", util.RedactKey(endKey)))
return
}

Expand Down Expand Up @@ -490,8 +490,8 @@ func (l *RangeLock) tryLockRange(startKey, endKey []byte, regionID, regionVersio
zap.Uint64("regionID", regionID),
zap.Uint64("version", regionVersion),
zap.Uint64("resolvedTs", resolvedTs),
zap.String("startKey", hex.EncodeToString(startKey)),
zap.String("endKey", hex.EncodeToString(endKey)))
zap.String("startKey", util.RedactKey(startKey)),
zap.String("endKey", util.RedactKey(endKey)))

return LockRangeResult{
Status: LockRangeStatusSuccess,
Expand All @@ -503,7 +503,7 @@ func (l *RangeLock) tryLockRange(startKey, endKey []byte, regionID, regionVersio
var overlapStr []string
for _, r := range overlappedRangeLocks {
overlapStr = append(overlapStr, fmt.Sprintf("regionID: %v, ver: %v, start: %v, end: %v",
r.regionID, r.regionVersion, hex.EncodeToString(r.startKey), hex.EncodeToString(r.endKey))) // DEBUG
r.regionID, r.regionVersion, util.RedactKey(r.startKey), util.RedactKey(r.endKey))) // DEBUG
}

// Check if the current acuqiring range is stale,
Expand All @@ -523,8 +523,8 @@ func (l *RangeLock) tryLockRange(startKey, endKey []byte, regionID, regionVersio

log.Info("try lock range staled",
zap.Uint64("lockID", l.id), zap.Uint64("regionID", regionID),
zap.String("startKey", hex.EncodeToString(startKey)),
zap.String("endKey", hex.EncodeToString(endKey)),
zap.String("startKey", util.RedactKey(startKey)),
zap.String("endKey", util.RedactKey(endKey)),
zap.Strings("allOverlapping", overlapStr)) // DEBUG

for _, r := range overlappedRangeLocks {
Expand Down Expand Up @@ -561,8 +561,8 @@ func (l *RangeLock) tryLockRange(startKey, endKey []byte, regionID, regionVersio

log.Info("lock range blocked",
zap.Uint64("lockID", l.id), zap.Uint64("regionID", regionID),
zap.String("startKey", hex.EncodeToString(startKey)),
zap.String("endKey", hex.EncodeToString(endKey)),
zap.String("startKey", util.RedactKey(startKey)),
zap.String("endKey", util.RedactKey(endKey)),
zap.Strings("blockedBy", overlapStr)) // DEBUG

return LockRangeResult{
Expand Down
4 changes: 1 addition & 3 deletions maintainer/operator/operator_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package operator

import (
"encoding/hex"
"fmt"
"strings"

Expand Down Expand Up @@ -67,8 +66,7 @@ func buildMergedSpanInfo(toMergedReplicaSets []*replica.SpanReplication) string
var spansInfo strings.Builder
for _, replicaSet := range toMergedReplicaSets {
span := replicaSet.Span
fmt.Fprintf(&spansInfo, "[%s,%s,%d]",
hex.EncodeToString(span.StartKey), hex.EncodeToString(span.EndKey), span.TableID)
fmt.Fprintf(&spansInfo, "[%s]", common.FormatTableSpan(span))
}
return spansInfo.String()
}
Expand Down
4 changes: 1 addition & 3 deletions maintainer/operator/operator_split.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package operator

import (
"encoding/hex"
"fmt"
"strings"
"sync"
Expand Down Expand Up @@ -80,8 +79,7 @@ func NewSplitDispatcherOperator(
) *SplitDispatcherOperator {
var spansInfo strings.Builder
for _, span := range splitSpans {
fmt.Fprintf(&spansInfo, "[%s,%s]",
hex.EncodeToString(span.StartKey), hex.EncodeToString(span.EndKey))
fmt.Fprintf(&spansInfo, "[%s]", common.FormatTableSpan(span))
}
op := &SplitDispatcherOperator{
replicaSet: replicaSet,
Expand Down
12 changes: 4 additions & 8 deletions maintainer/replica/replication_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package replica

import (
"bytes"
"encoding/hex"
"sync"

"github.com/pingcap/log"
Expand Down Expand Up @@ -73,8 +72,7 @@ func NewSpanReplication(cfID common.ChangeFeedID,
zap.Int64("tableID", span.TableID),
zap.String("groupID", replica.GetGroupName(r.groupID)),
zap.Uint64("checkpointTs", checkpointTs),
zap.String("start", hex.EncodeToString(span.StartKey)),
zap.String("end", hex.EncodeToString(span.EndKey)))
zap.String("span", common.FormatTableSpan(span)))
return r
}

Expand All @@ -100,8 +98,7 @@ func NewWorkingSpanReplication(
zap.Int64("schemaID", SchemaID),
zap.Int64("tableID", span.TableID),
zap.Int64("groupID", r.groupID),
zap.String("start", hex.EncodeToString(span.StartKey)),
zap.String("end", hex.EncodeToString(span.EndKey)))
zap.String("span", common.FormatTableSpan(span)))
return r
}

Expand Down Expand Up @@ -149,9 +146,8 @@ func (r *SpanReplication) initGroupID() {
log.Warn("invalid span range",
zap.Stringer("changefeedID", r.ChangefeedID),
zap.String("dispatcherID", r.ID.String()), zap.Int64("tableID", span.TableID),
zap.String("totalSpan", totalSpan.String()),
zap.String("start", hex.EncodeToString(span.StartKey)),
zap.String("end", hex.EncodeToString(span.EndKey)))
zap.String("totalSpan", common.FormatTableSpan(&totalSpan)),
zap.String("span", common.FormatTableSpan(&span)))
}
if !bytes.Equal(span.StartKey, totalSpan.StartKey) || !bytes.Equal(span.EndKey, totalSpan.EndKey) {
r.groupID = replica.GenGroupID(replica.GroupTable, span.TableID)
Expand Down
7 changes: 4 additions & 3 deletions maintainer/split/region_count_splitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/pingcap/ticdc/heartbeatpb"
"github.com/pingcap/ticdc/pkg/common"
appcontext "github.com/pingcap/ticdc/pkg/common/context"
"github.com/pingcap/ticdc/pkg/util"
"github.com/tikv/client-go/v2/tikv"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -109,9 +110,9 @@ func (m *regionCountSplitter) split(
zap.String("keyspace", m.changefeedID.Keyspace()),
zap.String("changefeed", m.changefeedID.Name()),
zap.String("span", common.FormatTableSpan(span)),
zap.Stringer("lastSpan", spans[len(spans)-1]),
zap.Any("startKey", startKey),
zap.Any("endKey", endKey))
zap.String("lastSpan", common.FormatTableSpan(spans[len(spans)-1])),
zap.String("startKey", util.RedactKey(startKey)),
zap.String("endKey", util.RedactKey(endKey)))
return []*heartbeatpb.TableSpan{span}
}
spans = append(spans, &heartbeatpb.TableSpan{
Expand Down
6 changes: 3 additions & 3 deletions pkg/common/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
package common

import (
"encoding/hex"
"fmt"
"strings"

"github.com/pingcap/log"
"github.com/pingcap/ticdc/heartbeatpb"
"github.com/pingcap/ticdc/pkg/util"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -100,8 +100,8 @@ func FormatTableSpan(s *heartbeatpb.TableSpan) string {
sb := strings.Builder{}
fmt.Fprintf(&sb, "tableID: %d, startKey: %s, endKey: %s, keyspaceID: %d",
s.TableID,
hex.EncodeToString(s.StartKey),
hex.EncodeToString(s.EndKey),
util.RedactKey(s.StartKey),
util.RedactKey(s.EndKey),
s.KeyspaceID)
return sb.String()
}
Expand Down
46 changes: 28 additions & 18 deletions pkg/common/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package common
import (
"testing"

"github.com/pingcap/errors"
"github.com/pingcap/ticdc/heartbeatpb"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -162,34 +163,43 @@ func TestFormatInfluencedDispatchers(t *testing.T) {
}

func TestFormatTableSpan(t *testing.T) {
t.Parallel()
original := errors.RedactLogEnabled.Load()
t.Cleanup(func() { errors.RedactLogEnabled.Store(original) })
span := &heartbeatpb.TableSpan{
TableID: 42,
StartKey: []byte{0x74, 0x80, 0xab},
EndKey: []byte{0x74, 0x80, 0xcd},
KeyspaceID: 1,
}

testCases := []struct {
name string
input *heartbeatpb.TableSpan
isEmptyString bool
mode string
expected string
expectedEmpty string
}{
{
name: "nil span",
input: nil,
isEmptyString: true,
mode: errors.RedactLogEnable,
expected: "tableID: 42, startKey: ?, endKey: ?, keyspaceID: 1",
expectedEmpty: "tableID: 0, startKey: ?, endKey: ?, keyspaceID: 0",
},
{
name: "normal span",
input: &heartbeatpb.TableSpan{
TableID: 1,
StartKey: []byte("start"),
EndKey: []byte("end"),
},
isEmptyString: false,
mode: errors.RedactLogDisable,
expected: "tableID: 42, startKey: 7480AB, endKey: 7480CD, keyspaceID: 1",
expectedEmpty: "tableID: 0, startKey: , endKey: , keyspaceID: 0",
},
{
mode: errors.RedactLogMarker,
expected: "tableID: 42, startKey: ‹7480AB›, endKey: ‹7480CD›, keyspaceID: 1",
expectedEmpty: "tableID: 0, startKey: ‹›, endKey: ‹›, keyspaceID: 0",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
result := FormatTableSpan(tc.input)
require.Equal(t, tc.isEmptyString, result == "")
t.Run(tc.mode, func(t *testing.T) {
errors.RedactLogEnabled.Store(tc.mode)
require.Equal(t, tc.expected, FormatTableSpan(span))
require.Equal(t, tc.expectedEmpty, FormatTableSpan(&heartbeatpb.TableSpan{}))
require.Empty(t, FormatTableSpan(nil))
})
}
}
Expand Down
Loading