1
0
Fork 0

Start adding multi-node tests

master
Philip O Toole 9 years ago
parent 347109e4bb
commit b058458a0f

@ -25,7 +25,7 @@ type Store interface {
// transaction is held on the database.
Query(queries []string, tx, leader bool) ([]*sql.Rows, error)
// Join joins the node, reachable at addr, to the cluster.
// Join joins the node, reachable at addr, to this node.
Join(addr string) error
// Stats returns stats on the Store.

@ -0,0 +1,36 @@
package store
import (
"net"
"time"
)
// networkLayer represents the connection between nodes.
type networkLayer struct {
ln net.Listener
addr net.Addr
}
// newnetworkLayer returns a new instance of networkLayer.
func newnetworkLayer(ln net.Listener) *networkLayer {
return &networkLayer{
ln: ln,
addr: ln.Addr(),
}
}
// Addr returns the local address for the layer.
func (l *networkLayer) Addr() net.Addr {
return l.addr
}
// Dial creates a new network connection.
func (l *networkLayer) Dial(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("tcp", addr, timeout)
}
// Accept waits for the next connection.
func (l *networkLayer) Accept() (net.Conn, error) { return l.ln.Accept() }
// Close closes the layer.
func (l *networkLayer) Close() error { return l.ln.Close() }

@ -40,6 +40,7 @@ type Store struct {
mu sync.RWMutex // Sync access between queries and snapshots.
ln *networkLayer
raft *raft.Raft // The consensus mechanism
dbConf *sql.Config
dbPath string
@ -102,14 +103,12 @@ func (s *Store) Open(enableSingle bool) error {
}
// Setup Raft communication.
addr, err := net.ResolveTCPAddr("tcp", s.raftBind)
if err != nil {
return err
}
transport, err := raft.NewTCPTransport(s.raftBind, addr, 3, 10*time.Second, os.Stderr)
ln, err := net.Listen("tcp", s.raftBind)
if err != nil {
return err
}
s.ln = newnetworkLayer(ln)
transport := raft.NewNetworkTransport(s.ln, 3, 10*time.Second, os.Stderr)
// Create peer storage.
peerStore := raft.NewJSONPeers(s.raftDir, transport)
@ -153,6 +152,10 @@ func (s *Store) Path() string {
return s.raftDir
}
func (s *Store) Addr() net.Addr {
return s.ln.Addr()
}
// Leader returns the current leader. Returns a blank string if there is
// no leader.
func (s *Store) Leader() string {

Loading…
Cancel
Save