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

Prevent CREATE TABLE from using dangling tablespace #876

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

gfphoenix78
Copy link
Contributor

When DROP TABLESPACE is running, it's possible to still use the dropping tablespace in CREATE TABLE. It's bad behavior that the table may use a dropped tablespace, which means that data files are stored out of the database.

This commit controls creating files in a tablespace and dropping tablespace running in exclusive mode. The key timelines for dropping a tablespace is:

  1. Lock tuple of pg_tablespace in AccessExclusive mode.
  2. CommitTransaction.
  3. Remove directories of the tablespace.
  4. Release the lock of the tablespace tuple.

Fixes #ISSUE_Number

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


When DROP TABLESPACE is running, it's possible to still use the dropping
tablespace in CREATE TABLE. It's bad behavior that the table may use
a dropped tablespace, which means that data files are stored out of
the database.

This commit controls creating files in a tablespace and dropping tablespace
running in exclusive mode. The key timelines for dropping a tablespace is:
1. Lock tuple of pg_tablespace in AccessExclusive mode.
2. CommitTransaction.
3. Remove directories of the tablespace.
4. Release the lock of the tablespace tuple.
Copy link
Contributor

@avamingli avamingli left a comment

Choose a reason for hiding this comment

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

Nice catch!
LGTM except two minimal comments.

src/backend/commands/tablespace.c Show resolved Hide resolved
src/backend/commands/tablespace.c Outdated Show resolved Hide resolved
@gfphoenix78
Copy link
Contributor Author

The lock of tablespace tuple can't handle queries from different database connection. I'll fix it.

my-ship-it
my-ship-it previously approved these changes Jan 17, 2025
src/backend/commands/tablespace.c Outdated Show resolved Hide resolved
@gfphoenix78
Copy link
Contributor Author

The lock of tablespace tuple can't handle queries from different database connection. I'll fix it.

fixed. Lock the shared object instead of database scoped object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants