@@ -2,18 +2,12 @@ package master
22
33import (
44 "os"
5- "time"
65
76 "github.com/PaddlePaddle/Paddle/go/connection"
87 "github.com/PaddlePaddle/recordio"
98 log "github.com/sirupsen/logrus"
109)
1110
12- // Addresser provide the address of the master server.
13- type Addresser interface {
14- Address () string
15- }
16-
1711// Client is the client of the master server.
1812type Client struct {
1913 conn * connection.Conn
@@ -24,11 +18,11 @@ type Client struct {
2418//
2519// bufSize is the record buffer size. NextRecord will read from this
2620// buffer.
27- func NewClient (addr Addresser , bufSize int ) * Client {
21+ func NewClient (addrCh <- chan string , bufSize int ) * Client {
2822 c := & Client {}
2923 c .conn = connection .New ()
3024 c .ch = make (chan []byte , bufSize )
31- go c .monitorMaster (addr )
25+ go c .monitorMaster (addrCh )
3226 go c .getRecords ()
3327 return c
3428}
@@ -72,12 +66,10 @@ func (c *Client) getRecords() {
7266 }
7367}
7468
75- func (c * Client ) monitorMaster (addr Addresser ) {
69+ func (c * Client ) monitorMaster (addrCh <- chan string ) {
7670 lastMaster := ""
77- monitor := func () {
78- // get the lastest address of the master server,
71+ for curMaster := range addrCh {
7972 // connect to the new address once address changed.
80- curMaster := addr .Address ()
8173 if curMaster != lastMaster {
8274 if curMaster == "" {
8375 err := c .conn .Close ()
@@ -94,18 +86,10 @@ func (c *Client) monitorMaster(addr Addresser) {
9486 // to retry next time.
9587 curMaster = lastMaster
9688 }
97-
9889 }
9990 }
100-
10191 lastMaster = curMaster
10292 }
103-
104- monitor ()
105- ticker := time .NewTicker (10 * time .Second )
106- for _ = range ticker .C {
107- monitor ()
108- }
10993}
11094
11195// SetDataset set dataset for the master server to dispatch.
0 commit comments