Esempio n. 1
0
func (s *Sentinel) updateKeepersState(keepersState cluster.KeepersState, keepersInfo cluster.KeepersInfo, keepersPGState map[string]*cluster.PostgresState) cluster.KeepersState {
	// Create newKeepersState as a copy of the current keepersState
	newKeepersState := keepersState.Copy()

	// Add new keepersInfo to newKeepersState
	for id, ki := range keepersInfo {
		if _, ok := newKeepersState[id]; !ok {
			newKeepersState[id] = &cluster.KeeperState{
				ErrorStartTime:     time.Time{},
				ID:                 ki.ID,
				ClusterViewVersion: ki.ClusterViewVersion,
				ListenAddress:      ki.ListenAddress,
				Port:               ki.Port,
				PGListenAddress:    ki.PGListenAddress,
				PGPort:             ki.PGPort,
			}
		}
	}

	// Update keeperState with keepersInfo
	for id, ki := range keepersInfo {
		if ki.Changed(newKeepersState[id]) {
			newKeepersState[id] = &cluster.KeeperState{
				ID:                 ki.ID,
				ClusterViewVersion: ki.ClusterViewVersion,
				ListenAddress:      ki.ListenAddress,
				Port:               ki.Port,
				PGListenAddress:    ki.PGListenAddress,
				PGPort:             ki.PGPort,
			}
		}
	}

	// Mark not found keepersInfo as in error
	for id, _ := range newKeepersState {
		if _, ok := keepersInfo[id]; !ok {
			newKeepersState[id].SetError()
		} else {
			newKeepersState[id].CleanError()
		}
	}

	// Update PGstate
	for id, k := range newKeepersState {
		if kpg, ok := keepersPGState[id]; !ok {
			newKeepersState[id].SetError()
		} else {
			newKeepersState[id].CleanError()
			k.PGState = kpg
		}
	}

	// Update Healthy state
	for _, k := range newKeepersState {
		k.Healthy = s.isKeeperHealthy(k)
	}

	return newKeepersState
}
Esempio n. 2
0
func (s *Sentinel) updateKeepersState(keepersState cluster.KeepersState, keepersInfo cluster.KeepersInfo, keepersPGState map[string]*cluster.PostgresState) cluster.KeepersState {
	// Create newKeepersState as a copy of the current keepersState
	newKeepersState := keepersState.Copy()

	// Add new keepersInfo to newKeepersState
	for id, ki := range keepersInfo {
		if _, ok := newKeepersState[id]; !ok {
			if err := newKeepersState.NewFromKeeperInfo(ki); err != nil {
				// This shouldn't happen
				panic(err)
			}
		}
	}

	// Update keeperState with keepersInfo
	for id, ki := range keepersInfo {
		changed, err := newKeepersState[id].ChangedFromKeeperInfo(ki)
		if err != nil {
			// This shouldn't happen
			panic(err)
		}
		if changed {
			newKeepersState[id].UpdateFromKeeperInfo(ki)
		}
	}

	// Mark not found keepersInfo as in error
	for id, _ := range newKeepersState {
		if _, ok := keepersInfo[id]; !ok {
			newKeepersState[id].SetError()
		} else {
			newKeepersState[id].CleanError()
		}
	}

	// Update PGstate
	for id, k := range newKeepersState {
		if kpg, ok := keepersPGState[id]; !ok {
			newKeepersState[id].SetError()
		} else {
			newKeepersState[id].CleanError()
			k.PGState = kpg
		}
	}

	// Update Healthy state
	for _, k := range newKeepersState {
		k.Healthy = s.isKeeperHealthy(k)
	}

	return newKeepersState
}