-
Notifications
You must be signed in to change notification settings - Fork 11.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1/n][dialect_support]Generalize indexer code to support different sql dialects #17167
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
3 Ignored Deployments
|
c59e08e
to
a65d285
Compare
a65d285
to
e2de681
Compare
e2de681
to
f005ad4
Compare
crates/sui-indexer/src/store/mod.rs
Outdated
.read_only() | ||
.run($query) | ||
.map_err(|e| IndexerError::PostgresReadError(e.to_string())) | ||
($pool:expr, $query:expr, $repeatable_read:expr) => {{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could we have the repeatable_read bool come before the query:expr? it took me a hot sec looking at where we use this macro before realizing a bool was added
@@ -193,14 +208,8 @@ impl GovernanceReadApi { | |||
|
|||
/// Cached exchange rates for validators for the given epoch, the cache size is 1, it will be cleared when the epoch changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: thoughts on lifting this up to the struct field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah it's possible now, will do
{ | ||
pool: ConnectionPool<T>, | ||
package_resolver: Arc<Resolver<PackageStoreWithLruCache<IndexerStorePackageResolver<T>>>>, | ||
package_obj_type_cache: Arc<Mutex<SizedCache<String, Option<ObjectID>>>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this mainly intended for CoinMetadata
and TreasuryCap
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it is meant to replace this usage of memoization specifically:
type = "SizedCache<String, Option<ObjectID>>",
create = "{ SizedCache::with_size(10000) }",
convert = r#"{ format!("{}{}", package_id, obj_type) }"#,
result = true
)]
fn get_single_obj_id_from_package_publish(
reader: &IndexerReader,
package_id: ObjectID,
obj_type: String,```
.downcast_mut::<PoolConnection<diesel::MysqlConnection>>() | ||
.unwrap() | ||
.transaction($query) | ||
.map_err(|e| IndexerError::PostgresReadError(e.to_string())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: MysqlReadError? Or a more generic DbReadError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah a more generic error type makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I'm about to put up a change that shifts this package cache to using GraphQL's Db
type (an alias for its PgExecutor
type), which should make this change unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I skimmed thru the DB setup & writing side of the change and looks great overall! I have |
crates/sui-indexer/Cargo.toml
Outdated
@@ -16,8 +16,14 @@ chrono.workspace = true | |||
serde_with.workspace = true | |||
clap.workspace = true | |||
tap.workspace = true | |||
diesel.workspace = true | |||
diesel-derive-enum.workspace = true | |||
diesel = { features = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reading the doc of i-implement-a-third-party-backend-and-opt-into-breaking-changes
, seems like it's recommended to pin to a minor version?
https://github.com/diesel-rs/diesel/blob/master/guide_drafts/migration_guide.md#removed-most-of-the-non-public-reachable-api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also curious what functionalities do we use of this feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to remove this from here, and just use the workspace (but I copied it from root level Cargo.toml)
crates/sui-indexer/src/db.rs
Outdated
IndexerError::PostgresResetError(db_err_msg) | ||
})?; | ||
} | ||
let (_registry_service, registry) = start_prometheus_server( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's keep prometheus in main.rs as they are not exactly db setup?
use diesel::upsert::excluded; | ||
use diesel::ExpressionMethods; | ||
use diesel::OptionalExtension; | ||
use diesel::{QueryDsl, RunQueryDsl}; | ||
use downcast::Any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this gets used in the macro but i'll double check (and remove if not)
@@ -93,24 +96,27 @@ where | |||
metrics, | |||
indexed_checkpoint_sender, | |||
package_buffer: IndexingPackageBuffer::start(package_tx), | |||
_phantom: Default::default(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this and how is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because we added _phantom: PhantomData<T>,
in the struct definition, we need to remember the connection type so later we can return the type in the connection pool. Check below function: fn pg_blocking_cp(&self) -> Result<ConnectionPool<T>, IndexerError> {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c03fdf2
to
f6e5afc
Compare
f6e5afc
to
1a401bd
Compare
1a401bd
to
6bb762e
Compare
6bb762e
to
c8e42dc
Compare
c8e42dc
to
a8cc33b
Compare
…fferent sql dialects
a8cc33b
to
a83ba36
Compare
Description
This PR generalizes the code in
sui-indexer
crate such that different diesel backends can be enabled through feature flags when compiling. The default backend is still postgres which means nothing changes in terms of how we build our binaries today.sui-indexer
, all instances ofdiesel::PgConnection
are pulled withpostgres-feature
and similary all instances ofdiesel::MySqlConnection
are pulled withmysql-feature
run_query
andrun_query_async
are replaced with their corresponding macro invocationssui-indexer
generic in this PR. This includessui-graphql-rpc
which just works withIndexerReader<PgConnection>
for now (in the future we will refactor read for other db backends but for now the focus is to get writes to be compatible first)#[Cached(..)]
had to be replaced with an explicit usage ofSizedCache
as this macro doesn't seem to work for functions which take type parameters.sui-indexer
for mysqlTest plan
Running this locally works:
cargo run --bin sui-indexer -- --db-url "postgres://sadhansood:sadhansood@localhost/test" --rpc-client-url "<>" --fullnode-sync-worker --reset-db