ColumnArrayT, ColumnTupleT, ColumnMapT: a rejected Append leaves part of the value in the column and corrupts the next rows
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 67/100
調査の方向性
Read clickhouse/columns/array.h around ColumnArrayT::Append and clickhouse/columns/tuple.h around AppendTuple; the issue identifies both as the source of partial appends. Check the related column append tests and add coverage for rejected Array, Tuple, and Map values followed by a valid row. Done means the rejected append leaves the columns unchanged and the reproduction reads and inserts the later values correctly.
索引モデルが issue の本文から書いたものです。
説明
Description
When ColumnArrayT::Append, ColumnTupleT::Append, or ColumnMapT::Append rejects an element of the value (for example a 3-byte string for FixedString(2): ValidationError), the elements that it appended before stay in the nested columns, but Size() does not change. When the caller catches the exception and continues, the next rows read those elements:
Array(FixedString(2)): after the rejected['bb','xxx'], the next row['cc']reads['bb'].Tuple(FixedString(2), UInt8): after the rejected('xxx',20), the next row('cc',30)reads('cc',20).Map(FixedString(2), UInt8): after the rejected{'xxx':2}, the next row{'cc':3}reads{'cc':2}.
An insert of such a column:
- after
Slice()(for example, an insert in chunks) succeeds and stores the wrong values; - of the column itself sends more bytes than the block declares, and fails with no row stored. When the column is the last one in the block, the server closes the connection (
UNKNOWN_PACKET_FROM_CLIENT). When it is not, the server waits for more data:Insert()blocks untilreceive_timeout(300 s), then fails withSOCKET_TIMEOUT.
The same defect was reported for clickhouse-java in https://github.com/ClickHouse/clickhouse-java/issues/3410.
Steps to reproduce
Run the program below. It creates the table t_rejected.
Reproduction program (C++, 42 lines)
#include <clickhouse/client.h>
#include <iostream>
using namespace clickhouse;
int main() {
std::cout << std::unitbuf;
Client client(ClientOptions().SetHost("localhost"));
client.Execute("DROP TABLE IF EXISTS t_rejected");
client.Execute("CREATE TABLE t_rejected (id UInt8, a Array(FixedString(2)), t Tuple(FixedString(2), UInt8)) "
"ENGINE = MergeTree ORDER BY id");
auto id = std::make_shared<ColumnUInt8>();
auto a = std::make_shared<ColumnArrayT<ColumnFixedString>>(2);
auto t = std::make_shared<ColumnTupleT<ColumnFixedString, ColumnUInt8>>(
std::make_tuple(std::make_shared<ColumnFixedString>(2), std::make_shared<ColumnUInt8>()));
id->Append(1); a->Append(std::vector<std::string>{"aa"}); t->Append(std::make_tuple(std::string_view("aa"), uint8_t(10)));
// Row 2: "xxx" is too long for FixedString(2). The caller skips the row.
try { a->Append(std::vector<std::string>{"bb", "xxx"}); } catch (const ValidationError& e) { std::cout << "rejected: " << e.what() << "\n"; }
try { t->Append(std::make_tuple(std::string_view("xxx"), uint8_t(20))); } catch (const ValidationError& e) { std::cout << "rejected: " << e.what() << "\n"; }
id->Append(3); a->Append(std::vector<std::string>{"cc"}); t->Append(std::make_tuple(std::string_view("cc"), uint8_t(30)));
std::cout << "a.At(1)[0] = " << a->At(1)[0] << ", t.At(1) = (" << std::get<0>(t->At(1)) << ","
<< int(std::get<1>(t->At(1))) << ")\n";
// 1. Insert a slice (as in chunked inserts): succeeds, stores wrong values.
Block sliced;
sliced.AppendColumn("id", id->Slice(0, 2));
sliced.AppendColumn("a", a->Slice(0, 2));
sliced.AppendColumn("t", t->Slice(0, 2));
client.Insert("t_rejected", sliced);
client.Select("SELECT id, toString(a), toString(t) FROM t_rejected ORDER BY id", [](const Block& b) {
for (size_t i = 0; i < b.GetRowCount(); ++i)
std::cout << "stored: " << int(b[0]->As<ColumnUInt8>()->At(i)) << ", " << b[1]->As<ColumnString>()->At(i)
<< ", " << b[2]->As<ColumnString>()->At(i) << "\n";
});
// 2. Insert the columns: fails, no row is stored.
Block direct;
direct.AppendColumn("id", id);
direct.AppendColumn("t", t);
try { client.Insert("t_rejected", direct); } catch (const std::exception& e) { std::cout << "Insert: " << e.what() << "\n"; }
}
Actual output
rejected: Expected string of length not greater than 2 bytes, received 3 bytes.
rejected: Expected string of length not greater than 2 bytes, received 3 bytes.
a.At(1)[0] = bb, t.At(1) = (cc,20)
stored: 1, ['aa'], ('aa',10)
stored: 3, ['bb'], ('cc',20)
Insert: connection closed by peer while reading
Server log of the last insert: Code: 99. DB::Exception: Unknown packet 30 from client. (UNKNOWN_PACKET_FROM_CLIENT).
Expected behavior
A rejected Append does not change the column, as for ColumnNullableT (#535) and ColumnLowCardinalityT. Row 3 reads and stores ['cc'] and ('cc',30), and the second insert succeeds.
Root cause
ColumnArrayT::Append(begin, end)(clickhouse/columns/array.h:305-317) appends each element to the nested column and adds the offset only after the loop, so an exception leaves the earlier elements without an offset.ColumnArray::SaveBody(array.cpp:175-180) writes the whole nested column;AtandSliceread it by offsets.ColumnTupleT::AppendTuple(clickhouse/columns/tuple.h:162-171) appends the elements from last to first, so an element that throws leaves the later element columns one row longer.ColumnTuple::Size()(tuple.cpp:75-77) reads only the first element.ColumnMapT::Append(map.h:225-244) reaches both through itsArray(Tuple(K, V)).
The fix is in the two Append functions. Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related
- #543:
AppendAsColumnwith a wrong-typed column; other trigger, same stream desync.
Environment
- Client:
masterat b2a1f6a (v2.6.2 has the same code) - Server: 26.10.4.207
- Compiler: clang 18, Linux (Docker)
Classification: impact: Data integrity · area: Data types & formats (Array, Tuple, Map)
Found by automated analysis (Polyglot AI) while checking clickhouse-java#3410 against the other client repos. Verified against a live server.
- 主要言語
- C
- スター
- 388
- フォーク
- 220
- 平均マージ
- 1日 25分
- マージ済み PR(30日)
- 16
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ClickHouse/clickhouse-cpp のほかの issue
-
bug data-types
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ClickHouse/clickhouse-cpp#645 ·
メンテナーはふだん 1 日以内に返信
-
bug queries
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
ClickHouse/clickhouse-cpp#644 ·
メンテナーはふだん 1 日以内に返信
-
bug data-types native-format
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
ClickHouse/clickhouse-cpp#643 ·
メンテナーはふだん 1 日以内に返信
-
bug connectivity native-protocol
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ClickHouse/clickhouse-cpp#638 ·
メンテナーはふだん 1 日以内に返信
-
Core SQL test harness: ParseSetAssignments does not skip comments inside SET対応中かも @puretechteam が 12 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
ClickHouse/clickhouse-cpp#626 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
ClickHouse/clickhouse-cpp の issue をすべて見る
似ている issue
-
CF_CFDP_S_SendFileData computes the file checksum from the SB buffer after CFE_SB_TransmitBufferオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
389ds/389-ds-base#8251 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100