8000 Classify ClickHouse errors and stop on fatal failures instead of retrying forever by minguyen9988 · Pull Request #1315 · Altinity/clickhouse-sink-connector · GitHub
[go: up one dir, main page]

Skip to content

Classify ClickHouse errors and stop on fatal failures instead of retrying forever - #1315

Merged
subkanthi merged 4 commits into
2.10.0from
fix/error-classification-silent-failure-v2
Jun 13, 2026
Merged

subkanthi merged 4 commits into
2.10.0from
fix/error-classification-silent-failure-v2

Conversation

@minguyen9988
Copy link
Copy Markdown
Collaborator

Summary

Fixes #1310
Related: #1308

The ClickHouse Sink Connector silently swallows all exceptions thrown during batch processing in ClickHouseBatchRunnable.run(). When a ClickHouse write fails with a deterministic error (authentication failure, schema mismatch, too many parts, etc.), the connector:

  1. Logs the error
  2. Retains currentBatch (the failed batch stays in the retry variable)
  3. On the next scheduled run, retries the exact same batch ("***** RETRYING the same batch again")
  4. The retry fails with the same deterministic error
  5. Repeat forever

This infinite retry loop blocks binlog position advancement, causing silent data loss across all tables in the replication pipeline. New records arriving on Kafka are queued behind the permanently-stuck batch and never reach ClickHouse.

Root Cause

In ClickHouseBatchRunnable.run() (line 308), the catch block swallows all exceptions without classification:

} catch (Exception e) {
    log.error(...);
    // No rethrow. No stop. No classification.
    // currentBatch remains non-null, so it will be retried forever.
}

In runLegacyMode(), currentBatch is only cleared on success (if (result) { currentBatch = null; }), so failed batches are retried indefinitely.

Fix

New ClickHouseErrorClassifier utility that classifies ClickHouse errors by error code:

  • FATAL (will never succeed on retry):

    • Authentication/authorization: AUTHENTICATION_FAILED (516), ACCESS_DENIED (497)
    • Schema mismatches: UNKNOWN_TABLE (60), UNKNOWN_DATABASE (81), NO_SUCH_COLUMN_IN_TABLE (16), TYPE_MISMATCH (53), NUMBER_OF_COLUMNS_DOESNT_MATCH (50)
    • Resource limits: TOO_MANY_PARTS (252), MEMORY_LIMIT_EXCEEDED (241), TOO_MANY_PARTITIONS (396)
    • Data format: CANNOT_PARSE_TEXT (27), CANNOT_READ_ALL_DATA (33), ARGUMENT_OUT_OF_BOUND (69), INVALID_PARTITION_VALUE (349)
  • RETRIABLE (transient, may succeed on retry):

    • Network errors, timeouts, and any unrecognized ClickHouse error code

Modified ClickHouseBatchRunnable.run() catch block:

  • On FATAL error: log, clear currentBatch, rethrow to stop the executor
  • On RETRIABLE/UNKNOWN error: log warning, allow normal retry behavior

Files Changed

  • New: ClickHou 8000 seErrorClassifier.java — error code extraction and classification
  • Modified: ClickHouseBatchRunnable.java — catch block uses classifier to stop on fatal errors
  • New: ClickHouseErrorClassifierTest.java — 20 unit tests covering all classified codes, cause chain traversal, edge cases

Testing

The new ClickHouseErrorClassifierTest covers:

  • Error code extraction from simple messages and nested cause chains
  • All fatal error codes (auth, schema, resource, data format)
  • Retriable errors (network, timeout)
  • Edge cases (null exception, no error code, deeply nested causes)

minguyen9988 and others added 4 commits June 12, 2026 13:15
Add ClickHouseErrorClassifier that categorizes ClickHouse exceptions as
FATAL or RETRIABLE based on error codes extracted from exception messages.

Fatal errors (auth failures, schema mismatches, resource limits) will
never succeed on retry. Previously, the connector silently swallowed
all exceptions in ClickHouseBatchRunnable.run(), retaining the failed
batch in currentBatch and retrying it indefinitely. This blocked binlog
position advancement, causing silent data loss across all tables in the
replication pipeline.

Changes:
- New ClickHouseErrorClassifier utility with error code extraction,
  fatal/retriable classification, and cause-chain traversal
- Modified ClickHouseBatchRunnable.run() catch block to classify errors:
  - FATAL: log error, clear currentBatch, rethrow to stop the executor
  - RETRIABLE/UNKNOWN: log warning, allow normal retry on next run
- Comprehensive unit tests for all classified error codes

Fixes #1310
Related: #1308
@subkanthi
subkanthi merged commit 019c984 into 2.10.0 Jun 13, 2026
9 checks passed
@subkanthi
subkanthi deleted the fix/error-classification-silent-failure-v2 branch June 13, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0