lightning: errormanager.Init aborts with Error 1142 when target user lacks CREATE VIEW privilege
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
### What did you do?
Run TiDB Lightning against a target TiDB cluster using a target user provisioned with the privilege set documented in the TiDB Lightning prerequisites page:
```sql
GRANT CREATE, SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, INDEX ON *.* TO 'lightning_user'@'%';
```
This privilege set matches what the [TiDB Lightning Requirements](https://docs.pingcap.com/tidb/stable/tidb-lightning-requirements) doc lists for the target table and the `task-info-schema-name` schema.
### What did you expect to see?
Lightning runs to completion, or fails with a clear and actionable error if the privilege set is insufficient for the requested import mode and conflict tracking configuration.
### What did you see instead?
Lightning aborts at `errormanager.Init` with an opaque `Error 1142`, before any data is loaded:
```
[Lightning:DB:ErrInitErrManager]init error manager error: create conflict view failed: Error 1142 (42000): CREATE VIEW command denied to user 'lightning_user'@'%' for table 'conflict_view'
```
The failure happens because Lightning's `errormanager` creates an internal `conflict_view` (a UNION view over `conflict_error_v4` / `conflict_records_v2`) at task init whenever conflict tracking is enabled, and the documented privilege set does not include `CREATE VIEW`.
The error surfaces from deep inside Lightning init, with no upfront privilege precheck and no clear pointer to the missing privilege.
Additional observation: the error tables (`conflict_records_v2`, plus `conflict_error_v4` in physical mode) are created **before** the view creation aborts, leaving partial state in the `lightning_task_info` schema. Subsequent retries with the same user re-hit the view error, leaving the orphans in place.
### Reproduction
Standalone reproduction with 8 scenarios across logical (TiDB backend) and physical (Local backend) modes, TiDB v8.5.5 + Lightning v8.5.5:
https://github.com/alastori/tidb-sandbox/blob/feat/lab-01-lightning-create-view-privilege/labs/lightning/lab-01-create-view-privilege/lab-01-create-view-privilege.md
Key results:
- **L1 / P1** (documented grant set, no `CREATE VIEW`): identical `Error 1142` failure in both logical and physical modes. Different view variant (V2-only in logical, V1+V2 union in physical), same privilege check, same failure path.
- **L0 / P0** (`GRANT ALL PRIVILEGES`, the typical real-world setup): both pass cleanly. The bug is silently bypassed by overprivileged users, which is why it has been latent since the view was introduced in 2024.
- **L2 / P2** (documented grant set + `CREATE VIEW`): both pass.
- **L3 / P3** (existing config flags that disable the view path: `task-info-schema-name = ""` for logical, `[conflict] strategy = "none"` and `precheck-conflict-before-import = false` for physical): both pass with the same documented-grant-only user that fails L1 / P1.
### Documentation gap
The TiDB Lightning prerequisites doc does not list `CREATE VIEW` in the target user privilege requirements:
- [TiDB Lightning Requirements](https://docs.pingcap.com/tidb/stable/tidb-lightning-requirements)
The privilege requirement for the internal `conflict_view` is undocumented in the OSS Lightning user-facing docs.
### Related issues and PRs
- pingcap/tidb#52306 - "Optimization for lightning conflict detection" (the design issue that introduced `conflict_view`)
- pingcap/tidb#52307 - "lightning: merge conflict record tables for preprocess duplicate detection and post-import conflict detection" (the implementation PR, merged with cherry-pick to release-8.1)
- pingcap/tiflow#11811 - sibling closed bug, same `[Lightning:DB:ErrInitErrManager]init error manager error: create conflict view failed` failure path, but with `Error 1146` (table doesn't exist race) instead of `Error 1142` (privilege denied), fixed via tiflow#11904
### What is your TiDB version?
Reproduced on:
- TiDB v8.5.5 (`tiup playground v8.5.5`, server version `8.0.11-TiDB-v8.5.5`)
- TiDB Lightning v8.5.5 (`tidb-lightning-v8.5.5-darwin-arm64`)
The view creation code shipped via pingcap/tidb#52307 with cherry-pick to release-8.1, so all releases 8.1+ are affected.
Contributor guide
Assessment
This issue has not been assessed yet.