-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[Done] Sync master client between passes and fix recordio split #2948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
6cea7ba
c950b73
0391bf5
5a402b5
30adaa8
56309b2
9215501
e3d7c22
419d553
31bf3fb
bd2a610
149ced5
ec6b16e
270bdb3
8c0755b
9891627
c1e8c9b
f07dc95
fb9f810
7d2d744
cc45124
ebb007f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,24 +43,31 @@ func NewClient(addrCh <-chan string, bufSize int) *Client { | |
| c.conn = connection.New() | ||
| c.ch = make(chan record, bufSize) | ||
| go c.monitorMaster(addrCh) | ||
| go c.getRecords() | ||
| // FIXME: async connection creation | ||
| time.Sleep(time.Second) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the comment and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. Connection is created in a go-routine |
||
| err := c.addClient() | ||
| if err != nil { | ||
| log.Errorln("init client(addClient) error:", err) | ||
| } | ||
| return c | ||
| } | ||
|
|
||
| func (c *Client) getRecords() { | ||
| for { | ||
| t, err := c.getTask() | ||
| if err != nil { | ||
| // getTask call. | ||
| log.Errorf("Get task failed, sleep 3 seconds and continue, %s", err) | ||
| time.Sleep(3 * time.Second) | ||
| continue | ||
| if err.Error() == ErrAllTaskFinishError.Error() || err.Error() == ErrNoMoreAvailableError.Error() { | ||
| log.Infof("Got %v, stopping getRecords routine.", err) | ||
| c.ch <- record{nil, err} | ||
| return | ||
| } | ||
| log.Errorf("getTask error: %s", err) | ||
| } | ||
|
|
||
| for _, chunk := range t.Chunks { | ||
| f, err := os.Open(chunk.Path) | ||
| if err != nil { | ||
| log.Errorln(err) | ||
| f, e := os.Open(chunk.Path) | ||
| if e != nil { | ||
| log.Errorln(e) | ||
| continue | ||
| } | ||
|
|
||
|
|
@@ -116,12 +123,17 @@ func (c *Client) monitorMaster(addrCh <-chan string) { | |
| } | ||
| } | ||
|
|
||
| // SetDataset set dataset for the master server to dispatch. | ||
| // SetDataset sets dataset to dispatch for the master server. | ||
| // | ||
| // SetDataset can be call multiple times at one pass. But only the first call | ||
| // will be honored. | ||
| // | ||
| // SetDataset can be call multiple times from different nodes. But | ||
| // only the first call will be honored. | ||
| // After all tasks are done, another call of SetDataset will start another pass. | ||
| func (c *Client) SetDataset(globPaths []string) error { | ||
| return c.conn.Call("Service.SetDataset", globPaths, nil) | ||
| err := c.conn.Call("Service.SetDataset", globPaths, nil) | ||
| // start to getRecords go-routine before each pass | ||
|
||
| go c.getRecords() | ||
|
||
| return err | ||
| } | ||
|
|
||
| // getTask gets a new task from the master server. | ||
|
|
@@ -147,5 +159,26 @@ func (c *Client) taskFailed(meta TaskMeta) error { | |
| // thread-safe. | ||
| func (c *Client) NextRecord() ([]byte, error) { | ||
| r := <-c.ch | ||
| if r.err != nil && (r.err.Error() == ErrAllTaskFinishError.Error() || r.err.Error() == ErrNoMoreAvailableError.Error()) { | ||
| err := c.PassFinish() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| return r.r, r.err | ||
| } | ||
|
|
||
| func (c *Client) addClient() error { | ||
| return c.conn.Call("Service.AddClient", 0, nil) | ||
| } | ||
|
|
||
| // PassFinish set current pass to finish | ||
| func (c *Client) PassFinish() error { | ||
| err := c.conn.Call("Service.PassFinish", 0, nil) | ||
| return err | ||
| } | ||
|
|
||
| // PassStart reset pass counter. | ||
| func (c *Client) PassStart() error { | ||
| return c.conn.Call("Service.PassStart", 0, nil) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious why do we need to sleep one second?