Repository navigation
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()andrange()methods ofReadOnlyTableandReadOnlyMultimapTable.
They returned'staticguards and iterators, which did not keep the transaction alive. Use the
methods onReadableTableandReadableMultimapTableinstead, orget_owned()andrange_owned()
if the result must outlive the table. - Change
RangeandMultimapRangeto 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, andVacantEntryto 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 returnFileBackendinstead of aResult. - Change
ReadableTable::lower_bound()andReadableTable::upper_bound()to be required methods. - Change
ReadableDatabaseto be a sealed trait. - Remove
Table::extract_from_if(). Useextract_if()instead. - Change
Table::extract_if()to take a range as its first argument, like
BTreeMap::extract_if(). Useextract_if(.., predicate)to visit the whole table. - Remove
Builder::create_file(). UseBuilder::create_with_backend(FileBackend::new(file))instead. - Remove
WriteTransaction::print_allocated_page_debug(). - Remove
From<PoisonError<T>>forStorageErrorandError. - Change
range(),range_owned(),retain_in(), andextract_if()to take aKeyRangeinstead
of aRangeBounds. The key type no longer needs to be specified. For example,
table.range::<u64>(..)becomestable.range(..). - Change the I/O methods of
StorageBackendto returnBackendErrorinstead ofio::Error. An
io::Errorcan still be converted with?. Note that anio::Errorof kindUnsupportedis
now converted toBackendError::Ioinstead ofBackendError::Unsupported. Lock methods may
return either to indicate that locking is not supported. - Change the
TableTypeMismatchandTypeDefinitionChangedvariants ofTableErrorandError
to contain aBox. Their fields are replaced by methods on the newTableTypeMismatchand
TypeDefinitionInfostructs. - Change
Database::compact()to take aCompactionMode, which selects how thoroughly to compact.
Usecompact(CompactionMode::Balanced)to compact as before. - Remove the
chrono_v0_4feature, because thechronocrate is no longer maintained. To read
existing tables of its types, implementValueandKeyfor a type of your own with the same
TypeNameand 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::Balancedleaves for later inserts to fill. - Add
Legacy<T>, for reading tables ofOption<T>that were created prior to version 5.0. - Add
BackendError::Other, for errors from a storage backend that are not anio::Error. It is
reported asStorageError::BackendandError::Backend.
Bug fixes
- Fix a bug where
compact()on aSingleWriterorMultiWriterdatabase could return
CompactionError::TransactionInProgress, while an attempt to open the same file for writing in
ExclusiveWritermode 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::PreviousIountil the database is reopened.