You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ORCA planner run regression reindextable_while_reindex_idx_ao_part_btree
Operating System
CI [icw-orca-test]'s OS
Anything else
The regression is under ORCA, it seems has nothing to do with parallel, I guess.
Until this commit, GUC gp_appendonly_insert_files is not enabled with enable_parallel is false. So, it should has nothing with that too.
Any reindex is a writeable operation, can't be parallel in principle.
I saw this regression failed several times at Gitlab last month.
This bug is a lot more easier to reproduce under high load.
When running it in a stress-free environment (load average 2.5/8), the bug occurs in 1 out of 200 tries. But when I use a stress -u 6 to simulate resource-critical situation (load average 6.5/8) the bug occurs in under 5 times (at most 13 times) of tries.
Seems this bug can also be replicated w/o Orca enabled.
I use export PGOPTIONS='-c optimizer=off'; and psql -c 'explain select version();' to verify the setting is working before executing the test command to turn Orca off. The bug still shows.
Seems this bug is irrelevant to gp_appendonly_insert_files. gpconfig -s gp_appendonly_insert_files returns 4 as default value. and icw actually set it to 0 before run the test. I manually test the two situations, the bug occurred in both of them.
This bug is a lot more easier to reproduce under high load.
When running it in a stress-free environment (load average 2.5/8), the bug occurs in 1 out of 200 tries. But when I use a
stress -u 6 to simulate resource-critical situation (load average 6.5/8) the bug occurs in under 5 times (at most 13 times) of tries.
Nice. Reproduce is a good start.
Seems this bug is irrelevant to gp_appendonly_insert_files.
gpconfig -s gp_appendonly_insert_files returns 4 as default value. and icw actually set it to 0 before run the test. I manually test the two situations, the bug occurred in both of them.
Yeah, it should has nothing to do with that GUC. I prefer to take a look at reindex concurrently related codes.
I'll try to further dive into this issue from now on.
I've found that three part_btree-related tests (reindextable_while_reindex_idx_aoco_part_btree, reindextable_while_reindex_idx_ao_part_btree and reindextable_while_reindex_idx_heap_part_btree) are all problematic whereas three corresponding bitmap-related tests are all fine. Things start getting interesting... 🤔 🤔
This issue is mainly due to the unstable nature of the three part_btree-related tests themselves. They use tx1 to lock the table exclusively, then release the lock for tx2 and tx3 to compete (at the red arrow). The tests actually assume that the txn2 get the lock before txn3, and txn2 blocked by it until txn3 completes:
When it's not the case, i.e., when txn2 get the lock and finished running in the small interval at the red arrow, the assumption no longer stands, causing the test to fail.
why snapshot and MVCC cannot prevent this
this issue is irrelevant to MVCC and snapshot. In postgres and greenplum a snapshot is not issued at the begin command, but at the first non-transaction-management statement of the txn, that's exactly when txn2 and 3 already competes for lock. So this issue is only caused by lock.
why reordering 3: begin stmt cannot fix this
One might say that reorder begin to the beginning of the file could fix this. Unfortunately, this is not the case. Due to another bug also found in postgres and greenplum, select-s from pg_class sometimes could return intermediate result even in RR isolation level, so "fixing this issue by reordering 3: begin stmt" can actually only transform this issue to another issue, wherein due to the duplication records INSERT 16 are reported (the correct answer is INSERT 14). This is strange because although updates w.r.t. pg_class is in-place not transactional, it should directly overwrite the tuple instead of exposing a mixed, intermediate state to the user.
Any prove on this
Use @pre_run and @post_run hooks one can reliability detect whether txn2 is still blocked by txn3 when txn3 get the lock.
How to fix this
A workaround has been proposed by generally move some test work from 'ctx diff' into the SQL file itself:
apparently this is not the best way. but to stabilize the test and not introduce any alternation to the isolation2 test suite, this is the best we can do I suppose.
A PR is on the way once I packed all these into a nice write-up in the comment of the test file.
Activity
github-actions commentedon Jul 20, 2023
Hey, @avamingli welcome!🎊 Thanks for taking the time to point this out.🙌
Ray-Eldath commentedon Aug 4, 2023
initial findings:
When running it in a stress-free environment (load average 2.5/8), the bug occurs in 1 out of 200 tries. But when I use a
stress -u 6to simulate resource-critical situation (load average 6.5/8) the bug occurs in under 5 times (at most 13 times) of tries.I use
export PGOPTIONS='-c optimizer=off';andpsql -c 'explain select version();'to verify the setting is working before executing the test command to turn Orca off. The bug still shows.gp_appendonly_insert_files.gpconfig -s gp_appendonly_insert_filesreturns4as default value. and icw actually set it to0before run the test. I manually test the two situations, the bug occurred in both of them.scripts to reproduce the bug:
avamingli commentedon Aug 4, 2023
Nice. Reproduce is a good start.
Yeah, it should has nothing to do with that GUC. I prefer to take a look at
reindex concurrentlyrelated codes.Ray-Eldath commentedon Aug 4, 2023
I just found that GPDB has the same bug as well. This bug is from the upstream.
I'll try to further dive into this issue from now on.
I've found that three
part_btree-related tests (reindextable_while_reindex_idx_aoco_part_btree,reindextable_while_reindex_idx_ao_part_btreeandreindextable_while_reindex_idx_heap_part_btree) are all problematic whereas three correspondingbitmap-related tests are all fine. Things start getting interesting... 🤔 🤔Ray-Eldath commentedon Aug 17, 2023
Concluding Remarks
This issue is mainly due to the unstable nature of the three
part_btree-related tests themselves. They use tx1 to lock the table exclusively, then release the lock for tx2 and tx3 to compete (at the red arrow). The tests actually assume that the txn2 get the lock before txn3, and txn2 blocked by it until txn3 completes:When it's not the case, i.e., when txn2 get the lock and finished running in the small interval at the red arrow, the assumption no longer stands, causing the test to fail.
why snapshot and MVCC cannot prevent this
this issue is irrelevant to MVCC and snapshot. In postgres and greenplum a snapshot is not issued at the
begincommand, but at the first non-transaction-management statement of the txn, that's exactly when txn2 and 3 already competes for lock. So this issue is only caused by lock.why reordering
3: beginstmt cannot fix thisOne might say that reorder
beginto the beginning of the file could fix this. Unfortunately, this is not the case. Due to another bug also found in postgres and greenplum,select-s frompg_classsometimes could return intermediate result even in RR isolation level, so "fixing this issue by reordering3: beginstmt" can actually only transform this issue to another issue, wherein due to the duplication recordsINSERT 16are reported (the correct answer isINSERT 14). This is strange because although updates w.r.t.pg_classis in-place not transactional, it should directly overwrite the tuple instead of exposing a mixed, intermediate state to the user.Any prove on this
Use
@pre_runand@post_runhooks one can reliability detect whether txn2 is still blocked by txn3 when txn3 get the lock.How to fix this
A workaround has been proposed by generally move some test work from 'ctx diff' into the SQL file itself:

apparently this is not the best way. but to stabilize the test and not introduce any alternation to the isolation2 test suite, this is the best we can do I suppose.
A PR is on the way once I packed all these into a nice write-up in the comment of the test file.
Fix unstable tests reindextable_while_reindex_idx
Fix unstable tests reindextable_while_reindex_idx
Fix unstable tests reindextable_while_reindex_idx
Fix unstable tests reindextable_while_reindex_idx
Refactor gp_activetable (#26)
Refactor gp_activetable (#26)
Refactor gp_activetable (apache#26)
Refactor gp_activetable (apache#26)
Refactor gp_activetable (apache#26)
Refactor gp_activetable (apache#26)
Refactor gp_activetable (apache#26)
Add yezzey build option (apache#26)
Add yezzey build option (#26)