-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
busgo
committed
Jul 31, 2019
1 parent
16fed4e
commit 7814c82
Showing
10 changed files
with
141 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package forest | ||
|
||
import ( | ||
"fmt" | ||
"github.com/labstack/gommon/log" | ||
"time" | ||
) | ||
|
||
// fail over the job snapshot when the task client | ||
|
||
type JobSnapshotFailOver struct { | ||
node *JobNode | ||
deleteClientEventChans chan *JobClientDeleteEvent | ||
} | ||
|
||
// new job snapshot fail over | ||
func NewJobSnapshotFailOver(node *JobNode) (f *JobSnapshotFailOver) { | ||
|
||
f = &JobSnapshotFailOver{ | ||
node: node, | ||
deleteClientEventChans: make(chan *JobClientDeleteEvent, 50), | ||
} | ||
|
||
f.loop() | ||
|
||
return | ||
} | ||
|
||
// loop | ||
func (f *JobSnapshotFailOver) loop() { | ||
|
||
go func() { | ||
|
||
for ch := range f.deleteClientEventChans { | ||
f.handleJobClientDeleteEvent(ch) | ||
} | ||
}() | ||
} | ||
|
||
// handle job client delete event | ||
func (f *JobSnapshotFailOver) handleJobClientDeleteEvent(event *JobClientDeleteEvent) { | ||
|
||
var ( | ||
keys [][]byte | ||
values [][]byte | ||
err error | ||
client *Client | ||
success bool | ||
) | ||
|
||
RETRY: | ||
prefixKey := fmt.Sprintf(JobClientSnapshotPath, event.Group.name, event.Client.name) | ||
if keys, values, err = f.node.etcd.GetWithPrefixKey(prefixKey); err != nil { | ||
log.Errorf("the fail client:%v for path:%s,error must retry", event.Client, prefixKey) | ||
time.Sleep(time.Second) | ||
goto RETRY | ||
} | ||
|
||
if len(keys) == 0 || len(values) == 0 { | ||
log.Warnf("the fail client:%v for path:%s is empty", event.Client, prefixKey) | ||
return | ||
} | ||
|
||
for pos := 0; pos < len(keys); pos++ { | ||
|
||
if client, err = event.Group.selectClient(); err != nil { | ||
log.Warnf("%v", err) | ||
continue | ||
} | ||
|
||
to := fmt.Sprintf(JobClientSnapshotPath, event.Group.name, client.name) | ||
|
||
from := string(keys[pos]) | ||
value := string(values[pos]) | ||
// transfer the kv | ||
if success, _ = f.node.etcd.transfer(from, to, value); success { | ||
log.Infof("the fail client:%v for path:%s success transfer form %s to %s", event.Client, prefixKey, from, to) | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters