Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
davissp14 committed Jun 23, 2024
1 parent 4eb76da commit 6eda635
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/flypg/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,46 +511,46 @@ func (n *Node) evaluateCollationIntegrity(ctx context.Context, conn *pgx.Conn) e

log.Printf("[WARN] Collation mismatches detected. Refreshing collation versions.\n")

// Detect any indexes that are currently impacted by collation mismatches.
// Unfortunately, we will need to do this for each database.
dbs, err := admin.ListDatabases(ctx, conn)
if err != nil {
return fmt.Errorf("failed to list databases: %s", err)
}

// Manually adding this, since it's not returned by the list databases query.
dbs = append(dbs, admin.DbInfo{Name: "template1"})

mismatches := 0

// Iterate over each database and evaluate collation integrity.
for _, db := range dbs {
// Establish a connection to the specified database.
dbConn, err := n.NewLocalConnection(ctx, db.Name, n.SUCredentials)
if err != nil {
return fmt.Errorf("failed to establish connection to database %s: %s", db.Name, err)
}
defer func() { _ = dbConn.Close(ctx) }()

// TODO - Identify the impacted objects and log them.
// Count collation mismatches
count, err := countCollationMismatchs(ctx, dbConn)
if err != nil {
log.Printf("[WARN] Failed to count collation mismatches: %s\n", err)
}

// Skip if no mismatches are found.
// Skip if no mismatches were found.
if err == nil && count == 0 {
continue
}

mismatches++

log.Printf("[WARN] %d collation mismatches detected %s\n", count, db.Name)

// Identify any impacted indexes and re-index them concurrently.
if err := reIndexMismatchedIndexes(ctx, dbConn); err != nil {
return fmt.Errorf("failed to reindex database: %s", err)
}
}

// We won't be able to confirm the collation integrity until the next boot since impacted
// indexes will be reindexed concurrently.
if mismatches > 0 {
return nil
}
Expand Down

0 comments on commit 6eda635

Please sign in to comment.