本文整理汇总了Golang中github.com/coreos/etcd/snap.Message.CloseNotify方法的典型用法代码示例。如果您正苦于以下问题:Golang Message.CloseNotify方法的具体用法?Golang Message.CloseNotify怎么用?Golang Message.CloseNotify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/etcd/snap.Message
的用法示例。
在下文中一共展示了Message.CloseNotify方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sendMergedSnap
func (s *EtcdServer) sendMergedSnap(merged snap.Message) {
atomic.AddInt64(&s.inflightSnapshots, 1)
s.r.transport.SendSnapshot(merged)
go func() {
select {
case ok := <-merged.CloseNotify():
// delay releasing inflight snapshot for another 30 seconds to
// block log compaction.
// If the follower still fails to catch up, it is probably just too slow
// to catch up. We cannot avoid the snapshot cycle anyway.
if ok {
select {
case <-time.After(releaseDelayAfterSnapshot):
case <-s.done:
}
}
atomic.AddInt64(&s.inflightSnapshots, -1)
case <-s.done:
return
}
}()
}
示例2: testSnapshotSend
func testSnapshotSend(t *testing.T, sm *snap.Message) (bool, []os.FileInfo) {
d, err := ioutil.TempDir(os.TempDir(), "snapdir")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(d)
r := &fakeRaft{}
tr := &Transport{pipelineRt: &http.Transport{}, ClusterID: types.ID(1), Raft: r}
ch := make(chan struct{}, 1)
h := &syncHandler{newSnapshotHandler(tr, r, snap.New(d), types.ID(1)), ch}
srv := httptest.NewServer(h)
defer srv.Close()
picker := mustNewURLPicker(t, []string{srv.URL})
snapsend := newSnapshotSender(tr, picker, types.ID(1), newPeerStatus(types.ID(1)))
defer snapsend.stop()
snapsend.send(*sm)
sent := false
select {
case <-time.After(time.Second):
t.Fatalf("timed out sending snapshot")
case sent = <-sm.CloseNotify():
}
// wait for handler to finish accepting snapshot
<-ch
files, rerr := ioutil.ReadDir(d)
if rerr != nil {
t.Fatal(rerr)
}
return sent, files
}