gc

package
v0.0.0-...-db0ae72 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

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

View Source
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

func RemoveServiceGCSafepoint

func RemoveServiceGCSafepoint(ctx context.Context, pdCli pd.Client, serviceID string) error

RemoveServiceGCSafepoint removes a service safepoint from PD.

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

func NewManager

func NewManager(pdClient pd.Client) Manager

NewManager creates a new 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) GetTS

func (m *MockPDClient) GetTS(ctx context.Context) (int64, int64, error)

GetTS implements pd.Client.GetTS.

func (*MockPDClient) UpdateServiceGCSafePoint

func (m *MockPDClient) UpdateServiceGCSafePoint(ctx context.Context, serviceID string, ttl int64, safePoint uint64) (uint64, error)

UpdateServiceGCSafePoint implements pd.Client.UpdateServiceGCSafePoint.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL