func (p *Process) xlogPosFromStatus(member string, status *replSetStatus) (xlog.Position, error) { for _, m := range status.Members { if m.Name == member { return xlog.Position(strconv.FormatInt(m.Optime.Timestamp, 10)), nil } } return p.XLog().Zero(), fmt.Errorf("error getting xlog, couldn't find member in replSetStatus") }
func (p *Postgres) checkReplStatus(name string) (sent, flushed xlog.Position, err error) { log := p.log.New("fn", "checkReplStatus", "name", name) log.Debug("checking replication status") var s, f pgx.NullString err = p.db.QueryRow(` SELECT sent_location, flush_location FROM pg_stat_replication WHERE application_name = $1`, name).Scan(&s, &f) if err != nil && err != pgx.ErrNoRows { log.Error("error checking replication status", "err", err) return } sent, flushed = xlog.Position(s.String), xlog.Position(f.String) if err == pgx.ErrNoRows || sent == "" || flushed == "" { err = ErrNoReplicationStatus log.Debug("no replication status") return } log.Debug("got replication status", "sent_location", sent, "flush_location", flushed) return }
// XLogPosition returns the current XLogPosition of node specified by DSN. func (p *Process) nodeXLogPosition(dsn *DSN) (xlog.Position, error) { db, err := sql.Open("mysql", dsn.String()) if err != nil { return p.XLog().Zero(), err } defer db.Close() var gtid string if err := db.QueryRow(`SELECT @@gtid_current_pos`).Scan(>id); err != nil { return p.XLog().Zero(), err } return xlog.Position(gtid), nil }
func (p *Postgres) XLogPosition() (xlog.Position, error) { p.dbMtx.RLock() defer p.dbMtx.RUnlock() if !p.running() || p.db == nil { return "", errors.New("postgres is not running") } fn := "pg_last_xlog_replay_location()" if p.config().Role == state.RolePrimary { fn = "pg_current_xlog_location()" } var res string err := p.db.QueryRow("SELECT " + fn).Scan(&res) return xlog.Position(res), err }
// MakePosition constructs an xlog position string from a numeric file part and // offset. func makePosition(filepart int, offset int) xlog.Position { return xlog.Position(fmt.Sprintf("%X/%08X", filepart, offset)) }