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

Fix segfault when deleting from compressed chunk #5643

Merged
merged 1 commit into from
May 3, 2023

Conversation

sb230132
Copy link
Contributor

@sb230132 sb230132 commented May 1, 2023

During UPDATE/DELETE on compressed hypertables, we iterate over plan
tree to collect all scan nodes. For each scan nodes there can be
filter conditions.

Prior to this patch we collect only first filter condition and use
for first chunk which may be wrong. In this patch as and when we
encounter a target scan node, we immediately process those chunks.

Fixes #5640

@codecov
Copy link

codecov bot commented May 1, 2023

Codecov Report

Merging #5643 (6feab56) into main (90f585e) will decrease coverage by 0.03%.
The diff coverage is 97.14%.

@@            Coverage Diff             @@
##             main    #5643      +/-   ##
==========================================
- Coverage   90.98%   90.96%   -0.03%     
==========================================
  Files         230      230              
  Lines       54460    54446      -14     
==========================================
- Hits        49550    49525      -25     
- Misses       4910     4921      +11     
Impacted Files Coverage Δ
tsl/src/compression/compression.h 0.00% <ø> (ø)
tsl/src/init.c 96.29% <ø> (ø)
tsl/src/compression/compression.c 95.79% <96.96%> (-0.06%) ⬇️
src/nodes/hypertable_modify.c 72.95% <100.00%> (-0.64%) ⬇️

... and 6 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@sb230132 sb230132 marked this pull request as ready for review May 1, 2023 13:32
@sb230132 sb230132 requested a review from antekresic May 1, 2023 13:32
@github-actions
Copy link

github-actions bot commented May 1, 2023

@mkindahl, @gayyappan: please review this pull request.

Powered by pull-review

Copy link
Contributor

@antekresic antekresic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs tests that cover this specific issue.

@sb230132
Copy link
Contributor Author

sb230132 commented May 2, 2023

Needs tests that cover this specific issue.

For segfault there don't seem to be any testcase for now. However i found testcase which results in unwanted decompression on join tables. For this i have added testcase.

@antekresic antekresic self-requested a review May 2, 2023 06:46
@sb230132 sb230132 removed the request for review from gayyappan May 2, 2023 06:54
Copy link
Member

@svenklemm svenklemm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only fixes part of the issues mentioned by the ticket and does not adress the problems with JOINS.

Copy link
Contributor

@mkindahl mkindahl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why you disable the changelog check. You need to add one eventually anyway.

@sb230132 sb230132 force-pushed the compress_segfault branch 2 times, most recently from 92d2efb to fe9e57c Compare May 2, 2023 11:02
@sb230132
Copy link
Contributor Author

sb230132 commented May 2, 2023

Not sure why you disable the changelog check. You need to add one eventually anyway.

Fixed.

@sb230132
Copy link
Contributor Author

sb230132 commented May 2, 2023

Not sure why you disable the changelog check. You need to add one eventually anyway.

This only fixes part of the issues mentioned by the ticket and does not adress the problems with JOINS.

For segfault, iam unable to get a testcase. However now i save filters for each chunk separately and process each chunk against its own filters so, the issue of segfault occurring due to mismatch in attribute number should not occur.

@svenklemm
Copy link
Member

Not sure why you disable the changelog check. You need to add one eventually anyway.

We don't need changelog entry since the bug is not present in any released version.

src/nodes/hypertable_modify.c Outdated Show resolved Hide resolved
src/nodes/hypertable_modify.c Show resolved Hide resolved
@sb230132 sb230132 force-pushed the compress_segfault branch 2 times, most recently from 0d92431 to dc9f185 Compare May 3, 2023 08:25
@sb230132 sb230132 requested a review from svenklemm May 3, 2023 08:26
tsl/test/shared/sql/compression_dml.sql Outdated Show resolved Hide resolved
tsl/src/compression/compression.c Outdated Show resolved Hide resolved
@sb230132 sb230132 force-pushed the compress_segfault branch 2 times, most recently from 3c25745 to 04e1a1a Compare May 3, 2023 12:17
@sb230132 sb230132 requested a review from svenklemm May 3, 2023 12:22
Copy link
Contributor

@antekresic antekresic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, we can postpone compression test refactoring in a followup PR.

Copy link
Member

@svenklemm svenklemm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some bugs will need to be fixed in followup PRs but approving to unblock other followup PRs.

Copy link
Contributor

@kgyrtkirk kgyrtkirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that I've already posted this....can be handled later as a follow up as well

scankeys =
build_update_delete_scankeys(&decompressor, filters, &num_scankeys, &null_columns);
}
if (decompress_batches(&decompressor,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the return value contract of this method? (its not documented...)

...but anyway - I think it would be better to instead of passing a writeable bool ptr; have that as return value?

note that: currently I see 3 return-s in this method; from which:

  • 2 doesn't free scankeys
    • not necessarily an issue - I think you can just remove the if+pfree
  • 1 may not end with an ERROR ; and can exit the method without closing the heapScan - what could be the consequences of that?

...and I now wonder why that method tries to mask concurrent deletes/updates on the compressed table - instead of erroring out straight away? as it is now it may leave the table in an inconsistent state...

                        if (IsolationUsesXactSnapshot())
                                ereport(ERROR,
                                                (errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
                                                 errmsg("could not serialize access due to concurrent update")));

During UPDATE/DELETE on compressed hypertables, we iterate over plan
tree to collect all scan nodes. For each scan nodes there can be
filter conditions.

Prior to this patch we collect only first filter condition and use
for first chunk which may be wrong. In this patch as and when we
encounter a target scan node, we immediatly process those chunks.

Fixes timescale#5640
@sb230132 sb230132 enabled auto-merge (rebase) May 3, 2023 17:08
@sb230132 sb230132 merged commit 769f9fe into timescale:main May 3, 2023
39 of 41 checks passed
@timescale-automation
Copy link

Automated backport to 2.10.x not done: cherry-pick failed.

Git status

HEAD detached at origin/2.10.x
You are currently cherry-picking commit 769f9fe6.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   tsl/test/sql/compression.sql

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	both modified:   src/cross_module_fn.h
	both modified:   src/nodes/hypertable_modify.c
	both modified:   tsl/src/compression/compression.c
	both modified:   tsl/src/compression/compression.h
	both modified:   tsl/src/init.c
	both modified:   tsl/test/expected/compression.out
	deleted by us:   tsl/test/expected/compression_update_delete.out
	deleted by us:   tsl/test/sql/compression_update_delete.sql


Job log

@timescale-automation timescale-automation added the auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) label May 3, 2023
@sb230132 sb230132 deleted the compress_segfault branch May 24, 2023 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segfault when deleting from compressed chunk
7 participants