v0.5.0 #308
ecton
announced in
Announcements
v0.5.0
#308
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Breaking Changes
The Minimum Supported Rust Version (MSRV) has been changed to 1.70.
All features in the
bonsaidbcrate have been updated to support the newfeatures in Rust 1.60. Instead of needing separate flags for
client-websocketsandserver-websockets, a single feature flagwebsocketsis now able to work in conjunction with theclient/serverfeatures to ensure everything works correctly.
The net change is fewer feature flags. If you find that a feature flag is
missing on upgrade, try removing "local-", "client-", or "server-" from the
beginning of the feature and recompiling.
The
Keyimplementation forOption<T>has changed. If you wish to preservebackwards compatibility, wrap the key type with
OptionKeyV1.The old behavior was broken in two ways:
This only affects code that was using composite keys.
distinguish between a 0-length contained value and None. Thus,
Some("")would panic as a precaution. However, this type of lurking panic in an
esoteric edge case is exactly the behavior a database should never exhibit.
The
Keyimplementation for tuples (e.g.,(T1, T2)) has changed. If youwish to preserve backwards compatibility, wrap the key type with
TupleKeyV1.The old behavior had an incorrect sort order for the generated bytes. Instead
of sorting only by the values themselves, the lengths of the variable-length
Keytypes were taking precedence over the values. For more information, seeissue #240.
This change also deprecates
encode_composite_key()/decode_composite_key()in favor of two new types:
CompositeKeyEncoderandCompositeKeyDecoder.Collection's get/list/list_with_prefix/insert/overwrite and View's
with_key_range/with_key_prefix have all been updated to accept borrowed
representations of keys. For example, when a Collection's
PrimaryKeyisString,&strcan now be supplied to these functions.For most users, adding
&in front of the argument will generally fix thecompiler error upon upgrade.
DocumentIdis no longerCopy, and now can support up to 64kb of data.Previously, the type was limited to 64 total bytes of stack space.
[Async]StorageConnection::schematic()have been moved to its own trait,HasSchema.[Async]StorageConnection::authenticate()no longer takes a username or userid directly. This has been moved to the
Authenticationtype.AuthenticationMethodhas moved frombonsaidb::core::permissions::bonsaitobonsaidb::core::connectionApiNamehas been moved frombonsaidb::core::schematobonsaidb::core::api.Various error variants that were simply
Stringrepresentations have beenconsoldiated into
bonsaidb::core::Error::Other.bonsaidb::server::Backendnow takes a&selfparameter in all functionsexcept
configure(). ImplementingDefaultfor yourBackendimplementorwill allow all existing code to continue working.
Client::effective_permissions()is no longer async.CustomServer::connected_clients()is no longer async.CustomServer::broadcast()is no longer async.CustomServer::listen_onnow takesimpl Into<BonsaiListenConfig>instead ofjust a u16 parameter specifying the port.
BonsaiListenConfigimplementsFrom<u16>to minimize code breakage.The command-line
Servetype has had itslisten-onfield changed to aSocketAddrtype to reflect the support forBonsaiListenConfig. The fulladdress and port must be specified when providing a
listen-onargument now.Clienthas been renamed toAsyncClient, and a new type,BlockingClienthas been added. This splits the
Clientinto two separate parts: anasyncversion and a blocking version. This makes it less likely to accidentally call
a blocking method in an async context.
Client::send_api_request_asynchas been renamed tosend_api_request.This change has also been introduced to
RemoteDatabaseandRemoteSubscriber: both async and blocking versions are available.#254
Key::from_ord_byteshas had its&'k [u8]parameter changed to a new typewith an additional lifetime:
ByteSource<'k, 'e>. This new type allowsfrom_ord_bytesto be called with an ownedVec<u8>, aKey-lifetime boundbyte slice (
&'k [u8]), or an ephemeral byte slice (&'e [u8]).This change allows code paths that can pass an owned
Vec<u8>in for decodingto not require allocations in some cases -- for example, when using
Vec<u8>::from_ord_bytes.This change also means that
Keyimplementors should expect to be called withany of the three variants of
ByteSource, because BonsaiDb's internal codeonly passes borrowed slices in some code paths.
Thank you to @asonix for the request and help on implementation!
KeyEncoding::describeis a new function that allows a key encoder todocument the data contained within the encoded representation. The goal of
this is to allow tools to generically operate on key types used within
BonsaiDb. This function is automatically implemented when using the
Keyderive.
The new
KeyDescriptiontype uses this function to create a nestedrepresentation of the contained information.
Types that utilize a custom encoding format can use
KeyDescription::Othertouniquely identify the key.
Schematichas had several methods changed toimpl Iteratorof the originaltype being returned to avoid extra unnecessary allocations. These methods are:
Schematic::views_in_collectionSchematic::eager_views_in_collectionSchematic::collectionsStorageConnection::list_available_schemas/AsyncStorageConnection::list_available_schemasnow return a
Vec<SchemaSummary>. TheSchemaSummarytype containsadditional information such as what collections and views each schema
contains.
bonsaidb::cli::Commandnow flattens theservercommand rather thanin-lining the
admincommand. This introduces additional top-level commandsthat were previously hidden underneath the
servercommand.ConnectedClient::all_sessions()is a new function that returns all of theactive sessions for the given client.
View schemas are now partially deriveble, and have had their map/reduce
functionality split into their own traits. The following notes all apply to
this refactoring:
ViewSchema::map()andViewSchema::reduce()have been moved to a newtrait:
MapReduce.CollectionViewSchemahas been removed, and themap()andreduce()functions have been moved to a new trait:
CollectionMapReduce.ViewSchema::unique()andViewSchema::lazy()have been replaced withViewSchema::update_policy(), which returns a new enum:ViewUpdatePolicy.This enum contains three variants: Lazy, Eager, and Unique, allowing the same
options that the previous two methods supported without any ambiguities.
ViewSchemais now implementable/derivable for all views, regardless ofwhether the map/reduce functionality utilizes
SerializedCollections ornot.
ViewSchema::MappedKey<'doc>is a new associated type with a genericassociated lifetime that enables
map()/reduce()to utilize borrowed datafor the view's key type. This has caused the
map()andreduce()functionsto have new lifetime annotations added. These changes are part of an effort to
support more flows where borrowing data is possible to minimize allocations
while indexing and querying views.
For all existing users, setting this associated type to the view's Key type
will work, or pasting this associated type definition in:
natural_idsupport in theCollectionderive macro has been changed. Theattribute now expects an expression rather than a closure. The expression can
reference
self. This was done to avoid the required type annotations thatthe closure approach required.
Alternatively,
#[natural_id]can be annotated directly on a field to have itbecome the natural id automatically.
bonsaidb::server::api::Handlerhas had its generic arguments order reversed,which allows the type to specify a default
BackendofNoBackend.View query APIs now return
CollectionMaptypes instead ofMaptypes. Thechange allows for the
Collection::PrimaryKeytype to be used instead ofDocumentId. The affected APIs are:bonsaidb::core::connection::View::query()bonsaidb::core::connection::View::query_with_docs()bonsaidb::core::connection::AsyncView::query()bonsaidb::core::connection::AsyncView::query_with_docs()bonsaidb::core::connection::LowLevelConnection::query()bonsaidb::core::connection::LowLevelConnection::query_with_docs()bonsaidb::core::connection::AsyncLowLevelConnection::query()bonsaidb::core::connection::AsyncLowLevelConnection::query_with_docs()MappedDocuments: Bothmappingsanddocumentshave had their typesupdated.
MappedSerialiedSocuments::deserialized()Deprecated
bonsaidb::core::connection::ViewMappingsas been moved tobonsaidb::core::schema::view::ViewMappings. A deprecated re-export has beenprovided to minimize code breakage when upgrading.
Added
#239
Keycan now be derived on enums and structs, allowing an easier wayto use composite keys. The
primary-keysexample has been updated to use thederive macro instead of a tuple for the composite key.
Keyis now implemented forResult<T,E>, where T and E both implementKeyand
KeyEncodingusing the same error type.Keyis now implemented forCow<'a, str>.Keyis now implemented forisizeandusize. This is implemented usingvariable integer encoding, allowing for proper cross-architecture behavior.
When trying to decode a value that is too large for the given target
architecture, an error will be returned.
Keyis now implemented forNonZeroU*andNonZeroI*types, wrapping theinner type's encoding functionality and adding extra checks for 0 values. For
signed types,
next_value()will skip 0.bonsaidb::core::key::KeyFormatis a newtransmog::Formatthat can be usedas a
SerializedCollection::Formatassociated type. This implementsserialization using the
Keytrait rather than Serde.When deriving the
Collectiontrait, specifyingserialization = Keywilluse this format.
ViewSchemacan now be derived.bonsaidb_core::Error::is_unique_key_error()is a convenience function toquickly check if an error is a result of a unique key violation from a
specific view.
bonsaidb_core::Error::conflicting_document()is a convenience function toreturn the conflicting document's header if the error is a conflict from a
specific collection.
Operation::Checkis a new operation that can be performed during atransaction. It checks whether a document exists in a given collection, and
optionally can verify that a revision matches the currently stored revision.
These constructor functions provide more ergonomic ways to create this variant:
Operation::check_document_id_exists(CollectionName,DocumentId)Operation::check_document_exists<Collection>(Collection::PrimaryKey)Operation::check_document_is_current(&impl HasHeader)Storagenow acquires an exclusive lock to ensure multiple instances are notable to be opened at the same time. This lock is held across all locations the
database is accessed, including background threads.
bonsaidb-filesis a new crate that enables storing large files in BonsaiDb,and includes abstractions for reading/writing files using common
traits:
std::io::Readstd::io::Seekstd::io::Writetokio::io::AsyncReadtokio::io::AsyncSeektokio::io::AsyncWriteIterator<Item = std::io::Result<Vec<u8>>>futures::Stream<Item = std::io::Result<Vec<u8>>>This crate can be added directly to your project, or if you're using the
omnibus crate, feature
fileswill enable this crate atbonsaidb::files.SerializedCollection::push_all[_async]()is a new function that accepts aniterator of document contents to push into the database using a single
transaction. It returns the created collection documents if successful. If any
errors occur, no documents will be inserted.
ViewSchema::lazy()/CollectionViewSchema::lazy()are provided functionsthat return true by default. This preserves the existing behavior for
map/reduce views -- they are only updated when queried, and as dictated by the
AccessPolicy. By returning false, a view can become eagerly updated, whichmeans that the views are fully updated by the time each transaction completes.
This was how unique views already functioned, but now users who have workflows
where an eagerly-updated view will be more efficient than a lazy view can
opt-in to this behavior.
bonsaidb::server::cli::Commandhas a new function,execute_onwhichaccepts an already constructed server instance.
ServerDatabase,AnyDatabase, andAnyConnectionnow all implementCloneand
Debug.DefaultPermissionsnow implementsFrom<Vec<Statement>>andFrom<Statement>, enabling simpler usage when usingdefault_permissions()and
authenticated_permissions().[Async]StorageConnection::authenticate_with_passwordare new functionsproviding a simpler interface for authenticating with a username/user id and
password.
[Async]StorageConnection::authenticate_with_tokenis a new function thatallows authenticating with a previously created
AuthenticationToken.Token authentication is an optional feature, enabled with the
token-authenticationfeature. This feature is currently powered byBLAKE3, but has been written to be
able to support multiple algorithms.
An
AuthenticationTokenis a randomly generated id, a private token, and anidentity that are used to perform a cryptographically secure verification
during authentication without transferring the private token to the server.
Upon successful authentication, the identity is assumed on the newly returned
connection. This supports both assuming users and roles.
The
Apitrait can now be derived.SerializedViewhas two new methods:entriesandentries_async, whichenable a "Type-first" query pattern. These two statements produce the same
results:
These new APIs are provided purely for style preference considerations.
LimitedResolutionDurationnow has a functionchecked_add()supportsiter::Sum into
Option<LimitedResolutionDuration<T>>orLimitedResolutionDuration<T>. The option-wrapped version does a checkedoperation, and the other will panic if the result of the operation is not
representable by the
LimitedResolutionDuration.BonsaiListenConfigis a new structure that controls the settings of theBonsaiDb network protocol server socket. This structure currently allows
specifying the specific
SocketAddrto listen on and whether theSO_REUSEADDRflag should be specified on the underlying socket.CollectionDocumentnow implements Serialize and/or Deserialize if bothPrimaryKeyandContentsare Serialize and/or Deserialize, respectively.Backend::client_session_endedis a new function that is invoked any time aconnected client's session is ending.
VarInt<T>is a new type that implementsKeyusing theordered-varintcrate. This allows using types such as
VarInt<u64>instead ofu64toreduce the number of bytes encoded keys consume on average.
SerializedCollectionnow hasinsert_in_transaction(),push_in_transaction(), andoverwrite_in_transaction()which are newhelpers that help writing transactional code easier by creating and pushing
the
Operationsin one step.CollectionDocument<T>now hasupdate_in_transaction()anddelete_in_transaction()which are new helpers that help writingtransactional code easier by creating and pushing the
Operationsin onestep.
Client's builder now has two additional settings:request_timeoutandconnect_timeout. If not specified, both timeouts are 60 seconds. Thank youto @phantie for requesting these settings in List of imperfections #296.
CollectionDocument::refresh()/CollectionDocument::refresh_async()are newmethods that reload the document from the database.
ConnectedClient::connected()is a new function that returns the currentstate of whether the client is still connected. Because
ConnectedClientisable to be cloned and sent between threads, this allows other threads to
notice when clients have disconnected without needing to be notified via the
Backend.Changed
bonsaidb::cli::Command::Servernow callsCommandLine::open_server()ratherthan constructing the server directly. This allows CommandLine implementors to
use
open_serveras a location to launch extra services upon server startup.bonsaidb::cli::Argsandbonsaidb::cli::Command::executenow accept a tokenid or a username, allowing for commands to be executed with authentication if
the features are enabled.
bonsaidb::local::cli::Commandnow offers the ability to create a user andset a user's password.
bonsaidb::local::cli::adminis a newly exposed module that allows some basicuser management. This set of commands is also available on
bonsaidb::cli::Commandthrough theAdminvariant, allowing for both localand remote administration.
Header,CollectionHeader, andRevisionnow all implementHash.and in hindsight, the feature was removed in favor of strictness. Because the
database name is used as a directory name on-disk, care must be taken on
case-insensitive filesystems to not attempt to create two databases with
different casing.
TimedArgonParametersnow guarantees that the minimum parameters chosen willmeet the
OWASPrecommendations. Manual configuration still is allowed to setexact parameters.
Fixed
is performed that resulted in a new document being created.
was being supplied in bytes, but the underlying API was expecting kilobytes.
reindexing. Previously, BonsaiDb was lazily cleaning up the entries, which led
to slower reindexing and disk bloat.
sourcefield of mappings returned from a View query when adocument was updated but emitted the same key. Previously the value was
correctly updated, but the source's revision was not updated.
AccessPolicy::NoUpdate, the integrity scanner isnow checked and waited upon before allowing access to the view.
AccessPolicy::UpdateAfter, the update task is nolonger blocked until complete.
CustomServer::listen_for_shutdown()now listens forCustomServer::shutdown()in addition to operating system signals.Clientwill no longer return aSessionfrom a previous connection. Becausethe
Clientautomatically reconnects, theSessions are no longerauthenticated.
CustomServer::shutdownnow fully shuts down the server by forcefullydisconnecting clients after the optional grace period has elapsed.
Additionally, QUIC-connected workers are sent the proper disconnection
notification.
Keygeneric parameter toOperation::overwrite_serializedis now usedin the function definition. Because previously
C::PrimaryKeywas hard-coded,any existing code should work as long as the correct
Keytype was provided.This fix also allows for types like
strto be used instead ofStringwiththis function.
results.
CustomServer::listen_onno longer will return an error if an incomingconnection fails during the TLS or QUIC handshake. Thank you to @phantie for
reporting this in List of imperfections #296.
This discussion was created from the release v0.5.0.
All reactions