Skip to content
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

vfs support - ready for full review to merge #16

Open
wants to merge 144 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
73745c0
created dynamic traits for vfs
Buggaboo Sep 7, 2023
11abba7
fleshed out create_vfs
Buggaboo Sep 7, 2023
103277d
fleshed out create_io_methods
Buggaboo Sep 7, 2023
f4940de
start building Mem Vfs example
Buggaboo Sep 7, 2023
65119d5
add docs placeholder
Buggaboo Sep 7, 2023
3875348
see patterns of duplication in C code
Buggaboo Sep 8, 2023
0412d3d
add access to default vfs/file methods
Buggaboo Sep 10, 2023
b7e96c5
wrote completely untested code to check if C struct polymorphism work…
Buggaboo Sep 12, 2023
02c86e3
fleshed out the plumbing
Buggaboo Sep 13, 2023
f1d2e38
totally untested, things will explode
Buggaboo Sep 13, 2023
c1b3647
add functions to load from file, or write to file
Buggaboo Sep 13, 2023
a4f6acd
add test
Buggaboo Sep 13, 2023
62797e9
run valgrind on mac M1 etc.
Buggaboo Aug 31, 2023
96300fb
update docker shell script
Buggaboo Sep 11, 2023
3070d57
move test to tests
Buggaboo Sep 13, 2023
4c7b545
fix address
Buggaboo Sep 14, 2023
6a6f4a2
test result: no such vfs: memvfs -- wtf
Buggaboo Sep 14, 2023
909f214
fixed careless copy/paste stuff
Buggaboo Sep 14, 2023
83f4509
removed unnecessary call to default vfs
Buggaboo Sep 14, 2023
38ee9d5
update dep
Buggaboo Sep 14, 2023
7d6c8e4
add pahole to diagnose alignment issues
Buggaboo Sep 14, 2023
ac3db3e
fixed maligned issue
Buggaboo Sep 14, 2023
2435349
no such vfs: memvfs wth
Buggaboo Sep 14, 2023
35d60d5
fix various issues
Buggaboo Sep 15, 2023
3e6f587
now figuring out how to safely write and read in MemFile, WiP
Buggaboo Sep 15, 2023
c9b77bf
more tweaking
Buggaboo Sep 15, 2023
69c42ee
so, evidently changed state within a Box, will cause panic
Buggaboo Sep 15, 2023
703a44a
sync changes
Buggaboo Sep 15, 2023
52e4f6c
clean up
Buggaboo Sep 15, 2023
28eb73a
ignore valgrind artefacts
Buggaboo Sep 16, 2023
0be7839
solved CString mem leak
Buggaboo Sep 16, 2023
4a72c9e
no errors
Buggaboo Sep 16, 2023
d5f7a8e
unit tests work, but this error shows up when loading on test.sql
Buggaboo Sep 16, 2023
9b25d72
solved CString leak issue, uncovered other issues
Buggaboo Sep 16, 2023
5dae5b4
when we Err, we leak, also refactored out error handling
Buggaboo Sep 16, 2023
374d432
some minor clean up
Buggaboo Sep 16, 2023
9ad9016
minor clean up; the same error is back on the loadable extension
Buggaboo Sep 16, 2023
074a53b
it turns out when something is unsafe, sometimes people really mean it
Buggaboo Sep 16, 2023
65e03eb
clean up, no leaks detected, we still have a segfault when actually l…
Buggaboo Sep 16, 2023
5888966
add command to check build options of sqilte
Buggaboo Sep 16, 2023
bbd0d00
actually, the extension is loading, only the vfs_to_file memfaults
Buggaboo Sep 16, 2023
247895f
removed function preventing the bigger feature
Buggaboo Sep 16, 2023
5fa35c1
reined in visibility of certain callback functions
Buggaboo Sep 17, 2023
df5c139
fix incorrectly generated c_uint issue
Buggaboo Sep 19, 2023
c16e04c
remove unnecessary constants because bindgen generates the correctly …
Buggaboo Sep 19, 2023
0f7ca3f
removed comment about bindgen not generating the correctly signed values
Buggaboo Sep 19, 2023
cf1c8c8
remove unused imports
Buggaboo Sep 19, 2023
d66c4f2
missed one import
Buggaboo Sep 19, 2023
342fd99
change depndency to sqlite3ext
Buggaboo Sep 19, 2023
41628fa
the io_uring example compiles
Buggaboo Sep 26, 2023
4603056
added failing test
Buggaboo Sep 26, 2023
53960cc
at least read works, 2/5 fail
Buggaboo Sep 27, 2023
37bf51b
add close op
Buggaboo Sep 27, 2023
f3170db
rewrote file size
Buggaboo Sep 28, 2023
272fba6
minor variable name adjustments
Buggaboo Sep 28, 2023
045a805
replace magic numbers
Buggaboo Sep 28, 2023
e5d51f2
add read and write flag when opening a file
Buggaboo Sep 28, 2023
9eef967
add test that gives false negatives
Buggaboo Sep 28, 2023
897ecc1
clean up
Buggaboo Sep 28, 2023
4a0bd29
the extension loads
Buggaboo Sep 28, 2023
ca0b42f
minor improvements, everything is still broken
Buggaboo Sep 29, 2023
8d08224
add compulsory mode in case of O_CREAT
Buggaboo Sep 29, 2023
3d90dcc
renamed function; extracted fd
Buggaboo Sep 29, 2023
0ddfd66
fix: sqlite3 --init test.sql
Buggaboo Sep 29, 2023
7151ef7
fixed 4/5 tests
Buggaboo Oct 3, 2023
6dc1154
reverted o_trunc to initial implementation with ftruncate
Buggaboo Oct 3, 2023
e140b5a
setup test to debug munmap_chunk, illegal free issue
Buggaboo Oct 3, 2023
4679462
implemented io_uring, all memory issues resolved
Buggaboo Oct 4, 2023
c0d436c
add tests in examples for hyperfine
Buggaboo Oct 5, 2023
66e1e3c
add script for hyperfine
Buggaboo Oct 5, 2023
81f2ebd
ignore hyperfine generated files
Buggaboo Oct 5, 2023
6ebb3a0
Merge pull request #1 from Buggaboo/benchmark/vfs-io-uring
Buggaboo Oct 5, 2023
e98e5bd
increase varchar range
Buggaboo Oct 5, 2023
fa80922
clean up and documentation
Buggaboo Oct 5, 2023
53cc6f7
found error in template, must redo tests
Buggaboo Oct 5, 2023
2d5f93b
shorten run-time of tests
Buggaboo Oct 5, 2023
59c0313
more fixes to examples
Buggaboo Oct 5, 2023
ff87692
improve hyperfine script
Buggaboo Oct 5, 2023
e9988dd
remove databases before running tests
Buggaboo Oct 5, 2023
dfc8bb5
improve readme
Buggaboo Oct 5, 2023
967f5c3
improve README
Buggaboo Oct 5, 2023
1bbec48
fix layout raw data
Buggaboo Oct 5, 2023
6fde56d
prepare for WAL research, see if concurrent reads match with uring io
Buggaboo Oct 6, 2023
b5fa749
prepare to debug errors
Buggaboo Oct 6, 2023
9260b3e
* rearranged code with templates, .in = include, .rs for code hi-lite
Buggaboo Oct 7, 2023
16b14e4
update parameters; keep things DRY
Buggaboo Oct 7, 2023
66db18e
update comment
Buggaboo Oct 7, 2023
2ae651a
simplified code; but still segfaults on a production build,
Buggaboo Oct 7, 2023
562d014
Merge branch 'main' into feature/vfs-merge
Buggaboo Oct 9, 2023
3013009
diagnose and comment on memory issues; deps updated
Buggaboo Oct 11, 2023
238c41c
the sqlite3_file ptr offset by one trick to shim on does not work
Buggaboo Oct 16, 2023
799eeba
reduce required callbacks to implement;
Buggaboo Oct 19, 2023
ea74fdd
borrowed from https://github.com/rkusa/sqlite-vfs.git
Buggaboo Oct 23, 2023
bb33b83
improve error messages, convert vfs errors to std::io
Buggaboo Oct 24, 2023
becac89
cargo fmt -- --emit files
Buggaboo Oct 24, 2023
42e3e9e
the benchmark vfs project can compile
Buggaboo Oct 24, 2023
2b51eb9
cargo fmt -- --emit files
Buggaboo Oct 24, 2023
38fb48c
managed to strip out only lock related code
Buggaboo Oct 25, 2023
81559f0
add identifiers for crashes
Buggaboo Oct 25, 2023
cda0005
fix tests
Buggaboo Oct 25, 2023
555ba29
fix last unit test
Buggaboo Oct 26, 2023
5202276
trim docker scripts
Buggaboo Oct 26, 2023
778398f
improve error flow
Buggaboo Oct 26, 2023
b29eb78
remove locks, clean up
Buggaboo Oct 26, 2023
59f3682
fix tests / benchmark
Buggaboo Oct 26, 2023
f426ff2
fix benchmark tests
Buggaboo Oct 26, 2023
28b557c
removed over-reliance on Boxes when pointers could suffice,
Buggaboo Nov 16, 2023
dffd498
fixed locking, then other delete issue
Buggaboo Nov 19, 2023
46826a3
cargo fmt
Buggaboo Nov 19, 2023
2522867
fixed benchmark iouring vfs compilation issue
Buggaboo Nov 19, 2023
e8d22a6
simplified VFS File struct
Buggaboo Nov 27, 2023
1844478
fix filename issue with trailing stuff
Buggaboo Nov 28, 2023
4f75933
add log trace, remove some unwraps
Buggaboo Nov 30, 2023
ef2b391
err: database disk image is malformed
Buggaboo Nov 30, 2023
bd4b58c
solve CString issue
Buggaboo Dec 6, 2023
b73f7d7
for some reason if the completion queue is not drained completely,
Buggaboo Dec 9, 2023
fe470eb
update deps
Buggaboo Dec 9, 2023
ac381a1
change ftruncate to truncate that uses the file path
Buggaboo Dec 9, 2023
34c58b0
Some op tests were false positives, write and truncate are being diff…
Buggaboo Dec 9, 2023
a722dc9
cast regardless of arm(64) or x86_64 arch, resp. u8, i8
Buggaboo Dec 9, 2023
58aab2d
tested separately on vm x86_64 debian, and docker arm64 apple ubuntu,…
Buggaboo Dec 9, 2023
a5a0502
removed sqlite3_file parameter from file trait functions
Buggaboo Dec 9, 2023
ff8520c
tried very hard to make o_truncate work by using o_file_size and fall…
Buggaboo Dec 9, 2023
224344d
switched from fd to file_index
Buggaboo Dec 9, 2023
103916e
simplified queue error handling with expect
Buggaboo Dec 9, 2023
d2959aa
add test coverage, and register sparse file indices
Buggaboo Dec 9, 2023
910a548
make suffixed file names testable
Buggaboo Dec 9, 2023
bc5f522
made certain type casts non-specific
Buggaboo Dec 9, 2023
b004751
split up two types of ops
Buggaboo Dec 11, 2023
f9f59a7
prep update tests
Buggaboo Dec 11, 2023
456f686
write up report on speed performance
Buggaboo Dec 11, 2023
f742dbf
clean up
Buggaboo Dec 11, 2023
642d0f9
update docs; clean up
Buggaboo Dec 11, 2023
725d61f
adjust table formatting
Buggaboo Dec 11, 2023
452a1dd
adjust tables and docs
Buggaboo Dec 11, 2023
264a811
add linux kernel version
Buggaboo Dec 11, 2023
d233560
update doc, how to load the vfs
Buggaboo Dec 11, 2023
2e089c3
adapted sql script to test the loadable vfs
Buggaboo Dec 11, 2023
179df1e
improve error handling, add comments
Buggaboo Dec 11, 2023
b6e5f19
reuse default implementation of xAccess
Buggaboo Dec 11, 2023
db88eb6
fmt
Buggaboo Dec 11, 2023
ea90e30
add comment, fmt
Buggaboo Dec 12, 2023
a15cee2
fmt
Buggaboo Dec 12, 2023
54cdfed
rephrase comments
Buggaboo Dec 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
target/
*.db

*.cdtor.c
*.res
*.cdtor.o
rustc*/
wasm/
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ sqlite-loadable-macros={version="0.0.3", path="./sqlite-loadable-macros"}
serde = {version="1.0.147", features = ["derive"]}
serde_json = "1.0.87"
bitflags = "1.3.2"
libsqlite3-sys = {version="0.26.0", optional=true, features=["bundled"]}
libsqlite3-sys = {version="^0.26", optional=true, features=["bundled"]}

[dev-dependencies]
rusqlite = "0.29.0"
libsqlite3-sys = {version="0.26.0", default-features = false, features=["bundled"]}
libsqlite3-sys = {version="^0.26", default-features = false, features=["bundled"]}

[features]
static = ["libsqlite3-sys"]
exec = []
vfs_syscall = []
vfs_loadext = []

[lib]
doctest = false
Expand All @@ -47,3 +49,7 @@ crate-type = ["cdylib"]
[[example]]
name = "load_permanent"
crate-type = ["cdylib"]

[[example]]
name = "mem_vfs"
crate-type = ["cdylib"]
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# kernel 6.1
FROM debian:bookworm-slim

RUN apt-get update

# development
RUN apt-get install -y curl valgrind build-essential clang pahole git

# connect with vs code remote via ssh
RUN apt install -y openssh-server

# project
RUN apt-get install -y libsqlite3-dev sqlite3 liburing-dev

# upgrade kernel to 6.1
RUN apt upgrade -y linux-image-arm64

# rust
ENV RUST_VERSION=stable
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=$RUST_VERSION

# Install cargo-valgrind
RUN /bin/bash -c "source /root/.cargo/env && cargo install cargo-valgrind"

# Check sqlite compile options:
RUN echo "PRAGMA compile_options;" | sqlite3

RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

EXPOSE 22

ENTRYPOINT service ssh start && bash

# on visual code studio
# install "remote development" "remote - ssh" "rust-analyzer"
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ select * from xxx;

Some real-world non-Rust examples of traditional virtual tables in SQLite include the [CSV virtual table](https://www.sqlite.org/csv.html), the full-text search [fts5 extension](https://www.sqlite.org/fts5.html#fts5_table_creation_and_initialization), and the [R-Tree extension](https://www.sqlite.org/rtree.html#creating_an_r_tree_index).

### Virtual file system

There are two examples of how to apply this library to create your own vfs.
1. [io_uring_vfs](./benchmarks/vfs/io_uring/)
2. [mem_vfs](./examples/mem_vfs.rs)

In summary, you need to extend two traits "SqliteIoMethods" and "SqliteVfs", then attach those together
in the open function in SqliteVfs.

You can load the custom vfs in a compiled sqlite3 binary, by doing the following:
* In Cargo.toml, make sure the feature "static" is disabled: sqlite-loadable = {path="..."}
* Load the dynamic object, e.g.: sqlite3 -cmd '.load ./target/debug/lib_myvfs'
* in SQL: ATTACH 'file:my.db?vfs=myvfs' as myvfs

## Examples

The [`examples/`](./examples/) directory has a few bare-bones examples of extensions, which you can build with:
Expand Down Expand Up @@ -243,7 +257,7 @@ A hello world extension in C is `17KB`, while one in Rust is `469k`. It's still
- [ ] Stabilize virtual table interface
- [ ] Support [aggregate window functions](https://www.sqlite.org/windowfunctions.html#udfwinfunc) ([#1](https://github.com/asg017/sqlite-loadable-rs/issues/1))
- [ ] Support [collating sequences](https://www.sqlite.org/c3ref/create_collation.html) ([#2](https://github.com/asg017/sqlite-loadable-rs/issues/2))
- [ ] Support [virtual file systems](sqlite.org/vfs.html) ([#3](https://github.com/asg017/sqlite-loadable-rs/issues/3))
- [x] Support [virtual file systems](sqlite.org/vfs.html) ([#3](https://github.com/asg017/sqlite-loadable-rs/issues/3))

## Supporting

Expand Down
6 changes: 6 additions & 0 deletions benchmarks/vfs/io_uring/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.db
*-journal
sqlite3
leaky.txt
db/**
md/**
Loading