1
0
mirror of https://github.com/gluster/glusterd2.git synced 2026-02-05 12:45:38 +01:00

when glusterd2 starts,glusterd2 PID will be

added as a value under  alive/peerid key
and this is published as a liveness to the store.

peer list and peer status will contains
PID in HTTP response.

Signed-off-by: Madhu Rajanna <mrajanna@redhat.com>
This commit is contained in:
Madhu Rajanna
2018-06-19 14:59:54 +05:30
committed by Aravinda VK
parent e81536679b
commit 8aad2d0728
8 changed files with 37 additions and 14 deletions

View File

@@ -124,9 +124,10 @@ func peerStatusHandler(cmd *cobra.Command) {
failure("Failed to get Peers list", err, 1)
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"ID", "Name", "Client Addresses", "Peer Addresses", "Online"})
table.SetHeader([]string{"ID", "Name", "Client Addresses", "Peer Addresses", "Online", "PID"})
for _, peer := range peers {
table.Append([]string{peer.ID.String(), peer.Name, strings.Join(peer.ClientAddresses, "\n"), strings.Join(peer.PeerAddresses, "\n"), formatBoolYesNo(peer.Online)})
table.Append([]string{peer.ID.String(), peer.Name, strings.Join(peer.ClientAddresses, "\n"), strings.Join(peer.PeerAddresses, "\n"), formatBoolYesNo(peer.Online), formatPID(peer.PID)})
}
table.Render()
}

View File

@@ -17,6 +17,13 @@ func formatBoolYesNo(value bool) string {
return "no"
}
func formatPID(pid int) string {
if pid == 0 {
return ""
}
return strconv.Itoa(pid)
}
func sizeToMb(value string) (uint64, error) {
sizeParts := validSizeFormat.FindStringSubmatch(value)
if len(sizeParts) == 0 {

View File

@@ -32,12 +32,14 @@ func getPeerHandler(w http.ResponseWriter, r *http.Request) {
}
func createPeerGetResp(p *peer.Peer) *api.PeerGetResp {
pid, online := store.Store.IsNodeAlive(p.ID)
return &api.PeerGetResp{
ID: p.ID,
Name: p.Name,
PeerAddresses: p.PeerAddresses,
ClientAddresses: p.ClientAddresses,
Online: store.Store.IsNodeAlive(p.ID),
Online: online,
PID: pid,
Metadata: p.Metadata,
}
}

View File

@@ -35,12 +35,14 @@ func createPeerListResp(peers []*peer.Peer) *api.PeerListResp {
var resp api.PeerListResp
for _, p := range peers {
pid, online := store.Store.IsNodeAlive(p.ID)
resp = append(resp, api.PeerGetResp{
ID: p.ID,
Name: p.Name,
PeerAddresses: p.PeerAddresses,
ClientAddresses: p.ClientAddresses,
Online: store.Store.IsNodeAlive(p.ID),
Online: online,
PID: pid,
Metadata: p.Metadata,
})
}

View File

@@ -2,12 +2,15 @@ package store
import (
"context"
"os"
"strconv"
"time"
"github.com/gluster/glusterd2/glusterd2/gdctx"
"github.com/coreos/etcd/clientv3"
"github.com/pborman/uuid"
log "github.com/sirupsen/logrus"
)
const (
@@ -16,8 +19,8 @@ const (
LivenessKeyPrefix = "alive/"
)
// IsNodeAlive returns true if the node specified is alive as seen by the store
func (s *GDStore) IsNodeAlive(nodeID interface{}) bool {
// IsNodeAlive returns true and pid if the node specified is alive as seen by the store
func (s *GDStore) IsNodeAlive(nodeID interface{}) (int, bool) {
var keySuffix string
@@ -27,10 +30,10 @@ func (s *GDStore) IsNodeAlive(nodeID interface{}) bool {
case string:
keySuffix = nodeID.(string)
if uuid.Parse(keySuffix) == nil {
return false
return 0, false
}
default:
return false
return 0, false
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
@@ -39,10 +42,18 @@ func (s *GDStore) IsNodeAlive(nodeID interface{}) bool {
key := LivenessKeyPrefix + keySuffix
resp, err := s.Get(ctx, key)
if err != nil {
return false
return 0, false
}
return resp.Count == 1
if resp.Count == 1 {
pid, err := strconv.Atoi(string(resp.Kvs[0].Value))
if err != nil {
log.WithError(err).Error("failed to parse pid")
return 0, false
}
return pid, true
}
return 0, false
}
func (s *GDStore) publishLiveness() error {
@@ -50,8 +61,7 @@ func (s *GDStore) publishLiveness() error {
key := LivenessKeyPrefix + gdctx.MyUUID.String()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
_, err := s.Put(ctx, key, "", clientv3.WithLease(s.Session.Lease()))
_, err := s.Put(ctx, key, strconv.Itoa(os.Getpid()), clientv3.WithLease(s.Session.Lease()))
return err
}

View File

@@ -101,7 +101,7 @@ func (t *Txn) checkAlive() error {
for _, node := range t.Nodes {
// TODO: Using prefixed query, get all alive nodes in a single etcd query
if !store.Store.IsNodeAlive(node) {
if _, online := store.Store.IsNodeAlive(node); !online {
return fmt.Errorf("node %s is probably down", node.String())
}
}

View File

@@ -11,6 +11,7 @@ type Peer struct {
PeerAddresses []string `json:"peer-addresses"`
ClientAddresses []string `json:"client-addresses"`
Online bool `json:"online"`
PID int `json:"pid,omitempty"`
Metadata map[string]string `json:"metadata"`
}

View File

@@ -42,7 +42,7 @@ func getAvailableVgs(req *smartvolapi.Volume) ([]Vg, error) {
for _, p := range peers {
// If Peer is not online, do not consider this device/peer
if !store.Store.IsNodeAlive(p.ID) {
if _, online := store.Store.IsNodeAlive(p.ID); !online {
continue
}