Skip to content

Commit f8a1860

Browse files
authored
Merge branch 'master' into rekhoff/reapply-update-nativeaot-llvm-infrastructure
2 parents 5c665c9 + 9e2946b commit f8a1860

53 files changed

Lines changed: 1177 additions & 7797 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,36 +1025,6 @@ jobs:
10251025
- name: Check global.json policy
10261026
run: cargo ci global-json-policy
10271027

1028-
warn-python-smoketests:
1029-
name: Check for Python smoketest edits
1030-
runs-on: ubuntu-latest
1031-
if: github.event_name == 'pull_request'
1032-
permissions:
1033-
contents: read
1034-
steps:
1035-
- name: Checkout sources
1036-
uses: actions/checkout@v4
1037-
with:
1038-
fetch-depth: 0
1039-
1040-
- name: Fail if Python smoketests were modified
1041-
run: |
1042-
MERGE_BASE="$(git merge-base origin/${{ github.base_ref }} HEAD)"
1043-
PYTHON_SMOKETEST_CHANGES="$(git diff --name-only "$MERGE_BASE" HEAD -- 'smoketests/**.py')"
1044-
1045-
if [ -n "$PYTHON_SMOKETEST_CHANGES" ]; then
1046-
echo "::error::This PR modifies legacy Python smoketests. Please add new tests to the Rust smoketests in crates/smoketests/ instead."
1047-
echo ""
1048-
echo "Changed files:"
1049-
echo "$PYTHON_SMOKETEST_CHANGES"
1050-
echo ""
1051-
echo "The Python smoketests are being replaced by Rust smoketests."
1052-
echo "See crates/smoketests/DEVELOP.md for instructions on adding Rust smoketests."
1053-
exit 1
1054-
fi
1055-
1056-
echo "No Python smoketest changes detected."
1057-
10581028
smoketests_mod_rs_complete:
10591029
name: Check smoketests/mod.rs is complete
10601030
runs-on: ubuntu-latest

crates/bindings-typescript/src/react/useTable.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export interface UseTableCallbacks<RowType> {
2424
onInsert?: (row: RowType) => void;
2525
onDelete?: (row: RowType) => void;
2626
onUpdate?: (oldRow: RowType, newRow: RowType) => void;
27+
/** Whether the subscription is active. Defaults to `true`. */
28+
enabled?: boolean;
2729
}
2830

2931
type MembershipChange = 'enter' | 'leave' | 'stayIn' | 'stayOut';
@@ -67,6 +69,7 @@ export function useTable<TableDef extends UntypedTableDef>(
6769
callbacks?: UseTableCallbacks<Prettify<RowType<TableDef>>>
6870
): [readonly Prettify<RowType<TableDef>>[], boolean] {
6971
type UseTableRowType = RowType<TableDef>;
72+
const enabled = callbacks?.enabled ?? true;
7073
const accessorName = getQueryAccessorName(query);
7174
const whereExpr = getQueryWhereClause(query);
7275

@@ -93,6 +96,9 @@ export function useTable<TableDef extends UntypedTableDef>(
9396
readonly Prettify<UseTableRowType>[],
9497
boolean,
9598
] => {
99+
if (!enabled) {
100+
return [[], true];
101+
}
96102
const connection = connectionState.getConnection();
97103
if (!connection) {
98104
return [[], false];
@@ -107,7 +113,7 @@ export function useTable<TableDef extends UntypedTableDef>(
107113
// TODO: investigating refactoring so that this is no longer necessary, as we have had genuine bugs with missed deps.
108114
// See https://github.com/clockworklabs/SpacetimeDB/pull/4580.
109115
// eslint-disable-next-line react-hooks/exhaustive-deps
110-
}, [connectionState, accessorName, querySql, subscribeApplied]);
116+
}, [connectionState, accessorName, querySql, subscribeApplied, enabled]);
111117

112118
// Invalidate the cached snapshot when computeSnapshot changes (e.g. when
113119
// subscribeApplied flips to true) so getSnapshot() recomputes on the next
@@ -117,6 +123,10 @@ export function useTable<TableDef extends UntypedTableDef>(
117123
}, [computeSnapshot]);
118124

119125
useEffect(() => {
126+
if (!enabled) {
127+
setSubscribeApplied(false);
128+
return;
129+
}
120130
const connection = connectionState.getConnection()!;
121131
if (connectionState.isActive && connection) {
122132
const cancel = connection
@@ -129,10 +139,14 @@ export function useTable<TableDef extends UntypedTableDef>(
129139
cancel.unsubscribe();
130140
};
131141
}
132-
}, [querySql, connectionState.isActive, connectionState]);
142+
}, [querySql, connectionState.isActive, connectionState, enabled]);
133143

134144
const subscribe = useCallback(
135145
(onStoreChange: () => void) => {
146+
if (!enabled) {
147+
return () => {};
148+
}
149+
136150
const onInsert = (
137151
ctx: EventContextInterface<UntypedRemoteModule>,
138152
row: any
@@ -218,6 +232,7 @@ export function useTable<TableDef extends UntypedTableDef>(
218232
callbacks?.onDelete,
219233
callbacks?.onInsert,
220234
callbacks?.onUpdate,
235+
enabled,
221236
]
222237
);
223238

crates/bindings/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,9 +1110,10 @@ impl ReducerContext {
11101110
/// use spacetimedb::{reducer, ReducerContext, Uuid};
11111111
///
11121112
/// #[reducer]
1113-
/// fn generate_uuid_v4(ctx: &ReducerContext) -> Uuid {
1114-
/// let uuid = ctx.new_uuid_v4();
1113+
/// fn generate_uuid_v4(ctx: &ReducerContext) -> Result<(), Box<dyn std::error::Error>> {
1114+
/// let uuid = ctx.new_uuid_v4()?;
11151115
/// log::info!(uuid);
1116+
/// Ok(())
11161117
/// }
11171118
/// # }
11181119
/// ```
@@ -1131,9 +1132,10 @@ impl ReducerContext {
11311132
/// use spacetimedb::{reducer, ReducerContext, Uuid};
11321133
///
11331134
/// #[reducer]
1134-
/// fn generate_uuid_v7(ctx: &ReducerContext) -> Result<Uuid, Box<dyn std::error::Error>> {
1135+
/// fn generate_uuid_v7(ctx: &ReducerContext) -> Result<(), Box<dyn std::error::Error>> {
11351136
/// let uuid = ctx.new_uuid_v7()?;
11361137
/// log::info!(uuid);
1138+
/// Ok(())
11371139
/// }
11381140
/// # }
11391141
/// ```

crates/cli/src/subcommands/login.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn cli() -> Command {
2222
.arg(
2323
Arg::new("server")
2424
.long("server-issued-login")
25+
.hide(true)
2526
.group("login-method")
2627
.help("Log in to a SpacetimeDB server directly, without going through a global auth server"),
2728
)

crates/core/src/db/relational_db.rs

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use spacetimedb_datastore::locking_tx_datastore::datastore::TxMetrics;
1717
use spacetimedb_datastore::locking_tx_datastore::state_view::{
1818
IterByColEqMutTx, IterByColRangeMutTx, IterMutTx, StateView,
1919
};
20-
use spacetimedb_datastore::locking_tx_datastore::{IndexScanPointOrRange, MutTxId, TxId};
20+
use spacetimedb_datastore::locking_tx_datastore::{ApplyHistoryCounters, IndexScanPointOrRange, MutTxId, TxId};
2121
use spacetimedb_datastore::system_tables::{
2222
system_tables, StModuleRow, ST_CLIENT_ID, ST_CONNECTION_CREDENTIALS_ID, ST_VIEW_SUB_ID,
2323
};
@@ -1617,62 +1617,20 @@ impl RelationalDB {
16171617
}
16181618
}
16191619

1620-
fn apply_history<H>(datastore: &Locking, database_identity: Identity, history: H) -> Result<(), DBError>
1621-
where
1622-
H: durability::History<TxData = Txdata>,
1623-
{
1624-
log::info!("[{database_identity}] DATABASE: applying transaction history...");
1625-
1626-
// TODO: Revisit once we actually replay history suffixes, ie. starting
1627-
// from an offset larger than the history's min offset.
1628-
// TODO: We may want to require that a `tokio::runtime::Handle` is
1629-
// always supplied when constructing a `RelationalDB`. This would allow
1630-
// to spawn a timer task here which just prints the progress periodically
1631-
// in case the history is finite but very long.
1632-
let (_, max_tx_offset) = history.tx_range_hint();
1633-
let mut last_logged_percentage = 0;
1634-
let progress = |tx_offset: u64| {
1635-
if let Some(max_tx_offset) = max_tx_offset {
1636-
let percentage = f64::floor((tx_offset as f64 / max_tx_offset as f64) * 100.0) as i32;
1637-
if percentage > last_logged_percentage && percentage % 10 == 0 {
1638-
log::info!("[{database_identity}] Loaded {percentage}% ({tx_offset}/{max_tx_offset})");
1639-
last_logged_percentage = percentage;
1640-
}
1641-
// Print _something_ even if we don't know what's still ahead.
1642-
} else if tx_offset.is_multiple_of(10_000) {
1643-
log::info!("[{database_identity}] Loading transaction {tx_offset}");
1644-
}
1620+
fn apply_history(
1621+
datastore: &Locking,
1622+
database_identity: Identity,
1623+
history: impl durability::History<TxData = Txdata>,
1624+
) -> Result<(), DBError> {
1625+
let counters = ApplyHistoryCounters {
1626+
replay_commitlog_time_seconds: WORKER_METRICS
1627+
.replay_commitlog_time_seconds
1628+
.with_label_values(&database_identity),
1629+
replay_commitlog_num_commits: WORKER_METRICS
1630+
.replay_commitlog_num_commits
1631+
.with_label_values(&database_identity),
16451632
};
1646-
1647-
let time_before = std::time::Instant::now();
1648-
1649-
let mut replay = datastore.replay(
1650-
progress,
1651-
// We don't want to instantiate an incorrect state;
1652-
// if the commitlog contains an inconsistency we'd rather get a hard error than showing customers incorrect data.
1653-
spacetimedb_datastore::locking_tx_datastore::datastore::ErrorBehavior::FailFast,
1654-
);
1655-
let start_tx_offset = replay.next_tx_offset();
1656-
history
1657-
.fold_transactions_from(start_tx_offset, &mut replay)
1658-
.map_err(anyhow::Error::from)?;
1659-
1660-
let time_elapsed = time_before.elapsed();
1661-
WORKER_METRICS
1662-
.replay_commitlog_time_seconds
1663-
.with_label_values(&database_identity)
1664-
.set(time_elapsed.as_secs_f64());
1665-
1666-
let end_tx_offset = replay.next_tx_offset();
1667-
WORKER_METRICS
1668-
.replay_commitlog_num_commits
1669-
.with_label_values(&database_identity)
1670-
.set((end_tx_offset - start_tx_offset) as _);
1671-
1672-
log::info!("[{database_identity}] DATABASE: applied transaction history");
1673-
datastore.rebuild_state_after_replay()?;
1674-
log::info!("[{database_identity}] DATABASE: rebuilt state after replay");
1675-
1633+
spacetimedb_datastore::locking_tx_datastore::apply_history(datastore, database_identity, history, counters)?;
16761634
Ok(())
16771635
}
16781636

0 commit comments

Comments
 (0)