Skip to content

Commit 1c021b1

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

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

store/postgres/src/connection_pool.rs

Lines changed: 40 additions & 2 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,
@@ -1452,6 +1459,31 @@ impl PoolCoordinator {
14521459
/// code that does _not_ hold the migration lock as it will otherwise
14531460
/// deadlock
14541461
fn propagate(&self, pool: &PoolInner, count: MigrationCount) -> Result<(), StoreError> {
1462+
#[derive(Debug, QueryableByName)]
1463+
struct Name {
1464+
#[diesel(sql_type = Text)]
1465+
pub name: String,
1466+
}
1467+
1468+
let mut conn = pool.get()?;
1469+
let db = sql_query("select current_database() as name")
1470+
.get_result::<Name>(&mut conn)
1471+
.optional()?;
1472+
warn!(self.logger, "CURRENT DATABASE {:?}", db);
1473+
1474+
match sql_query(
1475+
"select table_name as name from information_schema.tables where table_schema = 'public' order by 1",
1476+
)
1477+
.load::<Name>(&mut conn).optional()? {
1478+
Some(tables) => {
1479+
let tables = tables.into_iter().map(|t| t.name).collect::<Vec<_>>();
1480+
warn!(self.logger, "PUBLIC SCHEMA: tables {:?}", tables);
1481+
}
1482+
None => {
1483+
warn!(self.logger, "PUBLIC SCHEMA: no tables");
1484+
}
1485+
}
1486+
14551487
// We need to remap all these servers into `pool` if the list of
14561488
// tables that are mapped have changed from the code of the previous
14571489
// version. Since dropping and recreating the foreign table
@@ -1547,6 +1579,7 @@ impl PoolCoordinator {
15471579
/// the setup was actually run, i.e. if `pool` was available
15481580
fn setup_bg(self: Arc<Self>, pool: PoolState) -> Result<bool, StoreError> {
15491581
let migrated = graph::spawn_thread("database-setup", move || {
1582+
std::thread::sleep(Duration::from_secs(1));
15501583
graph::block_on(self.setup(vec![pool.clone()]))
15511584
})
15521585
.join()
@@ -1609,6 +1642,7 @@ impl PoolCoordinator {
16091642
.cheap_clone()
16101643
.migrate(servers)
16111644
.map(|res| (state.cheap_clone(), res))
1645+
.inspect(|(state, res)| warn!(state.logger, "MIGRATE RESULT {:?}", res))
16121646
})
16131647
.collect::<Vec<_>>();
16141648
join_all(futures)
@@ -1658,6 +1692,10 @@ impl PoolCoordinator {
16581692

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

1695+
warn!(self.logger, "Sleeping for 5s"; "migrated" => migrated.len());
1696+
tokio::time::sleep(Duration::from_secs(5)).await;
1697+
warn!(self.logger, "Waking up");
1698+
16611699
let propagated = propagate(&self, migrated).await?;
16621700

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

0 commit comments

Comments
 (0)