Skip to content

Commit

Permalink
Merge pull request #30 from quixoten/patch-1
Browse files Browse the repository at this point in the history
always return byte lag 0 for primary
  • Loading branch information
film42 authored Mar 10, 2022
2 parents 781f2f8 + 911236c commit bca9506
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,29 +257,32 @@ FROM
nodeInfo.Xlog.ReceivedLocation = nodeInfo.Xlog.ReplayedLocation.Int64
}

pgCurrentWalLsn, err := ds.getPgCurrentWalLsn(ds.cfg.MaxHop, db)
if err != nil {
log.Println("Error getting pg_current_wal_lsn:", err)
return nil, err
}
// only calculate byte lag for replicas
if nodeInfo.State == 0 {
pgCurrentWalLsn, err := ds.getPgCurrentWalLsn(ds.cfg.MaxHop, db)
if err != nil {
log.Println("Error getting pg_current_wal_lsn:", err)
return nil, err
}

pgLastWalLsn, err := ds.getPgLastWalReplayLsn()
if err != nil {
log.Println("Error getting pg_last_wal_replay_lsn:", err)
return nil, err
}
// Skip the byte lag checks if the last wal lsn is empty
if pgLastWalLsn == "" {
return nodeInfo, nil
}
pgLastWalLsn, err := ds.getPgLastWalReplayLsn()
if err != nil {
log.Println("Error getting pg_last_wal_replay_lsn:", err)
return nil, err
}
// Skip the byte lag checks if the last wal lsn is empty
if pgLastWalLsn == "" {
return nodeInfo, nil
}

byteLag, err := ds.getPgWalLsnDiff(pgCurrentWalLsn, pgLastWalLsn)
if err != nil {
log.Println("Error getting pg_wal_lsn_diff:", err)
return nil, err
}
byteLag, err := ds.getPgWalLsnDiff(pgCurrentWalLsn, pgLastWalLsn)
if err != nil {
log.Println("Error getting pg_wal_lsn_diff:", err)
return nil, err
}

nodeInfo.ByteLag = byteLag
nodeInfo.ByteLag = byteLag
}

return nodeInfo, nil
}
Expand Down

0 comments on commit bca9506

Please sign in to comment.