Skip to content

5.0.0

Latest

Choose a tag to compare

@cberner cberner released this 18 Nov 20:39
· 3 commits to master since this release

Breaking changes

The encoding of Option<&str>, Option<String>, Option<bool>, and Option<char> has been changed
to optimize the storage of these types. The new encoding is not compatible with the one used in prior versions.
Tables that contain these Option types, and were created prior to version 5.0, will fail to open with
TableTypeMismatch. To load them, wrap the inner type in the new Legacy type. For example,
TableDefinition<u64, Option<&str>> becomes TableDefinition<u64, Option<Legacy<&str>>>. This also
applies to an Option that is nested inside another type, such as a tuple.
The recommended pattern to migrate is to create a new table, and then copy the data from the old table to the new table.

Important: If you have implemented Value for your own type, and its encoding uses
Option<&str>, Option<String>, Option<bool>, or Option<char> (including inside a Vec,
array, or tuple), redb cannot detect the change and will silently misread existing tables.
Change the implementation to use Option<Legacy<T>> to read existing tables, and use a new
TypeName for the new encoding.

A number of other APIs have changed in breaking ways:

  • Remove the inherent get() and range() methods of ReadOnlyTable and ReadOnlyMultimapTable.
    They returned 'static guards and iterators, which did not keep the transaction alive. Use the
    methods on ReadableTable and ReadableMultimapTable instead, or get_owned() and range_owned()
    if the result must outlive the table.
  • Change Range and MultimapRange to borrow the table until they are dropped. Mutating a table
    while a range over it is still in scope could panic, and is now a compile error.
  • Change Entry, OccupiedEntry, and VacantEntry to take a second lifetime, for the key, which
    no longer needs to live as long as the borrow of the table.
  • Change FileBackend::new() to return FileBackend instead of a Result.
  • Change ReadableTable::lower_bound() and ReadableTable::upper_bound() to be required methods.
  • Change ReadableDatabase to be a sealed trait.
  • Remove Table::extract_from_if(). Use extract_if() instead.
  • Change Table::extract_if() to take a range as its first argument, like
    BTreeMap::extract_if(). Use extract_if(.., predicate) to visit the whole table.
  • Remove Builder::create_file(). Use Builder::create_with_backend(FileBackend::new(file)) instead.
  • Remove WriteTransaction::print_allocated_page_debug().
  • Remove From<PoisonError<T>> for StorageError and Error.
  • Change range(), range_owned(), retain_in(), and extract_if() to take a KeyRange instead
    of a RangeBounds. The key type no longer needs to be specified. For example,
    table.range::<u64>(..) becomes table.range(..).
  • Change the I/O methods of StorageBackend to return BackendError instead of io::Error. An
    io::Error can still be converted with ?. Note that an io::Error of kind Unsupported is
    now converted to BackendError::Io instead of BackendError::Unsupported. Lock methods may
    return either to indicate that locking is not supported.
  • Change the TableTypeMismatch and TypeDefinitionChanged variants of TableError and Error
    to contain a Box. Their fields are replaced by methods on the new TableTypeMismatch and
    TypeDefinitionInfo structs.
  • Change Database::compact() to take a CompactionMode, which selects how thoroughly to compact.
    Use compact(CompactionMode::Balanced) to compact as before.
  • Remove the chrono_v0_4 feature, because the chrono crate is no longer maintained. To read
    existing tables of its types, implement Value and Key for a type of your own with the same
    TypeName and encoding.

no_std support

redb can now be built without the standard library by disabling the std feature.

If you depend on redb with default-features = false, add features = ["std"] to continue
building with the standard library.

File locking changes

Database files are now locked using only byte-range locks. On Linux, do not use redb 4.2 or earlier
on a database that redb 5.x has open. Their locking is incompatible, and only an ExclusiveWriter
writer can detect the older version.

A read-only open now fails with DatabaseError::LockProtocolMismatch if a read-only handle from
redb 4.3 or 4.4 has the file open. Previously, this was allowed in ExclusiveWriter mode.

Other changes

  • Add CompactionMode::Maximum. This reclaims the free space inside pages, which
    CompactionMode::Balanced leaves for later inserts to fill.
  • Add Legacy<T>, for reading tables of Option<T> that were created prior to version 5.0.
  • Add BackendError::Other, for errors from a storage backend that are not an io::Error. It is
    reported as StorageError::Backend and Error::Backend.

Bug fixes

  • Fix a bug where compact() on a SingleWriter or MultiWriter database could return
    CompactionError::TransactionInProgress, while an attempt to open the same file for writing in
    ExclusiveWriter mode was being refused.
  • Fix a process abort when a panic, such as one from a StorageBackend, unwound while a page of
    the write buffer was in use. The panic now propagates, and later operations return
    StorageError::PreviousIo until the database is reopened.