tidwall / summitdb

In-memory NoSQL database with ACID transactions, Raft consensus, and Redis API
Other
1.41k stars 78 forks source link

Is it (already) possible to retrieve a list of all the peers for a cluster? #19

Closed thisisaaronland closed 7 years ago

thisisaaronland commented 7 years ago

I know you can get the current state of any one peer but I'd like to be able to keep a list of all the peers in case the initial host that a client connects to goes down and reconnect to one of the other hosts without having to know that list in advance.

The context is this: https://github.com/thisisaaronland/go-artisanal-integers#summitdb

Also: This project (go-artisanal-integers) is as a dumb and silly as it sounds except for the part where it's been a running gag for going on 5 years now...

https://github.com/thisisaaronland/go-artisanal-integers#see-also

tidwall commented 7 years ago

Hi Aaron, The RAFTPEERS command will return a list of the peers and their status.

127.0.0.1:7481> raftpeers
1) "127.0.0.1:7481"
2) "Leader"
3) "127.0.0.1:7482"
4) "Follower"
5) "127.0.0.1:7483"
6) "Follower"

This is useful if you want to look for failures or log leadership changes, such as for cluster diagnostics.

Even with a sane cluster with all nodes running 100%, there will occasionally be leadership changes. As long as your client connection follows the -TRY <addr> responses and updates the leader, you should be good.

thisisaaronland commented 7 years ago

Thanks!

I now appear to be bumping up against the "What is redigo actually returning..." problem similar to an issue I filed for Tile-38.

I tried the OUTPUT json trick but it doesn't appear that SummitDB knows about this? Thoughts?

https://github.com/thisisaaronland/go-artisanal-integers/compare/peers

./bin/int -engine summitdb -dsn 'redis://localhost:7482'
2017/03/27 20:19:26 [[49 50 55 46 48 46 48 46 49 58 55 52 56 49] [73 110 118 97 108 105 100] [49 50 55 46 48 46 48 46 49 58 55 52 56 50] [70 111 108 108 111 119 101 114] [49 50 55 46 48 46 48 46 49 58 55 52 56 51] [76 101 97 100 101 114]]
tidwall commented 7 years ago

That's an array of bulk strings. The redis.Strings(conn.Do("RAFTPEERS")) should work.

thisisaaronland commented 7 years ago

Bingo, thanks! One day I will figure out redigo responses...

./bin/int -engine summitdb -dsn 'redis://localhost:7482'
2017/03/27 20:49:28 127.0.0.1:7481
2017/03/27 20:49:28 Invalid
2017/03/27 20:49:28 127.0.0.1:7482
2017/03/27 20:49:28 Follower
2017/03/27 20:49:28 127.0.0.1:7483
2017/03/27 20:49:28 Leader
summitdb told me to try redis://127.0.0.1:7483 instead, so here we go...
tidwall commented 7 years ago

I agree. Redigo can take a little getting use to.