in store/engine/postgresql/postgresql.go [247:277]
func (p *Postgresql) observeLeaderEvent() {
defer p.wg.Done()
for {
select {
case <-p.quitCh:
return
case notification := <-p.listener.Notify:
p.isReady.Store(true)
data := strings.SplitN(notification.Extra, ":", 2)
if len(data) != 2 {
logger.Get().With(
zap.Error(fmt.Errorf("failed to parse notification data: expected two parts separated by a colon")),
).Error("Failed to parse notification data")
}
operation := data[0]
leaderID := data[1]
if operation == "INSERT" {
p.leaderMu.Lock()
p.leaderID = leaderID
p.leaderMu.Unlock()
p.leaderChangeCh <- true
} else {
p.lockReleaseCh <- true
}
}
}
}