Skip to content

gh-134004: Dbm vacuuming #134028

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

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

Conversation

Andrea-Oliveri
Copy link

@Andrea-Oliveri Andrea-Oliveri commented May 15, 2025

gh-134004:

  1. Added a .reorganize() method to dbm.sqlite and dbm.dumb which allows to retrieve unused space from database files. Name was chosen for consistency with dbm.gnu.reorganize(). dbm.ndbm` does not support any such optimization.
  2. dbm.dumb.reorganize() is a new custom implementation rewriting the database file in-place and removing the gaps left by deletions, then truncating the excess.
  3. Added 3 tests to ensure .reorganize() runs as expected on all compatible dbm submodules.
  4. Updated the documentation of dbm module to include contributed methods as well as to highlight some of the limitations of the current implementations, such as lack of concurrency compatibility (for dbm.dumb) and lack of automatic reorganizing
  5. Added .reorganize() method to shelve to expose dbm's submodules methods
  6. Added documentation for shelve.reorganize()

Note: Unfortunately I did not feel comfortable changing the C code at this time, so I chose not to add an empty .reorganize() method to dbm.ndbm. This resulted in:

  1. Inconsistencies between the methods supported by dbm submodules.
  2. The added tests need to verify, using hasattr(), whether the dbm objects have the .reorganize() method and succeed early if that is not the case.
  3. The documentation clearly explains the situation described here.

@bedevere-app
Copy link

bedevere-app bot commented May 15, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot
Copy link

python-cla-bot bot commented May 15, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@Andrea-Oliveri Andrea-Oliveri changed the title gh134004: Dbm vacuuming gh-134004: Dbm vacuuming May 15, 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.

1 participant