Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testdrive: Add reproducer for 8893 #31113

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions test/testdrive/statistics-cpu.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.

# Reproducer for database-issues#8893

$ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
ALTER SYSTEM SET storage_statistics_collection_interval = 1000
ALTER SYSTEM SET storage_statistics_interval = 2000

> CREATE CLUSTER stats_cluster SIZE '4-4'

> CREATE SECRET pgpass AS 'postgres'
> CREATE CONNECTION pg TO POSTGRES (
HOST postgres,
DATABASE postgres,
USER postgres,
PASSWORD SECRET pgpass
)

$ postgres-execute connection=postgres://postgres:postgres@postgres
ALTER USER postgres WITH replication;
DROP SCHEMA IF EXISTS public CASCADE;
DROP PUBLICATION IF EXISTS mz_source;
CREATE SCHEMA public;

CREATE TABLE t1 (f1 TEXT);
ALTER TABLE t1 REPLICA IDENTITY FULL;
INSERT INTO t1 VALUES ('one');
INSERT INTO t1 VALUES ('two');

CREATE PUBLICATION mz_source FOR ALL TABLES;

> CREATE SOURCE mz_source
IN CLUSTER stats_cluster
FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source');

$ set-from-sql var=previous-offset-committed
SELECT
(SUM(u.offset_committed))::text
FROM mz_sources s
JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
WHERE s.name IN ('mz_source')

> CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE t1);

> SELECT COUNT(*) > 0 FROM t1;
true

$ postgres-execute connection=postgres://postgres:postgres@postgres
INSERT INTO t1 VALUES ('three');

> SELECT
s.name,
SUM(u.offset_committed) > ${previous-offset-committed},
SUM(u.offset_known) >= SUM(u.offset_committed),
SUM(u.snapshot_records_known),
SUM(u.snapshot_records_staged)
FROM mz_sources s
JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
WHERE s.name IN ('mz_source')
GROUP BY s.name
ORDER BY s.name
mz_source true true 2 2

$ set-from-sql var=pre-restart-offset-committed
SELECT
(SUM(u.offset_committed))::text
FROM mz_sources s
JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
WHERE s.name IN ('mz_source')

> SELECT mz_unsafe.mz_sleep(3600);
Loading