Skip to content

Commit 3335c18

Browse files
committed
debug: log more
1 parent 456bd8f commit 3335c18

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
POSTGRES_PASSWORD: postgres
7070
POSTGRES_DB: graph_node_test
7171
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
72-
POSTGRESQL_EXTRA_FLAGS: "-c max_connections=1000"
72+
POSTGRESQL_EXTRA_FLAGS: "-c max_connections=1000 -c log_statement=all"
7373
POSTGRESQL_REPLICATION_USE_PASSFILE: no
7474
options: >-
7575
--health-cmd "pg_isready -U postgres"

store/postgres/src/connection_pool.rs

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use diesel::r2d2::Builder;
2+
use diesel::sql_types::Text;
23
use diesel::{connection::SimpleConnection, pg::PgConnection};
34
use diesel::{
45
r2d2::{self, event as e, ConnectionManager, HandleEvent, Pool, PooledConnection},
56
Connection,
67
};
7-
use diesel::{sql_query, RunQueryDsl};
8+
use diesel::{sql_query, OptionalExtension, RunQueryDsl};
89

910
use diesel_migrations::{EmbeddedMigrations, HarnessWithOutput};
1011
use graph::cheap_clone::CheapClone;
@@ -380,13 +381,18 @@ impl PoolState {
380381

381382
use PoolStateInner::*;
382383
match &*guard {
383-
Created(pool, coord) => (pool.cheap_clone(), coord.cheap_clone()),
384+
Created(pool, coord) => {
385+
warn!(self.logger, "pool_state: pool not ready; creating");
386+
(pool.cheap_clone(), coord.cheap_clone())
387+
}
384388
Ready(pool) => return Ok(pool.clone()),
385389
}
386390
};
387391

388392
// self is `Created` and needs to have setup run
393+
warn!(self.logger, "pool_state: setting up pool");
389394
let migrated = coord.setup_bg(self.cheap_clone())?;
395+
warn!(self.logger, "pool_state: pool is ready");
390396
if migrated {
391397
Ok(pool)
392398
} else {
@@ -1329,6 +1335,7 @@ impl PoolInner {
13291335

13301336
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("./migrations");
13311337

1338+
#[derive(Debug)]
13321339
struct MigrationCount {
13331340
old: usize,
13341341
new: usize,
@@ -1377,11 +1384,13 @@ fn migrate_schema(logger: &Logger, conn: &mut PgConnection) -> Result<MigrationC
13771384
}
13781385

13791386
let migrations = catalog::migration_count(conn)?;
1380-
if migrations != old_count {
1381-
// Reset the query statistics since a schema change makes them not
1382-
// all that useful. An error here is not serious and can be ignored.
1383-
conn.batch_execute("select pg_stat_statements_reset()").ok();
1384-
}
1387+
/*
1388+
if migrations != old_count {
1389+
// Reset the query statistics since a schema change makes them not
1390+
// all that useful. An error here is not serious and can be ignored.
1391+
conn.batch_execute("select pg_stat_statements_reset()").ok();
1392+
}
1393+
*/
13851394

13861395
Ok(MigrationCount {
13871396
new: migrations,
@@ -1452,6 +1461,31 @@ impl PoolCoordinator {
14521461
/// code that does _not_ hold the migration lock as it will otherwise
14531462
/// deadlock
14541463
fn propagate(&self, pool: &PoolInner, count: MigrationCount) -> Result<(), StoreError> {
1464+
#[derive(Debug, QueryableByName)]
1465+
struct Name {
1466+
#[diesel(sql_type = Text)]
1467+
pub name: String,
1468+
}
1469+
1470+
let mut conn = pool.get()?;
1471+
let db = sql_query("select current_database() as name")
1472+
.get_result::<Name>(&mut conn)
1473+
.optional()?;
1474+
warn!(self.logger, "CURRENT DATABASE {:?}", db);
1475+
1476+
match sql_query(
1477+
"select table_name as name from information_schema.tables where table_schema = 'public' order by 1",
1478+
)
1479+
.load::<Name>(&mut conn).optional()? {
1480+
Some(tables) => {
1481+
let tables = tables.into_iter().map(|t| t.name).collect::<Vec<_>>();
1482+
warn!(self.logger, "PUBLIC SCHEMA: tables {:?}", tables);
1483+
}
1484+
None => {
1485+
warn!(self.logger, "PUBLIC SCHEMA: no tables");
1486+
}
1487+
}
1488+
14551489
// We need to remap all these servers into `pool` if the list of
14561490
// tables that are mapped have changed from the code of the previous
14571491
// version. Since dropping and recreating the foreign table
@@ -1547,6 +1581,7 @@ impl PoolCoordinator {
15471581
/// the setup was actually run, i.e. if `pool` was available
15481582
fn setup_bg(self: Arc<Self>, pool: PoolState) -> Result<bool, StoreError> {
15491583
let migrated = graph::spawn_thread("database-setup", move || {
1584+
std::thread::sleep(Duration::from_secs(1));
15501585
graph::block_on(self.setup(vec![pool.clone()]))
15511586
})
15521587
.join()
@@ -1609,6 +1644,7 @@ impl PoolCoordinator {
16091644
.cheap_clone()
16101645
.migrate(servers)
16111646
.map(|res| (state.cheap_clone(), res))
1647+
.inspect(|(state, res)| warn!(state.logger, "MIGRATE RESULT {:?}", res))
16121648
})
16131649
.collect::<Vec<_>>();
16141650
join_all(futures)
@@ -1658,6 +1694,10 @@ impl PoolCoordinator {
16581694

16591695
let migrated = migrate(&pools, self.servers.as_ref()).await?;
16601696

1697+
warn!(self.logger, "Sleeping for 20s"; "migrated" => migrated.len());
1698+
tokio::time::sleep(Duration::from_secs(20)).await;
1699+
warn!(self.logger, "Waking up");
1700+
16611701
let propagated = propagate(&self, migrated).await?;
16621702

16631703
primary.create_cross_shard_views(&self.servers)?;

0 commit comments

Comments
 (0)