Documentation ¶
Overview ¶
Package gc privodes TiDB GC related utilities.
Following graph shows how TiCDC manipulates GC safepoints.
```
┌───┐ ┌───┐ ┌──┐ ┌─────┐ │CLI│ │API│ │PD│ │Owner│ └─┬─┘ └─┬─┘ └┬─┘ └──┬──┘ │ │ │ │ ╔═══════════╪═════╤════════╪═════════════╪════════════════════════╪════════════╗ ║ "CLI OR API?" │ CLI │ │ │ ║ ╟─────────────────┘ │ │ │ ║ ║ │ service GC safepoint │ │ ║ ║ │ "cdc-creating-<ID>" │ │ ║ ║ │──────────────────────────>┌┴┐ │ ║ ║ │ │ │ │ │ ║ ║ │ Create changefeed │ │ │ ║ ║ │──────────────────────────>│ │ │ ║ ╠═══════════╪══════════════╪════════════╪═╪═══════════════════════╪════════════╣ ║ API │ │ │ │ │ ║ ║ │ │ Create changefeed API │ ║ ║ │ │─────────────────────────────────────>│ ║ ║ │ │ │ │ │ ║ ║ │ │ │ │ service GC safepoint│ ║ ║ │ │ │ │ "cdc-creating-<ID>" │ ║ ║ │ │ │ ┌─┐ <──────────────────── ║ ║ │ │ │ │ │ │ ║ ║ │ │ │ │ │ Create changefeed │ ║ ║ │ │ │ │ │ <──────────────────── ║ ╚═══════════╪══════════════╪════════════╪═╪═╪═════════════════════╪════════════╝ │ │ │ │ │ │ │ │ │ │ │ │ ╔═════════════════╗ │ │ │ │ │ GC safepoint "ticdc"│ ║using the minimal║ │ │ │ │ │ <──────────────────── ║checkpoint among ║ │ │ │ │ │ │ ║all changefeeds ║ │ │ │ │ │ │ ╚═════════════════╝ │ │ │ │ │Remove GC safepoint │ │ │ │ │ │"cdc-creating-<ID>" │ │ │ └┬└─┘ <──────────────────── │ │ │ │ │ │ │ │────┐ │ │ │ │ │ Start changefeed │ │ │ │<───┘ ┌─┴─┐ ┌─┴─┐ ┌┴─┐ ┌──┴──┐ │CLI│ │API│ │PD│ │Owner│ └───┘ └───┘ └──┘ └─────┘
```
When CLI/API creates a changefeed, it registers a service GC safepoint "ticdc-creating-<ID>" to cover the gap between creating changefeed and handling changefeed.
TiCDC Owner removes the service GC safepoint after new changefeed checkpoint is included in the "ticdc" service GC safepoint.
Index ¶
Constants ¶
const (
// CDCServiceSafePointID is the ID of CDC service in pd.UpdateServiceGCSafePoint.
CDCServiceSafePointID = "tikvcdc"
)
Variables ¶
This section is empty.
Functions ¶
func EnsureChangefeedStartTsSafety ¶
func EnsureChangefeedStartTsSafety( ctx context.Context, pdCli pd.Client, changefeedID string, TTL int64, startTs uint64, ) error
EnsureChangefeedStartTsSafety checks if the startTs less than the minimum of service GC safepoint and this function will update the service GC to startTs
Types ¶
type Manager ¶
type Manager interface { // TryUpdateGCSafePoint tries to update TiCDC service GC safepoint. // Manager may skip update when it thinks it is too frequent. // Set `forceUpdate` to force Manager update. TryUpdateGCSafePoint(ctx context.Context, checkpointTs model.Ts, forceUpdate bool) error CheckStaleCheckpointTs(ctx context.Context, changefeedID model.ChangeFeedID, checkpointTs model.Ts) error }
Manager is an interface for gc manager
type MockPDClient ¶
type MockPDClient struct { pd.Client UpdateServiceGCSafePointFunc func(ctx context.Context, serviceID string, ttl int64, safePoint uint64) (uint64, error) }
MockPDClient mocks pd.Client to facilitate unit testing.
func (*MockPDClient) UpdateServiceGCSafePoint ¶
func (m *MockPDClient) UpdateServiceGCSafePoint(ctx context.Context, serviceID string, ttl int64, safePoint uint64) (uint64, error)
UpdateServiceGCSafePoint implements pd.Client.UpdateServiceGCSafePoint.