Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current LSN : Account for NULL LSN value being returned #2372

Merged
merged 6 commits into from
Dec 19, 2024

Conversation

Amogh-Bharadwaj
Copy link
Contributor

@Amogh-Bharadwaj Amogh-Bharadwaj commented Dec 18, 2024

// ParseLSN parses the given XXX/XXX text format LSN used by PostgreSQL.
func ParseLSN(s string) (LSN, error) {
	var upperHalf uint64
	var lowerHalf uint64
	var nparsed int
	nparsed, err := fmt.Sscanf(s, "%X/%X", &upperHalf, &lowerHalf)
	if err != nil {
		return 0, fmt.Errorf("failed to parse LSN: %w", err)
	}

	if nparsed != 2 {
		return 0, fmt.Errorf("failed to parsed LSN: %s", s)
	}

	return LSN((upperHalf << 32) + lowerHalf), nil
}

It was recently seen for a read replica mirror that the above pglogrepl function we use to get the current LSN returned an EOF error at the first check - indicating that the LSN string we were giving it was not of the right format.

Upon research it seems like the functions in the query we run:

SELECT CASE WHEN pg_is_in_recovery() THEN pg_last_wal_receive_lsn() ELSE pg_current_wal_lsn() END

can return NULL as seen here for example.

It seems that this can occur when there is no more WAL activity to collect, not sure

This PR simply adds more logging around this.

@Amogh-Bharadwaj Amogh-Bharadwaj changed the title Current LSN : Account for NULL/bad LSN value being returned Current LSN : Account for NULL LSN value being returned Dec 18, 2024
heavycrystal and others added 2 commits December 19, 2024 14:08
Co-authored-by: Philip Dubé <serprex@users.noreply.github.com>
@heavycrystal heavycrystal enabled auto-merge (squash) December 19, 2024 14:45
@heavycrystal heavycrystal merged commit f931bc0 into main Dec 19, 2024
9 checks passed
@heavycrystal heavycrystal deleted the current-lsn-fetch-fix branch December 19, 2024 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants