Skip to content

Commit 6710fb3

Browse files
committed
Removing references to stdb
1 parent a3017b7 commit 6710fb3

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

crates/core/src/host/instance_env.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,22 @@ impl InstanceEnv {
171171
col_id: ColId,
172172
value: &[u8],
173173
) -> Result<u32, NodesError> {
174-
let stdb = &*self.dbic.db_engine;
174+
let db_engine = &*self.dbic.db_engine;
175175
let tx = &mut *self.get_tx()?;
176176

177177
// Interpret the `value` using the schema of the column.
178-
let eq_value = &stdb.decode_column(tx, table_id, col_id, value)?;
178+
let eq_value = &db_engine.decode_column(tx, table_id, col_id, value)?;
179179

180180
// Find all rows in the table where the column data equates to `value`.
181-
let rows_to_delete = stdb
181+
let rows_to_delete = db_engine
182182
.iter_by_col_eq_mut(ctx, tx, table_id, col_id, eq_value)?
183183
.map(|row_ref| row_ref.pointer())
184184
// `delete_by_field` only cares about 1 element,
185185
// so optimize for that.
186186
.collect::<SmallVec<[_; 1]>>();
187187

188188
// Delete them and count how many we deleted.
189-
Ok(stdb.delete(tx, table_id, rows_to_delete))
189+
Ok(db_engine.delete(tx, table_id, rows_to_delete))
190190
}
191191

192192
/// Deletes all rows in the table identified by `table_id`
@@ -196,29 +196,29 @@ impl InstanceEnv {
196196
/// Returns an error if no rows were deleted.
197197
#[tracing::instrument(skip(self, relation))]
198198
pub fn delete_by_rel(&self, table_id: TableId, relation: &[u8]) -> Result<u32, NodesError> {
199-
let stdb = &*self.dbic.db_engine;
199+
let db_engine = &*self.dbic.db_engine;
200200
let tx = &mut *self.get_tx()?;
201201

202202
// Find the row schema using it to decode a vector of product values.
203-
let row_ty = stdb.row_schema_for_table(tx, table_id)?;
203+
let row_ty = db_engine.row_schema_for_table(tx, table_id)?;
204204
// `TableType::delete` cares about a single element
205205
// so in that case we can avoid the allocation by using `smallvec`.
206206
let relation = ProductValue::decode_smallvec(&row_ty, &mut &*relation).map_err(NodesError::DecodeRow)?;
207207

208208
// Delete them and return how many we deleted.
209-
Ok(stdb.delete_by_rel(tx, table_id, relation))
209+
Ok(db_engine.delete_by_rel(tx, table_id, relation))
210210
}
211211

212212
/// Returns the `table_id` associated with the given `table_name`.
213213
///
214214
/// Errors with `TableNotFound` if the table does not exist.
215215
#[tracing::instrument(skip_all)]
216216
pub fn get_table_id(&self, table_name: &str) -> Result<TableId, NodesError> {
217-
let stdb = &*self.dbic.db_engine;
217+
let db_engine = &*self.dbic.db_engine;
218218
let tx = &mut *self.get_tx()?;
219219

220220
// Query the table id from the name.
221-
let table_id = stdb
221+
let table_id = db_engine
222222
.table_id_from_name_mut(tx, table_name)?
223223
.ok_or(NodesError::TableNotFound)?;
224224

@@ -244,7 +244,7 @@ impl InstanceEnv {
244244
index_type: u8,
245245
col_ids: Vec<u8>,
246246
) -> Result<(), NodesError> {
247-
let stdb = &*self.dbic.db_engine;
247+
let db_engine = &*self.dbic.db_engine;
248248
let tx = &mut *self.get_tx()?;
249249

250250
// TODO(george) This check should probably move towards src/db/index, but right
@@ -264,7 +264,7 @@ impl InstanceEnv {
264264
.build()
265265
.expect("Attempt to create an index with zero columns");
266266

267-
let is_unique = stdb.column_constraints(tx, table_id, &columns)?.has_unique();
267+
let is_unique = db_engine.column_constraints(tx, table_id, &columns)?.has_unique();
268268

269269
let index = IndexDef {
270270
columns,
@@ -273,7 +273,7 @@ impl InstanceEnv {
273273
index_type,
274274
};
275275

276-
stdb.create_index(tx, table_id, index)?;
276+
db_engine.create_index(tx, table_id, index)?;
277277

278278
Ok(())
279279
}
@@ -292,23 +292,23 @@ impl InstanceEnv {
292292
col_id: ColId,
293293
value: &[u8],
294294
) -> Result<Vec<Box<[u8]>>, NodesError> {
295-
let stdb = &*self.dbic.db_engine;
295+
let db_engine = &*self.dbic.db_engine;
296296
let tx = &mut *self.get_tx()?;
297297

298298
// Interpret the `value` using the schema of the column.
299-
let value = &stdb.decode_column(tx, table_id, col_id, value)?;
299+
let value = &db_engine.decode_column(tx, table_id, col_id, value)?;
300300

301301
// Find all rows in the table where the column data matches `value`.
302-
let chunks = ChunkedWriter::collect_iter(stdb.iter_by_col_eq_mut(ctx, tx, table_id, col_id, value)?);
302+
let chunks = ChunkedWriter::collect_iter(db_engine.iter_by_col_eq_mut(ctx, tx, table_id, col_id, value)?);
303303
Ok(chunks)
304304
}
305305

306306
#[tracing::instrument(skip_all)]
307307
pub fn iter_chunks(&self, ctx: &ExecutionContext, table_id: TableId) -> Result<Vec<Box<[u8]>>, NodesError> {
308-
let stdb = &*self.dbic.db_engine;
308+
let db_engine = &*self.dbic.db_engine;
309309
let tx = &mut *self.tx.get()?;
310310

311-
let chunks = ChunkedWriter::collect_iter(stdb.iter_mut(ctx, tx, table_id)?);
311+
let chunks = ChunkedWriter::collect_iter(db_engine.iter_mut(ctx, tx, table_id)?);
312312
Ok(chunks)
313313
}
314314

@@ -345,10 +345,10 @@ impl InstanceEnv {
345345
}
346346
}
347347

348-
let stdb = &self.dbic.db_engine;
348+
let db_engine = &self.dbic.db_engine;
349349
let tx = &mut *self.tx.get()?;
350350

351-
let schema = stdb.schema_for_table_mut(tx, table_id)?;
351+
let schema = db_engine.schema_for_table_mut(tx, table_id)?;
352352
let row_type = schema.get_row_type();
353353

354354
let filter = filter::Expr::from_bytes(
@@ -364,14 +364,14 @@ impl InstanceEnv {
364364
// TODO(Centril): consider caching from `filter: &[u8] -> query: QueryExpr`.
365365
let query = QueryExpr::new(schema.as_ref())
366366
.with_select(filter_to_column_op(table_id, filter))
367-
.optimize(&|table_id, table_name| stdb.row_count(table_id, table_name));
367+
.optimize(&|table_id, table_name| db_engine.row_count(table_id, table_name));
368368

369369
// TODO(Centril): Conditionally dump the `query` to a file and compare against integration test.
370370
// Invent a system where we can make these kinds of "optimization path tests".
371371

372372
let tx: TxMode = tx.into();
373373
// SQL queries can never reference `MemTable`s, so pass in an empty set.
374-
let mut query = build_query(ctx, stdb, &tx, &query, &mut NoInMemUsed)?;
374+
let mut query = build_query(ctx, db_engine, &tx, &query, &mut NoInMemUsed)?;
375375

376376
// write all rows and flush at row boundaries.
377377
let query_iter = std::iter::from_fn(|| query.next().transpose());

crates/core/src/host/wasm_common/module_host_actor.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,11 @@ impl<T: WasmInstance> ModuleInstance for WasmModuleInstance<T> {
400400

401401
let proposed_tables = get_tabledefs(&self.info).collect::<anyhow::Result<Vec<_>>>()?;
402402

403-
let stdb = &*self.database_instance_context().db_engine;
404-
let tx = stdb.begin_mut_tx(IsolationLevel::Serializable);
403+
let db_engine = &*self.database_instance_context().db_engine;
404+
let tx = db_engine.begin_mut_tx(IsolationLevel::Serializable);
405405

406406
let res = crate::db::update::update_database(
407-
stdb,
407+
db_engine,
408408
tx,
409409
proposed_tables,
410410
fence,
@@ -418,7 +418,7 @@ impl<T: WasmInstance> ModuleInstance for WasmModuleInstance<T> {
418418

419419
let update_result = match self.info.reducers.lookup_id(UPDATE_DUNDER) {
420420
None => {
421-
stdb.commit_tx(&ExecutionContext::internal(stdb.address()), tx)?;
421+
db_engine.commit_tx(&ExecutionContext::internal(db_engine.address()), tx)?;
422422
None
423423
}
424424

@@ -494,7 +494,7 @@ impl<T: WasmInstance> WasmModuleInstance<T> {
494494
let caller_address_opt = (caller_address != Address::__DUMMY).then_some(caller_address);
495495

496496
let dbic = self.database_instance_context();
497-
let stdb = &*dbic.db_engine.clone();
497+
let db_engine = &*dbic.db_engine.clone();
498498
let address = dbic.address;
499499
let reducer_name = &*self.info.reducers[reducer_id].name;
500500

@@ -522,7 +522,7 @@ impl<T: WasmInstance> WasmModuleInstance<T> {
522522
arg_bytes: args.get_bsatn().clone(),
523523
};
524524

525-
let tx = tx.unwrap_or_else(|| stdb.begin_mut_tx(IsolationLevel::Serializable));
525+
let tx = tx.unwrap_or_else(|| db_engine.begin_mut_tx(IsolationLevel::Serializable));
526526
let _guard = WORKER_METRICS
527527
.reducer_plus_query_duration
528528
.with_label_values(&address, op.name)

crates/core/src/subscription/module_subscription_actor.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,22 @@ impl ModuleSubscriptions {
168168
// Take a read lock on `subscriptions` before committing tx
169169
// else it can result in subscriber receiving duplicate updates.
170170
let subscriptions = self.subscriptions.read();
171-
let stdb = &self.db_engine;
171+
let db_engine = &self.db_engine;
172172

173173
let read_tx = match &mut event.status {
174174
EventStatus::Committed(db_update) => {
175-
let Some((tx_data, read_tx)) = stdb.commit_tx_downgrade(ctx, tx)? else {
175+
let Some((tx_data, read_tx)) = db_engine.commit_tx_downgrade(ctx, tx)? else {
176176
return Ok(Err(WriteConflict));
177177
};
178178
*db_update = DatabaseUpdate::from_writes(&tx_data);
179179
read_tx
180180
}
181-
EventStatus::Failed(_) | EventStatus::OutOfEnergy => stdb.rollback_mut_tx_downgrade(ctx, tx),
181+
EventStatus::Failed(_) | EventStatus::OutOfEnergy => db_engine.rollback_mut_tx_downgrade(ctx, tx),
182182
};
183183
let event = Arc::new(event);
184184

185185
match &event.status {
186-
EventStatus::Committed(_) => subscriptions.eval_updates(stdb, &read_tx, event.clone(), client),
186+
EventStatus::Committed(_) => subscriptions.eval_updates(db_engine, &read_tx, event.clone(), client),
187187
EventStatus::Failed(_) => {
188188
if let Some(client) = client {
189189
let message = TransactionUpdateMessage::<DatabaseUpdate> {

0 commit comments

Comments
 (0)