Skip to content

Add recompression spin lock #8018

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

Merged
merged 3 commits into from
May 6, 2025

Conversation

kpan2034
Copy link
Member

@kpan2034 kpan2034 commented Apr 25, 2025

Recompression tries to take an ExclusiveLock at the end of
compression in order to update the chunk status from partial to fully
compressed. This is mandatory when unique constraints are present in
the table. Otherwise recompression is aborted.

This adds a spin-lock during the ExclusiveLock only in the case of
unique constraints being present on the table. This functionality is
behind a GUC to allow users to maintain old behaviour.

Copy link

codecov bot commented Apr 25, 2025

Codecov Report

Attention: Patch coverage is 74.07407% with 7 lines in your changes missing coverage. Please review.

Project coverage is 82.14%. Comparing base (59f50f2) to head (5698591).
Report is 956 commits behind head on main.

Files with missing lines Patch % Lines
tsl/src/compression/recompress.c 74.07% 2 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8018      +/-   ##
==========================================
+ Coverage   80.06%   82.14%   +2.07%     
==========================================
  Files         190      253      +63     
  Lines       37181    47209   +10028     
  Branches     9450    11894    +2444     
==========================================
+ Hits        29770    38780    +9010     
- Misses       2997     3724     +727     
- Partials     4414     4705     +291     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

break;
}

(void) WaitLatch(MyLatch,
Copy link
Member

@akuzm akuzm Apr 28, 2025

Choose a reason for hiding this comment

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

Just for my understanding, why do we manually build a spinlock here? One reason I can imagine is that we want a predictable timeout and WaitOnLock doesn't have an explicit interface for that. I am wondering whether we could change the LockTimeout instead. This would give us better progress because we'd be on the wait queue, and also interrupt the interfering autovacuum tasks.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are two main goals with this PR: 1. Introduce a timeout so that compress_chunk doesn't block indefinitely. 2. Increase concurrency of DML operations in the uncompressed chunk.

I think we should avoid getting into the wait queue since that would block other DML operations.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should avoid getting into the wait queue since that would block other DML operations.

Isn't the purpose of the spin lock to block other dml operations?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we're in the wait queue, we'll block any new DML operations, which would reduce concurrency.
Since we use a spin lock, we won't do this.

@kpan2034 kpan2034 force-pushed the add-recompression-spin-lock branch 4 times, most recently from 1d20981 to 5866acb Compare April 29, 2025 21:07
@kpan2034 kpan2034 added this to the v2.20.0 milestone Apr 29, 2025
@kpan2034 kpan2034 force-pushed the add-recompression-spin-lock branch from 5866acb to 193afc3 Compare April 29, 2025 21:12
@kpan2034 kpan2034 marked this pull request as ready for review April 29, 2025 21:12
@kpan2034
Copy link
Member Author

Removed the GUC based on discussion with @antekresic.

There is already a GUC in place to require heavy locks during recompression, that can be used to avoid the spin-lock - enable_exclusive_locking_recompression

Recompression tries to take an ExclusiveLock at the end of compression
in order to update the chunk status from partial to fully compressed.
This is mandatory when unique constraints are present in the table.
Otherwise recompression is aborted.

This adds a spin-lock when acquiring an ExclusiveLock only in the case of
unique constraints being present on the table.
@kpan2034 kpan2034 force-pushed the add-recompression-spin-lock branch from 193afc3 to a43ce3e Compare May 5, 2025 19:24
@kpan2034 kpan2034 force-pushed the add-recompression-spin-lock branch from 546a0fe to ec3c134 Compare May 5, 2025 21:32
@kpan2034
Copy link
Member Author

kpan2034 commented May 5, 2025

Not sure why the code coverage check is still failing. The line should definitely be hit since a debug_waitpoint was added.

@kpan2034 kpan2034 force-pushed the add-recompression-spin-lock branch from 5698591 to 2abcdb3 Compare May 5, 2025 23:58
Comment on lines +564 to +568
if (ConditionalLockRelation(uncompressed_chunk_rel, ExclusiveLock))
{
try_updating_chunk_status(uncompressed_chunk, uncompressed_chunk_rel);
break;
}
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if this should be after the waitlatch since you will enter in this branch after failure on the first ConditionalLockRelation. Does it make sense?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did it this way because I wanted to keep the structure consistent with how Postgres implements a similar spin lock.

@kpan2034 kpan2034 enabled auto-merge (squash) May 6, 2025 03:03
@kpan2034 kpan2034 merged commit 0971d13 into timescale:main May 6, 2025
43 of 44 checks passed
@kpan2034 kpan2034 deleted the add-recompression-spin-lock branch May 6, 2025 03:05
@philkra philkra mentioned this pull request May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants