mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-10 15:02:56 +00:00
In order to exclude problems with synchronizing disk and memory logical size is not stored in metadata on disk. It is calculated on timeline "start" by scanning the contents of layered repo and then size is maintained via an atomic variable. This patch also adds new endpoint to pageserver http api: branch detail. It allows retrieval of a particular branch info by its name. Size info is also added to the response of the endpoint and used in tests.
40 lines
1.6 KiB
Python
40 lines
1.6 KiB
Python
from contextlib import closing
|
|
from uuid import UUID
|
|
import psycopg2.extras
|
|
from fixtures.zenith_fixtures import PostgresFactory, ZenithPageserver
|
|
|
|
|
|
def test_timeline_size(
|
|
zenith_cli, pageserver: ZenithPageserver, postgres: PostgresFactory, pg_bin
|
|
):
|
|
# Branch at the point where only 100 rows were inserted
|
|
zenith_cli.run(["branch", "test_timeline_size", "empty"])
|
|
|
|
client = pageserver.http_client()
|
|
res = client.branch_detail(UUID(pageserver.initial_tenant), "test_timeline_size")
|
|
assert res["current_logical_size"] == res["current_logical_size_non_incremental"]
|
|
|
|
pgmain = postgres.create_start("test_timeline_size")
|
|
print("postgres is running on 'test_timeline_size' branch")
|
|
|
|
with closing(pgmain.connect()) as conn:
|
|
with conn.cursor() as cur:
|
|
cur.execute("SHOW zenith.zenith_timeline")
|
|
|
|
# Create table, and insert the first 100 rows
|
|
cur.execute("CREATE TABLE foo (t text)")
|
|
cur.execute(
|
|
"""
|
|
INSERT INTO foo
|
|
SELECT 'long string to consume some space' || g
|
|
FROM generate_series(1, 10) g
|
|
"""
|
|
)
|
|
|
|
res = client.branch_detail(UUID(pageserver.initial_tenant), "test_timeline_size")
|
|
assert res["current_logical_size"] == res["current_logical_size_non_incremental"]
|
|
cur.execute("TRUNCATE foo")
|
|
|
|
res = client.branch_detail(UUID(pageserver.initial_tenant), "test_timeline_size")
|
|
assert res["current_logical_size"] == res["current_logical_size_non_incremental"]
|