reorganize#

Shrink the file after many deletes: the data is copied, without the free space, into a new file that takes the old one’s place and mode.

Synopsis#

delete @h{@old_keys};
$db->reorganize;

What you get back#

0, or -1 with errno set: GDBM_READER_CANT_REORGANIZE for a database tied GDBM_READER, GDBM_REORGANIZE_FAILED when it cannot be done.

Edge cases#

  • It fails while another tie in the same process has the file open, and should not be run while other processes use the file.

  • Writes pending are written first.

Differences from upstream#

The work is a copy of the file without its free pages; gdbm rebuilds its own file instead. The result is the same: a smaller file with the same data. Covered by t/82-native/Peta-LMDB/090-gdbm.t.

See also#

  • count - how many keys there are

  • sync - writes what is pending without shrinking