khonsulabs / bonsaidb

A developer-friendly document database that grows with you, written in Rust
https://bonsaidb.io/
Apache License 2.0
1.01k stars 37 forks source link

Make BonsaiDb able to be run in non-async code #220

Closed ecton closed 2 years ago

ecton commented 2 years ago

This pull request renames these existing traits:

New traits with the same name as the old have been introduced which have almost an identical API surface, but the traits are not async.

AsyncStorage and AsyncDatabase are new wrapper types that are able to be used in async code. While the same types under the hood are used, these wrappers provides an "async-safe" API surface where users can trust every available function is safe to be called in an async context.

Motivation

Under the hood, BonsaiDb has always wrapped Nebari by calling tokio::task::spawn_blocking. Under the hood, tokio manages a threadpool for these blocking operations. A few days ago, I had the thought experiment of seeing what it would take to offer a non-async interface. After some investigation, I found there were only two locations in bonsaidb-local that leveraged async in any beneficial way, and those two locations were easy to update with alternate options.

After confirming I theoretically could do this, I decided to see what the effects would be. There is still a lot of work left in this PR, but I'm excited at the prospects of these changes.

Tasks to complete