ClickHouse/ClickHouse

Creating materialized view over MaterializedPostgreSQL results in DB::Exception: Too large size passed to allocator.

Closed

#39,805 opened on Aug 1, 2022

 (5 comments) (5 reactions) (0 assignees)C++ (8,400 forks)batch import
experimental featurehelp wanted

Repository metrics

Stars
 (47,419 stars)
PR merge metrics
 (Avg merge 2d 2h) (1,000 merged PRs in 30d)

Description

Hi, I am trying to set up replication from Postgres to ClickHouse, and create some materialized view (call it my_view) on top of mirrored data. Replication (MaterializedPostgreSQL) without my_view works without issues. Once I create my_view - no new records occur in MaterializedPostgreSQL tables, my_view is empty and clickhouse-server.err.log contains errors. If I delete my_view and restart the server - replication continues without issues. But once my_view is created - it's broken again.

my_view - just for reverence, should contain total number of order (sum of orders_num) for each customer's first_name

How to reproduce

version 22.1.3.7 (official build)

version: '2'
services:
  clickhouse-server:
    image: clickhouse/clickhouse-server:latest
    ulimits:
      nofile:
        soft: 262144
        hard: 262144
  example-db:
    image: debezium/postgres:14
    environment:
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=postgres
#!/bin/bash
set -e

docker-compose down
docker-compose up -d

sleep 10

# docker-compose exec -T example-db psql -U admin -d admin -c 'SHOW wal_level'
# logical
# docker-compose exec -T example-db psql -U admin -d admin -c 'SHOW max_replication_slots'
# 4

echo 'add initial data to pg'
docker-compose exec -T example-db psql -U admin -d admin <<EOF
CREATE SCHEMA inventory;
SET search_path TO inventory;

CREATE TABLE customers (
  id SERIAL NOT NULL PRIMARY KEY,
  first_name VARCHAR(255) NOT NULL,
  last_name VARCHAR(255) NOT NULL,
  email VARCHAR(255) NOT NULL UNIQUE,
  orders_num INTEGER NOT NULL DEFAULT 0
);

INSERT INTO customers VALUES (default,'Sally','Thomas','sally.thomas@acme.com', 1);
EOF

echo 'setup postgres -> clickhouse '
docker-compose exec -T clickhouse-server clickhouse-client --multiquery --multiline --query "
SET allow_experimental_database_materialized_postgresql=1;
CREATE DATABASE example_db ENGINE = MaterializedPostgreSQL('example-db:5432', 'admin', 'admin', 'postgres')
SETTINGS
materialized_postgresql_schema = 'inventory',
materialized_postgresql_allow_automatic_update = 1
;
"

sleep 5

echo 'synced rows'
docker-compose exec -T clickhouse-server clickhouse-client -q "select * from example_db.customers order by id desc"

echo 'create materialized view'
docker-compose exec -T clickhouse-server clickhouse-client --multiline --query "CREATE MATERIALIZED VIEW default.my_view
ENGINE = AggregatingMergeTree() ORDER BY (first_name)
AS 
SELECT
    first_name,
    sumState(orders_num) total_orders,
    countState() request_count
FROM example_db.customers 
GROUP BY first_name"

echo 'add some data to pg'
docker-compose exec -T example-db psql -U admin -d admin <<EOF
SET search_path TO inventory;
INSERT INTO customers VALUES (default,'George','Bailey','gbailey@foobar.com', 2),
       (default,'Edward','Walker','ed@walker.com', 3),
       (default,'Anne','Kretchmar','annek@noanswer.org', 4),
       (default,'Anne','Walker','anne@walker.org', 2);
EOF

echo 'wait 30 secs'
sleep 30
echo 'synced rows'
docker-compose exec -T clickhouse-server clickhouse-client -q "select * from example_db.customers order by id desc"
echo 'materialized view data'
docker-compose exec -T clickhouse-server clickhouse-client -q "select * from default.my_view"

echo 'logs'

docker-compose exec -T clickhouse-server cat /var/log/clickhouse-server/clickhouse-server.err.log

Expected behavior

Creating materialized view doesn't break MaterializedPostgreSQL. Created materialized view is populated with new data from MaterializedPostgreSQL.

Error message and/or stacktrace There are 3 different error messages, depend on image, and probably something other

yandex/clickhouse-server:latest version 22.1.3.7 (official build)

2022.08.01 21:36:45.173790 [ 206 ] {} <Error> bool DB::MaterializedPostgreSQLConsumer::readFromReplicationSlot(): Code: 49. DB::Exception: Too large size (18392139944784180328) passed to allocator. It indicates an error. (LOGICAL_ERROR), Stack trace (when copying this message, always include the lines below):

0. DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool) @ 0xa82d07a in /usr/bin/clickhouse
1. DB::Exception::Exception<unsigned long&>(int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long&) @ 0xa87d072 in /usr/bin/clickhouse
2. Allocator<false, false>::checkSize(unsigned long) @ 0xa6e58cf in /usr/bin/clickhouse
3. Allocator<false, false>::realloc(void*, unsigned long, unsigned long, unsigned long) @ 0xa6e5e45 in /usr/bin/clickhouse
4. void DB::PODArrayBase<4ul, 4096ul, Allocator<false, false>, 15ul, 16ul>::reserveForNextSize<>() @ 0xa898f47 in /usr/bin/clickhouse
5. DB::insertPostgreSQLValue(DB::IColumn&, std::__1::basic_string_view<char, std::__1::char_traits<char> >, DB::ExternalResultDescription::ValueType, std::__1::shared_ptr<DB::IDataType const>, std::__1::unordered_map<unsigned long, DB::PostgreSQLArrayInfo, std::__1::hash<unsigned long>, std::__1::equal_to<unsigned long>, std::__1::allocator<std::__1::pair<unsigned long const, DB::PostgreSQLArrayInfo> > >&, unsigned long) @ 0x133170dc in /usr/bin/clickhouse
6. DB::MaterializedPostgreSQLConsumer::insertValue(DB::MaterializedPostgreSQLConsumer::StorageData::Buffer&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long) @ 0x1330c4c9 in /usr/bin/clickhouse
7. DB::MaterializedPostgreSQLConsumer::readTupleData(DB::MaterializedPostgreSQLConsumer::StorageData::Buffer&, char const*, unsigned long&, unsigned long, DB::MaterializedPostgreSQLConsumer::PostgreSQLQuery, bool) @ 0x1330cfb3 in /usr/bin/clickhouse
8. DB::MaterializedPostgreSQLConsumer::processReplicationMessage(char const*, unsigned long) @ 0x1330df1d in /usr/bin/clickhouse
9. DB::MaterializedPostgreSQLConsumer::readFromReplicationSlot() @ 0x1331249a in /usr/bin/clickhouse
10. DB::MaterializedPostgreSQLConsumer::consume(std::__1::vector<std::__1::pair<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >&) @ 0x13312d59 in /usr/bin/clickhouse
11. DB::PostgreSQLReplicationHandler::consumerFunc() @ 0x132ddf20 in /usr/bin/clickhouse
12. DB::BackgroundSchedulePoolTaskInfo::execute() @ 0x12f8470e in /usr/bin/clickhouse
13. DB::BackgroundSchedulePool::threadFunction() @ 0x12f870a7 in /usr/bin/clickhouse
14. ? @ 0x12f88170 in /usr/bin/clickhouse
15. ThreadPoolImpl<std::__1::thread>::worker(std::__1::__list_iterator<std::__1::thread, void*>) @ 0xa86f4b7 in /usr/bin/clickhouse
16. ? @ 0xa872ebd in /usr/bin/clickhouse
17. ? @ 0x400086d609 in ?
18. clone @ 0x40009a9293 in ?
 (version 22.1.3.7 (official build))

yandex/clickhouse-server:latest version 22.1.3.7 (official build) (the same image, sometimes ther is this one error, sometime - previous one)

2022.08.02 09:03:32.435449 [ 241 ] {} <Error> void DB::MaterializedPostgreSQLConsumer::syncTables(): Code: 393. DB::Exception: There is no query or query context has expired. (THERE_IS_NO_QUERY), Stack trace (when copying this message, always include the lines below):

0. DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool) @ 0xa82d07a in /usr/bin/clickhouse
1. DB::Context::getQueryContext() const @ 0x1349d34a in /usr/bin/clickhouse
2. DB::buildPushingToViewsChain(std::__1::shared_ptr<DB::IStorage> const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, std::__1::shared_ptr<DB::Context const>, std::__1::shared_ptr<DB::IAST> const&, bool, DB::ThreadStatus*, std::__1::atomic<unsigned long>*, DB::Block const&) @ 0x14a6e1dd in /usr/bin/clickhouse
3. DB::InterpreterInsertQuery::buildChainImpl(std::__1::shared_ptr<DB::IStorage> const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::Block const&, DB::ThreadStatus*, std::__1::atomic<unsigned long>*) @ 0x13a4aa6b in /usr/bin/clickhouse
4. DB::InterpreterInsertQuery::execute() @ 0x13a4ceb4 in /usr/bin/clickhouse
5. DB::MaterializedPostgreSQLConsumer::syncTables() @ 0x13310cd1 in /usr/bin/clickhouse
6. DB::MaterializedPostgreSQLConsumer::readFromReplicationSlot() @ 0x1331262c in /usr/bin/clickhouse
7. DB::MaterializedPostgreSQLConsumer::consume(std::__1::vector<std::__1::pair<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >&) @ 0x13312d59 in /usr/bin/clickhouse
8. DB::PostgreSQLReplicationHandler::consumerFunc() @ 0x132ddf20 in /usr/bin/clickhouse
9. DB::BackgroundSchedulePoolTaskInfo::execute() @ 0x12f8470e in /usr/bin/clickhouse
10. DB::BackgroundSchedulePool::threadFunction() @ 0x12f870a7 in /usr/bin/clickhouse
11. ? @ 0x12f88170 in /usr/bin/clickhouse
12. ThreadPoolImpl<std::__1::thread>::worker(std::__1::__list_iterator<std::__1::thread, void*>) @ 0xa86f4b7 in /usr/bin/clickhouse
13. ? @ 0xa872ebd in /usr/bin/clickhouse
14. ? @ 0x400086d609 in ?
15. clone @ 0x40009a9293 in ?
 (version 22.1.3.7 (official build))
2022.08.02 09:03:32.447263 [ 352 ] {} <Fatal> BaseDaemon: ########################################
2022.08.02 09:03:32.447689 [ 352 ] {} <Fatal> BaseDaemon: (version 22.1.3.7 (official build), build id: D11BC54A7FE20E44) (from thread 222) (no query) Received signal Segmentation fault (11)
2022.08.02 09:03:32.448025 [ 352 ] {} <Fatal> BaseDaemon: Address: 0x18 Access: read. Address not mapped to object.
2022.08.02 09:03:32.448443 [ 352 ] {} <Fatal> BaseDaemon: Stack trace: 0x13315e92 0x1330c4c9 0x1330cfb3 0x1330df1d 0x1331249a 0x13312d59 0x132ddf20 0x12f8470e 0x12f870a7 0x12f88170 0xa86f4b7 0xa872ebd 0x400086d609 0x40009a9293
2022.08.02 09:03:32.448853 [ 352 ] {} <Fatal> BaseDaemon: 2. DB::insertPostgreSQLValue(DB::IColumn&, std::__1::basic_string_view<char, std::__1::char_traits<char> >, DB::ExternalResultDescription::ValueType, std::__1::shared_ptr<DB::IDataType const>, std::__1::unordered_map<unsigned long, DB::PostgreSQLArrayInfo, std::__1::hash<unsigned long>, std::__1::equal_to<unsigned long>, std::__1::allocator<std::__1::pair<unsigned long const, DB::PostgreSQLArrayInfo> > >&, unsigned long) @ 0x13315e92 in /usr/bin/clickhouse
2022.08.02 09:03:32.449067 [ 352 ] {} <Fatal> BaseDaemon: 3. DB::MaterializedPostgreSQLConsumer::insertValue(DB::MaterializedPostgreSQLConsumer::StorageData::Buffer&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long) @ 0x1330c4c9 in /usr/bin/clickhouse
2022.08.02 09:03:32.449180 [ 352 ] {} <Fatal> BaseDaemon: 4. DB::MaterializedPostgreSQLConsumer::readTupleData(DB::MaterializedPostgreSQLConsumer::StorageData::Buffer&, char const*, unsigned long&, unsigned long, DB::MaterializedPostgreSQLConsumer::PostgreSQLQuery, bool) @ 0x1330cfb3 in /usr/bin/clickhouse
2022.08.02 09:03:32.449228 [ 352 ] {} <Fatal> BaseDaemon: 5. DB::MaterializedPostgreSQLConsumer::processReplicationMessage(char const*, unsigned long) @ 0x1330df1d in /usr/bin/clickhouse
2022.08.02 09:03:32.449261 [ 352 ] {} <Fatal> BaseDaemon: 6. DB::MaterializedPostgreSQLConsumer::readFromReplicationSlot() @ 0x1331249a in /usr/bin/clickhouse
2022.08.02 09:03:32.449337 [ 352 ] {} <Fatal> BaseDaemon: 7. DB::MaterializedPostgreSQLConsumer::consume(std::__1::vector<std::__1::pair<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >&) @ 0x13312d59 in /usr/bin/clickhouse
2022.08.02 09:03:32.449377 [ 352 ] {} <Fatal> BaseDaemon: 8. DB::PostgreSQLReplicationHandler::consumerFunc() @ 0x132ddf20 in /usr/bin/clickhouse
2022.08.02 09:03:32.449421 [ 352 ] {} <Fatal> BaseDaemon: 9. DB::BackgroundSchedulePoolTaskInfo::execute() @ 0x12f8470e in /usr/bin/clickhouse
2022.08.02 09:03:32.449462 [ 352 ] {} <Fatal> BaseDaemon: 10. DB::BackgroundSchedulePool::threadFunction() @ 0x12f870a7 in /usr/bin/clickhouse
2022.08.02 09:03:32.449488 [ 352 ] {} <Fatal> BaseDaemon: 11. ? @ 0x12f88170 in /usr/bin/clickhouse
2022.08.02 09:03:32.449538 [ 352 ] {} <Fatal> BaseDaemon: 12. ThreadPoolImpl<std::__1::thread>::worker(std::__1::__list_iterator<std::__1::thread, void*>) @ 0xa86f4b7 in /usr/bin/clickhouse
2022.08.02 09:03:32.449570 [ 352 ] {} <Fatal> BaseDaemon: 13. ? @ 0xa872ebd in /usr/bin/clickhouse
2022.08.02 09:03:32.449594 [ 352 ] {} <Fatal> BaseDaemon: 14. ? @ 0x400086d609 in ?
2022.08.02 09:03:32.449618 [ 352 ] {} <Fatal> BaseDaemon: 15. clone @ 0x40009a9293 in ?
2022.08.02 09:03:33.599628 [ 352 ] {} <Fatal> BaseDaemon: Calculated checksum of the binary: 38FD0E3944230CBD1E0C1028A9D68C83. There is no information about the reference checksum.

clickhouse/clickhouse-server:latest version 22.7.1.2484 (official build)

2022.08.02 09:00:45.130614 [ 197 ] {} <Error> void DB::MaterializedPostgreSQLConsumer::syncTables(): Code: 393. DB::Exception: There is no query or query context has expired. (THERE_IS_NO_QUERY), Stack trace (when copying this message, always include the lines below):

0. DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool) @ 0xa1b5588 in /usr/bin/clickhouse
1. DB::Context::getQueryContext() const @ 0x1309eae0 in /usr/bin/clickhouse
2. DB::buildPushingToViewsChain(std::__1::shared_ptr<DB::IStorage> const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, std::__1::shared_ptr<DB::Context const>, std::__1::shared_ptr<DB::IAST> const&, bool, DB::ThreadStatus*, std::__1::atomic<unsigned long>*, DB::Block const&) @ 0x145ef010 in /usr/bin/clickhouse
3. DB::InterpreterInsertQuery::buildChainImpl(std::__1::shared_ptr<DB::IStorage> const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::Block const&, DB::ThreadStatus*, std::__1::atomic<unsigned long>*) @ 0x134f5cf4 in /usr/bin/clickhouse
4. DB::InterpreterInsertQuery::execute() @ 0x134f9694 in /usr/bin/clickhouse
5. DB::MaterializedPostgreSQLConsumer::syncTables() @ 0x12d52d18 in /usr/bin/clickhouse
6. DB::MaterializedPostgreSQLConsumer::readFromReplicationSlot() @ 0x12d54c30 in /usr/bin/clickhouse
7. DB::MaterializedPostgreSQLConsumer::consume(std::__1::vector<std::__1::pair<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >&) @ 0x12d55268 in /usr/bin/clickhouse
8. DB::PostgreSQLReplicationHandler::consumerFunc() @ 0x12d21760 in /usr/bin/clickhouse
9. DB::BackgroundSchedulePoolTaskInfo::execute() @ 0x129d7708 in /usr/bin/clickhouse
10. DB::BackgroundSchedulePool::threadFunction() @ 0x129da660 in /usr/bin/clickhouse
11. ? @ 0x129db4f8 in /usr/bin/clickhouse
12. ThreadPoolImpl<std::__1::thread>::worker(std::__1::__list_iterator<std::__1::thread, void*>) @ 0xa275010 in /usr/bin/clickhouse
13. ? @ 0xa278084 in /usr/bin/clickhouse
14. start_thread @ 0x7624 in /usr/lib/aarch64-linux-gnu/libpthread-2.31.so
15. ? @ 0xd149c in /usr/lib/aarch64-linux-gnu/libc-2.31.so
 (version 22.7.1.2484 (official build))

Contributor guide