From 21fcff72bef3b12f600da861b7708ca5f30d9512 Mon Sep 17 00:00:00 2001 From: Patrick Kuo Date: Wed, 7 Dec 2022 17:33:26 +0000 Subject: [PATCH] set event db max connection size to 100 (#6641) --- crates/sui-core/src/event_handler.rs | 14 ++++++++++++-- crates/sui-storage/src/event_store/sql.rs | 9 +++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/crates/sui-core/src/event_handler.rs b/crates/sui-core/src/event_handler.rs index a37a7b7a27e98..c4e1d3e70e4ca 100644 --- a/crates/sui-core/src/event_handler.rs +++ b/crates/sui-core/src/event_handler.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use move_bytecode_utils::module_cache::SyncModuleCache; use tokio_stream::Stream; -use tracing::{debug, error, instrument, trace}; +use tracing::{debug, error, instrument, trace, warn}; use sui_json_rpc_types::SuiMoveStruct; use sui_storage::event_store::{EventStore, EventStoreType}; @@ -81,7 +81,17 @@ impl EventHandler { let envelopes = res?; // Ingest all envelopes together at once (for efficiency) into Event Store - self.event_store.add_events(&envelopes).await?; + let row_inserted: u64 = self.event_store.add_events(&envelopes).await?; + + if row_inserted != envelopes.len() as u64 { + warn!( + num_events = envelopes.len(), + row_inserted = row_inserted, + tx_digest =? effects.transaction_digest, + "Inserted event record is less than expected." + ); + } + trace!( num_events = envelopes.len(), tx_digest =? effects.transaction_digest, diff --git a/crates/sui-storage/src/event_store/sql.rs b/crates/sui-storage/src/event_store/sql.rs index c514b530c31f7..03eb1545f7e42 100644 --- a/crates/sui-storage/src/event_store/sql.rs +++ b/crates/sui-storage/src/event_store/sql.rs @@ -10,11 +10,12 @@ use std::path::Path; use async_trait::async_trait; use serde_json::{json, Value}; -use sqlx::ConnectOptions; +use sqlx::pool::PoolOptions; use sqlx::{ sqlite::{SqliteConnectOptions, SqliteJournalMode, SqliteRow, SqliteSynchronous}, Executor, QueryBuilder, Row, SqlitePool, }; +use sqlx::{ConnectOptions, Sqlite}; use strum::{EnumMessage, IntoEnumIterator}; use tracing::{info, instrument, log, warn}; @@ -121,9 +122,13 @@ impl SqlEventStore { .pragma("wal_autocheckpoint", "400") // In pages of 4KB each .create_if_missing(true); options.log_statements(log::LevelFilter::Off); - let pool = SqlitePool::connect_with(options) + + let pool = PoolOptions::::new() + .max_connections(100) + .connect_with(options) .await .map_err(convert_sqlx_err)?; + info!(?db_path, "Created/opened SQLite EventStore on disk"); Ok(Self { pool })