-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve HEAP_COMBOCID when restoring t_cid from WAL (#8503)
## Problem See #8499 ## Summary of changes Save HEAP_COMBOCID flag in WAL and do not clear it in redo handlers. Related Postgres PRs: neondatabase/postgres#457 neondatabase/postgres#458 neondatabase/postgres#459 ## Checklist before requesting a review - [ ] I have performed a self-review of my code. - [ ] If it is a core feature, I have added thorough tests. - [ ] Do we need to implement analytics? if so did you add the relevant metrics to the dashboard? - [ ] If this PR requires public announcement, mark it with /release-notes label and add several sentences in this section. ## Checklist before merging - [ ] Do not forget to reformat commit message to not include the above checklist --------- Co-authored-by: Konstantin Knizhnik <knizhnik@neon.tech> Co-authored-by: Heikki Linnakangas <heikki@neon.tech>
- Loading branch information
1 parent
c624317
commit 7a1736d
Showing
6 changed files
with
154 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
from fixtures.neon_fixtures import NeonEnvBuilder | ||
|
||
|
||
def do_combocid_op(neon_env_builder: NeonEnvBuilder, op): | ||
env = neon_env_builder.init_start() | ||
endpoint = env.endpoints.create_start( | ||
"main", | ||
config_lines=[ | ||
"shared_buffers='1MB'", | ||
], | ||
) | ||
|
||
conn = endpoint.connect() | ||
cur = conn.cursor() | ||
n_records = 1000 | ||
|
||
cur.execute("CREATE EXTENSION neon_test_utils") | ||
|
||
cur.execute("create table t(id integer, val integer)") | ||
|
||
cur.execute("begin") | ||
cur.execute("insert into t values (1, 0)") | ||
cur.execute("insert into t values (2, 0)") | ||
cur.execute(f"insert into t select g, 0 from generate_series(3,{n_records}) g") | ||
|
||
# Open a cursor that scroll it halfway through | ||
cur.execute("DECLARE c1 NO SCROLL CURSOR WITHOUT HOLD FOR SELECT * FROM t") | ||
cur.execute("fetch 500 from c1") | ||
rows = cur.fetchall() | ||
assert len(rows) == 500 | ||
|
||
# Perform specified operation | ||
cur.execute(op) | ||
|
||
# Clear the cache, so that we exercise reconstructing the pages | ||
# from WAL | ||
cur.execute("SELECT clear_buffer_cache()") | ||
|
||
# Check that the cursor opened earlier still works. If the | ||
# combocids are not restored correctly, it won't. | ||
cur.execute("fetch all from c1") | ||
rows = cur.fetchall() | ||
assert len(rows) == 500 | ||
|
||
cur.execute("rollback") | ||
|
||
|
||
def test_combocid_delete(neon_env_builder: NeonEnvBuilder): | ||
do_combocid_op(neon_env_builder, "delete from t") | ||
|
||
|
||
def test_combocid_update(neon_env_builder: NeonEnvBuilder): | ||
do_combocid_op(neon_env_builder, "update t set val=val+1") | ||
|
||
|
||
def test_combocid_lock(neon_env_builder: NeonEnvBuilder): | ||
do_combocid_op(neon_env_builder, "select * from t for update") | ||
|
||
|
||
def test_combocid_multi_insert(neon_env_builder: NeonEnvBuilder): | ||
env = neon_env_builder.init_start() | ||
endpoint = env.endpoints.create_start( | ||
"main", | ||
config_lines=[ | ||
"shared_buffers='1MB'", | ||
], | ||
) | ||
|
||
conn = endpoint.connect() | ||
cur = conn.cursor() | ||
n_records = 1000 | ||
|
||
cur.execute("CREATE EXTENSION neon_test_utils") | ||
|
||
cur.execute("create table t(id integer, val integer)") | ||
file_path = f"{endpoint.pg_data_dir_path()}/t.csv" | ||
cur.execute(f"insert into t select g, 0 from generate_series(1,{n_records}) g") | ||
cur.execute(f"copy t to '{file_path}'") | ||
cur.execute("truncate table t") | ||
|
||
cur.execute("begin") | ||
cur.execute(f"copy t from '{file_path}'") | ||
|
||
# Open a cursor that scroll it halfway through | ||
cur.execute("DECLARE c1 NO SCROLL CURSOR WITHOUT HOLD FOR SELECT * FROM t") | ||
cur.execute("fetch 500 from c1") | ||
rows = cur.fetchall() | ||
assert len(rows) == 500 | ||
|
||
# Delete all the rows. Because all of the rows were inserted earlier in the | ||
# same transaction, all the rows will get a combocid. | ||
cur.execute("delete from t") | ||
# Clear the cache, so that we exercise reconstructing the pages | ||
# from WAL | ||
cur.execute("SELECT clear_buffer_cache()") | ||
|
||
# Check that the cursor opened earlier still works. If the | ||
# combocids are not restored correctly, it won't. | ||
cur.execute("fetch all from c1") | ||
rows = cur.fetchall() | ||
assert len(rows) == 500 | ||
|
||
cur.execute("rollback") | ||
|
||
|
||
def test_combocid(neon_env_builder: NeonEnvBuilder): | ||
env = neon_env_builder.init_start() | ||
endpoint = env.endpoints.create_start("main") | ||
|
||
conn = endpoint.connect() | ||
cur = conn.cursor() | ||
n_records = 100000 | ||
|
||
cur.execute("create table t(id integer, val integer)") | ||
cur.execute(f"insert into t values (generate_series(1,{n_records}), 0)") | ||
|
||
cur.execute("begin") | ||
|
||
cur.execute("update t set val=val+1") | ||
assert cur.rowcount == n_records | ||
cur.execute("update t set val=val+1") | ||
assert cur.rowcount == n_records | ||
cur.execute("update t set val=val+1") | ||
assert cur.rowcount == n_records | ||
|
||
cur.execute("delete from t") | ||
assert cur.rowcount == n_records | ||
cur.execute("delete from t") | ||
assert cur.rowcount == 0 | ||
|
||
cur.execute(f"insert into t values (generate_series(1,{n_records}), 0)") | ||
cur.execute("update t set val=val+1") | ||
assert cur.rowcount == n_records | ||
cur.execute("update t set val=val+1") | ||
assert cur.rowcount == n_records | ||
cur.execute("update t set val=val+1") | ||
assert cur.rowcount == n_records | ||
|
||
cur.execute("rollback") |
Submodule postgres-v14
updated
2 files
+12 −8 | src/backend/access/heap/heapam.c | |
+1 −0 | src/include/access/heapam_xlog.h |
Submodule postgres-v15
updated
2 files
+12 −8 | src/backend/access/heap/heapam.c | |
+1 −0 | src/include/access/heapam_xlog.h |
Submodule postgres-v16
updated
2 files
+5 −2 | src/backend/access/heap/heapam.c | |
+1 −0 | src/include/access/heapam_xlog.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
{ | ||
"v16": [ | ||
"16.3", | ||
"5ea106b2583285849784e774b39d62eb2615bd5d" | ||
"47a9122a5a150a3217fafd3f3d4fe8e020ea718a" | ||
], | ||
"v15": [ | ||
"15.7", | ||
"39c51c33b383239c78b86afe561679f980e44842" | ||
"46b4b235f38413ab5974bb22c022f9b829257674" | ||
], | ||
"v14": [ | ||
"14.12", | ||
"a48faca1d9aef59649dd1bf34bc1b6303fa3489e" | ||
"3fd7a45f8aae85c080df6329e3c85887b7f3a737" | ||
] | ||
} |
7a1736d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2236 tests run: 2155 passed, 2 failed, 79 skipped (full report)
Failures on Postgres 14
test_pgbench_intensive_init_workload[neon_off-github-actions-selfhosted-1000]
: releasetest_heavy_write_workload[neon_off-github-actions-selfhosted-10-5-5]
: releaseCode coverage* (full report)
functions
:32.3% (7161 of 22162 functions)
lines
:50.3% (57922 of 115177 lines)
* collected from Rust tests only
7a1736d at 2024-08-14T07:06:55.483Z :recycle: