Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/pingcap/ticdc

go 1.25.8
go 1.25.5
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

require (
cloud.google.com/go/kms v1.15.8
cloud.google.com/go/storage v1.39.1
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.20.0
github.com/BurntSushi/toml v1.5.0
Expand All @@ -12,10 +13,11 @@ require (
github.com/agiledragon/gomonkey/v2 v2.11.0
github.com/apache/pulsar-client-go v0.13.0
github.com/aws/aws-sdk-go v1.55.5
github.com/aws/aws-sdk-go-v2 v1.40.0
github.com/aws/aws-sdk-go-v2 v1.41.1
github.com/aws/aws-sdk-go-v2/config v1.32.2
github.com/aws/aws-sdk-go-v2/credentials v1.19.2
github.com/aws/aws-sdk-go-v2/service/glue v1.134.1
github.com/aws/aws-sdk-go-v2/service/kms v1.49.5
github.com/benbjohnson/clock v1.3.5
github.com/bradleyjkemp/grpc-tools v0.2.5
github.com/cenkalti/backoff/v4 v4.2.1
Expand Down Expand Up @@ -91,6 +93,7 @@ require (
golang.org/x/term v0.34.0
golang.org/x/text v0.29.0
golang.org/x/time v0.12.0
google.golang.org/api v0.170.0
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.36.6
)
Expand All @@ -109,8 +112,7 @@ require (
cloud.google.com/go v0.112.2 // indirect
cloud.google.com/go/compute/metadata v0.5.0 // indirect
cloud.google.com/go/iam v1.1.7 // indirect
cloud.google.com/go/kms v1.15.8 // indirect
filippo.io/edwards25519 v1.1.1 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/AthenZ/athenz v1.10.39 // indirect
Expand Down Expand Up @@ -142,8 +144,8 @@ require (
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.3 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.14 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.14 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.14 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.17 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.17 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.14 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3 // indirect
Expand All @@ -155,7 +157,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/sso v1.30.5 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.10 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.41.2 // indirect
github.com/aws/smithy-go v1.23.2 // indirect
github.com/aws/smithy-go v1.24.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.14.3 // indirect
github.com/blacktear23/go-proxyprotocol v1.0.6 // indirect
Expand Down Expand Up @@ -363,7 +365,6 @@ require (
golang.org/x/mod v0.27.0 // indirect
golang.org/x/tools v0.36.0 // indirect
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
google.golang.org/api v0.170.0 // indirect
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250425173222-7b384671a197 // indirect
Expand Down
22 changes: 12 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1243,8 +1243,8 @@ cloud.google.com/go/workflows v1.12.2/go.mod h1:+OmBIgNqYJPVggnMo9nqmizW0qEXHhmn
cloud.google.com/go/workflows v1.12.3/go.mod h1:fmOUeeqEwPzIU81foMjTRQIdwQHADi/vEr1cx9R1m5g=
cloud.google.com/go/workflows v1.12.4/go.mod h1:yQ7HUqOkdJK4duVtMeBCAOPiN1ZF1E9pAMX51vpwB/w=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.1.1 h1:YpjwWWlNmGIDyXOn8zLzqiD+9TyIlPhGFG96P39uBpw=
filippo.io/edwards25519 v1.1.1/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8=
git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3pc=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
Expand Down Expand Up @@ -1392,8 +1392,8 @@ github.com/aws/aws-sdk-go v1.32.6/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU
github.com/aws/aws-sdk-go v1.44.204/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/aws/aws-sdk-go-v2 v1.40.0 h1:/WMUA0kjhZExjOQN2z3oLALDREea1A7TobfuiBrKlwc=
github.com/aws/aws-sdk-go-v2 v1.40.0/go.mod h1:c9pm7VwuW0UPxAEYGyTmyurVcNrbF6Rt/wixFqDhcjE=
github.com/aws/aws-sdk-go-v2 v1.41.1 h1:ABlyEARCDLN034NhxlRUSZr4l71mh+T5KAeGh6cerhU=
github.com/aws/aws-sdk-go-v2 v1.41.1/go.mod h1:MayyLB8y+buD9hZqkCW3kX1AKq07Y5pXxtgB+rRFhz0=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.3 h1:DHctwEM8P8iTXFxC/QK0MRjwEpWQeM9yzidCRjldUz0=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.3/go.mod h1:xdCzcZEtnSTKVDOmUZs4l/j3pSV6rpo1WXl5ugNsL8Y=
github.com/aws/aws-sdk-go-v2/config v1.32.2 h1:4liUsdEpUUPZs5WVapsJLx5NPmQhQdez7nYFcovrytk=
Expand All @@ -1402,10 +1402,10 @@ github.com/aws/aws-sdk-go-v2/credentials v1.19.2 h1:qZry8VUyTK4VIo5aEdUcBjPZHL2v
github.com/aws/aws-sdk-go-v2/credentials v1.19.2/go.mod h1:YUqm5a1/kBnoK+/NY5WEiMocZihKSo15/tJdmdXnM5g=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.14 h1:WZVR5DbDgxzA0BJeudId89Kmgy6DIU4ORpxwsVHz0qA=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.14/go.mod h1:Dadl9QO0kHgbrH1GRqGiZdYtW5w+IXXaBNCHTIaheM4=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.14 h1:PZHqQACxYb8mYgms4RZbhZG0a7dPW06xOjmaH0EJC/I=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.14/go.mod h1:VymhrMJUWs69D8u0/lZ7jSB6WgaG/NqHi3gX0aYf6U0=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.14 h1:bOS19y6zlJwagBfHxs0ESzr1XCOU2KXJCWcq3E2vfjY=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.14/go.mod h1:1ipeGBMAxZ0xcTm6y6paC2C/J6f6OO7LBODV9afuAyM=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.17 h1:xOLELNKGp2vsiteLsvLPwxC+mYmO6OZ8PYgiuPJzF8U=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.17/go.mod h1:5M5CI3D12dNOtH3/mk6minaRwI2/37ifCURZISxA/IQ=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.17 h1:WWLqlh79iO48yLkj1v3ISRNiv+3KdQoZ6JWyfcsyQik=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.17/go.mod h1:EhG22vHRrvF8oXSTYStZhJc1aUgKtnJe+aOiFEV90cM=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 h1:WKuaxf++XKWlHWu9ECbMlha8WOEGm0OUEZqm4K/Gcfk=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4/go.mod h1:ZWy7j6v1vWGmPReu0iSGvRiise4YI5SkR3OHKTZ6Wuc=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.14 h1:ITi7qiDSv/mSGDSWNpZ4k4Ve0DQR6Ug2SJQ8zEHoDXg=
Expand All @@ -1420,6 +1420,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.14 h1:FIouAnCE
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.14/go.mod h1:UTwDc5COa5+guonQU8qBikJo1ZJ4ln2r1MkF7Dqag1E=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.14 h1:FzQE21lNtUor0Fb7QNgnEyiRCBlolLTX/Z1j65S7teM=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.14/go.mod h1:s1ydyWG9pm3ZwmmYN21HKyG9WzAZhYVW85wMHs5FV6w=
github.com/aws/aws-sdk-go-v2/service/kms v1.49.5 h1:DKibav4XF66XSeaXcrn9GlWGHos6D/vJ4r7jsK7z5CE=
github.com/aws/aws-sdk-go-v2/service/kms v1.49.5/go.mod h1:1SdcmEGUEQE1mrU2sIgeHtcMSxHuybhPvuEPANzIDfI=
github.com/aws/aws-sdk-go-v2/service/s3 v1.92.1 h1:OgQy/+0+Kc3khtqiEOk23xQAglXi3Tj0y5doOxbi5tg=
github.com/aws/aws-sdk-go-v2/service/s3 v1.92.1/go.mod h1:wYNqY3L02Z3IgRYxOBPH9I1zD9Cjh9hI5QOy/eOjQvw=
github.com/aws/aws-sdk-go-v2/service/signin v1.0.2 h1:MxMBdKTYBjPQChlJhi4qlEueqB1p1KcbTEa7tD5aqPs=
Expand All @@ -1430,8 +1432,8 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.10 h1:GtsxyiF3Nd3JahRBJbxLCCd
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.10/go.mod h1:/j67Z5XBVDx8nZVp9EuFM9/BS5dvBznbqILGuu73hug=
github.com/aws/aws-sdk-go-v2/service/sts v1.41.2 h1:a5UTtD4mHBU3t0o6aHQZFJTNKVfxFWfPX7J0Lr7G+uY=
github.com/aws/aws-sdk-go-v2/service/sts v1.41.2/go.mod h1:6TxbXoDSgBQ225Qd8Q+MbxUxUh6TtNKwbRt/EPS9xso=
github.com/aws/smithy-go v1.23.2 h1:Crv0eatJUQhaManss33hS5r40CG3ZFH+21XSkqMrIUM=
github.com/aws/smithy-go v1.23.2/go.mod h1:LEj2LM3rBRQJxPZTB4KuzZkaZYnZPnvgIhb4pu07mx0=
github.com/aws/smithy-go v1.24.0 h1:LpilSUItNPFr1eY85RYgTIg5eIEPtvFbskaFcmmIUnk=
github.com/aws/smithy-go v1.24.0/go.mod h1:LEj2LM3rBRQJxPZTB4KuzZkaZYnZPnvgIhb4pu07mx0=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.5 h1:VvXlSJBzZpA/zum6Sj74hxwYI2DIxRWuNIoXAzHZz5o=
Expand Down
66 changes: 53 additions & 13 deletions logservice/eventstore/event_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/pingcap/ticdc/pkg/common"
appcontext "github.com/pingcap/ticdc/pkg/common/context"
"github.com/pingcap/ticdc/pkg/config"
"github.com/pingcap/ticdc/pkg/encryption"
"github.com/pingcap/ticdc/pkg/messaging"
"github.com/pingcap/ticdc/pkg/metrics"
"github.com/pingcap/ticdc/pkg/node"
Expand Down Expand Up @@ -116,6 +117,8 @@ type dispatcherStat struct {
resolvedTs atomic.Uint64
// the max ts of events which is not needed by this dispatcher
checkpointTs uint64
// keyspaceID for encryption (0 means default/classic)
keyspaceID uint32
// the difference between `subStat`, `pendingSubStat` and `removingSubStat`:
// 1) if there is no existing subscriptions which can be reused,
// or there is a existing subscription with exact span match,
Expand Down Expand Up @@ -182,9 +185,10 @@ type subscriptionStat struct {
type subscriptionStats map[logpuller.SubscriptionID]*subscriptionStat

type eventWithCallback struct {
subID logpuller.SubscriptionID
tableID int64
kvs []common.RawKVEntry
subID logpuller.SubscriptionID
tableID int64
keyspaceID uint32
kvs []common.RawKVEntry
// kv with commitTs <= currentResolvedTs will be filtered out
currentResolvedTs uint64
enqueueTimeNano int64
Expand Down Expand Up @@ -238,6 +242,8 @@ type eventStore struct {
compressionThreshold int
// enableZstdCompression controls whether to enable zstd compression for large values.
enableZstdCompression bool
// encryptionManager for encrypting/decrypting data (optional).
encryptionManager encryption.EncryptionManager
}

const (
Expand All @@ -258,6 +264,9 @@ func New(
log.Panic("fail to remove path", zap.String("path", dbPath), zap.Error(err))
}

// Try to get encryption manager from appcontext (optional)
encMgr, _ := appcontext.TryGetService[encryption.EncryptionManager]("EncryptionManager")

store := &eventStore{
pdClock: appcontext.GetService[pdutil.Clock](appcontext.DefaultPDClock),
subClient: subClient,
Expand All @@ -280,6 +289,7 @@ func New(
},
compressionThreshold: config.GetGlobalServerConfig().Debug.EventStore.CompressionThreshold,
enableZstdCompression: config.GetGlobalServerConfig().Debug.EventStore.EnableZstdCompression,
encryptionManager: encMgr,
}
store.gcManager = newGCManager(store.dbs, deleteDataRange, compactDataRange)

Expand Down Expand Up @@ -483,6 +493,7 @@ func (e *eventStore) RegisterDispatcher(
dispatcherID: dispatcherID,
tableSpan: dispatcherSpan,
checkpointTs: startTs,
keyspaceID: dispatcherSpan.KeyspaceID,
}
stat.resolvedTs.Store(startTs)

Expand Down Expand Up @@ -609,6 +620,7 @@ func (e *eventStore) RegisterDispatcher(
subStat.eventCh.Push(eventWithCallback{
subID: subStat.subID,
tableID: subStat.tableSpan.TableID,
keyspaceID: subStat.tableSpan.KeyspaceID,
kvs: kvs,
currentResolvedTs: subStat.resolvedTs.Load(),
enqueueTimeNano: now.UnixNano(),
Expand Down Expand Up @@ -900,16 +912,18 @@ func (e *eventStore) GetIterator(dispatcherID common.DispatcherID, dataRange com
}

return &eventStoreIter{
tableSpan: stat.tableSpan,
needCheckSpan: needCheckSpan,
innerIter: iter,
prevStartTs: 0,
prevCommitTs: 0,
startTs: dataRange.CommitTsStart,
endTs: dataRange.CommitTsEnd,
rowCount: 0,
decoder: decoder,
decoderPool: e.decoderPool,
tableSpan: stat.tableSpan,
needCheckSpan: needCheckSpan,
innerIter: iter,
prevStartTs: 0,
prevCommitTs: 0,
startTs: dataRange.CommitTsStart,
endTs: dataRange.CommitTsEnd,
rowCount: 0,
decoder: decoder,
decoderPool: e.decoderPool,
encryptionManager: e.encryptionManager,
keyspaceID: stat.keyspaceID,
}
}

Expand Down Expand Up @@ -1325,6 +1339,20 @@ func (e *eventStore) writeEvents(
metrics.EventStoreCompressedRowsCount.Inc()
}

// Encrypt if encryption is enabled (after compression)
if e.encryptionManager != nil {
encryptedValue, err := e.encryptionManager.EncryptData(context.Background(), event.keyspaceID, value)
if err != nil {
log.Error("encrypt event value failed",
zap.Uint32("keyspaceID", event.keyspaceID),
zap.Uint64("subID", uint64(event.subID)),
zap.Int64("tableID", event.tableID),
zap.Error(err))
return err
}
value = encryptedValue
}

key := EncodeKey(uint64(event.subID), event.tableID, &kv, compressionType)
if err := batch.Set(key, value, pebble.NoSync); err != nil {
log.Panic("failed to update pebble batch", zap.Error(err))
Expand Down Expand Up @@ -1370,6 +1398,9 @@ type eventStoreIter struct {
decoder *zstd.Decoder
decoderPool *sync.Pool
decodeBuf []byte
// encryptionManager for decrypting data (optional, can be nil).
encryptionManager encryption.EncryptionManager
keyspaceID uint32
}

func (iter *eventStoreIter) Next() (*common.RawKVEntry, bool) {
Expand All @@ -1381,6 +1412,15 @@ func (iter *eventStoreIter) Next() (*common.RawKVEntry, bool) {
key := iter.innerIter.Key()
value := iter.innerIter.Value()

// Decrypt if encrypted data is detected and encryption manager is available
if encryption.IsEncrypted(value) && iter.encryptionManager != nil {
decryptedValue, err := iter.encryptionManager.DecryptData(context.Background(), iter.keyspaceID, value)
if err != nil {
log.Panic("failed to decrypt value", zap.Error(err))
}
value = decryptedValue
}

_, compressionType := DecodeKeyMetas(key)
var decodedValue []byte
if compressionType == CompressionZSTD {
Expand Down
93 changes: 93 additions & 0 deletions logservice/eventstore/event_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package eventstore
import (
"bytes"
"context"
"errors"
"fmt"
"os"
"sync"
Expand All @@ -30,6 +31,7 @@ import (
"github.com/pingcap/ticdc/pkg/common"
appcontext "github.com/pingcap/ticdc/pkg/common/context"
"github.com/pingcap/ticdc/pkg/config"
"github.com/pingcap/ticdc/pkg/encryption"
"github.com/pingcap/ticdc/pkg/messaging"
"github.com/pingcap/ticdc/pkg/metrics"
"github.com/pingcap/ticdc/pkg/pdutil"
Expand All @@ -48,6 +50,27 @@ type mockSubscriptionClient struct {
subscriptions map[logpuller.SubscriptionID]*mockSubscriptionStat
}

type spyEncryptionManager struct {
encryptKeyspaceID uint32
decryptKeyspaceID uint32
}

func (m *spyEncryptionManager) EncryptData(ctx context.Context, keyspaceID uint32, data []byte) ([]byte, error) {
m.encryptKeyspaceID = keyspaceID
encrypted := make([]byte, encryption.EncryptionHeaderSize+len(data))
encrypted[0] = 0x01
copy(encrypted[encryption.EncryptionHeaderSize:], data)
return encrypted, nil
}

func (m *spyEncryptionManager) DecryptData(ctx context.Context, keyspaceID uint32, encryptedData []byte) ([]byte, error) {
m.decryptKeyspaceID = keyspaceID
if len(encryptedData) < encryption.EncryptionHeaderSize {
return nil, errors.New("encrypted data too short")
}
return encryptedData[encryption.EncryptionHeaderSize:], nil
}

func NewMockSubscriptionClient() logpuller.SubscriptionClient {
return &mockSubscriptionClient{
subscriptions: make(map[logpuller.SubscriptionID]*mockSubscriptionStat),
Expand Down Expand Up @@ -181,6 +204,76 @@ func TestEventStoreInteractionWithSubClient(t *testing.T) {
}
}

func TestEventStoreUsesKeyspaceIDForEncryption(t *testing.T) {
subClient, store := newEventStoreForTest(fmt.Sprintf("/tmp/%s", t.Name()))
es := store.(*eventStore)
spy := &spyEncryptionManager{}
es.encryptionManager = spy

dispatcherID := common.NewDispatcherID()
cfID := common.NewChangefeedID4Test("default", "test-cf")
span := &heartbeatpb.TableSpan{
TableID: 1,
StartKey: []byte("a"),
EndKey: []byte("z"),
KeyspaceID: 42,
}
ok := store.RegisterDispatcher(cfID, dispatcherID, span, 0, func(uint64, uint64) {}, false, false)
require.True(t, ok)

es.dispatcherMeta.RLock()
stat := es.dispatcherMeta.dispatcherStats[dispatcherID]
subStat := stat.subStat
if subStat == nil {
subStat = stat.pendingSubStat
}
es.dispatcherMeta.RUnlock()
require.NotNil(t, subStat)

kv := common.RawKVEntry{
OpType: common.OpTypePut,
CRTs: 10,
StartTs: 5,
Key: []byte("k"),
Value: []byte("v"),
}
encoder, err := zstd.NewWriter(nil)
require.NoError(t, err)
defer encoder.Close()

events := []eventWithCallback{
{
subID: subStat.subID,
tableID: subStat.tableSpan.TableID,
keyspaceID: subStat.tableSpan.KeyspaceID,
kvs: []common.RawKVEntry{kv},
currentResolvedTs: 0,
callback: func() {},
},
}
var compressionBuf []byte
err = es.writeEvents(es.dbs[subStat.dbIndex], events, encoder, &compressionBuf)
require.NoError(t, err)
require.Equal(t, uint32(42), spy.encryptKeyspaceID)

subStat.resolvedTs.Store(kv.CRTs)
dataRange := common.DataRange{
Span: span,
CommitTsStart: 0,
CommitTsEnd: kv.CRTs,
}
iter := es.GetIterator(dispatcherID, dataRange)
require.NotNil(t, iter)

_, ok = iter.Next()
require.True(t, ok)
require.Equal(t, uint32(42), spy.decryptKeyspaceID)

_, err = iter.Close()
require.NoError(t, err)
subClient.(*mockSubscriptionClient).Unsubscribe(subStat.subID)
}

func markSubStatsInitializedForTest(store EventStore, tableID int64) {
es := store.(*eventStore)
subStats := es.dispatcherMeta.tableStats[tableID]
Expand Down
Loading