Skip to content

Commit

Permalink
feat(core): add sqlite db for nx (nrwl#26891)
Browse files Browse the repository at this point in the history
## Current Behavior
<!-- This is the behavior we have today -->

Nx has some persistent storage managed as separate files on disk. For
example, the local cache queries the file system for existing
directories.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

Nx has a new more performant persistent storage via SQLite database. The
db is used for the following purposes now:
1. Storing task details of different hashes (This serves as reference
for other tables to get more information about a hash)
2. Storing a record of cached artifacts
3. Storing a history of tasks which have run

The cache in particular has the following benefits:
* It's faster, YMMV but it's definitely faster because it writes and
reads less from disk.
* It's able to track access of different cached artifacts
* It purges cached artifacts more intelligently by looking at when
artifacts were last ACCESSED rather than when they were CREATED. This
will also eliminate cache misses due to the cached artifacts being
purged simply because they were CREATED.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
  • Loading branch information
FrozenPandaz authored Aug 21, 2024
1 parent 9269de7 commit cade5bc
Show file tree
Hide file tree
Showing 42 changed files with 1,559 additions and 344 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
fi
build:
needs: [resolve-required-data]
needs: [ resolve-required-data ]
if: ${{ github.repository_owner == 'nrwl' }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -287,7 +287,7 @@ jobs:
if-no-files-found: error

build-freebsd:
needs: [resolve-required-data]
needs: [ resolve-required-data ]
if: ${{ github.repository_owner == 'nrwl' }}
runs-on: ubuntu-latest
name: Build FreeBSD
Expand Down Expand Up @@ -397,7 +397,10 @@ jobs:
run: ls -R artifacts
shell: bash
- name: Build Wasm
run: pnpm build:wasm
run: |
wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-23/wasi-sdk-23.0-x86_64-linux.tar.gz
tar -xvf wasi-sdk-23.0-x86_64-linux.tar.gz
pnpm build:wasm
- name: Publish
env:
VERSION: ${{ needs.resolve-required-data.outputs.version }}
Expand Down Expand Up @@ -437,7 +440,7 @@ jobs:
pr_failure_comment:
# Run this job if it is a PR release, running on the nrwl origin, and any of the required jobs failed
if: ${{ github.repository_owner == 'nrwl' && github.event.inputs.pr && always() && contains(needs.*.result, 'failure') }}
needs: [resolve-required-data, build, build-freebsd, publish]
needs: [ resolve-required-data, build, build-freebsd, publish ]
name: (PR Release Failure Only) Create comment for failed PR release
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jest.debug.config.js
/graph/client/src/assets/generated-source-maps
/nx-dev/nx-dev/public/documentation
/nx-dev/nx-dev/public/images/open-graph
**/tests/temp-db

# Issues scraper creates these files, stored by github's cache
/scripts/issues-scraper/cached
Expand Down Expand Up @@ -58,3 +59,4 @@ out
.rustup/
target
*.wasm
/wasi-sdk*
171 changes: 168 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"preinstall": "node ./scripts/preinstall.js",
"test": "nx run-many -t test",
"e2e": "nx run-many -t e2e --projects ./e2e/*",
"build:wasm": "rustup override set nightly-2024-07-04 && rustup target add wasm32-wasip1-threads && pnpm exec nx run-many -t build-native-wasm && rustup override unset"
"build:wasm": "rustup override set nightly-2024-07-19 && rustup target add wasm32-wasip1-threads && WASI_SDK_PATH=\"$(pwd)/wasi-sdk-23.0-x86_64-linux\" CMAKE_BUILD_PARALLEL_LEVEL=2 LIBSQLITE3_FLAGS=\"-DLONGDOUBLE_TYPE=double\" pnpm exec nx run-many -t build-native-wasm && rustup override unset"
},
"devDependencies": {
"@actions/core": "^1.10.0",
Expand Down
12 changes: 7 additions & 5 deletions packages/nx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ edition = '2021'

[profile.release-wasi]
codegen-units = 16
debug = 'full'
inherits = "release"
lto = "thin"
opt-level = "z"
strip = "none"
debug = 'full'
inherits = "release"
lto = "thin"
opt-level = "z"
strip = "none"

[dependencies]
anyhow = "1.0.71"
Expand All @@ -34,6 +34,7 @@ nom = '7.1.3'
regex = "1.9.1"
rayon = "1.7.0"
rkyv = { version = "0.7", features = ["validation"] }
rusqlite = { version = "0.29.0", features = ["bundled", "array", "vtab", "wasm32-wasi-vfs"] }
thiserror = "1.0.40"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
Expand All @@ -58,6 +59,7 @@ watchexec = "3.0.1"
watchexec-events = "2.0.1"
watchexec-filterer-ignore = "3.0.0"
watchexec-signals = "2.1.0"
machine-uid = "0.5.2"

[lib]
crate-type = ['cdylib']
Expand Down
Loading

0 comments on commit cade5bc

Please sign in to comment.