-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IndexedDB views backend #1630
IndexedDB views backend #1630
Conversation
41cd210
to
41dba18
Compare
87ba6b0
to
4dc6352
Compare
4dc6352
to
20a491a
Compare
607ddb5
to
054c492
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for web
to be a priori different from indexed_db
?
@@ -37,7 +37,7 @@ permissions: | |||
jobs: | |||
test: | |||
runs-on: ubuntu-latest-16-cores | |||
timeout-minutes: 90 | |||
timeout-minutes: 95 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that still needed, I thought that we decreased the need for such long times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know where the 90
came from, but the +5 accounts (with a little wiggle room) for the runtime of wasm-pack test
on my laptop.
linera-views/src/indexed_db.rs
Outdated
/// The number of streams for the test | ||
pub const TEST_INDEX_DB_MAX_STREAM_QUERIES: usize = 10; | ||
|
||
const DATABASE_NAME: &str = "linera-views"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems inadequate. Within the framework of this library, all databases could claim to be linera-views
. Why not use IndexedDB
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this is a name provided to the (multi-application) database operated by the browser.
"linera" is perhaps a bit more precise because we sometime use a linera-views KV store directly (without views) e.g. to store certificates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Within IndexedDB, all databases can claim to be IndexedDB :) As the name of an IndexedDB database, this key is namespaced within IndexedDB, not within linera-views
— though actually, since IndexedDB is automatically isolated between domains, this whole string is essentially arbitrary (we don't need to distinguish it from anything else).
loop { | ||
let Some(key) = cursor.primary_key() else { | ||
break; | ||
}; | ||
let key = js_sys::Uint8Array::new(&key); | ||
key_values.push(( | ||
key.subarray(key_prefix.len() as u32, key.length()).to_vec(), | ||
js_sys::Uint8Array::new(&cursor.value()).to_vec(), | ||
)); | ||
if !cursor.continue_cursor()?.await? { | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a little bit puzzling that the find_key_values_by_prefix
implementation is significantly different from the find_keys_by_prefix
. Is it questions of ownership?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because the IndexedDB API has a convenient one-shot function for getting a range of keys, or a range of values, but not for getting both keys and values. Rather than perform one query to get the list of keys and then n queries to get a value for each key, I fell back to the slightly lower-level cursor API, which does allow getting both keys and values.
Ideally I think that |
linera-views/src/indexed_db.rs
Outdated
/// The number of streams for the test | ||
pub const TEST_INDEX_DB_MAX_STREAM_QUERIES: usize = 10; | ||
|
||
const DATABASE_NAME: &str = "linera-views"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this is a name provided to the (multi-application) database operated by the browser.
"linera" is perhaps a bit more precise because we sometime use a linera-views KV store directly (without views) e.g. to store certificates.
5b2bf71
to
7b3ae7d
Compare
Use `indexed_db_futures` to implement `Local{Readable,Writable,Admin}KeyValueStore`. `indexed_db_futures` is a little inconveniently low-level, but seems to be by far the most widely-used crate for IndexedDB in Rust, so should remain supported for some time.
7b3ae7d
to
50101be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the good work.
Motivation
#1610
Proposal
Add an IndexedDB storage backend to
linera-views
.This branch uses a patched fork of
indexed_db_futures
because of Alorel/rust-indexed-db#34, which will otherwise break our non-Web Wasm build.Test Plan
A set of tests is added to CI.
Release Plan
No user-visible changes (yet).
Links
linera-storage
#1610.