Skip to content

Native Common Virtuals for NATS - #101139

Merged
Michicosun merged 3 commits into
masterfrom
native_common_virtuals/NATS
Apr 1, 2026
Merged

Michicosun merged 3 commits into
masterfrom
native_common_virtuals/NATS

Conversation

@Michicosun

@Michicosun Michicosun commented Mar 29, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Part of #100766

Version info

  • Merged into: 26.4.1.482

@clickhouse-gh

clickhouse-gh Bot commented Mar 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8692a7e]

Summary: ❌

job_name test_name status info comment
Stress test (arm_msan) failure
MemorySanitizer: use-of-uninitialized-value (STID: 2410-543a) FAIL cidb

AI Review

Summary

This PR adds NATS support for the common virtual column _table by extending createVirtuals and wiring value population in NATSSource. The implementation itself looks consistent with existing virtual-column patterns, but test coverage is insufficient for the new virtual-column path, especially for STREAM error-handling behavior.

Findings

⚠️ Majors

  • [src/Storages/NATS/StorageNATS.cpp:170] New _table virtual column was added without end-to-end tests for selection/planner behavior and interaction with input_format_allow_errors_* under STREAM mode.
    • Suggested fix: add stateless/integration tests that select _table in both normal parsing and parse-error paths (nats_handle_error_mode = 'stream') and validate resulting virtual columns.
Tests

⚠️ Add a test that validates _table is populated for successfully parsed messages.

⚠️ Add a test for nats_handle_error_mode='stream' ensuring _table remains correct when _raw_message and _error are populated.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    • Add end-to-end tests for the new NATS _table virtual column, including STREAM error-handling coverage.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Mar 29, 2026
Comment thread src/Storages/StorageSnapshot.cpp Outdated
{
auto all_columns = metadata->getColumns().get(options);
const auto & common_virtual_columns = IStorage::getCommonVirtuals();
const auto common_virtual_columns = storage.getCommonVirtuals();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StorageSnapshot currently snapshots metadata and virtual_columns in the constructor, but common_virtual_columns is re-read from storage.getCommonVirtuals() inside each accessor. After this PR, common virtuals are mutable (MultiVersionVirtualsDescriptionPtr), so a concurrent setVirtuals can change common virtuals mid-query and make one StorageSnapshot observe mixed versions.

That can lead to inconsistent behavior in a single query path (e.g. getColumns and later check seeing different common virtual sets). Please snapshot common virtuals in StorageSnapshot ctor (store a VirtualsDescriptionPtr common_virtual_columns) and use that member in all methods, same as virtual_columns.

Comment thread src/Storages/NATS/StorageNATS.cpp Resolved
@yariks5s yariks5s self-assigned this Mar 31, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.20% +0.10%
Functions 90.90% 90.90% +0.00%
Branches 76.70% 76.70% +0.00%

Changed lines: 20.83% (5/24) · Uncovered code

Full report · Diff report

@Michicosun
Michicosun added this pull request to the merge queue Apr 1, 2026
Merged via the queue into master with commit a264789 Apr 1, 2026
159 of 160 checks passed
@Michicosun
Michicosun deleted the native_common_virtuals/NATS branch April 1, 2026 10:40
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 1, 2026
lilredbot pushed a commit to JTCunning/ClickHouse that referenced this pull request Nov 4, 2026
…og sources

Since the "native common virtuals" series (ClickHouse#101138 for Kafka, ClickHouse#101411 for
RabbitMQ, ClickHouse#101139 for NATS, ClickHouse#101006 for FileLog) the streaming sources
fill the `_table` virtual column inside the per-row (NATS: per-message)
loop with `getStorageID().getTableName()`. `IStorage::getStorageID()`
locks the table-wide `id_mutex` and copies the `StorageID`, and all
reader-place virtuals are materialized for every row whether or not the
query selects `_table`, so every consumer thread of one table took the
same mutex for every row and consumers of one table serialized on it
(ClickHouse#120032). The Kafka, StorageKafka2 and RabbitMQ dead-letter branches did
the same once per failed message.

Take one `StorageID` snapshot plus a `Field` with the table name before
the consume loop and fill `_table` / the dead-letter element from it.
A block now carries the table name read when the block started, which is
the identity `streamToViews` inserts the block under.

Measured with a bpftrace uprobe on `IStorage::getStorageID` while a
materialized view drains the table: calls made by the source function
itself go from one per row (100000 for 100000 Kafka / StorageKafka2 /
FileLog rows, 20000 for 20000 NATS / RabbitMQ rows) to one per block
(2-8 for Kafka, StorageKafka2, FileLog and NATS; 261-371 for RabbitMQ,
which drains in small blocks).

The existing virtual-column tests now also check `_table` for Kafka (both
engines), RabbitMQ, NATS and FileLog.

Closes ClickHouse#120032

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants