@@ -1037,16 +1037,14 @@ impl PoolInner {
1037
1037
let result = pool
1038
1038
. configure_fdw ( coord. servers . as_ref ( ) )
1039
1039
. and_then ( |( ) | pool. drop_cross_shard_views ( ) )
1040
- . and_then ( |( ) | migrate_schema ( & pool. logger , & mut conn) )
1041
- . and_then ( |count| {
1042
- pool. create_cross_shard_views ( coord. servers . as_ref ( ) )
1043
- . map ( |( ) | count)
1044
- } ) ;
1040
+ . and_then ( |( ) | migrate_schema ( & pool. logger , & mut conn) ) ;
1045
1041
debug ! ( & pool. logger, "Release migration lock" ) ;
1046
1042
advisory_lock:: unlock_migration ( & mut conn) . unwrap_or_else ( |err| {
1047
1043
die ( & pool. logger , "failed to release migration lock" , & err) ;
1048
1044
} ) ;
1049
- let result = result. and_then ( |count| coord. propagate ( & pool, count) ) ;
1045
+ let result = result
1046
+ . and_then ( |count| coord. propagate ( & pool, count) )
1047
+ . and_then ( |( ) | pool. create_cross_shard_views ( coord. servers . as_ref ( ) ) ) ;
1050
1048
result. unwrap_or_else ( |err| die ( & pool. logger , "migrations failed" , & err) ) ;
1051
1049
1052
1050
// Locale check
@@ -1178,9 +1176,9 @@ impl PoolInner {
1178
1176
. await
1179
1177
}
1180
1178
1181
- // The foreign server `server` had schema changes, and we therefore need
1182
- // to remap anything that we are importing via fdw to make sure we are
1183
- // using this updated schema
1179
+ /// The foreign server `server` had schema changes, and we therefore
1180
+ /// need to remap anything that we are importing via fdw to make sure we
1181
+ /// are using this updated schema
1184
1182
pub fn remap ( & self , server : & ForeignServer ) -> Result < ( ) , StoreError > {
1185
1183
if & server. shard == & * PRIMARY_SHARD {
1186
1184
info ! ( & self . logger, "Mapping primary" ) ;
@@ -1211,10 +1209,6 @@ impl MigrationCount {
1211
1209
fn had_migrations ( & self ) -> bool {
1212
1210
self . old != self . new
1213
1211
}
1214
-
1215
- fn is_new ( & self ) -> bool {
1216
- self . old == 0
1217
- }
1218
1212
}
1219
1213
1220
1214
/// Run all schema migrations.
@@ -1334,13 +1328,22 @@ impl PoolCoordinator {
1334
1328
/// code that does _not_ hold the migration lock as it will otherwise
1335
1329
/// deadlock
1336
1330
fn propagate ( & self , pool : & PoolInner , count : MigrationCount ) -> Result < ( ) , StoreError > {
1337
- // pool is a new shard, map all other shards into it
1338
- if count. is_new ( ) {
1339
- for server in self . servers . iter ( ) {
1340
- pool. remap ( server) ?;
1341
- }
1331
+ // Strictly speaking, we only need to remap all these servers into
1332
+ // `pool` if `pool` is a new shard (`count.is_new())`) or if the
1333
+ // list of tables that are mapped have changed from the previous
1334
+ // verison. Since creating foreign tables is pretty fast, we don't
1335
+ // try to be too clever and just recreate these mappings every time.
1336
+ // If that slows startup down unacceptably, we need to do something
1337
+ // better here
1338
+ for server in self . servers . iter ( ) {
1339
+ pool. remap ( server) ?;
1342
1340
}
1343
- // pool had schema changes, refresh the import from pool into all other shards
1341
+
1342
+ // pool had schema changes, refresh the import from pool into all
1343
+ // other shards. This makes sure that schema changes to
1344
+ // already-mapped tables are propagated to all other shards. Since
1345
+ // we run `propagate` after migrations have been applied to `pool`,
1346
+ // we can be sure that these mappings use the correct schema
1344
1347
if count. had_migrations ( ) {
1345
1348
let server = self . server ( & pool. shard ) ?;
1346
1349
for pool in self . pools . lock ( ) . unwrap ( ) . values ( ) {
0 commit comments