Skip to content

Commit bd2b509

Browse files
authored
indexer stability: revert diesel-async changes (MystenLabs#11017)
## Description The reason is that read_only queries will still build tx, see code [pointer](https://github.com/MystenLabs/sui/blob/main/crates/sui-indexer/src/store/mod.rs#L24-L34) and when Diesel gets concurrent tx, it will check if some other tx is in process [here](https://github.com/diesel-rs/diesel/blob/4b2ebca2ddb25f08bf9107869f064f5774efbb83/diesel/src/connection/transaction_manager.rs#L286), if there is another on-going tx, even it is a read-only tx, Diesel will return error AlreadyInTransaction More context can be found in #sui_testnet_n_inc_307 ## Test Plan CI
1 parent d3a3b18 commit bd2b509

File tree

5 files changed

+167
-258
lines changed

5 files changed

+167
-258
lines changed

crates/sui-indexer/benches/indexer_benchmark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn indexer_benchmark(c: &mut Criterion) {
5151
});
5252

5353
c.bench_function("persist_checkpoint", |b| {
54-
b.iter(|| rt.block_on(store.persist_all_checkpoint_data(&checkpoints.pop().unwrap())))
54+
b.iter(|| store.persist_all_checkpoint_data(&checkpoints.pop().unwrap()))
5555
});
5656

5757
let mut checkpoints = (20..100).cycle().map(CheckpointId::SequenceNumber);

crates/sui-indexer/src/handlers/checkpoint_handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,14 +365,15 @@ where
365365
// otherwise send it to channel to be committed later.
366366
if epoch.last_epoch.is_none() {
367367
let epoch_db_guard = self.metrics.epoch_db_commit_latency.start_timer();
368+
info!("Persisting first epoch...");
368369
let mut persist_first_epoch_res = self.state.persist_epoch(&epoch).await;
369370
while persist_first_epoch_res.is_err() {
370371
warn!("Failed to persist first epoch, retrying...");
371372
persist_first_epoch_res = self.state.persist_epoch(&epoch).await;
372373
}
373-
self.state.persist_epoch(&epoch).await?;
374374
epoch_db_guard.stop_and_record();
375375
self.metrics.total_epoch_committed.inc();
376+
info!("Persisted first epoch");
376377
} else {
377378
let epoch_sender_guard = self.epoch_sender.lock().await;
378379
// NOTE: when the channel is full, epoch_sender_guard will wait until the channel has space.

crates/sui-indexer/src/store/indexer_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub trait IndexerStore {
189189
) -> Result<usize, IndexerError>;
190190
// TODO(gegaowp): keep this method in this trait for now for easier reverting,
191191
// will remove it if it's no longer needed.
192-
async fn persist_all_checkpoint_data(
192+
fn persist_all_checkpoint_data(
193193
&self,
194194
data: &TemporaryCheckpointStore,
195195
) -> Result<usize, IndexerError>;

crates/sui-indexer/src/store/mod.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,6 @@ mod diesel_marco {
2121
}};
2222
}
2323

24-
macro_rules! read_only {
25-
($pool:expr, $query:expr) => {{
26-
let mut pg_pool_conn = crate::get_async_pg_pool_connection($pool).await?;
27-
pg_pool_conn
28-
.build_transaction()
29-
.read_only()
30-
.run($query)
31-
.await
32-
.map_err(|e| IndexerError::PostgresReadError(e.to_string()))
33-
}};
34-
}
35-
36-
macro_rules! transactional {
37-
($pool:expr, $query:expr) => {{
38-
let mut pg_pool_conn = crate::get_async_pg_pool_connection($pool).await?;
39-
pg_pool_conn
40-
.build_transaction()
41-
.serializable()
42-
.read_write()
43-
.run($query)
44-
.await
45-
.map_err(|e| IndexerError::PostgresWriteError(e.to_string()))
46-
}};
47-
}
48-
4924
macro_rules! transactional_blocking {
5025
($pool:expr, $query:expr) => {{
5126
let mut pg_pool_conn = crate::get_pg_pool_connection($pool)?;
@@ -57,8 +32,6 @@ mod diesel_marco {
5732
.map_err(|e| IndexerError::PostgresWriteError(e.to_string()))
5833
}};
5934
}
60-
pub(crate) use read_only;
6135
pub(crate) use read_only_blocking;
62-
pub(crate) use transactional;
6336
pub(crate) use transactional_blocking;
6437
}

0 commit comments

Comments
 (0)