GeezerVison is showing github.com — Integrate tiered storage (#6305) · clockworklabs/SpacetimeDB@4d685de
File treeExpand file treeCollapse file tree Open diff view settings Codegen.Tests/fixtures/server
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Cargo.lock +24Lines changed: 24 additions & 0 deletions Collapse file Copy file name to clipboardExpand all lines: Cargo.toml +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,6 +34,7 @@ members = [ | 34 | 34 | "crates/sats", | 35 | 35 | "crates/schema", | 36 | 36 | "crates/smoketests", | | 37 | + "crates/tiered-storage", | 37 | 38 | "sdks/csharp/test-harness~", | 38 | 39 | "sdks/rust", | 39 | 40 | "sdks/unreal", | @@ -199,6 +200,7 @@ spacetimedb-subscription = { path = "crates/subscription", version = "=2.16.0" } | 199 | 200 | spacetimedb-sql-parser = { path = "crates/sql-parser", version = "=2.16.0" } | 200 | 201 | spacetimedb-table = { path = "crates/table", version = "=2.16.0" } | 201 | 202 | spacetimedb-test-datastore = { path = "crates/test-datastore", version = "=2.16.0" } | | 203 | +spacetimedb-tiered-storage = { path = "crates/tiered-storage", version = "=2.16.0" } | 202 | 204 |
| 203 | 205 | # Prevent `ahash` from pulling in `getrandom` by disabling default features. | 204 | 206 | # Modules use `getrandom02` and we need to prevent an incompatible version | @@ -221,6 +223,7 @@ blake3 = "1.5.1" | 221 | 223 | brotli = { version = "3.5", default-features = false, features = ["std"] } | 222 | 224 | bytemuck = { version = "1.16.2", features = ["must_cast"] } | 223 | 225 | bytes = "1.10.1" | | 226 | +bytesize = "2.0.1" | 224 | 227 | bytestring = { version = "1.2.0", features = ["serde"] } | 225 | 228 | cargo_metadata = "0.17.0" | 226 | 229 | chrono = { version = "0.4.24", default-features = false } | |
Collapse file Copy file name to clipboardExpand all lines: crates/bench/benches/special.rs +6-5Lines changed: 6 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,7 +9,7 @@ use spacetimedb_lib::sats::{self, bsatn}; | 9 | 9 | use spacetimedb_lib::{bsatn::ToBsatn as _, ProductValue}; | 10 | 10 | use spacetimedb_schema::schema::TableSchema; | 11 | 11 | use spacetimedb_schema::table_name::TableName; | 12 | | -use spacetimedb_table::page_pool::PagePool; | | 12 | +use spacetimedb_table::tiered::{EvictionPolicy, PageManager}; | 13 | 13 | use spacetimedb_testing::modules::{Csharp, ModuleLanguage, Rust}; | 14 | 14 | use std::sync::Arc; | 15 | 15 | use std::sync::OnceLock; | @@ -141,24 +141,25 @@ fn serialize_benchmarks< | 141 | 141 | let mut table = spacetimedb_table::table::Table::new( | 142 | 142 | Arc::new(table_schema), | 143 | 143 | spacetimedb_table::indexes::SquashedOffset::COMMITTED_STATE, | | 144 | + PageManager::new_for_test().into(), | | 145 | + EvictionPolicy::NeverEvict, | 144 | 146 | ); | 145 | | - let pool = PagePool::new_for_test(); | 146 | | - let mut blob_store = spacetimedb_table::blob_store::HashMapBlobStore::default(); | | 147 | + let blob_store = spacetimedb_table::tiered::BlobSet::new_for_test(); | 147 | 148 |
| 148 | 149 | let ptrs = data_pv | 149 | 150 | .elements | 150 | 151 | .iter() | 151 | 152 | .map(|row| { | 152 | 153 | table | 153 | | - .insert(&pool, &mut blob_store, row.as_product().unwrap()) | | 154 | + .insert(&blob_store, row.as_product().unwrap()) | 154 | 155 | .unwrap() | 155 | 156 | .1 | 156 | 157 | .pointer() | 157 | 158 | }) | 158 | 159 | .collect::<Vec<_>>(); | 159 | 160 | let refs = ptrs | 160 | 161 | .into_iter() | 161 | | - .map(|ptr| table.get_row_ref(&blob_store, ptr).unwrap()) | | 162 | + .map(|ptr| table.get_row_ref(&blob_store, ptr).unwrap().unwrap()) | 162 | 163 | .collect::<Vec<_>>(); | 163 | 164 | group.bench_function(format!("bflatn_to_bsatn_slow_path/count={count}"), |b| { | 164 | 165 | b.iter(|| { | |
Collapse file Copy file name to clipboardExpand all lines: crates/bench/src/spacetime_raw.rs +9-6Lines changed: 9 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,10 @@ use crate::{ | 3 | 3 | schemas::{table_name, BenchTable, IndexStrategy}, | 4 | 4 | ResultBench, | 5 | 5 | }; | 6 | | -use spacetimedb::db::relational_db::{tests_utils::TestDB, RelationalDB}; | | 6 | +use spacetimedb::{ | | 7 | + db::relational_db::{tests_utils::TestDB, RelationalDB}, | | 8 | + error::DatastoreError, | | 9 | +}; | 7 | 10 | use spacetimedb_datastore::execution_context::Workload; | 8 | 11 | use spacetimedb_primitives::{ColId, IndexId, TableId}; | 9 | 12 | use spacetimedb_sats::{bsatn, AlgebraicValue}; | @@ -120,8 +123,8 @@ impl BenchDatabase for SpacetimeRaw { | 120 | 123 | .db | 121 | 124 | .iter_mut(tx, *table_id)? | 122 | 125 | .take(row_count as usize) | 123 | | - .map(|row| row.to_product_value()) | 124 | | - .collect::<Vec<_>>(); | | 126 | + .map(|row| row.map(|r| r.to_product_value())) | | 127 | + .collect::<Result<Vec<_>, DatastoreError>>()?; | 125 | 128 |
| 126 | 129 | assert_eq!(rows.len(), row_count as usize, "not enough rows found for update_bulk!"); | 127 | 130 | let mut scratch = Vec::new(); | @@ -133,7 +136,7 @@ impl BenchDatabase for SpacetimeRaw { | 133 | 136 | .db | 134 | 137 | .iter_by_col_eq_mut(tx, *table_id, 0, &row.elements[0])? | 135 | 138 | .next() | 136 | | - .expect("failed to find row during update!") | | 139 | + .expect("failed to find row during update!")? | 137 | 140 | .pointer(); | 138 | 141 |
| 139 | 142 | assert_eq!( | @@ -160,7 +163,7 @@ impl BenchDatabase for SpacetimeRaw { | 160 | 163 | fn iterate(&mut self, table_id: &Self::TableId) -> ResultBench<()> { | 161 | 164 | self.db.with_auto_commit(Workload::Internal, |tx| { | 162 | 165 | for row in self.db.iter_mut(tx, *table_id)? { | 163 | | - black_box(row); | | 166 | + black_box(row?); | 164 | 167 | } | 165 | 168 | Ok(()) | 166 | 169 | }) | @@ -174,7 +177,7 @@ impl BenchDatabase for SpacetimeRaw { | 174 | 177 | ) -> ResultBench<()> { | 175 | 178 | self.db.with_auto_commit(Workload::Internal, |tx| { | 176 | 179 | for row in self.db.iter_by_col_eq_mut(tx, *table_id, col_id, &value)? { | 177 | | - black_box(row); | | 180 | + black_box(row?); | 178 | 181 | } | 179 | 182 | Ok(()) | 180 | 183 | }) | |
Collapse file Copy file name to clipboardExpand all lines: crates/bindings-csharp/Codegen.Tests/fixtures/server/Lib.cs +9-2Lines changed: 9 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -212,8 +212,15 @@ public static void Init(ReducerContext ctx) | 212 | 212 | } | 213 | 213 | } | 214 | 214 |
| 215 | | -[SpacetimeDB.Table(Accessor = "MultiTable1", Public = true)] | 216 | | -[SpacetimeDB.Table(Accessor = "MultiTable2")] | | 215 | +[SpacetimeDB.Table( | | 216 | + Accessor = "MultiTable1", | | 217 | + Public = true, | | 218 | + CachePolicy = SpacetimeDB.TableCachePolicy.RequiredOnDisk | | 219 | +)] | | 220 | +[SpacetimeDB.Table( | | 221 | + Accessor = "MultiTable2", | | 222 | + CachePolicy = SpacetimeDB.TableCachePolicy.NoRequirement | | 223 | +)] | 217 | 224 | public partial struct MultiTableRow | 218 | 225 | { | 219 | 226 | [SpacetimeDB.Index.BTree(Table = "MultiTable1")] | |
Collapse file Copy file name to clipboardExpand all lines: crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module#FFI.verified.cs +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2238,6 +2238,9 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar | 2238 | 2238 |
| 2239 | 2239 | public static SpacetimeDB.Internal.RawScheduleDefV10? MakeScheduleDesc() => null; | 2240 | 2240 |
| | 2241 | + public static SpacetimeDB.TableCachePolicy CachePolicy => | | 2242 | + SpacetimeDB.TableCachePolicy.RequiredOnDisk; | | 2243 | + | 2241 | 2244 | /// <summary> | 2242 | 2245 | /// Returns the number of rows in this table. | 2243 | 2246 | /// | @@ -2374,6 +2377,9 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar | 2374 | 2377 |
| 2375 | 2378 | public static SpacetimeDB.Internal.RawScheduleDefV10? MakeScheduleDesc() => null; | 2376 | 2379 |
| | 2380 | + public static SpacetimeDB.TableCachePolicy CachePolicy => | | 2381 | + SpacetimeDB.TableCachePolicy.NoRequirement; | | 2382 | + | 2377 | 2383 | /// <summary> | 2378 | 2384 | /// Returns the number of rows in this table. | 2379 | 2385 | /// | |
Collapse file Copy file name to clipboardExpand all lines: crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module.net10#FFI.verified.cs +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2516,6 +2516,9 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar | 2516 | 2516 |
| 2517 | 2517 | public static SpacetimeDB.Internal.RawScheduleDefV10? MakeScheduleDesc() => null; | 2518 | 2518 |
| | 2519 | + public static SpacetimeDB.TableCachePolicy CachePolicy => | | 2520 | + SpacetimeDB.TableCachePolicy.RequiredOnDisk; | | 2521 | + | 2519 | 2522 | /// <summary> | 2520 | 2523 | /// Returns the number of rows in this table. | 2521 | 2524 | /// | @@ -2715,6 +2718,9 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar | 2715 | 2718 |
| 2716 | 2719 | public static SpacetimeDB.Internal.RawScheduleDefV10? MakeScheduleDesc() => null; | 2717 | 2720 |
| | 2721 | + public static SpacetimeDB.TableCachePolicy CachePolicy => | | 2722 | + SpacetimeDB.TableCachePolicy.NoRequirement; | | 2723 | + | 2718 | 2724 | /// <summary> | 2719 | 2725 | /// Returns the number of rows in this table. | 2720 | 2726 | /// | |
Collapse file Copy file name to clipboardExpand all lines: crates/bindings-csharp/Codegen/Codegen.csproj +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 11 | 11 | <IsPackable>false</IsPackable> | 12 | 12 | <IsRoslynComponent>true</IsRoslynComponent> | 13 | 13 | <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules> | | 14 | + <DefineConstants>$(DefineConstants);SPACETIMEDB_CODEGEN</DefineConstants> | 14 | 15 | </PropertyGroup> | 15 | 16 |
| 16 | 17 | <PropertyGroup> | | 37 | 38 | <ItemGroup> | 38 | 39 | <!-- reuse attribute and adjacent types from the runtime --> | 39 | 40 | <Compile Include="../Runtime/Attrs.cs" /> | | 41 | + <Compile Include="../Runtime/Internal/Autogen/TableCachePolicy.g.cs" /> | 40 | 42 | </ItemGroup> | 41 | 43 |
| 42 | 44 | <!-- Local project references (used by SpacetimeDB/modules/*-cs) don't use NuGet resolution. --> | |
Collapse file Copy file name to clipboardExpand all lines: crates/bindings-csharp/Codegen/Module.cs +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -278,6 +278,7 @@ record TableAccessor | 278 | 278 | public readonly string? CanonicalName; | 279 | 279 | public readonly bool IsPublic; | 280 | 280 | public readonly bool IsEvent; | | 281 | + public readonly TableCachePolicy CachePolicy; | 281 | 282 | public readonly Scheduled? Scheduled; | 282 | 283 |
| 283 | 284 | public string Identifier => EscapeIdentifier(Name); | @@ -290,6 +291,7 @@ public TableAccessor(TableDeclaration table, AttributeData data, DiagReporter di | 290 | 291 | CanonicalName = attr.Name; | 291 | 292 | IsPublic = attr.Public; | 292 | 293 | IsEvent = attr.Event; | | 294 | + CachePolicy = attr.CachePolicy; | 293 | 295 | if ( | 294 | 296 | attr.Scheduled is { } reducer | 295 | 297 | && table.GetColumnIndex(data, attr.ScheduledAt, diag) is { } scheduledAtIndex | @@ -1027,6 +1029,10 @@ public IEnumerable<GeneratedTableAccessor> GenerateTableAccessors() | 1027 | 1029 | var accessorIdentifier = v.Identifier; | 1028 | 1030 | var iTable = | 1029 | 1031 | $"global::SpacetimeDB.Internal.ITableView<{accessorIdentifier}, {globalName}>"; | | 1032 | + var cachePolicy = | | 1033 | + v.CachePolicy == TableCachePolicy.RequiredInMemory | | 1034 | + ? "" | | 1035 | + : $"\n\npublic static SpacetimeDB.TableCachePolicy CachePolicy => SpacetimeDB.TableCachePolicy.{v.CachePolicy};"; | 1030 | 1036 | var tableArgument = sharedContexts ? "__state" : ""; | 1031 | 1037 | var rowArgument = sharedContexts ? "row, __state" : "row"; | 1032 | 1038 | var instanceMembers = sharedContexts | @@ -1104,7 +1110,7 @@ private static __InstanceState __CreateInstance(int contextInstance) | 1104 | 1110 | v.Scheduled is { } scheduled | 1105 | 1111 | ? $"{iTable}.MakeSchedule(\"{scheduled.ReducerName}\", {scheduled.ScheduledAtColumn})" | 1106 | 1112 | : "null" | 1107 | | - )}}}; | | 1113 | + )}}};{{{cachePolicy}}} | 1108 | 1114 |
| 1109 | 1115 | /// <summary> | 1110 | 1116 | /// Returns the number of rows in this table. | |
Collapse file Copy file name to clipboardExpand all lines: crates/bindings-csharp/Runtime/Attrs.cs +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -85,6 +85,9 @@ public sealed class TableAttribute : Attribute | 85 | 85 |
| 86 | 86 | public bool Event { get; init; } = false; | 87 | 87 |
| | 88 | + /// <summary>The furthest storage tier the table's pages and blobs may reside in.</summary> | | 89 | + public TableCachePolicy CachePolicy { get; init; } = TableCachePolicy.RequiredInMemory; | | 90 | + | 88 | 91 | /// <summary> | 89 | 92 | /// If set, the name of the reducer that will be invoked when the scheduled time is reached. | 90 | 93 | /// </summary> | |
|