Skip to content

Commit

Permalink
add format pg lsn
Browse files Browse the repository at this point in the history
  • Loading branch information
kizuna-lek committed Sep 14, 2023
1 parent c19f36f commit 1e3556e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lorry/component/postgres/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package postgres
import (
"bufio"
"context"
"fmt"
"strconv"
"strings"

Expand Down Expand Up @@ -323,8 +324,8 @@ func ParsePgLsn(str string) int64 {
return prefix*0x100000000 + suffix
}

func formatPgLsn(lsn int64) string {
return ""
func FormatPgLsn(lsn int64) string {
return fmt.Sprintf("%X/%X", lsn>>32, lsn&0xFFFFFFFF)
}

func ParsePrimaryConnInfo(str string) map[string]string {
Expand Down
9 changes: 9 additions & 0 deletions lorry/component/postgres/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ func TestParsePGLsn(t *testing.T) {
})
}

func TestFormatPgLsn(t *testing.T) {
t.Run("format lsn", func(t *testing.T) {
lsn := int64(97500059720)

lsnStr := FormatPgLsn(lsn)
assert.Equal(t, "16/B374D848", lsnStr)
})
}

func TestParsePrimaryConnInfo(t *testing.T) {
t.Run("legal primary conn info str", func(t *testing.T) {
primaryConnInfoStr := "host=pg-pg-replication-0.pg-pg-replication-headless port=5432 user=postgres application_name=my-application"
Expand Down

0 comments on commit 1e3556e

Please sign in to comment.