Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
6c3fd0f4
Unverified
Commit
6c3fd0f4
authored
Nov 08, 2024
by
Tobias Koppers
Committed by
GitHub
Nov 08, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "[Turbopack] add rocksdb" (#72505)
parent
0c22b004
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
28 additions
and
422 deletions
+28
-422
build_and_test.yml
.github/workflows/build_and_test.yml
+0
-2
Cargo.lock
Cargo.lock
+4
-105
Cargo.toml
turbopack/crates/turbo-tasks-backend/Cargo.toml
+2
-5
mod.rs
turbopack/crates/turbo-tasks-backend/src/database/mod.rs
+0
-7
mod.rs
...ck/crates/turbo-tasks-backend/src/database/rocksdb/mod.rs
+0
-232
kv_backing_storage.rs
...pack/crates/turbo-tasks-backend/src/kv_backing_storage.rs
+7
-7
lib.rs
turbopack/crates/turbo-tasks-backend/src/lib.rs
+13
-38
run.rs
turbopack/crates/turbo-tasks-testing/src/run.rs
+2
-26
No files found.
.github/workflows/build_and_test.yml
View file @
6c3fd0f4
...
@@ -190,7 +190,6 @@ jobs:
...
@@ -190,7 +190,6 @@ jobs:
-
'
--scenario=heavy-npm-deps-build
--page=homepage'
-
'
--scenario=heavy-npm-deps-build
--page=homepage'
uses
:
./.github/workflows/build_reusable.yml
uses
:
./.github/workflows/build_reusable.yml
with
:
with
:
skipNativeBuild
:
'
yes'
afterBuild
:
pnpm install && ./node_modules/.bin/devlow-bench ./scripts/devlow-bench.mjs --datadog=ubuntu-latest-16-core ${{ matrix.mode }} ${{ matrix.selector }}
afterBuild
:
pnpm install && ./node_modules/.bin/devlow-bench ./scripts/devlow-bench.mjs --datadog=ubuntu-latest-16-core ${{ matrix.mode }} ${{ matrix.selector }}
stepName
:
'
devlow-bench-${{
matrix.mode
}}-${{
matrix.selector
}}'
stepName
:
'
devlow-bench-${{
matrix.mode
}}-${{
matrix.selector
}}'
secrets
:
inherit
secrets
:
inherit
...
@@ -296,7 +295,6 @@ jobs:
...
@@ -296,7 +295,6 @@ jobs:
uses
:
./.github/workflows/build_reusable.yml
uses
:
./.github/workflows/build_reusable.yml
with
:
with
:
skipNativeBuild
:
'
yes'
afterBuild
:
rustup target add wasm32-unknown-unknown && curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh && node ./scripts/normalize-version-bump.js && turbo run build-wasm -- --target nodejs && git checkout . && mv crates/wasm/pkg crates/wasm/pkg-nodejs && node ./scripts/setup-wasm.mjs && NEXT_TEST_MODE=start TEST_WASM=true node run-tests.js test/production/pages-dir/production/test/index.test.ts test/e2e/streaming-ssr/index.test.ts
afterBuild
:
rustup target add wasm32-unknown-unknown && curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh && node ./scripts/normalize-version-bump.js && turbo run build-wasm -- --target nodejs && git checkout . && mv crates/wasm/pkg crates/wasm/pkg-nodejs && node ./scripts/setup-wasm.mjs && NEXT_TEST_MODE=start TEST_WASM=true node run-tests.js test/production/pages-dir/production/test/index.test.ts test/e2e/streaming-ssr/index.test.ts
stepName
:
'
test-next-swc-wasm'
stepName
:
'
test-next-swc-wasm'
secrets
:
inherit
secrets
:
inherit
...
...
Cargo.lock
View file @
6c3fd0f4
...
@@ -713,26 +713,6 @@ dependencies = [
...
@@ -713,26 +713,6 @@ dependencies = [
"serde",
"serde",
]
]
[[package]]
name = "bindgen"
version = "0.69.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088"
dependencies = [
"bitflags 2.5.0",
"cexpr",
"clang-sys",
"itertools 0.12.1",
"lazy_static",
"lazycell",
"proc-macro2",
"quote",
"regex",
"rustc-hash 1.1.0",
"shlex",
"syn 2.0.58",
]
[[package]]
[[package]]
name = "binding_macros"
name = "binding_macros"
version = "5.0.0"
version = "5.0.0"
...
@@ -940,17 +920,6 @@ dependencies = [
...
@@ -940,17 +920,6 @@ dependencies = [
"serde",
"serde",
]
]
[[package]]
name = "bzip2-sys"
version = "0.1.11+1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc"
dependencies = [
"cc",
"libc",
"pkg-config",
]
[[package]]
[[package]]
name = "camino"
name = "camino"
version = "1.1.6"
version = "1.1.6"
...
@@ -1009,13 +978,12 @@ checksum = "a2698f953def977c68f935bb0dfa959375ad4638570e969e2f1e9f433cbf1af6"
...
@@ -1009,13 +978,12 @@ checksum = "a2698f953def977c68f935bb0dfa959375ad4638570e969e2f1e9f433cbf1af6"
[[package]]
[[package]]
name = "cc"
name = "cc"
version = "1.
1.36
"
version = "1.
0.83
"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "
baee610e9452a8f6f0a1b6194ec09ff9e2d85dea54432acdae41aa0761c95d7
0"
checksum = "
f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d
0"
dependencies = [
dependencies = [
"jobserver",
"jobserver",
"libc",
"libc",
"shlex",
]
]
[[package]]
[[package]]
...
@@ -1024,15 +992,6 @@ version = "1.1.0"
...
@@ -1024,15 +992,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
[[package]]
name = "cexpr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
"nom",
]
[[package]]
[[package]]
name = "cfg-expr"
name = "cfg-expr"
version = "0.15.4"
version = "0.15.4"
...
@@ -1162,17 +1121,6 @@ dependencies = [
...
@@ -1162,17 +1121,6 @@ dependencies = [
"half",
"half",
]
]
[[package]]
name = "clang-sys"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
dependencies = [
"glob",
"libc",
"libloading",
]
[[package]]
[[package]]
name = "clap"
name = "clap"
version = "4.5.2"
version = "4.5.2"
...
@@ -3210,9 +3158,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
...
@@ -3210,9 +3158,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]]
[[package]]
name = "jobserver"
name = "jobserver"
version = "0.1.
32
"
version = "0.1.
26
"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "
48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0
"
checksum = "
936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2
"
dependencies = [
dependencies = [
"libc",
"libc",
]
]
...
@@ -3299,12 +3247,6 @@ version = "1.4.0"
...
@@ -3299,12 +3247,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
[[package]]
name = "leb128"
name = "leb128"
version = "0.2.5"
version = "0.2.5"
...
@@ -3446,22 +3388,6 @@ dependencies = [
...
@@ -3446,22 +3388,6 @@ dependencies = [
"libc",
"libc",
]
]
[[package]]
name = "librocksdb-sys"
version = "0.16.0+8.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce3d60bc059831dc1c83903fb45c103f75db65c5a7bf22272764d9cc683e348c"
dependencies = [
"bindgen",
"bzip2-sys",
"cc",
"glob",
"libc",
"libz-sys",
"lz4-sys",
"zstd-sys",
]
[[package]]
[[package]]
name = "libz-sys"
name = "libz-sys"
version = "1.1.8"
version = "1.1.8"
...
@@ -3661,16 +3587,6 @@ dependencies = [
...
@@ -3661,16 +3587,6 @@ dependencies = [
"url",
"url",
]
]
[[package]]
name = "lz4-sys"
version = "1.11.1+lz4-1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bd8c0d6c6ed0cd30b3652886bb8711dc4bb01d637a68105a3d5158039b418e6"
dependencies = [
"cc",
"libc",
]
[[package]]
[[package]]
name = "lz4_flex"
name = "lz4_flex"
version = "0.11.3"
version = "0.11.3"
...
@@ -5475,16 +5391,6 @@ dependencies = [
...
@@ -5475,16 +5391,6 @@ dependencies = [
"syn 1.0.109",
"syn 1.0.109",
]
]
[[package]]
name = "rocksdb"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bd13e55d6d7b8cd0ea569161127567cd587676c99f4472f779a0279aa60a7a7"
dependencies = [
"libc",
"librocksdb-sys",
]
[[package]]
[[package]]
name = "rstest"
name = "rstest"
version = "0.16.0"
version = "0.16.0"
...
@@ -6009,12 +5915,6 @@ dependencies = [
...
@@ -6009,12 +5915,6 @@ dependencies = [
"memmap2 0.6.2",
"memmap2 0.6.2",
]
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
[[package]]
name = "signal-hook"
name = "signal-hook"
version = "0.3.17"
version = "0.3.17"
...
@@ -8507,7 +8407,6 @@ dependencies = [
...
@@ -8507,7 +8407,6 @@ dependencies = [
"pot",
"pot",
"rand",
"rand",
"rayon",
"rayon",
"rocksdb",
"rustc-hash 1.1.0",
"rustc-hash 1.1.0",
"serde",
"serde",
"serde_path_to_error",
"serde_path_to_error",
...
...
turbopack/crates/turbo-tasks-backend/Cargo.toml
View file @
6c3fd0f4
...
@@ -13,11 +13,9 @@ bench = false
...
@@ -13,11 +13,9 @@ bench = false
workspace
=
true
workspace
=
true
[features]
[features]
default
=
[
"rocksdb"
]
default
=
[]
verify_serialization
=
[]
verify_serialization
=
[]
trace_aggregation_update
=
[]
trace_aggregation_update
=
[]
lmdb
=
["dep:lmdb-rkv"]
rocksdb
=
["dep:rocksdb"]
[dependencies]
[dependencies]
anyhow
=
{
workspace
=
true
}
anyhow
=
{
workspace
=
true
}
...
@@ -29,13 +27,12 @@ dashmap = { workspace = true, features = ["raw-api"]}
...
@@ -29,13 +27,12 @@ dashmap = { workspace = true, features = ["raw-api"]}
either
=
{
workspace
=
true
}
either
=
{
workspace
=
true
}
hashbrown
=
{
workspace
=
true
,
features
=
["raw"]
}
hashbrown
=
{
workspace
=
true
,
features
=
["raw"]
}
indexmap
=
{
workspace
=
true
}
indexmap
=
{
workspace
=
true
}
lmdb-rkv
=
{
version
=
"0.14.0"
,
optional
=
true
}
lmdb-rkv
=
"0.14.0"
once_cell
=
{
workspace
=
true
}
once_cell
=
{
workspace
=
true
}
parking_lot
=
{
workspace
=
true
}
parking_lot
=
{
workspace
=
true
}
pot
=
"3.0.0"
pot
=
"3.0.0"
rand
=
{
workspace
=
true
}
rand
=
{
workspace
=
true
}
rayon
=
{
workspace
=
true
}
rayon
=
{
workspace
=
true
}
rocksdb
=
{
version
=
"0.22.0"
,
optional
=
true
}
rustc-hash
=
{
workspace
=
true
}
rustc-hash
=
{
workspace
=
true
}
serde
=
{
workspace
=
true
}
serde
=
{
workspace
=
true
}
serde_path_to_error
=
{
workspace
=
true
}
serde_path_to_error
=
{
workspace
=
true
}
...
...
turbopack/crates/turbo-tasks-backend/src/database/mod.rs
View file @
6c3fd0f4
...
@@ -2,21 +2,14 @@ mod by_key_space;
...
@@ -2,21 +2,14 @@ mod by_key_space;
pub
mod
db_versioning
;
pub
mod
db_versioning
;
pub
mod
fresh_db_optimization
;
pub
mod
fresh_db_optimization
;
pub
mod
key_value_database
;
pub
mod
key_value_database
;
#[cfg(feature
=
"lmdb"
)]
pub
mod
lmdb
;
pub
mod
lmdb
;
pub
mod
noop_kv
;
pub
mod
noop_kv
;
pub
mod
read_transaction_cache
;
pub
mod
read_transaction_cache
;
#[cfg(feature
=
"rocksdb"
)]
pub
mod
rocksdb
;
mod
startup_cache
;
mod
startup_cache
;
pub
use
db_versioning
::
handle_db_versioning
;
pub
use
db_versioning
::
handle_db_versioning
;
pub
use
fresh_db_optimization
::{
is_fresh
,
FreshDbOptimization
};
pub
use
fresh_db_optimization
::{
is_fresh
,
FreshDbOptimization
};
#[cfg(feature
=
"lmdb"
)]
pub
use
lmdb
::
LmbdKeyValueDatabase
;
#[allow(unused_imports)]
#[allow(unused_imports)]
pub
use
noop_kv
::
NoopKvDb
;
pub
use
noop_kv
::
NoopKvDb
;
pub
use
read_transaction_cache
::
ReadTransactionCache
;
pub
use
read_transaction_cache
::
ReadTransactionCache
;
#[cfg(feature
=
"rocksdb"
)]
pub
use
rocksdb
::
RocksDbKeyValueDatabase
;
pub
use
startup_cache
::
StartupCacheLayer
;
pub
use
startup_cache
::
StartupCacheLayer
;
turbopack/crates/turbo-tasks-backend/src/database/rocksdb/mod.rs
deleted
100644 → 0
View file @
0c22b004
use
std
::{
hash
::{
BuildHasher
,
BuildHasherDefault
},
iter
::
once
,
path
::
Path
,
thread
::{
available_parallelism
,
scope
},
time
::
Instant
,
};
use
anyhow
::{
Context
,
Result
};
use
rocksdb
::{
ColumnFamily
,
Env
,
SliceTransform
,
WriteBatch
as
RdbWriteBack
,
WriteOptions
,
DB
};
use
rustc_hash
::
FxHasher
;
use
crate
::
database
::
key_value_database
::{
KeySpace
,
KeyValueDatabase
,
WriteBatch
};
macro_rules!
make_names
{
(
$name
:
ident
,
$prefix
:
literal
)
=>
{
make_names!
(
$name
,
$prefix
,
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
);
};
(
$name
:
ident
,
$prefix
:
literal
,
$
(
$i
:
expr
)
*
)
=>
{
static
$name
:
[
&
str
;
SHARDS
]
=
[
$
(
concat!
(
$prefix
,
$i
),)
*
];
};
}
// Atomic flush doesn't support parallel flushing of the column families so we can't use it
const
USE_ATOMIC_FLUSH
:
bool
=
false
;
const
SHARD_BITS
:
usize
=
4
;
const
SHARDS
:
usize
=
1
<<
SHARD_BITS
;
make_names!
(
TASK_DATA
,
"task-data-"
);
make_names!
(
TASK_META
,
"task-meta-"
);
make_names!
(
FORWARD_TASK_CACHE
,
"forward-task-cache-"
);
make_names!
(
REVERSE_TASK_CACHE
,
"reverse-task-cache-"
);
pub
struct
RocksDbKeyValueDatabase
{
db
:
DB
,
}
impl
RocksDbKeyValueDatabase
{
pub
fn
new
(
path
:
&
Path
)
->
Result
<
Self
>
{
let
parallelism
=
available_parallelism
()
.map_or
(
4
,
|
p
|
p
.get
()
as
i32
);
let
mut
env
=
Env
::
new
()
?
;
env
.set_background_threads
(
parallelism
);
env
.set_high_priority_background_threads
(
parallelism
);
env
.set_bottom_priority_background_threads
(
parallelism
);
env
.set_low_priority_background_threads
(
parallelism
);
let
mut
options
=
rocksdb
::
Options
::
default
();
options
.set_env
(
&
env
);
options
.create_if_missing
(
true
);
options
.create_missing_column_families
(
true
);
if
USE_ATOMIC_FLUSH
{
options
.set_atomic_flush
(
true
);
}
options
.set_allow_concurrent_memtable_write
(
false
);
options
.set_allow_mmap_reads
(
true
);
options
.set_allow_mmap_writes
(
true
);
#[allow(deprecated)]
options
.set_max_background_flushes
(
parallelism
);
#[allow(deprecated)]
options
.set_max_background_compactions
(
parallelism
);
options
.set_enable_blob_files
(
true
);
options
.set_enable_blob_gc
(
true
);
options
.set_min_blob_size
(
1024
*
1024
);
let
mut
cf_options
=
rocksdb
::
Options
::
default
();
cf_options
.set_compaction_style
(
rocksdb
::
DBCompactionStyle
::
Universal
);
cf_options
.set_level_compaction_dynamic_level_bytes
(
false
);
cf_options
.set_allow_concurrent_memtable_write
(
false
);
cf_options
.set_prefix_extractor
(
SliceTransform
::
create_noop
());
cf_options
.set_memtable_factory
(
rocksdb
::
MemtableFactory
::
Vector
);
cf_options
.set_compression_type
(
rocksdb
::
DBCompressionType
::
Lz4
);
cf_options
.set_compression_options
(
-
14
,
32767
,
0
,
1024
);
cf_options
.set_bottommost_compression_type
(
rocksdb
::
DBCompressionType
::
Zstd
);
cf_options
.set_bottommost_zstd_max_train_bytes
(
1024
,
true
);
cf_options
.optimize_for_point_lookup
(
8
);
cf_options
.set_min_blob_size
(
1024
*
1024
);
cf_options
.set_enable_blob_files
(
true
);
cf_options
.set_blob_compression_type
(
rocksdb
::
DBCompressionType
::
Zstd
);
let
cfs
=
Self
::
all_cf_names
()
.map
(|
name
|
(
name
,
cf_options
.clone
()))
.collect
::
<
Vec
<
_
>>
();
let
db
=
DB
::
open_cf_with_opts
(
&
options
,
path
,
cfs
)
?
;
Ok
(
Self
{
db
})
}
fn
all_cf_names
()
->
impl
Iterator
<
Item
=
&
'static
str
>
{
once
(
"default"
)
.chain
(
TASK_DATA
.iter
()
.copied
())
.chain
(
TASK_META
.iter
()
.copied
())
.chain
(
FORWARD_TASK_CACHE
.iter
()
.copied
())
.chain
(
REVERSE_TASK_CACHE
.iter
()
.copied
())
}
fn
cf_handle
(
&
self
,
key_space
:
KeySpace
,
key
:
&
[
u8
])
->
Result
<&
ColumnFamily
>
{
let
shard
=
if
key
.len
()
<=
4
{
// It's a TaskId in little-endian, we can take the first byte
(
key
[
0
]
&
(
SHARDS
as
u8
-
1
))
as
usize
}
else
{
let
hash
=
BuildHasherDefault
::
<
FxHasher
>
::
default
()
.hash_one
(
key
);
(
hash
as
u8
&
(
SHARDS
as
u8
-
1
))
as
usize
};
self
.db
.cf_handle
(
match
key_space
{
KeySpace
::
Infra
=>
"default"
,
KeySpace
::
TaskMeta
=>
TASK_META
[
shard
],
KeySpace
::
TaskData
=>
TASK_DATA
[
shard
],
KeySpace
::
ForwardTaskCache
=>
FORWARD_TASK_CACHE
[
shard
],
KeySpace
::
ReverseTaskCache
=>
REVERSE_TASK_CACHE
[
shard
],
})
.context
(
"Failed to get column family"
)
}
}
impl
KeyValueDatabase
for
RocksDbKeyValueDatabase
{
type
ReadTransaction
<
'l
>
=
()
where
Self
:
'l
;
fn
lower_read_transaction
<
'l
:
'i
+
'r
,
'i
:
'r
,
'r
>
(
tx
:
&
'r
Self
::
ReadTransaction
<
'l
>
,
)
->
&
'r
Self
::
ReadTransaction
<
'i
>
{
tx
}
fn
begin_read_transaction
(
&
self
)
->
Result
<
Self
::
ReadTransaction
<
'_
>>
{
Ok
(())
}
type
ValueBuffer
<
'l
>
=
Vec
<
u8
>
where
Self
:
'l
;
fn
get
<
'l
,
'db
:
'l
>
(
&
'l
self
,
_transaction
:
&
'l
Self
::
ReadTransaction
<
'db
>
,
key_space
:
super
::
key_value_database
::
KeySpace
,
key
:
&
[
u8
],
)
->
Result
<
Option
<
Self
::
ValueBuffer
<
'l
>>>
{
let
cf
=
self
.cf_handle
(
key_space
,
key
)
?
;
Ok
(
self
.db
.get_cf
(
cf
,
key
)
?
)
}
type
WriteBatch
<
'l
>
=
RocksDbWriteBatch
<
'l
>
where
Self
:
'l
;
fn
write_batch
(
&
self
)
->
Result
<
Self
::
WriteBatch
<
'_
>>
{
Ok
(
RocksDbWriteBatch
{
batch
:
RdbWriteBack
::
default
(),
this
:
self
,
})
}
}
pub
struct
RocksDbWriteBatch
<
'a
>
{
batch
:
RdbWriteBack
,
this
:
&
'a
RocksDbKeyValueDatabase
,
}
impl
<
'a
>
WriteBatch
<
'a
>
for
RocksDbWriteBatch
<
'a
>
{
type
ValueBuffer
<
'l
>
=
Vec
<
u8
>
where
Self
:
'l
,
'a
:
'l
;
fn
get
<
'l
>
(
&
'l
self
,
key_space
:
KeySpace
,
key
:
&
[
u8
])
->
Result
<
Option
<
Self
::
ValueBuffer
<
'l
>>>
where
'a
:
'l
,
{
self
.this
.get
(
&
(),
key_space
,
key
)
}
fn
put
(
&
mut
self
,
key_space
:
KeySpace
,
key
:
std
::
borrow
::
Cow
<
[
u8
]
>
,
value
:
std
::
borrow
::
Cow
<
[
u8
]
>
,
)
->
Result
<
()
>
{
let
cf
=
self
.this
.cf_handle
(
key_space
,
&
key
)
?
;
self
.batch
.put_cf
(
cf
,
key
,
value
);
Ok
(())
}
fn
delete
(
&
mut
self
,
key_space
:
KeySpace
,
key
:
std
::
borrow
::
Cow
<
[
u8
]
>
)
->
Result
<
()
>
{
let
cf
=
self
.this
.cf_handle
(
key_space
,
&
key
)
?
;
self
.batch
.delete_cf
(
cf
,
key
);
Ok
(())
}
fn
commit
(
self
)
->
Result
<
()
>
{
let
start
=
Instant
::
now
();
let
mut
write_options
=
WriteOptions
::
default
();
if
USE_ATOMIC_FLUSH
{
write_options
.disable_wal
(
true
);
}
self
.this.db
.write_opt
(
self
.batch
,
&
write_options
)
?
;
println!
(
"Write took {:?}"
,
start
.elapsed
());
let
start
=
Instant
::
now
();
if
!
USE_ATOMIC_FLUSH
{
scope
(|
s
|
{
let
threads
=
RocksDbKeyValueDatabase
::
all_cf_names
()
.map
(|
name
|
{
s
.spawn
(
move
||
{
let
cf
=
self
.this
.db
.cf_handle
(
name
)
.context
(
"Failed to get column family"
)
?
;
self
.this.db
.flush_cf
(
cf
)
?
;
anyhow
::
Ok
(())
})
})
.collect
::
<
Vec
<
_
>>
();
for
thread
in
threads
{
thread
.join
()
.unwrap
()
?
;
}
anyhow
::
Ok
(())
})
?
;
}
let
mut
wait_for_compact_options
=
rocksdb
::
WaitForCompactOptions
::
default
();
wait_for_compact_options
.set_flush
(
USE_ATOMIC_FLUSH
);
self
.this.db
.wait_for_compact
(
&
wait_for_compact_options
)
?
;
println!
(
"Flush took {:?}"
,
start
.elapsed
());
Ok
(())
}
}
turbopack/crates/turbo-tasks-backend/src/kv_backing_storage.rs
View file @
6c3fd0f4
...
@@ -26,7 +26,7 @@ struct IntKey([u8; 4]);
...
@@ -26,7 +26,7 @@ struct IntKey([u8; 4]);
impl
IntKey
{
impl
IntKey
{
fn
new
(
value
:
u32
)
->
Self
{
fn
new
(
value
:
u32
)
->
Self
{
Self
(
value
.to_
l
e_bytes
())
Self
(
value
.to_
b
e_bytes
())
}
}
}
}
...
@@ -37,7 +37,7 @@ impl AsRef<[u8]> for IntKey {
...
@@ -37,7 +37,7 @@ impl AsRef<[u8]> for IntKey {
}
}
fn
as_u32
(
bytes
:
impl
Borrow
<
[
u8
]
>
)
->
Result
<
u32
>
{
fn
as_u32
(
bytes
:
impl
Borrow
<
[
u8
]
>
)
->
Result
<
u32
>
{
let
n
=
u32
::
from_
l
e_bytes
(
bytes
.borrow
()
.try_into
()
?
);
let
n
=
u32
::
from_
b
e_bytes
(
bytes
.borrow
()
.try_into
()
?
);
Ok
(
n
)
Ok
(
n
)
}
}
...
@@ -144,7 +144,7 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorage
...
@@ -144,7 +144,7 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorage
.put
(
.put
(
KeySpace
::
Infra
,
KeySpace
::
Infra
,
Cow
::
Borrowed
(
IntKey
::
new
(
META_KEY_SESSION_ID
)
.as_ref
()),
Cow
::
Borrowed
(
IntKey
::
new
(
META_KEY_SESSION_ID
)
.as_ref
()),
Cow
::
Borrowed
(
&
session_id
.to_
l
e_bytes
()),
Cow
::
Borrowed
(
&
session_id
.to_
b
e_bytes
()),
)
)
.with_context
(||
anyhow!
(
"Unable to write next session id"
))
?
;
.with_context
(||
anyhow!
(
"Unable to write next session id"
))
?
;
}
}
...
@@ -153,7 +153,7 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorage
...
@@ -153,7 +153,7 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorage
KeySpace
::
Infra
,
KeySpace
::
Infra
,
IntKey
::
new
(
META_KEY_NEXT_FREE_TASK_ID
)
.as_ref
(),
IntKey
::
new
(
META_KEY_NEXT_FREE_TASK_ID
)
.as_ref
(),
)
?
{
)
?
{
Some
(
bytes
)
=>
u32
::
from_
l
e_bytes
(
bytes
.borrow
()
.try_into
()
?
),
Some
(
bytes
)
=>
u32
::
from_
b
e_bytes
(
bytes
.borrow
()
.try_into
()
?
),
None
=>
1
,
None
=>
1
,
};
};
{
{
...
@@ -187,7 +187,7 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorage
...
@@ -187,7 +187,7 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorage
.put
(
.put
(
KeySpace
::
ForwardTaskCache
,
KeySpace
::
ForwardTaskCache
,
Cow
::
Borrowed
(
&
task_type_bytes
),
Cow
::
Borrowed
(
&
task_type_bytes
),
Cow
::
Borrowed
(
&
task_id
.to_
l
e_bytes
()),
Cow
::
Borrowed
(
&
task_id
.to_
b
e_bytes
()),
)
)
.with_context
(||
{
.with_context
(||
{
anyhow!
(
"Unable to write task cache {task_type:?} => {task_id}"
)
anyhow!
(
"Unable to write task cache {task_type:?} => {task_id}"
)
...
@@ -208,7 +208,7 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorage
...
@@ -208,7 +208,7 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorage
.put
(
.put
(
KeySpace
::
Infra
,
KeySpace
::
Infra
,
Cow
::
Borrowed
(
IntKey
::
new
(
META_KEY_NEXT_FREE_TASK_ID
)
.as_ref
()),
Cow
::
Borrowed
(
IntKey
::
new
(
META_KEY_NEXT_FREE_TASK_ID
)
.as_ref
()),
Cow
::
Borrowed
(
&
next_task_id
.to_
l
e_bytes
()),
Cow
::
Borrowed
(
&
next_task_id
.to_
b
e_bytes
()),
)
)
.with_context
(||
anyhow!
(
"Unable to write next free task id"
))
?
;
.with_context
(||
anyhow!
(
"Unable to write next free task id"
))
?
;
}
}
...
@@ -279,7 +279,7 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorage
...
@@ -279,7 +279,7 @@ impl<T: KeyValueDatabase + Send + Sync + 'static> BackingStorage
return
Ok
(
None
);
return
Ok
(
None
);
};
};
let
bytes
=
bytes
.borrow
()
.try_into
()
?
;
let
bytes
=
bytes
.borrow
()
.try_into
()
?
;
let
id
=
TaskId
::
from
(
u32
::
from_
l
e_bytes
(
bytes
));
let
id
=
TaskId
::
from
(
u32
::
from_
b
e_bytes
(
bytes
));
Ok
(
Some
(
id
))
Ok
(
Some
(
id
))
}
}
let
id
=
self
let
id
=
self
...
...
turbopack/crates/turbo-tasks-backend/src/lib.rs
View file @
6c3fd0f4
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
mod
backend
;
mod
backend
;
mod
backing_storage
;
mod
backing_storage
;
mod
data
;
mod
data
;
pub
mod
database
;
mod
database
;
mod
kv_backing_storage
;
mod
kv_backing_storage
;
mod
utils
;
mod
utils
;
...
@@ -12,37 +12,22 @@ use std::path::Path;
...
@@ -12,37 +12,22 @@ use std::path::Path;
use
anyhow
::
Result
;
use
anyhow
::
Result
;
pub
use
self
::{
backend
::
TurboTasksBackend
,
kv_backing_storage
::
KeyValueDatabaseBackingStorage
};
pub
use
self
::{
backend
::
TurboTasksBackend
,
kv_backing_storage
::
KeyValueDatabaseBackingStorage
};
use
crate
::
database
::
NoopKvDb
;
use
crate
::
database
::{
handle_db_versioning
,
is_fresh
,
lmdb
::
LmbdKeyValueDatabase
,
FreshDbOptimization
,
NoopKvDb
,
ReadTransactionCache
,
StartupCacheLayer
,
};
#[cfg(feature
=
"lmdb"
)]
pub
type
LmdbBackingStorage
=
KeyValueDatabaseBackingStorage
<
pub
type
LmdbBackingStorage
=
KeyValueDatabaseBackingStorage
<
crate
::
database
::
ReadTransactionCache
<
ReadTransactionCache
<
StartupCacheLayer
<
FreshDbOptimization
<
LmbdKeyValueDatabase
>>>
,
crate
::
database
::
StartupCacheLayer
<
crate
::
database
::
FreshDbOptimization
<
crate
::
database
::
LmbdKeyValueDatabase
>
,
>
,
>
,
>
;
>
;
#[cfg(feature
=
"lmdb"
)]
pub
fn
lmdb_backing_storage
(
path
:
&
Path
)
->
Result
<
LmdbBackingStorage
>
{
pub
fn
lmdb_backing_storage
(
path
:
&
Path
)
->
Result
<
LmdbBackingStorage
>
{
let
path
=
crate
::
database
::
handle_db_versioning
(
path
)
?
;
let
path
=
handle_db_versioning
(
path
)
?
;
let
fresh_db
=
crate
::
database
::
is_fresh
(
&
path
);
let
fresh_db
=
is_fresh
(
&
path
);
let
database
=
crate
::
database
::
LmbdKeyValueDatabase
::
new
(
&
path
)
?
;
let
database
=
LmbdKeyValueDatabase
::
new
(
&
path
)
?
;
let
database
=
crate
::
database
::
FreshDbOptimization
::
new
(
database
,
fresh_db
);
let
database
=
FreshDbOptimization
::
new
(
database
,
fresh_db
);
let
database
=
let
database
=
StartupCacheLayer
::
new
(
database
,
path
.join
(
"startup.cache"
),
fresh_db
)
?
;
crate
::
database
::
StartupCacheLayer
::
new
(
database
,
path
.join
(
"startup.cache"
),
fresh_db
)
?
;
let
database
=
ReadTransactionCache
::
new
(
database
);
let
database
=
crate
::
database
::
ReadTransactionCache
::
new
(
database
);
Ok
(
KeyValueDatabaseBackingStorage
::
new
(
database
))
}
#[cfg(feature
=
"rocksdb"
)]
pub
type
RocksDBBackingStorage
=
KeyValueDatabaseBackingStorage
<
crate
::
database
::
RocksDbKeyValueDatabase
>
;
#[cfg(feature
=
"rocksdb"
)]
pub
fn
rocksdb_backing_storage
(
path
:
&
Path
)
->
Result
<
RocksDBBackingStorage
>
{
let
path
=
crate
::
database
::
handle_db_versioning
(
path
)
?
;
let
database
=
crate
::
database
::
RocksDbKeyValueDatabase
::
new
(
&
path
)
?
;
Ok
(
KeyValueDatabaseBackingStorage
::
new
(
database
))
Ok
(
KeyValueDatabaseBackingStorage
::
new
(
database
))
}
}
...
@@ -52,18 +37,8 @@ pub fn noop_backing_storage(_path: &Path) -> Result<NoopBackingStorage> {
...
@@ -52,18 +37,8 @@ pub fn noop_backing_storage(_path: &Path) -> Result<NoopBackingStorage> {
Ok
(
KeyValueDatabaseBackingStorage
::
new
(
NoopKvDb
))
Ok
(
KeyValueDatabaseBackingStorage
::
new
(
NoopKvDb
))
}
}
#[cfg(feature
=
"rocksdb"
)]
pub
type
DefaultBackingStorage
=
RocksDBBackingStorage
;
#[cfg(feature
=
"rocksdb"
)]
pub
fn
default_backing_storage
(
path
:
&
Path
)
->
Result
<
DefaultBackingStorage
>
{
rocksdb_backing_storage
(
path
)
}
#[cfg(all(not(feature
=
"rocksdb"
),
feature
=
"lmdb"
))]
pub
type
DefaultBackingStorage
=
LmdbBackingStorage
;
pub
type
DefaultBackingStorage
=
LmdbBackingStorage
;
#[cfg(all(not(feature
=
"rocksdb"
),
feature
=
"lmdb"
))]
pub
fn
default_backing_storage
(
path
:
&
Path
)
->
Result
<
DefaultBackingStorage
>
{
pub
fn
default_backing_storage
(
path
:
&
Path
)
->
Result
<
DefaultBackingStorage
>
{
rocks
db_backing_storage
(
path
)
lm
db_backing_storage
(
path
)
}
}
turbopack/crates/turbo-tasks-testing/src/run.rs
View file @
6c3fd0f4
...
@@ -79,7 +79,6 @@ where
...
@@ -79,7 +79,6 @@ where
fn
closure_to_name
<
T
>
(
value
:
&
T
)
->
String
{
fn
closure_to_name
<
T
>
(
value
:
&
T
)
->
String
{
let
name
=
std
::
any
::
type_name_of_val
(
value
);
let
name
=
std
::
any
::
type_name_of_val
(
value
);
println!
(
"Closure name: {}"
,
name
);
name
.replace
(
"::{{closure}}"
,
""
)
.replace
(
"::"
,
"_"
)
name
.replace
(
"::{{closure}}"
,
""
)
.replace
(
"::"
,
"_"
)
}
}
...
@@ -91,33 +90,20 @@ where
...
@@ -91,33 +90,20 @@ where
F
:
Future
<
Output
=
Result
<
T
>>
+
Send
+
'static
,
F
:
Future
<
Output
=
Result
<
T
>>
+
Send
+
'static
,
T
:
Debug
+
PartialEq
+
Eq
+
TraceRawVcs
+
Send
+
'static
,
T
:
Debug
+
PartialEq
+
Eq
+
TraceRawVcs
+
Send
+
'static
,
{
{
let
name
=
closure_to_name
(
&
fut
);
run_with_tt
(
registration
,
move
|
tt
|
run_once
(
tt
,
fut
()))
.await
run_internal
(
registration
,
name
,
move
|
tt
|
run_once
(
tt
,
fut
()))
.await
}
}
pub
async
fn
run_with_tt
<
T
,
F
>
(
pub
async
fn
run_with_tt
<
T
,
F
>
(
registration
:
&
Registration
,
registration
:
&
Registration
,
fut
:
impl
Fn
(
Arc
<
dyn
TurboTasksApi
>
)
->
F
+
Send
+
'static
,
fut
:
impl
Fn
(
Arc
<
dyn
TurboTasksApi
>
)
->
F
+
Send
+
'static
,
)
->
Result
<
()
>
)
->
Result
<
()
>
where
F
:
Future
<
Output
=
Result
<
T
>>
+
Send
+
'static
,
T
:
Debug
+
PartialEq
+
Eq
+
TraceRawVcs
+
Send
+
'static
,
{
let
name
=
closure_to_name
(
&
fut
);
run_internal
(
registration
,
name
,
fut
)
.await
}
pub
async
fn
run_internal
<
T
,
F
>
(
registration
:
&
Registration
,
name
:
String
,
fut
:
impl
Fn
(
Arc
<
dyn
TurboTasksApi
>
)
->
F
+
Send
+
'static
,
)
->
Result
<
()
>
where
where
F
:
Future
<
Output
=
Result
<
T
>>
+
Send
+
'static
,
F
:
Future
<
Output
=
Result
<
T
>>
+
Send
+
'static
,
T
:
Debug
+
PartialEq
+
Eq
+
TraceRawVcs
+
Send
+
'static
,
T
:
Debug
+
PartialEq
+
Eq
+
TraceRawVcs
+
Send
+
'static
,
{
{
registration
.ensure_registered
();
registration
.ensure_registered
();
let
name
=
closure_to_name
(
&
fut
);
let
tt
=
registration
.create_turbo_tasks
(
&
name
,
true
);
let
tt
=
registration
.create_turbo_tasks
(
&
name
,
true
);
println!
(
"Run #1 (without cache)"
);
println!
(
"Run #1 (without cache)"
);
let
start
=
std
::
time
::
Instant
::
now
();
let
start
=
std
::
time
::
Instant
::
now
();
...
@@ -131,11 +117,6 @@ where
...
@@ -131,11 +117,6 @@ where
let
start
=
std
::
time
::
Instant
::
now
();
let
start
=
std
::
time
::
Instant
::
now
();
tt
.stop_and_wait
()
.await
;
tt
.stop_and_wait
()
.await
;
println!
(
"Stopping TurboTasks took {:?}"
,
start
.elapsed
());
println!
(
"Stopping TurboTasks took {:?}"
,
start
.elapsed
());
// TODO enable that when turbo-tasks-memory is removed
// assert_eq!(Arc::strong_count(&tt), 1);
let
start
=
std
::
time
::
Instant
::
now
();
drop
(
tt
);
println!
(
"Dropping TurboTasks took {:?}"
,
start
.elapsed
());
let
tt
=
registration
.create_turbo_tasks
(
&
name
,
false
);
let
tt
=
registration
.create_turbo_tasks
(
&
name
,
false
);
println!
(
"Run #3 (with persistent cache if available, new TurboTasks instance)"
);
println!
(
"Run #3 (with persistent cache if available, new TurboTasks instance)"
);
let
start
=
std
::
time
::
Instant
::
now
();
let
start
=
std
::
time
::
Instant
::
now
();
...
@@ -144,11 +125,6 @@ where
...
@@ -144,11 +125,6 @@ where
let
start
=
std
::
time
::
Instant
::
now
();
let
start
=
std
::
time
::
Instant
::
now
();
tt
.stop_and_wait
()
.await
;
tt
.stop_and_wait
()
.await
;
println!
(
"Stopping TurboTasks took {:?}"
,
start
.elapsed
());
println!
(
"Stopping TurboTasks took {:?}"
,
start
.elapsed
());
// TODO enable that when turbo-tasks-memory is removed
// assert_eq!(Arc::strong_count(&tt), 1);
let
start
=
std
::
time
::
Instant
::
now
();
drop
(
tt
);
println!
(
"Dropping TurboTasks took {:?}"
,
start
.elapsed
());
assert_eq!
(
first
,
third
);
assert_eq!
(
first
,
third
);
Ok
(())
Ok
(())
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment