Schedule icon
Query icon
Switch icon
SlackIncomingWebhook icon
If icon
Log icon

TiDB TiKV Region Peer Replication Health Sentinel

Audit TiDB TiKV Raft region peer states, detect offline or lagging replicas, alert Slack on quorum risks, and inspect storage node health.

Categories
DataInfrastructure

TiDB is an open-source, distributed Hybrid Transactional and Analytical Processing (HTAP) database powered by the TiKV distributed key-value storage engine. In TiDB, all table data and secondary indexes are partitioned into dynamic continuous ranges called Raft Regions, which are replicated across multiple TiKV storage nodes via Multi-Raft consensus. When a storage node experiences hardware failure, disk I/O stall, network partitioning, or ungraceful shutdown, region replicas enter DOWN or PENDING states. If offline peers exceed fault tolerance intervals or multiple peers in the same region fail, Raft quorum is compromised, resulting in partition unavailability, transaction write stalls, and potential data loss. This blueprint provides automated surveillance over information_schema.tikv_region_peers and information_schema.tikv_region_status, classifies peer replication health, escalates incidents to Slack, and correlates offline replicas with degraded TiKV store daemons.

How it works

  1. Scheduled trigger (every_fifteen_minutes) initiates diagnostic health verification every 15 minutes, with manual runs supported via customizable inputs.
  2. Diagnostic probe (probe_degraded_region_peers) connects to TiDB over the MySQL wire protocol (port 4000) via io.kestra.plugin.jdbc.mysql.Query and inspects information_schema.tikv_region_peers joined with information_schema.tikv_region_status for any peers in DOWN or PENDING states.
  3. Classification logic evaluates the query output using Pebble templating, discerning whether any peers have been down longer than down_seconds_threshold (CRITICAL), if peers are temporarily pending/lagging (WARNING), if all peers are healthy (HEALTHY), or if the database connection failed (PROBE_FAILED).
  4. Routing task (route_by_cluster_health) switches execution along dedicated paths according to the classified severity.
  5. On CRITICAL or WARNING states, structured Slack incident cards notify operations channels with impacted cluster endpoints, degraded peer counts, and affected table scopes.
  6. When critical down peers are identified and inspect_offline_stores is enabled, query_offline_stores interrogates information_schema.tikv_store_status to identify specific storage node addresses that have fallen out of the Up state.
  7. On PROBE_FAILED, dedicated alerts notify administrators of unreachable ports or authentication failures.
  8. Audit log task (log_audit_summary) writes execution metadata and evaluated region counts to task logs.

What you get

  • Automated continuous surveillance of TiDB and TiKV Raft region peer replication states across all database schemas.
  • Proactive detection of persistently offline storage peers before regional consensus quorums breach.
  • Automated correlation between offline region peers and host TiKV store daemon addresses.
  • Differentiated incident routing separating transient log catchup (PENDING) from severe node failure (DOWN).
  • Full execution traceability and audit logging without leaking database credentials in logs or alert payloads.

Who it's for

  • Database Administrators and Platform Engineers managing production TiDB and TiKV clusters.
  • Site Reliability Engineers responsible for distributed transactional database availability and uptime SLAs.
  • Data Engineers deploying high-throughput streaming and analytics workloads on TiDB HTAP infrastructure.

Why orchestrate this with Kestra

  • Declarative YAML definition unifies distributed database health verification, conditional severity branching, and diagnostic diagnostics into version-controlled GitOps workflows.
  • Native MySQL JDBC plugin connectivity communicates directly with TiDB's MySQL wire protocol without external agent binaries or Python container overhead.
  • Built-in conditional routing isolates healthy baseline checks from multi-tiered incident notification cards.
  • Immutable execution history provides operational evidence documenting cluster recovery timelines and storage degradation intervals.
  • Resilient flow-level error trapping guarantees that unexpected network or credential errors trigger immediate emergency alerts.

Prerequisites

  • TiDB cluster running with MySQL wire compatibility enabled (default port 4000).
  • Database user with read access to information_schema.tikv_region_peers, information_schema.tikv_region_status, and information_schema.tikv_store_status.
  • Slack incoming webhook URL for operational incident dispatch.

Secrets

  • TIDB_USERNAME: Username for authenticating to the TiDB MySQL wire interface (e.g. root or monitoring user).
  • TIDB_PASSWORD: Password for the TiDB database user.
  • SLACK_WEBHOOK_URL: Incoming webhook URL for posting incident cards to Slack.

Quick start

  1. Configure TIDB_USERNAME, TIDB_PASSWORD, and SLACK_WEBHOOK_URL in your Kestra namespace secrets.
  2. Deploy this blueprint to your Kestra instance and trigger an initial manual run with default inputs to verify connectivity against your TiDB server.
  3. Review the execution log in the Kestra UI to verify region peer query execution from information_schema.tikv_region_peers.
  4. Enable the every_fifteen_minutes schedule trigger to activate automated continuous monitoring.

How to extend

  • Add PD (Placement Driver) API queries to monitor cluster-wide region balance and scheduling operator backlogs.
  • Integrate PagerDuty alerting via io.kestra.plugin.pagerduty.notifications.PagerDutyAlert for immediate on-call dispatch during persistent storage store loss.
  • Attach TiFlash replica monitoring via information_schema.tiflash_replica to verify columnar analytical replica synchronization freshness.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.