IMPORT INTO chunkWorker skips index writer Close after data writer Close error
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
This is a deterministic fault-injection/unit-level repro for the `IMPORT INTO` global-sort close path.
1. Create a `chunkWorker` in `pkg/dxf/importinto` with both data and index writers initialized.
2. Append data so that both writers have accepted buffered KV.
3. Inject a deterministic error from the data writer's underlying object writer during `Close`.
4. Call `chunkWorker.Close`.
5. Observe both the returned error and whether `indexWriter.Close` reaches its terminal close/flush hook.
The current-source RED observed:
```text
returned error: ai-native data writer close failed
index Close count: 0
```
So the root data-writer error is returned, but the sibling index writer is not closed.
### 2. What did you expect to see? (Required)
`chunkWorker.Close` should preserve the first/root data-writer close error, but it should still close sibling writers that have already been created and have accepted buffered KV.
In other words, the final error should still explain the root failure, while all owned terminal writers should reach their required `Close`/flush/cleanup path.
### 3. What did you see instead (Required)
When `dataWriter.Close` returns an error, the current implementation returns immediately and skips `indexWriter.Close`.
For a user-facing `IMPORT INTO` operation, the import already fails with the data-writer close error. The problem is that index-side terminal actions are skipped: buffered index KV flush/close hooks and writer summaries/cleanup hooks are not reached through the normal close path.
A local minimal fix that records the first/root error, continues to close the index writer, and returns the root error afterwards makes the same repro pass:
```text
returned error: ai-native data writer close failed
index Close count: 1
index terminal logs: flush sorted kv / flush kv / close writer
```
### 4. What is your TiDB version? (Required)
```text
Current master source commit: 13282a8bd06bd33324a4dbfd3c1c03685f3cd9aa
```
Likely root cause and fix direction
The close path treats returning the root error as sufficient, but that loses ownership of sibling terminal resources. `chunkWorker` owns both data and index writers. Once both writers have accepted KV, an error from one writer's `Close` should not prevent the other writer from reaching its terminal close path.
The fix direction is to accumulate the first/root close error, continue closing the remaining owned writers, and then return the first error or a combined error according to the desired product policy.
Contributor guide
Research direction
Start at chunkWorker.Close in pkg/dxf/importinto and run the deterministic unit-level reproduction described in the issue, injecting a data-writer Close error. Done means the first data-writer error is still returned while the already-created index writer reaches its Close, flush, and cleanup path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100