-
Notifications
You must be signed in to change notification settings - Fork 24
/
kv.go
107 lines (91 loc) · 2.96 KB
/
kv.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2020 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
//go:generate msgp
package model
import (
"fmt"
"github.com/tikv/migration/cdc/pkg/regionspan"
)
// OpType for the kv, delete or put
type OpType int
// OpType for kv
// Use explicit values to avoid compatibility issues.
const (
OpTypeUnknown OpType = 0
OpTypePut OpType = 1
OpTypeDelete OpType = 2
OpTypeResolved OpType = 3
)
// RegionFeedEvent from the kv layer.
// Only one of the event will be setted.
//
//msgp:ignore RegionFeedEvent
type RegionFeedEvent struct {
Val *RawKVEntry
Resolved *ResolvedSpan
// Additional debug info
RegionID uint64
}
func (e RegionFeedEvent) String() string {
return fmt.Sprintf("Val: %v, Resolved: %v, RegionID: %v", e.Val, e.Resolved, e.RegionID)
}
// GetValue returns the underlying value
func (e *RegionFeedEvent) GetValue() interface{} {
if e.Val != nil {
return e.Val
} else if e.Resolved != nil {
return e.Resolved
}
return nil
}
// ResolvedSpan guarantees all the KV value event
// with commit ts less than ResolvedTs has been emitted.
//
//msgp:ignore ResolvedSpan
type ResolvedSpan struct {
Span regionspan.ComparableSpan
ResolvedTs uint64
}
// String implements fmt.Stringer interface.
func (rs *ResolvedSpan) String() string {
return fmt.Sprintf("span: %s, resolved-ts: %d", rs.Span, rs.ResolvedTs)
}
// RawKVEntry notify the KV operator
type RawKVEntry struct {
OpType OpType `msg:"op_type"`
Key []byte `msg:"key"`
// nil for delete type
Value []byte `msg:"value"`
// nil for insert type
OldValue []byte `msg:"old_value"`
StartTs uint64 `msg:"start_ts"`
// Commit or resolved TS
CRTs uint64 `msg:"crts"`
ExpiredTs uint64 `msg:"expired_ts"`
// Additional debug info
RegionID uint64 `msg:"region_id"`
KeySpanID uint64 `msg:"keyspan_id"`
// For providing additional sequence number.
// To keep `RawKVEntries` from the same region in order during unstable sorting of `sorter`.
// The sequence number is generated by auto-increment in `puller` node of `processor.pipeline`.
Sequence uint64 `msg:"sequence"`
}
func (v *RawKVEntry) String() string {
return fmt.Sprintf("OpType: %v, Key: %s, Value: %s, StartTs: %d, CRTs: %d, RegionID: %d, KeySpanID: %d, Sequence: %d",
v.OpType, string(v.Key), string(v.Value), v.StartTs, v.CRTs, v.RegionID, v.KeySpanID, v.Sequence)
}
// ApproximateDataSize calculate the approximate size of protobuf binary
// representation of this event.
func (v *RawKVEntry) ApproximateDataSize() int64 {
return int64(len(v.Key) + len(v.Value) + len(v.OldValue))
}