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 caed7bb commit 5f78f46
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/flypg/collation.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func collationHashChanged(versionHash string) (bool, error) {
func calculateLocaleVersionHash() (string, error) {
output, err := utils.RunCommand("locale --version", "postgres")
if err != nil {
return "", fmt.Errorf("failed to capture ldd version: %w", err)
return "", fmt.Errorf("failed to read locale version: %w", err)
}

hash := sha256.Sum256(output)
Expand Down
16 changes: 10 additions & 6 deletions internal/flypg/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@ func (n *Node) PostInit(ctx context.Context) error {
}
}

// There was an OS change that can impact certain users during a Flex upgrade.
// This is a safety check to ensure that the collation integrity is maintained.
// This is a safety check to ensure collation integrity is maintained.
if err := n.evaluateCollationIntegrity(ctx, conn); err != nil {
log.Printf("[WARN] Problem occurred while evaluating collation integrity: %s", err)
}
Expand Down Expand Up @@ -480,7 +479,7 @@ func setDirOwnership() error {
}

func (n *Node) evaluateCollationIntegrity(ctx context.Context, conn *pgx.Conn) error {
// Capture the current collation version hash.
// Calculate the current collation version hash.
versionHash, err := calculateLocaleVersionHash()
if err != nil {
return fmt.Errorf("failed to calculate collation sum: %w", err)
Expand Down Expand Up @@ -518,11 +517,14 @@ func (n *Node) evaluateCollationIntegrity(ctx context.Context, conn *pgx.Conn) e

log.Printf("[INFO] Refreshing collations for database %s\n", db.Name)

// Refresh collations for the database.
if err := refreshCollations(ctx, dbConn, db.Name); err != nil {
return fmt.Errorf("failed to refresh collations for db %s: %s", db.Name, err)
}

// TODO - Consider logging a link to documentation on how to resolve collation issues not resolved by the refresh process.

// The collation refresh process should resolve "most" issues, but there are cases that may require
// re-indexing or other manual intervention. In the event any objects are found we will log a warning.
colObjects, err := impactedCollationObjects(ctx, dbConn)
if err != nil {
return fmt.Errorf("failed to fetch impacted collation objects: %s", err)
Expand All @@ -534,15 +536,17 @@ func (n *Node) evaluateCollationIntegrity(ctx context.Context, conn *pgx.Conn) e
}
}

// Don't set the version file if there are collation issues.
// This will force the system to re-evaluate the collation integrity on the next boot and ensure
// issues continue to be logged.
if collationIssues > 0 {
return nil
}

// No collation issues found, we can safely update the version file.
// This will prevent the system from re-evaluating the collation integrity on every boot.
log.Printf("[INFO] No collation mismatches detected. Updating collation version file.\n")
if err := writeCollationVersionFile(versionHash); err != nil {
return fmt.Errorf("failed to write collation lock: %s", err)
return fmt.Errorf("failed to write collation version file: %s", err)
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions internal/utils/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"syscall"
)

// TODO - RunCommand should take a context.

func RunCommand(cmdStr, usr string) ([]byte, error) {
uid, gid, err := SystemUserIDs(usr)
if err != nil {
Expand Down

0 comments on commit 5f78f46

Please sign in to comment.